uniapp

最近在用uniapp 开发微信小程序 vue + vuex + vue-cli3 + hbuilderx 

 1 export function checkForAuthorization(scope){
 2     return new Promise((resolve,reject)=>{
 3         uni.getSetting({
 4             success(res) {
 5                 console.log(res.authSetting)
 6                 if (!res.authSetting[scope]) {
 7                     uni.authorize({
 8                         scope,
 9                         success() {
10                             resolve()
11                         },
12                         fail() {
13                             uni.hideLoading();
14                             uni.showModal({
15                                 title: '温馨提示',
16                                 content: '您已拒绝授权,是否去设置打开?',
17                                 confirmText: "确认",
18                                 cancelText: "取消",
19                                 success: function(res) {
20                                     // console.log(res);
21                                     if (res.confirm) {
22                                         uni.hideLoading();
23                                         uni.openSetting({
24                                             success: (res) => {
25                                                 res.authSetting[scope] = true
26                                                 resolve()
27                                             }
28                                         });
29                                     } else {
30                                         reject({errMsg:'用户拒绝授权'})
31                                     }
32                                 },
33                                 fail(res) {
34                                     reject(res)
35                                 }
36                             });
37                      
38                         }
39                     })
40                 } else {
41                     resolve()
42                 }
43             },
44             fail(res) {
45                 reject(res)
46             }
47         })
48     })
原文地址:https://www.cnblogs.com/kitty-blog/p/13739624.html