location.vue 8.3 KB

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