location.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <view class="container">
  3. <!-- 地图区域 -->
  4. <view class="map"><map style="width: 100%; height: 100%;" :latitude="latitude" :longitude="longitude" :scale="16" :markers="covers"></map></view>
  5. <!-- 盒子区域 -->
  6. <view class="box">
  7. <!-- 定位区域 -->
  8. <view class="top">
  9. <view class="left">
  10. <view class="left_title">我的位置</view>
  11. <view class="left_place">{{ address }}</view>
  12. </view>
  13. <view class="right" @click="handleRefresh"><img src="./imgs/refresh.png" /></view>
  14. </view>
  15. <!-- 拍照区域 -->
  16. <view class="center">
  17. <view class="center_left">拍摄场景照片(必填)</view>
  18. <view class="center_right" @click="handlePhoto"><img src="./imgs/photo.png" /></view>
  19. </view>
  20. <!-- 提示倒计时区域 -->
  21. <view class="bottom">
  22. <view class="button">请在{{ timeRange }}时间段之内提交打卡</view>
  23. </view>
  24. </view>
  25. <!-- 认证结果弹窗 -->
  26. <uni-popup ref="popup" :is-mask-click="false">
  27. <view class="popup-content">
  28. <view class="title">
  29. <view class="icon"><img src="./imgs/success2.png" /></view>
  30. <view class="title_info">打卡成功</view>
  31. </view>
  32. <view class="time">{{ nowTime_pop }}</view>
  33. <view class="popup_button" @click="handleGoHome">我知道了</view>
  34. </view>
  35. </uni-popup>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. // 定位经纬度
  43. latitude: null,
  44. longitude: null,
  45. // 地图标记点属性
  46. covers: [
  47. {
  48. id: 1,
  49. latitude: null,
  50. longitude: null,
  51. iconPath: '../../static/imgs/location.png',
  52. width: 30,
  53. height: 30
  54. }
  55. ],
  56. // 照片信息
  57. imgUrl: '',
  58. // 定位位置信息
  59. address: '',
  60. // 时间段信息
  61. timeRange: '',
  62. // 规则id
  63. id: '',
  64. // 是否需要人脸识别,值为1时是不需要
  65. flag: '',
  66. // 弹窗当前时间
  67. nowTime_pop: ''
  68. }
  69. },
  70. onLoad(options) {
  71. if (options.flag) {
  72. this.flag = options.flag
  73. }
  74. if (options.obj) {
  75. let obj = JSON.parse(options.obj)
  76. this.timeRange = obj.timeRange
  77. this.id = obj.id
  78. }
  79. this.getLocationData()
  80. },
  81. methods: {
  82. // 获取定位具体信息
  83. getLocationData() {
  84. // 获取经纬度
  85. uni.getLocation({
  86. type: 'gcj02',
  87. success: res => {
  88. const KEY = 'X57BZ-ZISE3-KTN3O-3P45H-C3J7Q-D5B67'
  89. let url = 'https://apis.map.qq.com/ws/geocoder/v1'
  90. let locationdata = res.latitude + ',' + res.longitude
  91. this.$jsonp(url, {
  92. key: KEY,
  93. output: 'jsonp',
  94. location: locationdata
  95. })
  96. .then(json => {
  97. // console.log(json)
  98. if (json.status == 0) {
  99. // 获取详细地址信息
  100. this.address = json.result.address
  101. // 获取地址经纬度
  102. this.latitude = json.result.location.lat
  103. this.longitude = json.result.location.lng
  104. // 获取标记点地址经纬度
  105. this.covers[0].latitude = json.result.location.lat
  106. this.covers[0].longitude = json.result.location.lng
  107. } else {
  108. uni.showToast({
  109. title: `${json.message},请求定位失败`,
  110. icon: 'none'
  111. })
  112. }
  113. })
  114. .catch(err => {
  115. console.log(err)
  116. })
  117. },
  118. fail: error => {
  119. uni.showModal({
  120. title: '提示',
  121. content: '请先开启定位权限,否则将无法使用定位功能',
  122. cancelText: '不授权',
  123. confirmText: '授权',
  124. success: function(res) {
  125. if (res.confirm) {
  126. uni.openSetting({
  127. success(res) {}
  128. })
  129. } else if (res.cancel) {
  130. uni.redirectTo({
  131. url: '/pages/index/index'
  132. })
  133. }
  134. }
  135. })
  136. }
  137. })
  138. },
  139. // 点击刷新按钮回调
  140. handleRefresh() {
  141. uni.showLoading({
  142. title: '刷新中',
  143. mask: true
  144. })
  145. this.getLocationData()
  146. setTimeout(() => {
  147. uni.hideLoading()
  148. }, 1500)
  149. },
  150. // 点击拍照图标回调
  151. handlePhoto() {
  152. // 选择图片
  153. uni.chooseImage({
  154. count: 1,
  155. sizeType: ['compressed'],
  156. sourceType: ['camera'],
  157. success: res => {
  158. // console.log(res);
  159. uni.showLoading({
  160. title: '上传中',
  161. mask: true
  162. })
  163. uni.uploadFile({
  164. url: `https://chtech.ncjti.edu.cn/campusclock/attendance/api/file/upload`,
  165. filePath: res.tempFilePaths[0],
  166. name: 'file',
  167. header: {
  168. platform: 2,
  169. 'Accept-Language': 'zh-CN,zh;q=0.9'
  170. },
  171. success: uploadFileRes => {
  172. let imgUrl = JSON.parse(uploadFileRes.data).data
  173. if (this.flag == 1) {
  174. this.handleUploading(imgUrl)
  175. } else {
  176. uni.redirectTo({
  177. url: `/pages/authentication/authentication?imgUrl=${imgUrl}&id=${this.id}&address=${this.address}&latitude=${this.latitude}&longitude=${
  178. this.longitude
  179. }`
  180. })
  181. }
  182. },
  183. fail: () => {
  184. uni.showToast({
  185. title: '上传失败',
  186. icon: 'error'
  187. })
  188. }
  189. })
  190. }
  191. })
  192. },
  193. // 打卡请求
  194. async handleUploading(imgUrl) {
  195. let res = await this.$myRequest_clockIn({
  196. url: '/attendance/api/sign/check/in/update',
  197. method: 'put',
  198. header: {
  199. 'content-type': 'application/json'
  200. },
  201. data: {
  202. id: this.id,
  203. lat: this.latitude,
  204. lng: this.longitude,
  205. location: this.address,
  206. sceneImage: imgUrl
  207. }
  208. })
  209. // console.log(res);
  210. if (res.code == 200) {
  211. this.getNowTimePop()
  212. this.$refs.popup.open()
  213. }
  214. },
  215. getNowTimePop() {
  216. let date = new Date()
  217. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  218. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  219. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  220. this.nowTime_pop = hours + ':' + minutes + ':' + seconds
  221. },
  222. // 点击 我知道了按钮 跳回首页
  223. handleGoHome() {
  224. this.$refs.popup.close()
  225. uni.reLaunch({
  226. url: '/pages/home/home'
  227. })
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss" scoped>
  233. .container {
  234. .map {
  235. position: relative;
  236. width: 100vw;
  237. height: 100vh;
  238. }
  239. .box {
  240. position: absolute;
  241. left: 30rpx;
  242. bottom: 30rpx;
  243. width: 690rpx;
  244. height: 387rpx;
  245. .top {
  246. display: flex;
  247. box-sizing: border-box;
  248. padding: 0 30rpx;
  249. width: 690rpx;
  250. height: 123rpx;
  251. border-radius: 14rpx 14rpx 0 0;
  252. background-color: #fff;
  253. .left {
  254. display: flex;
  255. flex-direction: column;
  256. justify-content: space-evenly;
  257. flex: 6;
  258. .left_title {
  259. font-size: 32rpx;
  260. }
  261. .left_place {
  262. font-size: 24rpx;
  263. font-weight: 200;
  264. color: #808080;
  265. }
  266. }
  267. .right {
  268. display: flex;
  269. justify-content: center;
  270. align-items: center;
  271. flex: 1;
  272. img {
  273. width: 42rpx;
  274. height: 42rpx;
  275. }
  276. }
  277. }
  278. .center {
  279. display: flex;
  280. box-sizing: border-box;
  281. padding: 0 30rpx;
  282. width: 690rpx;
  283. height: 122rpx;
  284. line-height: 122rpx;
  285. background-color: #fff;
  286. .center_left {
  287. flex: 6;
  288. font-size: 32rpx;
  289. }
  290. .center_right {
  291. flex: 1;
  292. display: flex;
  293. justify-content: center;
  294. align-items: center;
  295. img {
  296. width: 49rpx;
  297. height: 39rpx;
  298. }
  299. }
  300. }
  301. .bottom {
  302. display: flex;
  303. justify-content: center;
  304. align-items: center;
  305. box-sizing: border-box;
  306. padding: 0 30rpx;
  307. width: 690rpx;
  308. height: 140rpx;
  309. border-radius: 0 0 14rpx 14rpx;
  310. background-color: #fff;
  311. .button {
  312. width: 630rpx;
  313. height: 80rpx;
  314. line-height: 80rpx;
  315. border-radius: 16rpx;
  316. text-align: center;
  317. font-size: 32rpx;
  318. color: #fff;
  319. background: linear-gradient(180deg, #00acfc 0%, #0082fc 100%);
  320. }
  321. }
  322. }
  323. .popup-content {
  324. display: flex;
  325. flex-direction: column;
  326. justify-content: space-around;
  327. align-items: center;
  328. width: 630rpx;
  329. height: 376rpx;
  330. border-radius: 33rpx;
  331. background-color: #fff;
  332. .title {
  333. display: flex;
  334. justify-content: center;
  335. align-items: center;
  336. .icon {
  337. width: 40rpx;
  338. height: 40rpx;
  339. img {
  340. width: 100%;
  341. height: 100%;
  342. }
  343. }
  344. .title_info {
  345. margin-left: 8rpx;
  346. font-size: 36rpx;
  347. font-weight: 800;
  348. color: #0082fc;
  349. }
  350. }
  351. .time {
  352. font-size: 32rpx;
  353. }
  354. .popup_button {
  355. width: 50%;
  356. text-align: center;
  357. font-size: 32rpx;
  358. color: #0082fc;
  359. }
  360. }
  361. }
  362. </style>