location.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. </view>
  42. </template>
  43. <script>
  44. var QQMapWX = require('../util/qqmap-wx-jssdk1.1/qqmap-wx-jssdk');
  45. var qqmapsdk;
  46. export default {
  47. data() {
  48. return {
  49. // 定位经纬度
  50. latitude: null,
  51. longitude: null,
  52. // 地图标记点属性
  53. covers: [{
  54. id: 1,
  55. latitude: null,
  56. longitude: null,
  57. iconPath: '../static/imgs/location.png',
  58. width: 20,
  59. height: 20
  60. }],
  61. // 照片信息
  62. imgUrl: "",
  63. // 定位位置信息
  64. address: "",
  65. // 时间段信息
  66. timeRange: "",
  67. // 规则id
  68. id: ""
  69. };
  70. },
  71. onLoad(options) {
  72. let obj = JSON.parse(options.obj)
  73. this.timeRange = obj.timeRange
  74. this.id = obj.id
  75. // 实例化API核心类
  76. qqmapsdk = new QQMapWX({
  77. // 申请的key
  78. key: 'R43BZ-2XROX-L7T45-T5OQI-IBDFT-GNBOI'
  79. });
  80. this.getLocationData()
  81. },
  82. methods: {
  83. // 获取定位具体信息
  84. getLocationData() {
  85. qqmapsdk.reverseGeocoder({
  86. success: (res) => {
  87. // console.log(res);
  88. if (res.status == 0) {
  89. // 获取详细地址信息
  90. this.address = res.result.address
  91. // 获取地址经纬度
  92. this.latitude = res.result.location.lat
  93. this.longitude = res.result.location.lng
  94. // 获取标记点地址经纬度
  95. this.covers[0].latitude = res.result.location.lat
  96. this.covers[0].longitude = res.result.location.lng
  97. } else {
  98. uni.showToast({
  99. title: "请求定位失败",
  100. icon: 'none'
  101. })
  102. }
  103. }
  104. })
  105. },
  106. // 点击刷新按钮回调
  107. handleRefresh() {
  108. uni.showLoading({
  109. title: '刷新中',
  110. mask: true
  111. });
  112. this.getLocationData()
  113. setTimeout(() => {
  114. uni.hideLoading();
  115. }, 1500)
  116. },
  117. // 点击拍照图标回调
  118. handlePhoto() {
  119. // 获取用户摄像头权限
  120. uni.authorize({
  121. scope: 'scope.camera',
  122. success: () => {
  123. uni.chooseImage({
  124. count: 1,
  125. sourceType: ['camera'],
  126. success: (res) => {
  127. // console.log(res);
  128. uni.uploadFile({
  129. url: `https://www.web-server.top/attendance/api/file/upload`,
  130. filePath: res.tempFilePaths[0],
  131. name: 'file',
  132. success: (uploadFileRes) => {
  133. let imgUrl = JSON.parse(uploadFileRes.data)
  134. .data
  135. uni.navigateTo({
  136. url: `/pagesClockIn/authentication/authentication?imgUrl=${imgUrl}&id=${this.id}&address=${this.address}&latitude=${this.latitude}&longitude=${this.longitude}`
  137. })
  138. },
  139. fail: () => {
  140. uni.showToast({
  141. title: "上传失败",
  142. icon: 'error'
  143. })
  144. }
  145. });
  146. }
  147. });
  148. },
  149. fail() {
  150. uni.showModal({
  151. title: '提示',
  152. content: '请先开启摄像头权限,否则将无法使用打卡功能',
  153. cancelText: '不授权',
  154. confirmText: '授权',
  155. success: function(res) {
  156. if (res.confirm) {
  157. uni.openSetting({
  158. success(res) {}
  159. })
  160. }
  161. }
  162. });
  163. }
  164. })
  165. },
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .container {
  171. .map {
  172. position: relative;
  173. width: 100vw;
  174. height: 100vh;
  175. }
  176. .box {
  177. position: absolute;
  178. left: 30rpx;
  179. bottom: 30rpx;
  180. width: 690rpx;
  181. height: 387rpx;
  182. .top {
  183. display: flex;
  184. box-sizing: border-box;
  185. padding: 0 30rpx;
  186. width: 690rpx;
  187. height: 123rpx;
  188. border-radius: 14rpx 14rpx 0 0;
  189. background-color: #fff;
  190. .left {
  191. display: flex;
  192. flex-direction: column;
  193. justify-content: space-evenly;
  194. flex: 6;
  195. .left_title {
  196. font-size: 32rpx;
  197. }
  198. .left_place {
  199. font-size: 24rpx;
  200. font-weight: 200;
  201. color: #808080;
  202. }
  203. }
  204. .right {
  205. display: flex;
  206. justify-content: center;
  207. align-items: center;
  208. flex: 1;
  209. img {
  210. width: 42rpx;
  211. height: 42rpx;
  212. }
  213. }
  214. }
  215. .center {
  216. display: flex;
  217. box-sizing: border-box;
  218. padding: 0 30rpx;
  219. width: 690rpx;
  220. height: 122rpx;
  221. line-height: 122rpx;
  222. background-color: #fff;
  223. .center_left {
  224. flex: 6;
  225. font-size: 32rpx;
  226. }
  227. .center_right {
  228. flex: 1;
  229. display: flex;
  230. justify-content: center;
  231. align-items: center;
  232. img {
  233. width: 49rpx;
  234. height: 39rpx;
  235. }
  236. }
  237. }
  238. .bottom {
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. box-sizing: border-box;
  243. padding: 0 30rpx;
  244. width: 690rpx;
  245. height: 140rpx;
  246. border-radius: 0 0 14rpx 14rpx;
  247. background-color: #fff;
  248. .button {
  249. width: 630rpx;
  250. height: 80rpx;
  251. line-height: 80rpx;
  252. border-radius: 16rpx;
  253. text-align: center;
  254. font-size: 32rpx;
  255. color: #fff;
  256. background: linear-gradient(180deg, #00ACFC 0%, #0082FC 100%);
  257. }
  258. }
  259. }
  260. }
  261. </style>