location.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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.showToast({
  103. title: '请求定位失败',
  104. icon: 'none'
  105. })
  106. }
  107. }
  108. })
  109. },
  110. // 点击刷新按钮回调
  111. handleRefresh() {
  112. uni.showLoading({
  113. title: '刷新中',
  114. mask: true
  115. })
  116. this.getLocationData()
  117. setTimeout(() => {
  118. uni.hideLoading()
  119. }, 1500)
  120. },
  121. // 点击拍照图标回调
  122. handlePhoto() {
  123. // 获取用户摄像头权限
  124. uni.authorize({
  125. scope: 'scope.camera',
  126. success: () => {
  127. uni.chooseImage({
  128. count: 1,
  129. sizeType: ['compressed'],
  130. sourceType: ['camera'],
  131. success: res => {
  132. // console.log(res);
  133. uni.showLoading({
  134. title: '上传中,请稍后',
  135. mask: true
  136. })
  137. uni.uploadFile({
  138. url: `https://chtech.ncjti.edu.cn/campusclock/attendance/api/file/upload`,
  139. filePath: res.tempFilePaths[0],
  140. name: 'file',
  141. header: {
  142. platform: 2,
  143. 'Accept-Language': 'zh-CN,zh;q=0.9'
  144. },
  145. success: uploadFileRes => {
  146. let imgUrl = JSON.parse(uploadFileRes.data).data
  147. if (this.flag == 1) {
  148. this.handleUploading(imgUrl)
  149. } else {
  150. uni.redirectTo({
  151. url: `/pagesClockIn/authentication/authentication?imgUrl=${imgUrl}&id=${this.id}&address=${this.address}&latitude=${
  152. this.latitude
  153. }&longitude=${this.longitude}`
  154. })
  155. }
  156. // this.handleUploading(imgUrl)
  157. },
  158. fail: () => {
  159. uni.showToast({
  160. title: '上传失败',
  161. icon: 'error'
  162. })
  163. }
  164. })
  165. }
  166. })
  167. },
  168. fail() {
  169. uni.showModal({
  170. title: '提示',
  171. content: '请先开启摄像头权限,否则将无法使用打卡功能',
  172. cancelText: '不授权',
  173. confirmText: '授权',
  174. success: function(res) {
  175. if (res.confirm) {
  176. uni.openSetting({
  177. success(res) {}
  178. })
  179. }
  180. }
  181. })
  182. }
  183. })
  184. },
  185. // 打卡请求
  186. async handleUploading(imgUrl) {
  187. let res = await this.$myRequest_clockIn({
  188. url: '/attendance/api/sign/check/in/update',
  189. method: 'put',
  190. header: {
  191. Authorization: uni.getStorageSync('token'),
  192. platform: 2,
  193. 'Accept-Language': 'zh-CN,zh;q=0.9'
  194. },
  195. data: {
  196. id: this.id,
  197. lat: this.latitude,
  198. lng: this.longitude,
  199. location: this.address,
  200. sceneImage: imgUrl
  201. }
  202. })
  203. // console.log(res);
  204. if (res.code == 200) {
  205. this.getNowTimePop()
  206. this.$refs.popup.open()
  207. }
  208. },
  209. getNowTimePop() {
  210. let date = new Date()
  211. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  212. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  213. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  214. this.nowTime_pop = hours + ':' + minutes + ':' + seconds
  215. },
  216. // 点击 我知道了按钮 跳回首页
  217. handleGoHome() {
  218. this.$refs.popup.close()
  219. uni.reLaunch({
  220. url: '/pagesClockIn/home/home'
  221. })
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .container {
  228. .map {
  229. position: relative;
  230. width: 100vw;
  231. height: 100vh;
  232. }
  233. .box {
  234. position: absolute;
  235. left: 30rpx;
  236. bottom: 30rpx;
  237. width: 690rpx;
  238. height: 387rpx;
  239. .top {
  240. display: flex;
  241. box-sizing: border-box;
  242. padding: 0 30rpx;
  243. width: 690rpx;
  244. height: 123rpx;
  245. border-radius: 14rpx 14rpx 0 0;
  246. background-color: #fff;
  247. .left {
  248. display: flex;
  249. flex-direction: column;
  250. justify-content: space-evenly;
  251. flex: 6;
  252. .left_title {
  253. font-size: 32rpx;
  254. }
  255. .left_place {
  256. font-size: 24rpx;
  257. font-weight: 200;
  258. color: #808080;
  259. }
  260. }
  261. .right {
  262. display: flex;
  263. justify-content: center;
  264. align-items: center;
  265. flex: 1;
  266. img {
  267. width: 42rpx;
  268. height: 42rpx;
  269. }
  270. }
  271. }
  272. .center {
  273. display: flex;
  274. box-sizing: border-box;
  275. padding: 0 30rpx;
  276. width: 690rpx;
  277. height: 122rpx;
  278. line-height: 122rpx;
  279. background-color: #fff;
  280. .center_left {
  281. flex: 6;
  282. font-size: 32rpx;
  283. }
  284. .center_right {
  285. flex: 1;
  286. display: flex;
  287. justify-content: center;
  288. align-items: center;
  289. img {
  290. width: 49rpx;
  291. height: 39rpx;
  292. }
  293. }
  294. }
  295. .bottom {
  296. display: flex;
  297. justify-content: center;
  298. align-items: center;
  299. box-sizing: border-box;
  300. padding: 0 30rpx;
  301. width: 690rpx;
  302. height: 140rpx;
  303. border-radius: 0 0 14rpx 14rpx;
  304. background-color: #fff;
  305. .button {
  306. width: 630rpx;
  307. height: 80rpx;
  308. line-height: 80rpx;
  309. border-radius: 16rpx;
  310. text-align: center;
  311. font-size: 32rpx;
  312. color: #fff;
  313. background: linear-gradient(180deg, #00acfc 0%, #0082fc 100%);
  314. }
  315. }
  316. }
  317. .popup-content {
  318. display: flex;
  319. flex-direction: column;
  320. justify-content: space-around;
  321. align-items: center;
  322. width: 630rpx;
  323. height: 376rpx;
  324. border-radius: 33rpx;
  325. background-color: #fff;
  326. .title {
  327. display: flex;
  328. justify-content: center;
  329. align-items: center;
  330. .icon {
  331. width: 40rpx;
  332. height: 40rpx;
  333. img {
  334. width: 100%;
  335. height: 100%;
  336. }
  337. }
  338. .title_info {
  339. margin-left: 8rpx;
  340. font-size: 36rpx;
  341. font-weight: 800;
  342. color: #0082fc;
  343. }
  344. }
  345. .time {
  346. font-size: 32rpx;
  347. }
  348. .popup_button {
  349. width: 50%;
  350. text-align: center;
  351. font-size: 32rpx;
  352. color: #0082fc;
  353. }
  354. }
  355. }
  356. </style>