修改bug
This commit is contained in:
@@ -131,66 +131,41 @@ const chooseImg = () => {
|
||||
imgList.value.splice(index, 1);
|
||||
};
|
||||
|
||||
// 检查 App 端定位权限(Android/iOS)
|
||||
const checkAppLocationPermission = () => {
|
||||
// 跳转系统设置(App 端:Android/iOS;H5/小程序另有处理)
|
||||
const openAppSettings = () => {
|
||||
// #ifdef APP-PLUS
|
||||
try {
|
||||
const platform = uni.getSystemInfoSync().platform;
|
||||
if (platform === 'android') {
|
||||
const main = plus.android.runtimeMainActivity();
|
||||
const PackageManager = plus.android.importClass('android.content.pm.PackageManager');
|
||||
return main.checkSelfPermission('android.permission.ACCESS_FINE_LOCATION') === PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
if (platform === 'ios') {
|
||||
const CLAuthorizationStatus = plus.ios.importClass('CLAuthorizationStatus');
|
||||
const CLLocationManager = plus.ios.importClass('CLLocationManager');
|
||||
return CLLocationManager.authorizationStatus() !== 2; // 2 = denied
|
||||
const Intent = plus.android.importClass('android.content.Intent');
|
||||
const Settings = plus.android.importClass('android.provider.Settings');
|
||||
const Uri = plus.android.importClass('android.net.Uri');
|
||||
const mainActivity = plus.android.runtimeMainActivity();
|
||||
const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.setData(Uri.parse('package:' + mainActivity.getPackageName()));
|
||||
mainActivity.startActivity(intent);
|
||||
} else if (platform === 'ios') {
|
||||
const UIApplication = plus.ios.importClass('UIApplication');
|
||||
const NSURL = plus.ios.importClass('NSURL');
|
||||
UIApplication.sharedApplication().openURL(NSURL.URLWithString('app-settings:'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('检查权限失败', e);
|
||||
console.error('跳转系统设置异常:', e);
|
||||
uni.showToast({ title: '跳转失败,请手动前往系统设置开启定位权限', icon: 'none' });
|
||||
}
|
||||
// #endif
|
||||
return true; // 非 App 端默认通过
|
||||
};
|
||||
|
||||
// 跳转系统设置(App 端)
|
||||
const openAppSettings = () => {
|
||||
// #ifdef APP-PLUS
|
||||
const platform = uni.getSystemInfoSync().platform;
|
||||
if (platform === 'android') {
|
||||
const Intent = plus.android.importClass('android.content.Intent');
|
||||
const Settings = plus.android.importClass('android.provider.Settings');
|
||||
const Uri = plus.android.importClass('android.net.Uri');
|
||||
const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.setData(Uri.parse('package:' + plus.runtime.packageName));
|
||||
plus.android.runtimeMainActivity().startActivity(intent);
|
||||
} else if (platform === 'ios') {
|
||||
const UIApplication = plus.ios.importClass('UIApplication');
|
||||
const app = UIApplication.sharedApplication();
|
||||
const NSURL = plus.ios.importClass('NSURL');
|
||||
const url = NSURL.URLWithString('app-settings:');
|
||||
app.openURL(url);
|
||||
}
|
||||
// #ifdef H5
|
||||
uni.showToast({ title: '请手动在浏览器设置中允许定位权限', icon: 'none' });
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.openSetting({});
|
||||
// #endif
|
||||
};
|
||||
|
||||
// 重新定位(获取当前位置 + 逆地址解析)
|
||||
const reLocate = () => {
|
||||
// App 端先检查权限,无权限直接引导设置
|
||||
// #ifdef APP-PLUS
|
||||
if (!checkAppLocationPermission()) {
|
||||
uni.showModal({
|
||||
title: '需要定位权限',
|
||||
content: '请前往系统设置中允许本应用使用定位权限',
|
||||
confirmText: '去设置',
|
||||
success: (res) => {
|
||||
if (res.confirm) openAppSettings();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
// #endif
|
||||
|
||||
uni.showLoading({ title: '正在定位...', mask: true });
|
||||
|
||||
uni.getLocation({
|
||||
@@ -208,7 +183,7 @@ const reLocate = () => {
|
||||
uni.hideLoading();
|
||||
const errMsgStr = err?.errMsg || err?.message || JSON.stringify(err);
|
||||
console.error('定位失败:', err);
|
||||
if (err?.code === -22 || /权限|auth|deny|permission/i.test(errMsgStr)) {
|
||||
if (err?.code === -22 || /权限|授权|拒绝|auth|deny|permission/i.test(errMsgStr)) {
|
||||
uni.showModal({
|
||||
title: '需要定位权限',
|
||||
content: '请允许获取位置信息以显示具体地点',
|
||||
|
||||
Reference in New Issue
Block a user