location.vue 8.2 KB

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