location.vue 5.2 KB

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