index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="qiandao">
  3. <view class="top-box">
  4. <view class="flex justify-between align-center">
  5. <view style="font-weight: bold;font-size: 32rpx;color: #222222;">当前位置</view>
  6. <view style="color: #1EDA94;font-size: 28rpx;" @click="gxAddress">更新位置</view>
  7. </view>
  8. <view style="font-size: 28rpx;color: #AAAAAA;margin-top: 20rpx;">{{address}}</view>
  9. <view style="width: 100%;height: 1rpx;background: #E6E6E6;margin-top: 30rpx;"></view>
  10. <view class="flex align-center justify-between margin-top">
  11. <view style="color: #1EDA94;font-size: 28rpx;" @click="openMap">手动设置</view>
  12. <view class="btn" @tap="openSave" v-if="address">签到</view>
  13. <view class="btn" @tap="openMap" v-if="!address">选择地址</view>
  14. </view>
  15. </view>
  16. <view class=" margin-top">
  17. <view class="text-lg text-bold">服务区域(半径1km)</view>
  18. <view style="position: fixed;left: 0;bottom: 0;width: 750rpx;">
  19. <map style="width: 100%; height: 86vh;" :latitude="latitude" :longitude="longitude" :markers="covers">
  20. </map>
  21. </view>
  22. </view>
  23. <view class="range-box">
  24. <image class="icon" src="/static/images/index/map.png" mode=""></image>
  25. <view class="text">
  26. 服务区域(半径1km)
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. latitude: '',
  36. longitude: '',
  37. address: '',
  38. covers: [{
  39. latitude: '',
  40. longitude: '',
  41. iconPath: '../../static/images/address.png'
  42. }]
  43. }
  44. },
  45. onLoad() {
  46. let that = this
  47. uni.getLocation({
  48. type: 'gcj02',
  49. geocode: true, //设置该参数为true可直接获取经纬度及城市信息
  50. success: function(res) {
  51. console.log('当前位置的经度:' + res.longitude);
  52. console.log('当前位置的纬度:' + res.latitude);
  53. console.log('当前位置的位置:' + JSON.stringify(res));
  54. uni.setStorageSync('longitude', res.longitude);
  55. uni.setStorageSync('latitude', res.latitude);
  56. that.latitude = res.latitude
  57. that.longitude = res.longitude
  58. }
  59. });
  60. },
  61. onShow() {
  62. this.checkOpenGPSServiceByAndroid();
  63. },
  64. methods: {
  65. //判断用户是否开启定位-暂时不用
  66. checkOpenGPSServiceByAndroid() {
  67. let that = this
  68. // 1、判断手机定位服务【GPS】 是否授权
  69. uni.getSystemInfo({
  70. success(res) {
  71. // console.log(res)
  72. let locationEnabled = res.locationEnabled; //判断手机定位服务是否开启
  73. let locationAuthorized = res.locationAuthorized; //判断定位服务是否允许微信授权
  74. if (locationEnabled == false || locationAuthorized == false) {
  75. //手机定位服务(GPS)未授权
  76. uni.showModal({
  77. title: '提示',
  78. content: '当前未开启定位权限,请允许使用位置信息后再来操作吧!',
  79. showCancel: false, // 不显示取消按钮
  80. success() {
  81. uni.navigateBack({
  82. delta: 1, //返回层数,2则上上页
  83. })
  84. }
  85. })
  86. } else {
  87. //手机定位服务(GPS)已授权
  88. if (res.hostName == 'WeChat') {
  89. //2、判断微信小程序是否授权位置信息
  90. uni.getSetting({
  91. success(res) {
  92. let scopeUserLocation = res.authSetting["scope.userLocation"];
  93. if (scopeUserLocation) {
  94. // 微信小程序已授权位置信息
  95. } else {
  96. // 微信小程序未授权位置信息
  97. uni.showModal({
  98. title: '提示',
  99. content: '当前未开启定位权限,请在小程序设置中允许使用位置信息后再来操作吧!',
  100. showCancel: false, // 不显示取消按钮
  101. success() {
  102. uni.navigateBack({
  103. delta: 1, //返回层数,2则上上页
  104. })
  105. }
  106. })
  107. }
  108. },
  109. fail() {
  110. // 微信小程序未授权位置信息
  111. uni.showModal({
  112. title: '提示',
  113. content: '当前未开启定位权限,请在小程序设置中允许使用位置信息后再来操作吧!',
  114. showCancel: false, // 不显示取消按钮
  115. success() {
  116. uni.navigateBack({
  117. delta: 1, //返回层数,2则上上页
  118. })
  119. }
  120. })
  121. }
  122. });
  123. } else {
  124. }
  125. }
  126. },
  127. fail() {
  128. // 手机定位服务(GPS)未授权
  129. uni.showModal({
  130. title: '提示',
  131. content: '获取位置信息失败',
  132. showCancel: false, // 不显示取消按钮
  133. success() {
  134. uni.navigateBack({
  135. delta: 1, //返回层数,2则上上页
  136. })
  137. }
  138. })
  139. }
  140. });
  141. },
  142. gxAddress() {
  143. let that = this;
  144. if (!that.latitude || !that.longitude) {
  145. that.$queue.showToast("请在设置中打开定位权限后刷新小程序再来更新吧!")
  146. return;
  147. }
  148. let longitude = uni.getStorageSync('longitude');
  149. let latitude = uni.getStorageSync('latitude');
  150. let userId = uni.getStorageSync('userId')
  151. this.$queue.showLoading('更新中...')
  152. let data = {
  153. typeId: longitude,
  154. typeName: latitude,
  155. userId: userId
  156. }
  157. that.$Request.postJson('/app/message/insertArtificerLocation', data).then(
  158. res => {
  159. uni.hideLoading();
  160. if (res.code === 0) {
  161. that.$queue.showToast('更新成功!');
  162. }
  163. });
  164. },
  165. openSave() {
  166. this.$queue.showLoading('签到中...')
  167. if (!this.address) {
  168. uni.hideLoading();
  169. this.openMap();
  170. // this.$queue.showToast('请选择地址信息后进行签到!')
  171. return;
  172. }
  173. if (!this.latitude || !this.longitude) {
  174. this.$queue.showToast("请在设置中打开定位权限后刷新小程序再来更新吧!")
  175. return;
  176. }
  177. let data = {
  178. longitude: this.longitude,
  179. latitude: this.latitude,
  180. address: this.address,
  181. city: ''
  182. }
  183. this.$Request.postT('/app/artificer/signIn', data).then(res => {
  184. uni.hideLoading();
  185. if (res.code == 0) {
  186. this.$queue.showToast('签到成功!')
  187. setTimeout(d => {
  188. uni.navigateBack();
  189. }, 1000)
  190. } else {
  191. this.$queue.showToast(res.msg)
  192. }
  193. });
  194. },
  195. openMap() {
  196. let that = this
  197. uni.chooseLocation({
  198. success: function(res) {
  199. console.log('位置名称:' + res.name);
  200. console.log('详细地址:' + res.address);
  201. console.log('纬度:' + res.latitude);
  202. console.log('经度:' + res.longitude);
  203. that.latitude = res.latitude
  204. that.longitude = res.longitude
  205. that.address = res.address
  206. }
  207. });
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss">
  213. page{
  214. max-height: calc(100vh - 44px);
  215. }
  216. .qiandao {
  217. background: #F5F5F5;
  218. .top-box{
  219. padding: 90rpx 32rpx 20rpx;
  220. position: fixed;
  221. top: 0%;
  222. left: 0;
  223. z-index: 99;
  224. width: 100%;
  225. box-sizing: border-box;
  226. background: #fff;
  227. box-shadow: 0rpx 6rpx 20rpx 2rpx rgba(0,0,0,0.16);
  228. border-radius: 0rpx 0rpx 64rpx 64rpx;
  229. box-sizing: border-box;
  230. }
  231. .range-box{
  232. position: fixed;
  233. left: 88rpx;
  234. bottom: 184rpx;
  235. z-index: 99;
  236. width: 574rpx;
  237. height: 100rpx;
  238. background: #FFFFFF;
  239. box-shadow: 0rpx 6rpx 20rpx 2rpx rgba(0,0,0,0.16);
  240. border-radius: 52rpx 52rpx 52rpx 52rpx;
  241. display: flex;
  242. align-items: center;
  243. justify-content: center;
  244. .icon{
  245. width: 48rpx;
  246. height: 48rpx;
  247. }
  248. .text{
  249. font-weight: bold;
  250. font-size: 32rpx;
  251. color: #222222;
  252. }
  253. }
  254. }
  255. .bg {
  256. background: #FFFFFF;
  257. }
  258. .btn {
  259. width: 156rpx;
  260. height: 60rpx;
  261. line-height: 60rpx;
  262. text-align: center;
  263. background: #1EDA94;
  264. border-radius: 60rpx 60rpx 60rpx 60rpx;
  265. font-weight: bold;
  266. font-size: 28rpx;
  267. color: #FFFFFF;
  268. }
  269. </style>