location.vue 7.8 KB

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