diff --git a/App.vue b/App.vue index 63cf9bf..b925c36 100644 --- a/App.vue +++ b/App.vue @@ -8,12 +8,6 @@ import mqttUtil from "@/utils/mqttUtil.js" const mqttUrl = import.meta.env.VITE_BASE_MQTT; - // 引入插件包 - import { - requestPermissions, - goSetting - } from "@/js_sdk/yu-app-permission/yu-app-permission.js" - export default { data() { return { diff --git a/main.js b/main.js index 2475a00..1e0b5f7 100644 --- a/main.js +++ b/main.js @@ -44,9 +44,13 @@ import { createSSRApp } from 'vue' import uviewPlus from "@/uni_modules/uview-plus" -import directive from "@/directive" +import directive from "@/directive" import * as commonUtils from "@/utils/common.js" import constant from "@/utils/constant.js" +import { + VerifyPermissions +} from "@/utils/requestPermissions.js" + export function createApp() { const app = createSSRApp(App) app.use(uviewPlus) @@ -54,7 +58,8 @@ export function createApp() { app.config.globalProperties.$toast = commonUtils.toast; app.config.globalProperties.$showConfirm = commonUtils.showConfirm; app.config.globalProperties.$constant = constant; - + app.config.globalProperties.$VerifyPermissions = VerifyPermissions; + // #ifndef MP // 处理 wx.connectSocket promisify 兼容问题,强制返回 SocketTask uni.connectSocket = (function(connectSocket) { diff --git a/pages/index.vue b/pages/index.vue index 5a9e8c6..ae227f6 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -633,37 +633,27 @@ }, // 去扫码 async toQRCode() { - // // 权限检测成功则返回 { isSuc : true} ,未授权则弹出权限询问弹窗以及权限说明窗口 - // const { - // isSuc - // } = await requestPermissions({ - // title: "相机/摄像头权限申请说明", // 申请权限时弹出框标题 - // content: "便于您使用该功能扫描设备二维码,查看设备信息", // 申请权限时弹出框内容 - // permissionID: "CAMERA" // 权限ID - // }) - // if (!isSuc) { - // return false - // } - - var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module") - mpaasScanModule.mpaasScan({ - // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有 - 'scanType': ['qrCode', 'barCode'], - // 是否隐藏相册,默认false不隐藏 - 'hideAlbum': false, - //ios需要设置这个参数,只支持中英文 zh-Hans、en,默认中文 - 'language': 'en', - //相册选择照片识别错误提示(ios) - 'failedMsg': '未识别到二维码,请重试', - //Android支持全屏需要设置此参数 - 'screenType': 'full' - }, (ret) => { - console.error("ret:", ret); - if (ret.resp_code == 1000) { - const deviceCode = ret.resp_result; - // showModal.value = true - this.$toast(JSON.stringify(deviceCode)) - } + this.$VerifyPermissions("CAMERA", "扫描设备二维码,查看设备信息").then(res => { + var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module") + mpaasScanModule.mpaasScan({ + // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有 + 'scanType': ['qrCode', 'barCode'], + // 是否隐藏相册,默认false不隐藏 + 'hideAlbum': false, + //ios需要设置这个参数,只支持中英文 zh-Hans、en,默认中文 + 'language': 'en', + //相册选择照片识别错误提示(ios) + 'failedMsg': '未识别到二维码,请重试', + //Android支持全屏需要设置此参数 + 'screenType': 'full' + }, (ret) => { + console.error("ret:", ret); + if (ret.resp_code == 1000) { + const deviceCode = ret.resp_result; + // showModal.value = true + this.$toast(JSON.stringify(deviceCode)) + } + }) }) }, // 基站adc diff --git a/pages/login.vue b/pages/login.vue index a6be634..037e0d5 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -179,10 +179,7 @@ // 忘记密码 function forgotPassword() { - uni.showToast({ - title: "忘记密码,请联系管理员", - icon: "none" - }) + this.$toast("忘记密码,请联系管理员"); } const codeBtnText = ref('获取验证码'); @@ -195,21 +192,18 @@ } //验证正确手机号 if (!checkTelephone(loginForm.value.phone)) { - uni.showToast({ - title: "请输入正确手机号!", - icon: "none" - }) + this.$toast("请输入正确手机号!"); return } codeBtnDisabled.value = true; uni.showLoading({ - title: "正在获取验证码...", + title: "获取验证码...", mask: true }) getCodePhone(loginForm.value.phone).then(res => { - plugin.modal.closeLoading() + uni.hideLoading() if (res.smsResponse) { - plugin.modal.showToast("短信已发送") + this.$toast("短信已发送"); loginForm.value.uuid = res.uuid codeBtnTimer.value = 60 setCodeTimer(); @@ -294,10 +288,7 @@ loginSuccess() }) .catch(error => { - uni.showToast({ - title: error, - icon: "error" - }) + this.$toast(error); }) .finally(() => {}) } @@ -312,10 +303,7 @@ if (result.code == 200) { toIndex(result.user.userId); } else { - uni.showToast({ - title: result.msg, - icon: "none" - }) + this.$toast(result.msg); } }) //获取用户权限 @@ -323,10 +311,7 @@ .dispatch("getUserRoles") .then(res => {}) .catch(error => { - uni.showToast({ - title: "获取用户权限失败", - icon: "none" - }) + this.$toast("获取用户权限失败"); }) .finally(() => {}) } diff --git a/pages/mine/avatar/index.vue b/pages/mine/avatar/index.vue index 33f1341..3155f3c 100644 --- a/pages/mine/avatar/index.vue +++ b/pages/mine/avatar/index.vue @@ -137,6 +137,14 @@ }, async getImage() { var _this = this + const _CAMERA = await _this.$VerifyPermissions("CAMERA", "个性化设置头像") + if (!_CAMERA) { + return false; + } + const _READ_EXTERNAL_STORAGE = await _this.$VerifyPermissions("READ_EXTERNAL_STORAGE", "个性化设置头像") + if (!_READ_EXTERNAL_STORAGE) { + return false; + } uni.chooseImage({ success: function(res) { _this.setData({ diff --git a/utils/requestPermissions.js b/utils/requestPermissions.js new file mode 100644 index 0000000..fe2e0c4 --- /dev/null +++ b/utils/requestPermissions.js @@ -0,0 +1,50 @@ +// 引入插件包 +import { + requestPermissions, + goSetting +} from "@/js_sdk/yu-app-permission/yu-app-permission.js" + + +const permission = { + CAMERA: { + value: "CAMERA", + title: "相机/摄像头", + }, + CALL_PHONE: { + value: "CALL_PHONE", + title: "拨打电话", + }, + READ_EXTERNAL_STORAGE: { + value: "READ_EXTERNAL_STORAGE", + title: "访问相册", + }, +} +/** + * @param {Object} key permissionKey 类型 参考上方 + * @param {Object} content 功能描述 + */ +export function VerifyPermissions(key, content) { + return new Promise((resolve, reject) => { + // 权限检测成功则返回 { isSuc : true} ,未授权则弹出权限询问弹窗以及权限说明窗口 + // const { + // isSuc + // } = await requestPermissions({ + // title: title, // 申请权限时弹出框标题 + // content: content, // 申请权限时弹出框内容 + // permissionID: permissionID // 权限ID + // }) + // if (!isSuc) { + // return false + // } + + requestPermissions({ + title: permission[key].title, // 申请权限时弹出框标题 + content: content, // 申请权限时弹出框内容 + permissionID: permission[key].value // 权限ID + }).then(res => { + if (res.isSuc) { + resolve(true) + } + }) + }) +} \ No newline at end of file