忽略logger,我自己的另一个打印数据的类
function settingScopePromise(scope, notice) {
return new Promise((resolve, reject) => {
wx.getSetting({
success(res) {
if (res.authSetting[scope] == undefined) {
wx.authorize({
scope: scope,
success(res) {
resolve("authorize success");
},
fail(error) {
const reject_obj = {
scope: true,
data: "授权失败"
};
reject(reject_obj);
logger.error(reject_obj, error);
}
});
} else if (res.authSetting[scope] == false) {
wx.openSetting({
success(res) {
if (!res.authSetting[scope]) {
resolve("openSetting success cancel");
}
if (res.authSetting[scope]) {
resolve("openSetting success ok");
}
},
fail(error) {
const reject_obj = {
scope: true,
data: "打开设置授权失败"
};
reject(reject_obj);
logger.error(reject_obj, error);
}
});
} else if (res.authSetting[scope] == true) {
resolve("authorize success already");
}
},
fail(error) {
const reject_obj = {
scope: true,
data: "getSetting error"
};
reject(reject_obj);
logger.error(reject_obj, error);
}
});
});
}
function scopeOKBool(result) {
if (result == "openSetting success ok" || result == "authorize success" || result == "authorize success already") {
return true;
} else {
return false;
}
}