location.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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" :circles="circles">
  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. 南昌交通学院食堂
  19. </view>
  20. </view>
  21. <view class="right">
  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. 15:05:05 打卡(15分钟内提交打卡)
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. latitude: null,
  48. longitude: null,
  49. covers: [{
  50. id: 1,
  51. latitude: null,
  52. longitude: null,
  53. iconPath: '../../static/location.png',
  54. width: 20,
  55. height: 20
  56. }],
  57. circles: [{
  58. longitude: null,
  59. latitude: null,
  60. fillColor: "#FF2B431A",
  61. color: "#FF0000",
  62. radius: 100,
  63. strokeWidth: 1
  64. }],
  65. imgUrl: ""
  66. };
  67. },
  68. onLoad() {
  69. this.getLocationData()
  70. this.test()
  71. },
  72. methods: {
  73. getLocationData() {
  74. uni.getLocation({
  75. type: 'gcj02',
  76. success: (res) => {
  77. console.log(res);
  78. this.latitude = res.latitude
  79. this.longitude = res.longitude
  80. this.covers[0].latitude = res.latitude
  81. this.covers[0].longitude = res.longitude
  82. this.circles[0].latitude = res.latitude
  83. this.circles[0].longitude = res.longitude
  84. console.log('当前位置的经度:' + res.longitude);
  85. console.log('当前位置的纬度:' + res.latitude);
  86. }
  87. });
  88. },
  89. test() {
  90. console.log(789);
  91. uni.chooseLocation({
  92. success: (res) => {
  93. console.log('位置名称:' + res.name);
  94. console.log('详细地址:' + res.address);
  95. console.log('纬度:' + res.latitude);
  96. console.log('经度:' + res.longitude);
  97. }
  98. });
  99. },
  100. // 点击拍照图标回调
  101. handlePhoto() {
  102. // 获取用户摄像头权限
  103. uni.authorize({
  104. scope: 'scope.camera',
  105. success() {
  106. // uni.navigateTo({
  107. // url: "/pages/location/location"
  108. // })
  109. uni.chooseImage({
  110. count: 1,
  111. sourceType: ['camera'],
  112. success: (res) => {
  113. console.log(res);
  114. console.log(res.tempFilePaths[0]);
  115. console.log(JSON.stringify(res.tempFilePaths));
  116. // this.imgUrl = JSON.stringify(res.tempFilePaths)
  117. // console.log(this.imgUrl);
  118. uni.navigateTo({
  119. url: "/pages/authentication/authentication"
  120. })
  121. }
  122. });
  123. },
  124. fail() {
  125. uni.showModal({
  126. title: '提示',
  127. content: '请先开启摄像头权限,否则将无法使用打卡功能',
  128. cancelText: '不授权',
  129. confirmText: '授权',
  130. success: function(res) {
  131. if (res.confirm) {
  132. uni.openSetting({
  133. success(res) {}
  134. })
  135. } else if (res.cancel) {}
  136. }
  137. });
  138. }
  139. })
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .container {
  146. .map {
  147. position: relative;
  148. width: 100vw;
  149. height: 100vh;
  150. }
  151. .box {
  152. position: absolute;
  153. left: 30rpx;
  154. bottom: 30rpx;
  155. width: 690rpx;
  156. height: 387rpx;
  157. .top {
  158. display: flex;
  159. box-sizing: border-box;
  160. padding: 0 30rpx;
  161. width: 690rpx;
  162. height: 123rpx;
  163. border-radius: 14rpx 14rpx 0 0;
  164. background-color: #fff;
  165. .left {
  166. display: flex;
  167. flex-direction: column;
  168. justify-content: space-evenly;
  169. flex: 6;
  170. .left_title {
  171. font-size: 32rpx;
  172. }
  173. .left_place {
  174. font-size: 24rpx;
  175. font-weight: 200;
  176. color: #808080;
  177. }
  178. }
  179. .right {
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. flex: 1;
  184. img {
  185. width: 42rpx;
  186. height: 42rpx;
  187. }
  188. }
  189. }
  190. .center {
  191. display: flex;
  192. box-sizing: border-box;
  193. padding: 0 30rpx;
  194. width: 690rpx;
  195. height: 122rpx;
  196. line-height: 122rpx;
  197. background-color: #fff;
  198. .center_left {
  199. flex: 6;
  200. font-size: 32rpx;
  201. }
  202. .center_right {
  203. flex: 1;
  204. display: flex;
  205. justify-content: center;
  206. align-items: center;
  207. img {
  208. width: 49rpx;
  209. height: 39rpx;
  210. }
  211. }
  212. }
  213. .bottom {
  214. display: flex;
  215. justify-content: center;
  216. align-items: center;
  217. box-sizing: border-box;
  218. padding: 0 30rpx;
  219. width: 690rpx;
  220. height: 140rpx;
  221. border-radius: 0 0 14rpx 14rpx;
  222. background-color: #fff;
  223. .button {
  224. width: 630rpx;
  225. height: 80rpx;
  226. line-height: 80rpx;
  227. border-radius: 16rpx;
  228. text-align: center;
  229. font-size: 32rpx;
  230. color: #fff;
  231. background: linear-gradient(180deg, #00ACFC 0%, #0082FC 100%);
  232. }
  233. }
  234. }
  235. }
  236. </style>