location.vue 5.4 KB

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