location.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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.authorize({
  154. // scope: 'scope.camera',
  155. // success: () => {
  156. // uni.chooseImage({
  157. // count: 1,
  158. // sourceType: ['camera'],
  159. // success: res => {
  160. // // console.log(res);
  161. // uni.uploadFile({
  162. // url: `https://chtech.ncjti.edu.cn/campusclock/attendance/api/file/upload`,
  163. // filePath: res.tempFilePaths[0],
  164. // name: 'file',
  165. // header: {
  166. // platform: 2,
  167. // 'Accept-Language': 'zh-CN,zh;q=0.9'
  168. // },
  169. // success: uploadFileRes => {
  170. // let imgUrl = JSON.parse(uploadFileRes.data).data
  171. // // if (this.flag == 1) {
  172. // // this.handleUploading(imgUrl)
  173. // // } else {
  174. // // uni.redirectTo({
  175. // // url: `/pages/authentication/authentication?imgUrl=${imgUrl}&id=${this.id}&address=${this.address}&latitude=${this.latitude}&longitude=${this.longitude}`
  176. // // })
  177. // // }
  178. // this.handleUploading(imgUrl)
  179. // },
  180. // fail: () => {
  181. // uni.showToast({
  182. // title: '上传失败',
  183. // icon: 'error'
  184. // })
  185. // }
  186. // })
  187. // }
  188. // })
  189. // },
  190. // fail() {
  191. // uni.showModal({
  192. // title: '提示',
  193. // content: '请先开启摄像头权限,否则将无法使用打卡功能',
  194. // cancelText: '不授权',
  195. // confirmText: '授权',
  196. // success: function(res) {
  197. // if (res.confirm) {
  198. // uni.openSetting({
  199. // success(res) {}
  200. // })
  201. // }
  202. // }
  203. // })
  204. // }
  205. // })
  206. // },
  207. handlePhoto() {
  208. // 选择图片
  209. uni.chooseImage({
  210. count: 1,
  211. sourceType: ['camera'],
  212. success: res => {
  213. // console.log(res);
  214. uni.uploadFile({
  215. url: `https://chtech.ncjti.edu.cn/campusclock/attendance/api/file/upload`,
  216. filePath: res.tempFilePaths[0],
  217. name: 'file',
  218. header: {
  219. platform: 2,
  220. 'Accept-Language': 'zh-CN,zh;q=0.9'
  221. },
  222. success: uploadFileRes => {
  223. let imgUrl = JSON.parse(uploadFileRes.data).data
  224. if (this.flag == 1) {
  225. this.handleUploading(imgUrl)
  226. } else {
  227. uni.redirectTo({
  228. url: `/pages/authentication/authentication?imgUrl=${imgUrl}&id=${this.id}&address=${this.address}&latitude=${this.latitude}&longitude=${
  229. this.longitude
  230. }`
  231. })
  232. }
  233. // this.handleUploading(imgUrl)
  234. },
  235. fail: () => {
  236. uni.showToast({
  237. title: '上传失败',
  238. icon: 'error'
  239. })
  240. }
  241. })
  242. }
  243. })
  244. },
  245. // 打卡请求
  246. async handleUploading(imgUrl) {
  247. let res = await this.$myRequest_clockIn({
  248. url: '/attendance/api/sign/check/in/update',
  249. method: 'put',
  250. header: {
  251. 'content-type': 'application/json'
  252. },
  253. data: {
  254. id: this.id,
  255. lat: this.latitude,
  256. lng: this.longitude,
  257. location: this.address,
  258. sceneImage: imgUrl
  259. }
  260. })
  261. // console.log(res);
  262. if (res.code == 200) {
  263. this.getNowTimePop()
  264. this.$refs.popup.open()
  265. }
  266. },
  267. getNowTimePop() {
  268. let date = new Date()
  269. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  270. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  271. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  272. this.nowTime_pop = hours + ':' + minutes + ':' + seconds
  273. },
  274. // 点击 我知道了按钮 跳回首页
  275. handleGoHome() {
  276. this.$refs.popup.close()
  277. uni.reLaunch({
  278. url: '/pages/home/home'
  279. })
  280. }
  281. }
  282. }
  283. </script>
  284. <style lang="scss" scoped>
  285. .container {
  286. .map {
  287. position: relative;
  288. width: 100vw;
  289. height: 100vh;
  290. }
  291. .box {
  292. position: absolute;
  293. left: 30rpx;
  294. bottom: 30rpx;
  295. width: 690rpx;
  296. height: 387rpx;
  297. .top {
  298. display: flex;
  299. box-sizing: border-box;
  300. padding: 0 30rpx;
  301. width: 690rpx;
  302. height: 123rpx;
  303. border-radius: 14rpx 14rpx 0 0;
  304. background-color: #fff;
  305. .left {
  306. display: flex;
  307. flex-direction: column;
  308. justify-content: space-evenly;
  309. flex: 6;
  310. .left_title {
  311. font-size: 32rpx;
  312. }
  313. .left_place {
  314. font-size: 24rpx;
  315. font-weight: 200;
  316. color: #808080;
  317. }
  318. }
  319. .right {
  320. display: flex;
  321. justify-content: center;
  322. align-items: center;
  323. flex: 1;
  324. img {
  325. width: 42rpx;
  326. height: 42rpx;
  327. }
  328. }
  329. }
  330. .center {
  331. display: flex;
  332. box-sizing: border-box;
  333. padding: 0 30rpx;
  334. width: 690rpx;
  335. height: 122rpx;
  336. line-height: 122rpx;
  337. background-color: #fff;
  338. .center_left {
  339. flex: 6;
  340. font-size: 32rpx;
  341. }
  342. .center_right {
  343. flex: 1;
  344. display: flex;
  345. justify-content: center;
  346. align-items: center;
  347. img {
  348. width: 49rpx;
  349. height: 39rpx;
  350. }
  351. }
  352. }
  353. .bottom {
  354. display: flex;
  355. justify-content: center;
  356. align-items: center;
  357. box-sizing: border-box;
  358. padding: 0 30rpx;
  359. width: 690rpx;
  360. height: 140rpx;
  361. border-radius: 0 0 14rpx 14rpx;
  362. background-color: #fff;
  363. .button {
  364. width: 630rpx;
  365. height: 80rpx;
  366. line-height: 80rpx;
  367. border-radius: 16rpx;
  368. text-align: center;
  369. font-size: 32rpx;
  370. color: #fff;
  371. background: linear-gradient(180deg, #00acfc 0%, #0082fc 100%);
  372. }
  373. }
  374. }
  375. .popup-content {
  376. display: flex;
  377. flex-direction: column;
  378. justify-content: space-around;
  379. align-items: center;
  380. width: 630rpx;
  381. height: 376rpx;
  382. border-radius: 33rpx;
  383. background-color: #fff;
  384. .title {
  385. display: flex;
  386. justify-content: center;
  387. align-items: center;
  388. .icon {
  389. width: 40rpx;
  390. height: 40rpx;
  391. img {
  392. width: 100%;
  393. height: 100%;
  394. }
  395. }
  396. .title_info {
  397. margin-left: 8rpx;
  398. font-size: 36rpx;
  399. font-weight: 800;
  400. color: #0082fc;
  401. }
  402. }
  403. .time {
  404. font-size: 32rpx;
  405. }
  406. .popup_button {
  407. width: 50%;
  408. text-align: center;
  409. font-size: 32rpx;
  410. color: #0082fc;
  411. }
  412. }
  413. }
  414. </style>