评论

用时授权处理

用时授权处理

忽略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;
  }
}

点赞 0
收藏
评论
登录 后发表内容