feat: 添加位置授权和获取功能

This commit is contained in:
mkm 2024-07-19 16:51:39 +08:00
parent e2ae755323
commit 91bdf53348
1 changed files with 82 additions and 12 deletions

View File

@ -209,6 +209,20 @@
<up-modal :show="showModal" title="您还没设置密码" :closeOnClickOverlay="true" zoom confirmText='去设置' showCancelButton
@close='showModal=false' @cancel='showModal=false' @confirm="navgo('/pagesOrder/setPayPassword/index')"
confirmColor='#27B52F' cancelText='取消'></up-modal>
<up-popup :show="LocationShow" mode="bottom" @open="LocationShowOpen()">
<view style="margin: 40rpx 10rpx;">
<up-row customStyle="margin-bottom: 10px" gutter="10">
<up-col span="6">
<up-button text="取消" @click="userLocationfalse()"></up-button>
</up-col>
<up-col span="6">
<up-button type="primary" text="设置授权" color="#20B128" @click="opensettings()"></up-button>
</up-col>
</up-row>
</view>
</up-popup>
</view>
</template>
@ -249,6 +263,7 @@
const cartStore = useCartStore();
const reservation_time = ref('')
const is_storage = ref(0)
const LocationShow = ref(false)
const formData = ref({
remark: ""
@ -561,21 +576,76 @@
})
const getLocation = () => {
uni.getLocation({
type: "gcj02",
uni.getSetting({
success(res) {
location.lat = res.latitude;
location.long = res.longitude;
uni.setStorageSync('location', JSON.stringify(location))
checkOrder();
},
fail() {
uni.$u.toast('获取位置当前失败,为你推荐当前门店')
checkOrder(STORE_INFO.id);
},
complete() {}
if (res.authSetting["scope.userLocation"] == false) {
LocationShowOpen()
} else {
opensettings(true)
}
}
})
}
const LocationShowOpen = () => {
LocationShow.value = true;
}
const userLocationfalse = () => {
LocationShow.value = false;
uni.$u.toast('获取位置当前失败,为你推荐当前门店')
checkOrder(STORE_INFO.id);
}
const opensettings = (a = false) => {
if (a == false) {
uni.openSetting({
success(res) {
LocationShow.value = false;
if (res.authSetting["scope.userLocation"] == true) {
uni.authorize({
scope: 'scope.userLocation',
success() {
uni.getLocation({
type: "gcj02",
success(res) {
location.lat = res.latitude;
location.long = res.longitude;
uni.setStorageSync('location', JSON.stringify(
location))
checkOrder();
},
})
},
fail(e) {
userLocationfalse()
},
})
}
},
fail(e) {
userLocationfalse()
}
});
} else {
uni.authorize({
scope: 'scope.userLocation',
success() {
uni.getLocation({
type: "gcj02",
success(res) {
location.lat = res.latitude;
location.long = res.longitude;
uni.setStorageSync('location', JSON.stringify(location))
checkOrder();
},
})
},
fail(e) {
userLocationfalse()
},
})
}
}
onShow(() => {
getAddressList();
})