location.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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/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. let imgUrl = res.tempFilePaths[0]
  129. uni.navigateTo({
  130. url: `/pages/authentication/authentication?imgUrl=${imgUrl}&id=${this.id}&address=${this.address}&latitude=${this.latitude}&longitude=${this.longitude}`
  131. })
  132. }
  133. });
  134. },
  135. fail() {
  136. uni.showModal({
  137. title: '提示',
  138. content: '请先开启摄像头权限,否则将无法使用打卡功能',
  139. cancelText: '不授权',
  140. confirmText: '授权',
  141. success: function(res) {
  142. if (res.confirm) {
  143. uni.openSetting({
  144. success(res) {}
  145. })
  146. }
  147. }
  148. });
  149. }
  150. })
  151. },
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .container {
  157. .map {
  158. position: relative;
  159. width: 100vw;
  160. height: 100vh;
  161. }
  162. .box {
  163. position: absolute;
  164. left: 30rpx;
  165. bottom: 30rpx;
  166. width: 690rpx;
  167. height: 387rpx;
  168. .top {
  169. display: flex;
  170. box-sizing: border-box;
  171. padding: 0 30rpx;
  172. width: 690rpx;
  173. height: 123rpx;
  174. border-radius: 14rpx 14rpx 0 0;
  175. background-color: #fff;
  176. .left {
  177. display: flex;
  178. flex-direction: column;
  179. justify-content: space-evenly;
  180. flex: 6;
  181. .left_title {
  182. font-size: 32rpx;
  183. }
  184. .left_place {
  185. font-size: 24rpx;
  186. font-weight: 200;
  187. color: #808080;
  188. }
  189. }
  190. .right {
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. flex: 1;
  195. img {
  196. width: 42rpx;
  197. height: 42rpx;
  198. }
  199. }
  200. }
  201. .center {
  202. display: flex;
  203. box-sizing: border-box;
  204. padding: 0 30rpx;
  205. width: 690rpx;
  206. height: 122rpx;
  207. line-height: 122rpx;
  208. background-color: #fff;
  209. .center_left {
  210. flex: 6;
  211. font-size: 32rpx;
  212. }
  213. .center_right {
  214. flex: 1;
  215. display: flex;
  216. justify-content: center;
  217. align-items: center;
  218. img {
  219. width: 49rpx;
  220. height: 39rpx;
  221. }
  222. }
  223. }
  224. .bottom {
  225. display: flex;
  226. justify-content: center;
  227. align-items: center;
  228. box-sizing: border-box;
  229. padding: 0 30rpx;
  230. width: 690rpx;
  231. height: 140rpx;
  232. border-radius: 0 0 14rpx 14rpx;
  233. background-color: #fff;
  234. .button {
  235. width: 630rpx;
  236. height: 80rpx;
  237. line-height: 80rpx;
  238. border-radius: 16rpx;
  239. text-align: center;
  240. font-size: 32rpx;
  241. color: #fff;
  242. background: linear-gradient(180deg, #00ACFC 0%, #0082FC 100%);
  243. }
  244. }
  245. }
  246. }
  247. </style>