1.修改定位获取经纬度 问题

yj-dev
杨杰 2 years ago
parent b1e733c01c
commit 02d613067c
  1. 16
      App.vue
  2. 7
      pages.json
  3. 8
      pages/login/resetpasswd.vue
  4. 153
      pages/tabBar/home/home.vue
  5. 84
      subPages/recharge-centre/recharge-centre.vue
  6. 13
      subPages/unionComfirmation/unionComfirmation.vue
  7. 6
      uni_modules/mumu-getlocation/changelog.md
  8. 97
      uni_modules/mumu-getlocation/components/mumu-getlocation/geolocation.min.js
  9. 74
      uni_modules/mumu-getlocation/components/mumu-getlocation/mumu-getlocation.vue
  10. 84
      uni_modules/mumu-getlocation/package.json
  11. 107
      uni_modules/mumu-getlocation/readme.md

@ -5,15 +5,15 @@
// brestUrl: 'http://192.168.3.4:9302/brest', // brestUrl: 'http://192.168.3.4:9302/brest',
// imgUrl: 'https://192.168.3.4:9301/filesystem/', // imgUrl: 'https://192.168.3.4:9301/filesystem/',
// //
url: 'https://hsg.dctpay.com/crest', // url: 'https://hsg.dctpay.com/crest',
imgUrl: 'https://hsg.dctpay.com/filesystem/', // imgUrl: 'https://hsg.dctpay.com/filesystem/',
brestUrl : 'https://hsg.dctpay.com/brest', // brestUrl : 'https://hsg.dctpay.com/brest',
imageWxImg:'https://hsg.dctpay.com/filesystem/wxApplets/', // imageWxImg:'https://hsg.dctpay.com/filesystem/wxApplets/',
// //
// url: 'https://hsgcs.dctpay.com/crest', url: 'https://hsgcs.dctpay.com/crest',
// brestUrl : 'https://hsgcs.dctpay.com/brest', brestUrl : 'https://hsgcs.dctpay.com/brest',
// imgUrl: 'https://hsgcs.dctpay.com/filesystem/', imgUrl: 'https://hsgcs.dctpay.com/filesystem/',
// imageWxImg:'https://hsgcs.dctpay.com/filesystem/wxApplets/', imageWxImg:'https://hsgcs.dctpay.com/filesystem/wxApplets/',
userInfo: "", userInfo: "",
brestUserInfo : '', brestUserInfo : '',
openId: '', openId: '',

@ -332,12 +332,7 @@
"onReachBottomDistance": 50, "onReachBottomDistance": 50,
"app-plus": { "app-plus": {
"titleNView": false, // "titleNView": false, //
"softinputNavBar": "none", "softinputNavBar": "none"
"subNVues": [{
"id": "homeTitleNvue", //
"path": "pages/tabBar/home/subNvue/homeTitleNvue", //
"type": "navigationBar"
}]
} }
} }

@ -8,13 +8,13 @@
<view class="form re"> <view class="form re">
<view class="username"> <view class="username">
<!-- <view class="get-code" :style="{'color':getCodeBtnColor}" @click.stop="getCode()">{{getCodeText}}</view> --> <!-- <view class="get-code" :style="{'color':getCodeBtnColor}" @click.stop="getCode()">{{getCodeText}}</view> -->
<input placeholder="请输入旧密码" v-model="phoneNumber" placeholder-style="color: rgba(255,255,255,0.8);"/> <input placeholder="请输入旧密码" v-model="phoneNumber" placeholder-style="color: #333333;"/>
</view> </view>
<view class="code"> <view class="code">
<input placeholder="请输入新密码" v-model="code" password=true placeholder-style="color: rgba(255,255,255,0.8);"/> <input placeholder="请输入新密码" v-model="code" password=true placeholder-style="color: #333333;"/>
</view> </view>
<view class="password"> <view class="password">
<input placeholder="确认新密码" v-model="passwd" password=true placeholder-style="color: rgba(255,255,255,0.8);"/> <input placeholder="确认新密码" v-model="passwd" password=true placeholder-style="color: #333333;"/>
</view> </view>
<view class="btn" @click="sendUserPass">重置密码</view> <view class="btn" @click="sendUserPass">重置密码</view>
@ -154,7 +154,7 @@
let datas = { let datas = {
userId: app.globalData.brestUserInfo.id, userId: app.globalData.brestUserInfo.id,
oldPassword: this.phoneNumber, oldPassword: this.phoneNumber,
password : this.passwd newPassword : this.passwd
} }
sendUserPass(datas).then(res => { sendUserPass(datas).then(res => {
if (res.return_code == '000000') { if (res.return_code == '000000') {

@ -91,6 +91,7 @@
</button> </button>
<!-- #endif --> <!-- #endif -->
<!-- #ifdef H5 --> <!-- #ifdef H5 -->
<mumu-getlocation ref='muLocation'></mumu-getlocation>
<image :src="imagewxUrl+imgadres4" mode="widthFix" class="h5xfimg" @click="playPhone"></image> <image :src="imagewxUrl+imgadres4" mode="widthFix" class="h5xfimg" @click="playPhone"></image>
<!-- #endif --> <!-- #endif -->
<view class="height40"></view> <view class="height40"></view>
@ -113,10 +114,12 @@
findByLatAndLng findByLatAndLng
} from "../../../Utils/Api.js"; //api } from "../../../Utils/Api.js"; //api
import wybPopup from '../../../components/wyb-popup/wyb-popup.vue'; import wybPopup from '../../../components/wyb-popup/wyb-popup.vue';
import mumuGetlocation from '@/uni_modules/mumu-getlocation/components/mumu-getlocation/mumu-getlocation.vue';
let app = getApp(); let app = getApp();
export default { export default {
components: { components: {
wybPopup wybPopup,
mumuGetlocation
}, },
data() { data() {
return { return {
@ -162,7 +165,8 @@
homeCateList: [], homeCateList: [],
// //
cpStuats: 1, cpStuats: 1,
jumpType: '' jumpType: '',
locationRef: null, //
}; };
}, },
@ -198,7 +202,7 @@
app.globalData.h5code = arr2[1]; app.globalData.h5code = arr2[1];
} else { } else {
// openid // openid
this.jumpcdx(); that.jumpcdx();
uni.setStorage({ uni.setStorage({
key: "accountId", key: "accountId",
data: arr2[1] data: arr2[1]
@ -210,7 +214,7 @@
} }
if (app.globalData.h5code) { if (app.globalData.h5code) {
this.getH5AccessToken(); that.getH5AccessToken();
} }
// #endif // #endif
// #ifdef MP // #ifdef MP
@ -234,8 +238,51 @@
}, },
}) })
// #endif // #endif
// #ifdef H5
// 使 $nextTic
this.$nextTick(() => {
// 使 login
//
this.$refs.muLocation.__init().then(location => {
// data
this.locationRef = location;
this.getLocation();
}, err => {
this.city = '重庆市';
app.globalData.cityName = '重庆市';
app.globalData.cityId = '500000';
//
if (err.code === 1) {
uni.showModal({
title: '获取定位权限失败,默认城市重庆',
content: '你拒绝了位置授权服务。请允许当前页面获取定位授权,后刷新页面。'
})
this.getCouponListArea();
this.getCouponListgold();
this.getCmsContent();
this.getCmsAactibity();
this.getCmsContentcmshome();
this.getCmsContentcmsContent();
} else {
uni.showModal({
title: '获取定位权限失败,默认城市重庆',
content: '请确定手机定位已打开,并且当前浏览器允许获取定位,都开启后请刷新页面。'
})
this.getCouponListArea();
this.getCouponListgold();
this.getCmsContent();
this.getCmsAactibity();
this.getCmsContentcmshome();
this.getCmsContentcmsContent();
}
})
})
// #endif
// #ifdef MP
// //
this.postionIng(); that.postionIng();
// #endif
uni.getStorage({ uni.getStorage({
key: "user", key: "user",
success(e) { success(e) {
@ -265,7 +312,7 @@
methods: { methods: {
jumpcdx() { jumpcdx() {
location.href = location.href =
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa075e8509802f826&redirect_uri=https%3A%2F%2Fhsg.dctpay.com%2FhsgH5%2Findex.html%23%2F&response_type=code&scope=snsapi_base&state=1#wechat_redirect'; 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa075e8509802f826&redirect_uri=https%3A%2F%2Fhsgcs.dctpay.com%2FhsgH5%2Findex.html%23%2F&response_type=code&scope=snsapi_base&state=1#wechat_redirect';
}, },
// //
getCmsContentcmsContent() { getCmsContentcmsContent() {
@ -372,33 +419,6 @@
app.globalData.longitude = res.longitude; app.globalData.longitude = res.longitude;
uni.hideLoading(); uni.hideLoading();
that.findByLatAndLng(res.longitude, res.latitude); that.findByLatAndLng(res.longitude, res.latitude);
// that.getUserLocation(res.longitude, res.latitude);
// uni.request({
// url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + res.latitude +
// ',' + res.longitude + '&key=7UMBZ-HFEHX-HSD4Q-Z3QY6-OQKN7-2QBDB',
// data: {},
// success: function(res) {
// // that.city = res.data.result.address_component.city.replace(//g,
// // '');
// that.city = res.data.result.address_component.province;
// app.globalData.cityName = res.data.result.address_component
// .province;
// app.globalData.cityId = res.data.result.ad_info.adcode;
// uni.hideLoading();
// if (res.data.result.ad_info.adcode) {
// that.getCouponListArea();
// that.getCouponListgold();
// that.getCmsContent();
// that.getCmsAactibity();
// that.getCmsContentcmshome();
// that.getCmsContentcmsContent();
// }
// },
// fail(err) {
// uni.hideLoading()
// }
// })
}, },
fail: (err) => { fail: (err) => {
if (err.errCode == 2) { if (err.errCode == 2) {
@ -411,6 +431,21 @@
} }
}) })
}, },
//
getLocation() {
uni.showLoading({
title: '加载中'
})
let that = this;
that.locationRef.getLocation() // getLocation
.then(res => {
uni.hideLoading();
// res
app.globalData.latitude = res.lat;
app.globalData.longitude = res.lng;
that.findByLatAndLng(res.lng, res.lat);
})
},
// //
findByLatAndLng(item, item1) { findByLatAndLng(item, item1) {
let that = this; let that = this;
@ -467,58 +502,6 @@
} }
}); });
}, },
//H5
getUserLocation(long, lat) {
let that = this;
let url =
'https://apis.map.qq.com/ws/geocoder/v1?coord_type=5&get_poi=1&output=jsonp&poi_options=page_size=1;page_index=1';
let locationObj = lat + ',' + long;
this.$jsonp(url, {
key: '7UMBZ-HFEHX-HSD4Q-Z3QY6-OQKN7-2QBDB',
location: locationObj
})
.then(res => {
// vm.city = res.result.address_component.city.replace(//g, '');
// app.globalData.cityName = res.result.address_component.city.replace(//g, '');
// app.globalData.cityId = res.result.ad_info.adcode;
// vm.getCouponListArea();
// vm.getCouponListgold();
// uni.hideLoading()
uni.hideLoading();
that.city = res.result.address_component.city;
app.globalData.cityName = res.result.address_component
.city;
app.globalData.cityId = res.result.ad_info.adcode;
if (res.result.ad_info.adcode) {
// app.globalData.cityId = '500100';
that.getCouponListArea();
that.getCouponListgold();
that.getCmsContent();
that.getCmsAactibity();
that.getCmsContentcmshome();
that.getCmsContentcmsContent();
}
uni.getStorage({
key: 'accountType',
success(e) {
if (e.data) {
app.globalData.accountType = e.data;
if (e.data == '000000#/' && app.globalData.h5code) {
uni.navigateTo({
url: '../../goods/refuel-details/refuel-details'
})
}
}
}
})
})
.catch(err => {
uni.hideLoading()
});
},
// //
toSearch() { toSearch() {
uni.navigateTo({ uni.navigateTo({

@ -28,82 +28,11 @@
<view class="mart5 width90 font18 fcor333 fontwig6"> <view class="mart5 width90 font18 fcor333 fontwig6">
充值说明 充值说明
</view> </view>
<view v-if="current == 0"> <view class="width90 mart20" v-if="current == 0">
<view class="mart5 width80 font14 fcoreb5 fontwig6" style="list-style-type: decimal;"> <image mode="widthFix" :src="imagewxUrl+image2"></image>
<view style="width: 5%;" class="flleft">1:</view>
<view style="margin-left: 5%;">
此业务为话费慢充日常5个工作日内到账如遇月初月末运营商高峰期或系统更新到账时间会有一定延迟敬请谅解充值失败后系统会自动为您退款至原账户急单请选择6小时到账充值端口感谢您的支持
</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">2:</view>
<view style="margin-left: 5%;">慢充话费与营业厅充值一样只是到账时间稍长充值过程中可能出现分批到账的情况但是总金额不会少请耐心等待</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">3:</view>
<view style="margin-left: 5%;">
目前仅支持(移动联通电信三网号段)运营商黑名单号码(长期欠费或非实名制认证)携号转网空号虚拟卡(如165167170171162等等虚拟号段)副卡号码或做过某些特殊套餐绑定的卡暂不支持充值请勿下单
</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">4:</view>
<view style="margin-left: 5%;">停机号码需要额外补缴欠费后慢充话费才能到账<text
class="fcoreb5">此服务为虚拟充值类服务无特殊情况不支持退款下单前请确认充值的号码无误</text></view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">5:</view>
<view style="margin-left: 5%;">空号错号充值后不支持退款请您务必核对确认号码无误后再进行充值非空号欠费可充欠费1个月导致空号的不能充值损失自负无法退款
</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">6:</view>
<view style="margin-left: 5%;"><text
class="fcoreb5">本充值业务不提供发票</text>如需发票请在运营商手机客户端储开取电子发票也可以凭身份证到运营商实体营业厅打印发票</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">7:</view>
<view style="margin-left: 5%;">如遇系统维护充值失败将72小时后原路退款到付款账户 </view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6 marb40" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">8:</view>
<view style="margin-left: 5%;">请登录所属运营商app手机营业厅查看充值号码的到账情况如金额有出入或未到账请截图充值记录明细反馈给客服录明细反馈给客服</view>
</view>
</view> </view>
<view v-if="current == 1"> <view class="width90 mart20" v-if="current == 1">
<view class="mart5 width80 font14 fcoreb5 fontwig6" style="list-style-type: decimal;"> <image mode="widthFix" :src="imagewxUrl+image1"></image>
<view style="width: 5%;" class="flleft">1:</view>
<view style="margin-left: 5%;">
充值后6小时内到账请耐心等待如遇月初月末运营商充值压力大充值失败后系统会为您自动再提交一次如二次充值仍然失败系统将会自动为您退款至原账户请悉知
</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">2:</view>
<view style="margin-left: 5%;">
目前仅支持(移动联通电信三网号段)运营商黑名单号码(长期欠费或非实名制认证)携号转网空号虚拟卡(如165167170171162等等虚拟号段)副卡号码或做过某些特殊套餐绑定的卡暂不支持充值请勿下单
</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">3:</view>
<view style="margin-left: 5%;">停机号码需要额外补缴欠费后慢充话费才能到账此服务为虚拟充值类服务无特殊情况不支持退款下单前请确认充值的号码无误</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">4:</view>
<view style="margin-left: 5%;">空号错号充值后不支持退款请您务必核对确认号码无误后再进行充值非空号欠费可充欠费1个月导致空号的不能充值损失自负无法退款</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">5:</view>
<view style="margin-left: 5%;"><text
class="fcoreb5">本充值业务不提供发票</text>如需发票请在运营商手机客户端储开取电子发票也可以凭身份证到运营商实体营业厅打印发票</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">6:</view>
<view style="margin-left: 5%;">如遇系统维护充值失败将72小时后原路退款到付款账户
</view>
</view>
<view class="mart5 width80 font14 fcor999 fontwig6" style="list-style-type: decimal;">
<view style="width: 5%;" class="flleft">7:</view>
<view style="margin-left: 5%;">请登录所属运营商app(手机营业厅)查看充值号码的到账情况如金额有出入或未到账请截图充值记录明细反馈给客服录明细反馈给客服</view>
</view>
</view> </view>
<view class="height100p"></view> <view class="height100p"></view>
<view class="bombtn width94 font16"> <view class="bombtn width94 font16">
@ -139,7 +68,10 @@
amoutstatus: '', amoutstatus: '',
tabs: ["5个工作日", "6小时到账"], // tabs: ["5个工作日", "6小时到账"], //
current: 0, // current: 0, //
swiperCurrent: 2 swiperCurrent: 2,
imagewxUrl: app.globalData.imageWxImg,
image1:'telephone1.png',
image2:'telephone2.png'
} }
}, },
onLoad(options) { onLoad(options) {

@ -326,7 +326,6 @@
this.rechangeload(); this.rechangeload();
if (this.memDiscountId == item.id) { // if (this.memDiscountId == item.id) { //
this.memDiscountId = ''; this.memDiscountId = '';
this.reload();
this.deductionPrice = '0.00'; this.deductionPrice = '0.00';
this.priceCaluc(this.saveprice); this.priceCaluc(this.saveprice);
@ -361,15 +360,17 @@
let payprice = parseFloat(item * 100 * zkprice).toFixed(0); let payprice = parseFloat(item * 100 * zkprice).toFixed(0);
if (payprice > this.user.gold) { if (payprice > this.user.gold) {
this.availIntegal = this.user.gold; this.availIntegal = this.user.gold;
if (this.availIntegal < this.priceValue[1]) { this.priceValue[1] = 0;
this.priceValue[1] = this.user.gold; // if (this.availIntegal < this.priceValue[1]) {
this.reload(); // this.priceValue[1] = this.user.gold;
} // this.reload();
// }
} else { } else {
this.availIntegal = payprice; this.availIntegal = payprice;
this.priceValue[1] = 0; this.priceValue[1] = 0;
this.reload(); // this.reload();
} }
this.reload();
this.calculatepayPrice(); this.calculatepayPrice();
}, },
// //

@ -0,0 +1,6 @@
## 1.0.0(2022-06-09)
1. 新增 检测用户是否授权
2. 新增 检测设置定位服务权限是否打开
3. 优化 组件加载
## 0.0.1(2022-01-27)
版本上线

@ -0,0 +1,97 @@
// #ifdef H5
window.qq = window.qq || {}, qq.maps = qq.maps || {}, window.soso || (window.soso = qq), soso.maps || (soso.maps = qq
.maps), qq.maps.Geolocation = function() {
"use strict";
var e = [],
t = null,
o = 0,
n = "_geoIframe_" + Math.ceil(1e7 * Math.random()),
i = document.createElement("iframe"),
r = null,
s = null,
a = null,
c = null,
u = function(u, l) {
if (!u) return void alert("请输入key!");
if (!l) return void alert("请输入referer!");
var p = document.getElementById(n);
if (!p) {
i.setAttribute("id", n), i.setAttribute("allow", "geolocation");
var g = "https:";
i.setAttribute("src", g + "//apis.map.qq.com/tools/geolocation?key=" + u + "&referer=" + l), i
.setAttribute("style", "display: none; width: 100%; height: 30%"), document.body ? document
.body
.appendChild(i) : document.write(i.outerHTML);
var m = this;
window.addEventListener("message", function(n) {
var i = n.data;
if (i && "geolocation" == i.module) {
if (clearTimeout(c), e.length > 0) {
var u = e.shift();
u.sucCb && u.sucCb(i)
}
o = 2, m.executeNextGeo(), t && t(i)
} else {
s = (new Date).getTime();
var l = s - r;
if (l >= a) {
if (e.length > 0 && "geo" === e[0].type) {
var u = e.shift(),
p = {
type: "fail",
code: 5,
message: "The request"
};
u.errCb && u.errCb(p)
}
clearTimeout(c), o = -1, m.executeNextGeo()
}
if (e.length > 0 && "ip" === e[0].type) {
var u = e.shift();
u.errCb && u.errCb(p)
}
}
}, !1)
}
};
return u.prototype.executeNextGeo = function() {
1 !== o && e.length > 0 && (o = 1, e[0].geoprocess())
}, u.prototype.getLocation = function(t, n, i) {
if (i && i.timeout) {
var r = new RegExp("^[0-9]*$");
if (!r.test(i.timeout)) return void alert("timeout 请输入数字")
}
if (e.length > 10) throw new Error("geolocation queue must be lass than 10");
e.push({
sucCb: t,
errCb: n,
option: i,
geoprocess: this.getOnceLocation,
type: "geo"
}), 1 !== o && (o = 1, this.getOnceLocation())
}, u.prototype.getOnceLocation = function() {
var t = e[0] && e[0].option;
r = (new Date).getTime(), a = t && t.timeout ? +t.timeout : 1e4, clearTimeout(c), c = setTimeout(
function() {
if (e.length > 0) {
var t = e.shift();
t.errCb && t.errCb()
}
}, a), document.getElementById(n).contentWindow.postMessage("getLocation", "*")
}, u.prototype.getIpLocation = function(t, n) {
if (e.length > 10) throw new Error("geolocation queue mast be lass than 10");
e.push({
sucCb: t,
errCb: n,
geoprocess: this.getOnceIpLocation,
type: "ip"
}), 1 !== o && (o = 1, this.getOnceIpLocation())
}, u.prototype.getOnceIpLocation = function() {
document.getElementById(n).contentWindow.postMessage("getLocation.robust", "*")
}, u.prototype.watchPosition = function(e) {
t = e, document.getElementById(n).contentWindow.postMessage("watchPosition", "*")
}, u.prototype.clearWatch = function() {
t = null, document.getElementById(n).contentWindow.postMessage("clearWatch", "*")
}, u
}();
// #endif

@ -0,0 +1,74 @@
<template>
<view>
</view>
</template>
<script>
import './geolocation.min.js'
export default {
data() {
return {
myMap: {}
}
},
mounted() {
//this.__init()
},
methods: {
__init() {
if (origin.indexOf('https') === -1) throw '请在 https 环境中使用本插件。'
if (!navigator || !navigator.geolocation) throw '地理位置服务不可用'
const options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
/** err
code 1 表示用户拒绝授权
code 3 未获取到地址信息可能是设备没有开启定位服务或者系统没有给浏览器定位权限
* */
return new Promise((resolve, rejace) => {
navigator.geolocation.getCurrentPosition((res) => {
this.myMap = new qq.maps.Geolocation("7UMBZ-HFEHX-HSD4Q-Z3QY6-OQKN7-2QBDB",
"地图标点");
resolve(this)
}, rejace, options)
})
},
getLocation() {
return new Promise((resolve, reject) => {
this.myMap.getLocation(res => {
resolve(res)
}, err => {
reject(err)
})
})
},
getIpLocation() {
return new Promise((resolve, reject) => {
this.myMap.getIpLocation(res => {
resolve(res)
}, err => {
reject(err)
})
})
},
watchPosition(callBack) {
this.myMap.watchPosition(res => {
callBack(res)
})
},
clearWatch() {
this.myMap.clearWatch()
}
}
}
</script>
<style scoped>
</style>

@ -0,0 +1,84 @@
{
"id": "mumu-getlocation",
"displayName": "h5定位组件_获取精准定位_获取ip定位(可持续定位)",
"version": "1.0.0",
"description": "不需要任何 SDK 即可简单实现获取用户位置相关信息。可直接获取城市",
"keywords": [
"定位",
"ip位置",
"持续定位",
"获取城市",
""
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"category": [
"前端组件",
"通用组件"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "获取定位"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-vue": "n",
"app-nvue": "n"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "n",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

@ -0,0 +1,107 @@
# 插件简绍
## 插件原理
> 对腾讯地图的前端定位组件进行二次封装。[地图组件 | 腾讯位置服务 (qq.com)](https://lbs.qq.com/webApi/component/componentGuide/componentMarker)
## 使用环境
**本插件只支持H5平台。因部分浏览器调用位置需要 https 环境,推荐大家还是把 https 环境配置上。**
## 插件使用
**插件已支持 uni_modules 支持组件easycom,以下代码演示的是普通使用**
``` html
<!-- HTML -->
<mumu-getlocation ref='muLocation'></mumu-getlocation>
<button type="default" @click="getLocation">获取精准位置</button>
```
``` js
import mumuGetlocation from '@/uni_modules/mumu-getlocation/components/mumu-getlocation/mumu-getlocation.vue'
export default {
components: {
mumuGetlocation
},
data() {
return {
locationRef: null, // 用于接收定位对象
}
},
onLoad() {
// 使用 $nextTic 等待组件加载完成调用
this.$nextTick(() => {
// 在检测用户是否开启定位权限需要一个过程,推荐使用 login 提示一下
uni.showLoading({
title: '定位组件加载中...',
mask: true
})
// 初始化组件,并且检测是否开启与授权定位
this.$refs.muLocation.__init().then(location => {
// 用户授权了和开启了定位,把定位对象保存到 data 中
this.locationRef = location
uni.hideLoading()
}, err => {
// 用户拒绝了定位请求,获取系统没有开启定位功能
uni.hideLoading()
if (err.code === 1) {
uni.showModal({
title: '获取定位权限失败',
content: '你拒绝了位置授权服务。请允许当前页面获取定位授权,后刷新页面。'
})
} else {
uni.showModal({
title: '获取定位权限失败',
content: '请确定手机定位已打开,并且当前浏览器允许获取定位,都开启后请刷新页面。'
})
}
})
})
},
methods: {
// 获取精准定位
getLocation() {
this.locationRef.getLocation() // 调用 getLocation 方法获取精准定位
.then(res => {
// res 就是返回的数据
uni.showModal({
content:JSON.stringify(res, null, 4)
})
})
},
}
}
```
## 相关 API
### 可传属性(Props)
### 组件内部方法(Event)
**通过 refs 调用**
| 方法 | 传参 | 说明 | 返回类型 | 返回数据 |
| ------ | ---- | ------------------------------------ | -------- | -------------------------- |
| __init | 无 | 初始化组件,检测用户是否开启定位权限 | 对象 | 定位对象,用于后续方法调用 |
**定位对象属性**
| 方法名 | 传参 | 说明 | 返回(return) | 返回数据 |
| --------------- | -------- | ------------ | -------------- | ---------------- |
| getLocation() | 无 | 获取精准定位 | Promise | 精准定位数据 |
| getIpLocation() | 无 | 获取ip定位 | Promise | 获取ip定位数据 |
| watchPosition() | function | 持续监听定位 | 数据 | 持续监听定位数据 |
| clearWatch() | 无 | 关闭持续监听 | 无 | 无 |
## 案例演示
![](https://h5plugin.mumudev.top/public/getLocation/qrcode.png)
## 支持作者
![支持作者](https://student.mumudev.top/wxMP.jpg)
Loading…
Cancel
Save