location.vue 7.5 KB

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