收藏
回答

隐私同意授权后调用chooseLocation提示112错误码,但重启微信后就可以正常使用,为什么?

我在调用 chooseLocation 前已经提前执行 wx.authorize获取授权。并且,调用wx.getSetting接口得到如下结果

{scope.userLocation: true, scope.address: true, scope.invoice: true, scope.invoiceTitle: true, scope.userInfo: true}

但是在调用chooseLocation 的时候提示

{errMsg: "chooseLocation:fail api scope is not declared in the privacy agreement", errno: 112}

但是在我重启微信之后,重新进入到页面执行chooseLocation , 就可以正常使用,请问如何才能够在不重启微信的情况下,正常使用chooseLocation?

<template>
	<view class="content">
		<view class="content-top">
			<view class='cell-group'>
				<view class='cell-item cell-item-mid'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>收货人</view>
					</view>
					<view class='cell-item-bd' style="width: 70%;">
						<input type="text" class='cell-bd-input' placeholder='请填写收货人姓名' v-model="name"></input>
					</view>
				</view>
				<view class='cell-item cell-item-mid'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>手机号</view>
					</view>
					<view class='cell-item-bd' style="width: 70%;">
						<input type="number" class='cell-bd-input' placeholder='请填写收货人手机号' v-model="mobile"></input>
					</view>
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<view class='cell-item cell-item-mid right-img' @click="onChooseLocation">
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>收货地址</view>
					</view>
					<view class='cell-item-bd'>
						<view v-if="!location">点击选择收货地址</view>
						<view v-else>
							<view class="one-line fsz24">{{ location.name }}</view>
							<view class="location-address one-line fsz24">{{ location.address }}</view>
						</view>
					</view>
					<view class='cell-item-ft'>
						<image class="cell-ft-next icon" :src="'right.png' | cdn"></image>
					</view>
				</view>
				<!-- #endif -->


				<!-- #ifdef H5 -->
				<view class='cell-item cell-item-mid right-img'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>省市区</view>
					</view>


					<view class='cell-item-bd'>
						<input :value="pickerValue" readonly @focus="showThreePicker"></input>
						<area-picker ref="areaPicker" :areaId="areaId" :defaultIndex="defaultIndex"
							@onConfirm="onConfirm" class="fsz26"></area-picker>
					</view>


					<view class='cell-item-ft'>
						<image class='cell-ft-next icon' :src="'ic-pull-down.png' | cdn" @click="showThreePicker">
						</image>
					</view>
				</view>
				<!-- #endif -->


				<view class='cell-item cell-item-mid'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>门牌号</view>
					</view>
					<view class='cell-item-bd' style="width: 70%;">
						<input type="text" class='cell-bd-input' placeholder='详细地址, 例1层101室' v-model="address"></input>
					</view>
				</view>


				<view class='cell-item' @click="defaultChange">
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>设为默认</view>
					</view>
					<view class='cell-item-ft'>
						<label class="radio">
							<radio value="1" :checked="checked" color="#FF7159" />
						</label>
					</view>
				</view>
			</view>
		</view>
		<view class="button-bottom" style="height: 120rpx;">


			<button class="btn btn-big btn-w" @click="delShip" v-if="id && id != 0" hover-class="btn-hover2"
				:disabled='submitStatus' :loading='submitStatus'>删除</button>


			<button class="btn btn-big btn-b " @click="saveShip" hover-class="btn-hover2" :disabled='submitStatus'
				:loading='submitStatus'>保存</button>
		</view>
	</view>


</template>


<script>
	import areaPicker from "@/components/area-picker/areaPicker.vue";
	export default {
		components: {
			areaPicker
		},
		data() {
			return {
				id: 0,
				name: '',
				mobile: '',
				region: ['北京市', '北京市', '东城区'],
				areaId: 110101,
				address: '',
				is_def: 2,
				multiArray: [
					[],
					[],
					[]
				],
				checked: false,
				pickerValue: '',
				defaultIndex: [0, 0, 0],
				submitStatus: false,
				location: null
			}
		},
		computed: {},
		onShow() {
			uni.authorize({
				scope:'scope.userLocation',
				success: () => {
					console.log('好的');
				},
				fail: (err) => {
					console.log(err)
					uni.showModal({
						title: '提示',
						content: "您未开启位置信息,影响下单体验。操作请点击右上角“...”,在弹窗页面选择“设置”,在设置页面中点击“位置信息”并设置为“使用小程序时”,关闭微信后重新进入小程序,完成设置。",
						showCancel: false
					});
				}
			})
		},
		methods: {
			onChooseLocation() {
				wx.getSetting({
				  success (res) {
				    console.log(res.authSetting)
					uni.chooseLocation({
						success: (res) => {
							delete res.errMsg
							console.log(res)
							this.location = res
						},
						fail: (err) => {
							console.log(err)
							uni.showModal({
								title: '提示',
								content: "您未开启位置信息,影响下单体验。操作请点击右上角“...”,在弹窗页面选择“设置”,在设置页面中点击“位置信息”并设置为“使用小程序时”,关闭微信后重新进入小程序,完成设置。",
								showCancel: false
							});
						}
					});
				  }
				})


			},
			// 省市区联动初始化
			showThreePicker() {
				this.$refs.areaPicker.showPicker();
			},
			onConfirm(e) {
				let province_name = e[0].name;
				let city_name = e[1].name;
				let county_name = e[2].name;
				this.pickerValue = e[0].name + " " + e[1].name + " " + e[2].name
				let data = {
					province_name: province_name,
					city_name: city_name,
					county_name: county_name
				}
				let regionName = [province_name, city_name, county_name];
				this.$api.getAreaId(data, res => {
					if (res.status) {
						this.areaId = res.data
					} else {
						uni.showModal({
							title: '提示',
							content: '地区选择出现问题,请重新选择地区',
							showCancel: false
						});
					}
				});
			},
			// 信息验证
			checkData(data) {
				this.submitStatus = false;
				if (!data.name) {
					this.$common.errorToShow('请输入收货人姓名')
					return false
				} else if (!data.mobile) {
					this.$common.errorToShow('请输入收货人手机号')
					return false
				} else if (data.mobile.length !== 11) {
					this.$common.errorToShow('收货人手机号格式不正确')
					return false
				} else if (!data.location) {
					this.$common.errorToShow('请选择收货地址')
					return false
				} else if (!data.address) {
					this.$common.errorToShow('请输入门牌号')
					return false
				} else {
					return true
				}
			},
			//默认
			defaultChange() {
				if (this.checked) {
					this.checked = false;
					this.is_def = 2;
				} else {
					this.checked = true;
					this.is_def = 1;
				}
			},
			//编辑获取收货地址信息
			getShipInfo() {
				let data = {
					'id': this.id
				}
				this.$api.shipDetail(data, res => {
					if (res.status) {
						console.log(res)
						// let region = res.data.area_name.split(" ");
						this.name = res.data.name;
						this.mobile = res.data.mobile;
						this.location = JSON.parse(res.data.location)
						// this.region = region;
						this.areaId = res.data.area_id;


						// this.pickerValue = this.region[0]+ " "+ this.region[1]+" "+this.region[2]
						// #ifdef H5
						this.$refs.areaPicker.init(); //初始化插件
						// #endif


						this.address = res.data.address;
						this.is_def = res.data.is_def;
						if (res.data.is_def == 1) {
							this.checked = true;
						} else {
							this.checked = false;
						}
					} else {
						this.$common.errorToShow('获取收货地址信息出现问题');
						// this.submitStatus = false;
					}
				}, res => {
					this.submitStatus = false;
				});
			},
			//删除地址
			delShip() {
				this.submitStatus = true;
				this.$api.removeShip({
					'id': this.id
				}, res => {
					if (res.status) {
						// console.log(res);
						let user_ship = this.$store.state.userShip;
						// console.log(user_ship);
						if (user_ship.id == this.id) {
							let data = {}
							this.$store.commit("userShip", data)
						}


						this.$common.successToShow(res.msg, ress => {
							// this.submitStatus = false;
							uni.navigateBack({
								delta: 1
							});
						});
					} else {
						this.$common.errorToShow(res.msg);
						// this.submitStatus = false;
					}
				}, res => {
					this.submitStatus = false;
				});
			},
			//存储收货地址
			saveShip() {
				this.submitStatus = true;
				let data = {
					name: this.name,
					address: this.address,
					mobile: this.mobile,
					is_def: this.is_def,
					// area_id: this.areaId,
					area_id: 0,
					location: this.location,
				}


				if (this.id && this.id != 0) {
					//编辑存储
					data.id = this.id


					if (this.checkData(data)) {
						this.$api.editShip(data, res => {
							if (res.status) {
								this.$common.successToShow(res.msg, ress => {
									// this.submitStatus = false;
									uni.navigateBack({
										delta: 1
									});
								});
							} else {
								this.$common.errorToShow(res.msg);
								// this.submitStatus = false;
							}
						}, res => {
							this.submitStatus = false;
						});
					}
				} else {
					//添加
					if (this.checkData(data)) {
						this.$api.editShip(data, res => {
							if (res.status) {
								this.$common.successToShow(res.msg, ress => {
									// this.submitStatus = false;
									uni.navigateBack({
										delta: 1
									});
								});
							} else {
								this.$common.errorToShow(res.msg);
								// this.submitStatus = false;
							}
						}, res => {
							this.submitStatus = false;
						});
					}
				}
			}
		},
		onLoad(e) {
			if (e.ship_id) {
				//编辑
				this.id = e.ship_id;
				this.getShipInfo();
			} else {
				//添加
				this.pickerValue = '请选择省市区'; //this.region[0]+ " "+ this.region[1]+" "+this.region[2];//关闭默认省市区
				uni.setNavigationBarTitle({
					title: '添加地址'
				});
			}
			//没有地区信息时,再拉一次
			if (!this.$db.get('areaList')) {
				//获取地区信息
				this.$api.getAreaList({}, res => {
					if (res.status) {
						this.$db.set('areaList', res.data)
					}
				});
			}
		},
		onBackPress() {
			if (this.$refs.areaPicker.pickerShow) {
				this.$refs.areaPicker.closePicker();
				return true;
			}
		}
	}
</script>

最后一次编辑于  2023-11-03
回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2023-11-03

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2023-11-03
    有用
    回复 6
    • 云野
      云野
      2023-11-03
      您好, 代码已经上传, 麻烦帮看一下
      2023-11-03
      回复
    • Demons
      Demons
      2023-11-03回复云野
      上传哪里,链接呢
      2023-11-03
      回复
    • heartbeats
      heartbeats
      2023-12-04回复Demons
      你好,我们也遇到这个问题了,请问有解决办法吗
      2023-12-04
      回复
    • ,,,
      ,,,
      03-13
      你好,这个问题有办法解决吗
      03-13
      回复
    • Latias
      Latias
      04-24
      你好我也是这个问题  请问怎么解决
      04-24
      回复
    查看更多(1)
登录 后发表内容