location.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. },
  173. fail: () => {
  174. uni.showToast({
  175. title: "上传失败",
  176. icon: 'error'
  177. })
  178. }
  179. });
  180. }
  181. });
  182. },
  183. fail() {
  184. uni.showModal({
  185. title: '提示',
  186. content: '请先开启摄像头权限,否则将无法使用打卡功能',
  187. cancelText: '不授权',
  188. confirmText: '授权',
  189. success: function(res) {
  190. if (res.confirm) {
  191. uni.openSetting({
  192. success(res) {}
  193. })
  194. }
  195. }
  196. });
  197. }
  198. })
  199. },
  200. // 打卡请求
  201. async handleUploading(imgUrl) {
  202. let res = await this.$myRequest_clockIn({
  203. url: "/attendance/api/sign/check/in/update",
  204. method: "put",
  205. header: {
  206. 'Authorization': uni.getStorageSync("token"),
  207. 'platform': 2,
  208. 'Accept-Language': 'zh-CN,zh;q=0.9'
  209. },
  210. data: {
  211. id: this.id,
  212. lat: this.latitude,
  213. lng: this.longitude,
  214. location: this.address,
  215. sceneImage: imgUrl,
  216. }
  217. })
  218. // console.log(res);
  219. if (res.code == 200) {
  220. this.getNowTimePop()
  221. this.$refs.popup.open()
  222. }
  223. },
  224. getNowTimePop() {
  225. let date = new Date()
  226. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  227. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  228. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  229. this.nowTime_pop = hours + ':' + minutes + ':' + seconds
  230. },
  231. // 点击 我知道了按钮 跳回首页
  232. handleGoHome() {
  233. this.$refs.popup.close()
  234. uni.reLaunch({
  235. url: "/pagesClockIn/home/home"
  236. })
  237. },
  238. }
  239. }
  240. </script>
  241. <style lang="scss" scoped>
  242. .container {
  243. .map {
  244. position: relative;
  245. width: 100vw;
  246. height: 100vh;
  247. }
  248. .box {
  249. position: absolute;
  250. left: 30rpx;
  251. bottom: 30rpx;
  252. width: 690rpx;
  253. height: 387rpx;
  254. .top {
  255. display: flex;
  256. box-sizing: border-box;
  257. padding: 0 30rpx;
  258. width: 690rpx;
  259. height: 123rpx;
  260. border-radius: 14rpx 14rpx 0 0;
  261. background-color: #fff;
  262. .left {
  263. display: flex;
  264. flex-direction: column;
  265. justify-content: space-evenly;
  266. flex: 6;
  267. .left_title {
  268. font-size: 32rpx;
  269. }
  270. .left_place {
  271. font-size: 24rpx;
  272. font-weight: 200;
  273. color: #808080;
  274. }
  275. }
  276. .right {
  277. display: flex;
  278. justify-content: center;
  279. align-items: center;
  280. flex: 1;
  281. img {
  282. width: 42rpx;
  283. height: 42rpx;
  284. }
  285. }
  286. }
  287. .center {
  288. display: flex;
  289. box-sizing: border-box;
  290. padding: 0 30rpx;
  291. width: 690rpx;
  292. height: 122rpx;
  293. line-height: 122rpx;
  294. background-color: #fff;
  295. .center_left {
  296. flex: 6;
  297. font-size: 32rpx;
  298. }
  299. .center_right {
  300. flex: 1;
  301. display: flex;
  302. justify-content: center;
  303. align-items: center;
  304. img {
  305. width: 49rpx;
  306. height: 39rpx;
  307. }
  308. }
  309. }
  310. .bottom {
  311. display: flex;
  312. justify-content: center;
  313. align-items: center;
  314. box-sizing: border-box;
  315. padding: 0 30rpx;
  316. width: 690rpx;
  317. height: 140rpx;
  318. border-radius: 0 0 14rpx 14rpx;
  319. background-color: #fff;
  320. .button {
  321. width: 630rpx;
  322. height: 80rpx;
  323. line-height: 80rpx;
  324. border-radius: 16rpx;
  325. text-align: center;
  326. font-size: 32rpx;
  327. color: #fff;
  328. background: linear-gradient(180deg, #00ACFC 0%, #0082FC 100%);
  329. }
  330. }
  331. }
  332. .popup-content {
  333. display: flex;
  334. flex-direction: column;
  335. justify-content: space-around;
  336. align-items: center;
  337. width: 630rpx;
  338. height: 376rpx;
  339. border-radius: 33rpx;
  340. background-color: #fff;
  341. .title {
  342. display: flex;
  343. justify-content: center;
  344. align-items: center;
  345. .icon {
  346. width: 40rpx;
  347. height: 40rpx;
  348. img {
  349. width: 100%;
  350. height: 100%;
  351. }
  352. }
  353. .title_info {
  354. margin-left: 8rpx;
  355. font-size: 36rpx;
  356. font-weight: 800;
  357. color: #0082FC;
  358. }
  359. }
  360. .time {
  361. font-size: 32rpx;
  362. }
  363. .popup_button {
  364. width: 50%;
  365. text-align: center;
  366. font-size: 32rpx;
  367. color: #0082FC;
  368. }
  369. }
  370. }
  371. </style>