uni-auth 1.1.9 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/package.json +1 -1
- package/src/common/index.js +16 -2
- package/src/components/AuthPop.vue +21 -10
- package/src/index.js +3 -3
- package/src/util/app.js +4 -16
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
### 使用
|
|
2
|
+
|
|
3
|
+
1. 引入模块
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
import { ifUserAuth, AuthPop } from 'uni-auth'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
2. 调用方法
|
|
10
|
+
|
|
11
|
+
ifUserAuth 方法
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
const res = await ifUserAuth('设备信息', '请授权设备信息xxxx')
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
//参数1为授权类型,参数2为授权提示信息 参数2可不传用默认提示
|
|
18
|
+
res true为通过授权 false为拒绝授权
|
|
19
|
+
|
|
20
|
+
AuthPop 组件
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
<AuthPop />
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
为授权弹窗组件,用于弹出授权弹窗
|
package/package.json
CHANGED
package/src/common/index.js
CHANGED
|
@@ -15,8 +15,23 @@ export const contentEnum = {
|
|
|
15
15
|
},
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
export const APP = {
|
|
19
|
+
ios: {
|
|
20
|
+
相册: 'albumAuthorized',
|
|
21
|
+
相机: 'cameraAuthorized',
|
|
22
|
+
麦克风: 'microphoneAuthorized',
|
|
23
|
+
},
|
|
24
|
+
android: {
|
|
25
|
+
相册: 'android.permission.WRITE_EXTERNAL_STORAGE',
|
|
26
|
+
相机: 'android.permission.WRITE_EXTERNAL_STORAGE',
|
|
27
|
+
麦克风: 'android.permission.RECORD_AUDIO',
|
|
28
|
+
设备信息: 'android.permission.READ_PHONE_STATE',
|
|
29
|
+
电话: 'android.permission.CALL_PHONE',
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
export function hintOpenAuth(params = {}) {
|
|
19
|
-
const {
|
|
34
|
+
const { platform = 'android', content = '', isOpenAuth = false } = params || {}
|
|
20
35
|
return new Promise((resolve, reject) => {
|
|
21
36
|
uni.showModal({
|
|
22
37
|
content,
|
|
@@ -25,7 +40,6 @@ export function hintOpenAuth(params = {}) {
|
|
|
25
40
|
confirmText: platform === 'ios' ? '下一步' : '同意',
|
|
26
41
|
success: (res) => {
|
|
27
42
|
if (!res.confirm) return resolve(false)
|
|
28
|
-
uni.setStorageSync('authCode', code)
|
|
29
43
|
resolve(true)
|
|
30
44
|
isOpenAuth && uni.openAppAuthorizeSetting()
|
|
31
45
|
},
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<!-- #ifdef APP -->
|
|
2
|
+
<!-- #ifdef APP-PLUS -->
|
|
3
3
|
<view class="auth-pop" :style="{ marginTop: safeH }" v-if="isPermissionAlertShow">
|
|
4
|
-
<view class="title">{{
|
|
5
|
-
<view class="msg">{{ contentEnum['android'][
|
|
4
|
+
<view class="title">{{ list.join('、') }}权限使用说明</view>
|
|
5
|
+
<view class="msg" v-for="item in list" :key="item">{{ contentEnum['android'][item] }}</view>
|
|
6
6
|
</view>
|
|
7
7
|
<!-- #endif -->
|
|
8
8
|
</template>
|
|
9
9
|
|
|
10
10
|
<script setup>
|
|
11
|
-
// #ifdef APP
|
|
11
|
+
// #ifdef APP-PLUS
|
|
12
12
|
import { onMounted, onUnmounted, computed, ref } from 'vue'
|
|
13
|
-
import { contentEnum, safeHeight } from '../common/index.js'
|
|
14
|
-
const type = ref('')
|
|
13
|
+
import { contentEnum, safeHeight, APP } from '../common/index.js'
|
|
15
14
|
const permissionListener = ref(null)
|
|
16
15
|
const isPermissionAlertShow = ref(false)
|
|
16
|
+
const list = ref([])
|
|
17
17
|
const systemInfo = ref(uni.getSystemInfoSync())
|
|
18
18
|
const props = defineProps({
|
|
19
19
|
top: {
|
|
@@ -25,9 +25,8 @@ onMounted(() => {
|
|
|
25
25
|
if (systemInfo.value.platform !== 'ios') {
|
|
26
26
|
permissionListener.value = uni.createRequestPermissionListener()
|
|
27
27
|
permissionListener.value.onConfirm((e) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (type.value) isPermissionAlertShow.value = true
|
|
28
|
+
list.value = e.map((item) => getPermissionKeyByValue(item))
|
|
29
|
+
isPermissionAlertShow.value = true
|
|
31
30
|
})
|
|
32
31
|
permissionListener.value.onComplete((e) => {
|
|
33
32
|
isPermissionAlertShow.value = false
|
|
@@ -44,6 +43,16 @@ onUnmounted(() => {
|
|
|
44
43
|
permissionListener.value.stop()
|
|
45
44
|
}
|
|
46
45
|
})
|
|
46
|
+
|
|
47
|
+
function getPermissionKeyByValue(permissionValue) {
|
|
48
|
+
const androidPermissions = APP.android
|
|
49
|
+
for (const [key, value] of Object.entries(androidPermissions)) {
|
|
50
|
+
if (value === permissionValue) {
|
|
51
|
+
return key
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
47
56
|
// #endif
|
|
48
57
|
</script>
|
|
49
58
|
|
|
@@ -56,7 +65,7 @@ onUnmounted(() => {
|
|
|
56
65
|
min-height: 120rpx;
|
|
57
66
|
background: #f2f2f2;
|
|
58
67
|
box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
|
|
59
|
-
z-index:
|
|
68
|
+
z-index: 999999;
|
|
60
69
|
border-radius: 14rpx;
|
|
61
70
|
margin-left: 5%;
|
|
62
71
|
margin-right: 5%;
|
|
@@ -75,9 +84,11 @@ onUnmounted(() => {
|
|
|
75
84
|
.title {
|
|
76
85
|
font-weight: 600;
|
|
77
86
|
font-size: 26rpx;
|
|
87
|
+
margin-bottom: 20rpx;
|
|
78
88
|
}
|
|
79
89
|
.msg {
|
|
80
90
|
font-size: 24rpx;
|
|
81
91
|
letter-spacing: 2rpx;
|
|
92
|
+
margin-bottom: 10rpx;
|
|
82
93
|
}
|
|
83
94
|
</style>
|
package/src/index.js
CHANGED
|
@@ -2,12 +2,12 @@ import { appAuth } from './util/app.js'
|
|
|
2
2
|
import { wxAuth } from './util/wx.js'
|
|
3
3
|
export { default as AuthPop } from './components/AuthPop.vue'
|
|
4
4
|
|
|
5
|
-
export async function ifUserAuth(code) {
|
|
5
|
+
export async function ifUserAuth(code, msg) {
|
|
6
6
|
// #ifdef APP-PLUS
|
|
7
|
-
return await appAuth(code)
|
|
7
|
+
return await appAuth(code, msg)
|
|
8
8
|
// #endif
|
|
9
9
|
// #ifdef MP-WEIXIN
|
|
10
|
-
return await wxAuth(code)
|
|
10
|
+
return await wxAuth(code, msg)
|
|
11
11
|
// #endif
|
|
12
12
|
return true
|
|
13
13
|
}
|
package/src/util/app.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import { hintOpenAuth, contentEnum } from '../common/index.js'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
相册: 'albumAuthorized',
|
|
5
|
-
相机: 'cameraAuthorized',
|
|
6
|
-
麦克风: 'microphoneAuthorized',
|
|
7
|
-
},
|
|
8
|
-
android: {
|
|
9
|
-
相册: 'android.permission.WRITE_EXTERNAL_STORAGE',
|
|
10
|
-
相机: 'android.permission.WRITE_EXTERNAL_STORAGE',
|
|
11
|
-
麦克风: 'android.permission.RECORD_AUDIO',
|
|
12
|
-
设备信息: 'android.permission.READ_PHONE_STATE',
|
|
13
|
-
电话: 'android.permission.CALL_PHONE',
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
export function appAuth(code = '相册') {
|
|
1
|
+
import { hintOpenAuth, contentEnum, APP } from '../common/index.js'
|
|
2
|
+
|
|
3
|
+
export function appAuth(code = '相册', msg = '') {
|
|
17
4
|
return new Promise((resolve, reject) => {
|
|
18
5
|
const platform = uni.getSystemInfoSync().platform // ios/android
|
|
6
|
+
if (msg) contentEnum[platform][code] = msg
|
|
19
7
|
if (platform === 'ios') {
|
|
20
8
|
const permissionInfo = uni.getAppAuthorizeSetting()
|
|
21
9
|
const authStatus = permissionInfo[APP[platform][code]]
|