index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. console.log(longitude,latitude,'latitude===================');
  152. this.$queue.showLoading('更新中...')
  153. let data = {
  154. typeId: longitude,
  155. typeName: latitude,
  156. userId: userId
  157. }
  158. that.$Request.postJson('/app/message/insertArtificerLocation', data).then(
  159. res => {
  160. uni.hideLoading();
  161. if (res.code === 0) {
  162. that.$queue.showToast('更新成功!');
  163. }
  164. });
  165. },
  166. openSave() {
  167. this.$queue.showLoading('签到中...')
  168. if (!this.address) {
  169. uni.hideLoading();
  170. this.openMap();
  171. // this.$queue.showToast('请选择地址信息后进行签到!')
  172. return;
  173. }
  174. if (!this.latitude || !this.longitude) {
  175. this.$queue.showToast("请在设置中打开定位权限后刷新小程序再来更新吧!")
  176. return;
  177. }
  178. let data = {
  179. longitude: this.longitude,
  180. latitude: this.latitude,
  181. address: this.address,
  182. city: ''
  183. }
  184. this.$Request.postT('/app/artificer/signIn', data).then(res => {
  185. uni.hideLoading();
  186. if (res.code == 0) {
  187. this.$queue.showToast('签到成功!')
  188. setTimeout(d => {
  189. uni.navigateBack();
  190. }, 1000)
  191. } else {
  192. this.$queue.showToast(res.msg)
  193. }
  194. });
  195. },
  196. openMap() {
  197. let that = this
  198. uni.chooseLocation({
  199. success: function(res) {
  200. console.log('位置名称:' + res.name);
  201. console.log('详细地址:' + res.address);
  202. console.log('纬度:' + res.latitude);
  203. console.log('经度:' + res.longitude);
  204. that.latitude = res.latitude
  205. that.longitude = res.longitude
  206. that.address = res.address
  207. uni.setStorageSync('longitude', res.longitude);
  208. uni.setStorageSync('latitude', res.latitude);
  209. }
  210. });
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss">
  216. page{
  217. max-height: calc(100vh - 44px);
  218. }
  219. .qiandao {
  220. background: #F5F5F5;
  221. .top-box{
  222. padding: 90rpx 32rpx 20rpx;
  223. position: fixed;
  224. top: 0%;
  225. left: 0;
  226. z-index: 99;
  227. width: 100%;
  228. box-sizing: border-box;
  229. background: #fff;
  230. box-shadow: 0rpx 6rpx 20rpx 2rpx rgba(0,0,0,0.16);
  231. border-radius: 0rpx 0rpx 64rpx 64rpx;
  232. box-sizing: border-box;
  233. }
  234. .range-box{
  235. position: fixed;
  236. left: 88rpx;
  237. bottom: 184rpx;
  238. z-index: 99;
  239. width: 574rpx;
  240. height: 100rpx;
  241. background: #FFFFFF;
  242. box-shadow: 0rpx 6rpx 20rpx 2rpx rgba(0,0,0,0.16);
  243. border-radius: 52rpx 52rpx 52rpx 52rpx;
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. .icon{
  248. width: 48rpx;
  249. height: 48rpx;
  250. }
  251. .text{
  252. font-weight: bold;
  253. font-size: 32rpx;
  254. color: #222222;
  255. }
  256. }
  257. }
  258. .bg {
  259. background: #FFFFFF;
  260. }
  261. .btn {
  262. width: 156rpx;
  263. height: 60rpx;
  264. line-height: 60rpx;
  265. text-align: center;
  266. background: #1EDA94;
  267. border-radius: 60rpx 60rpx 60rpx 60rpx;
  268. font-weight: bold;
  269. font-size: 28rpx;
  270. color: #FFFFFF;
  271. }
  272. </style>