From dc91222fc05249868ecabe4a42b0b228912e0172 Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Sat, 28 Jun 2025 15:13:12 +0800 Subject: [PATCH] 1 --- mixins/configList.js | 6 ++++++ utils/authorize.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ utils/index.js | 2 ++ 3 files changed, 61 insertions(+) create mode 100644 utils/authorize.js diff --git a/mixins/configList.js b/mixins/configList.js index c535f64..ad5a42a 100644 --- a/mixins/configList.js +++ b/mixins/configList.js @@ -56,6 +56,12 @@ export default { } return o }, + onLoad(query) { + if (query.shareId) { + uni.setStorageSync('shareId', query.shareId) + } + console.log(`uni.setStorageSync('shareId', ${query.shareId})`); + }, methods: { } } \ No newline at end of file diff --git a/utils/authorize.js b/utils/authorize.js new file mode 100644 index 0000000..eca6537 --- /dev/null +++ b/utils/authorize.js @@ -0,0 +1,53 @@ + + + +function authorize(scope){ + return new Promise((success, error) => { + uni.authorize({ + /* scope.writePhotosAlbum 类型是保存到相册 */ + scope, + success, + complete(res) { + /* 判断如果没有授权就打开设置选项让用户重新授权 */ + uni.getSetting({ + success(res) { + if (!res.authSetting[scope]) { + setting() + } + } + }); + } + }); + + function setting(){ + uni.showModal({ + title: '当前操作未授权,请授权!', + content: '拒绝授权将影响本小程序部分功能的使用', + confirmText: '授权', + success(e) { + if(!e.confirm){ + return error() + } + uni.openSetting({ + success(res) { + if (!res.authSetting[scope]) { + uni.showToast({ + title: '授权失败', + icon: 'none', + }) + return error() + } + success() + } + }); + } + }) + } + }) +} + + + + + +export default authorize \ No newline at end of file diff --git a/utils/index.js b/utils/index.js index 490c426..07a0814 100644 --- a/utils/index.js +++ b/utils/index.js @@ -19,8 +19,10 @@ Vue.prototype.$wxPay = wxPay dayjs.locale('zh-cn') import Oss from '@/utils/oss-upload/oss/index.js' +import authorize from '@/utils/authorize.js' import { handleTree } from './tree.js' +Vue.prototype.$authorize = authorize Vue.prototype.$handleTree = handleTree Vue.prototype.$Oss = Oss Vue.prototype.$dayjs = dayjs