You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.8 KiB
84 lines
1.8 KiB
10 months ago
|
import permissionApi from "./permission";
|
||
|
|
||
|
|
||
|
var isIos
|
||
|
// #ifdef APP-PLUS
|
||
|
isIos = (plus.os.name == "iOS")
|
||
|
// #endif
|
||
|
|
||
|
const permsMaps = {
|
||
|
'android': {
|
||
|
'location': {
|
||
|
permissions: ['android.permission.ACCESS_FINE_LOCATION'],
|
||
|
permissionTitle: '位置',
|
||
|
content: '为了更好的服务,请授权使用定位服务'
|
||
|
}
|
||
|
},
|
||
|
'ios': {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getTargetSdkPersName(permission) {
|
||
|
let plat = isIos ? "ios" : "android";
|
||
|
return permsMaps[plat][permission]["permissions"]
|
||
|
}
|
||
|
|
||
|
function premissionCheck(permission) {
|
||
|
return new Promise(async (resolve, reject) => {
|
||
|
let plat = isIos ? "ios" : "android";
|
||
|
if (isIos) { // ios
|
||
|
|
||
|
} else { // android
|
||
|
let permission_arr = getTargetSdkPersName(permission);
|
||
|
let flag = true;
|
||
|
for (let i = 0; i < permission_arr.length; i++) {
|
||
|
let status = plus.navigator.checkPermission(permission_arr[i]);
|
||
|
if (status == "undetermined") {
|
||
|
flag = false;
|
||
|
}
|
||
|
}
|
||
|
if (flag == false) { // 未完全授权
|
||
|
permissionApi.requestAndroidPermission(permission_arr).then((res) => {
|
||
|
if (res == -1) {
|
||
|
const name = permsMaps[plat][permission]["permissionTitle"]
|
||
|
uni.showModal({
|
||
|
title: '提示',
|
||
|
content: `${name}权限已被拒绝,请手动前往设置`,
|
||
|
confirmText: "立即设置",
|
||
|
success: (res) => {
|
||
|
if (res.confirm) {
|
||
|
uni.openAppAuthorizeSetting()
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
resolve(res)
|
||
|
})
|
||
|
} else {
|
||
|
resolve(1)
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
export function locationRequest() {
|
||
|
return new Promise(async (resolve, reject) => {
|
||
|
premissionCheck('location').then(code => {
|
||
|
if (code == 1) {
|
||
|
uni.getLocation({
|
||
|
type: 'wgs84',
|
||
|
geocode: true,
|
||
|
success: (res) => {
|
||
|
resolve(res)
|
||
|
},
|
||
|
fail: (res) => {
|
||
|
reject(err)
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
reject()
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
}
|