uni-auth 1.1.9 → 1.2.0
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 +1 -1
- package/src/components/AuthPop.vue +5 -5
- package/src/index.js +3 -3
- package/src/util/app.js +2 -1
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
|
@@ -25,7 +25,7 @@ export function hintOpenAuth(params = {}) {
|
|
|
25
25
|
confirmText: platform === 'ios' ? '下一步' : '同意',
|
|
26
26
|
success: (res) => {
|
|
27
27
|
if (!res.confirm) return resolve(false)
|
|
28
|
-
uni.setStorageSync('
|
|
28
|
+
uni.setStorageSync('applyAuthCode', code)
|
|
29
29
|
resolve(true)
|
|
30
30
|
isOpenAuth && uni.openAppAuthorizeSetting()
|
|
31
31
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<!-- #ifdef APP -->
|
|
2
|
+
<!-- #ifdef APP-PLUS -->
|
|
3
3
|
<view class="auth-pop" :style="{ marginTop: safeH }" v-if="isPermissionAlertShow">
|
|
4
4
|
<view class="title">{{ type }}权限使用说明</view>
|
|
5
5
|
<view class="msg">{{ contentEnum['android'][type] }}</view>
|
|
@@ -8,7 +8,7 @@
|
|
|
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
13
|
import { contentEnum, safeHeight } from '../common/index.js'
|
|
14
14
|
const type = ref('')
|
|
@@ -25,12 +25,12 @@ onMounted(() => {
|
|
|
25
25
|
if (systemInfo.value.platform !== 'ios') {
|
|
26
26
|
permissionListener.value = uni.createRequestPermissionListener()
|
|
27
27
|
permissionListener.value.onConfirm((e) => {
|
|
28
|
-
type.value = uni.getStorageSync('
|
|
29
|
-
uni.removeStorageSync('authCode')
|
|
28
|
+
type.value = uni.getStorageSync('applyAuthCode') || ''
|
|
30
29
|
if (type.value) isPermissionAlertShow.value = true
|
|
31
30
|
})
|
|
32
31
|
permissionListener.value.onComplete((e) => {
|
|
33
32
|
isPermissionAlertShow.value = false
|
|
33
|
+
uni.removeStorageSync('applyAuthCode')
|
|
34
34
|
})
|
|
35
35
|
}
|
|
36
36
|
})
|
|
@@ -56,7 +56,7 @@ onUnmounted(() => {
|
|
|
56
56
|
min-height: 120rpx;
|
|
57
57
|
background: #f2f2f2;
|
|
58
58
|
box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
|
|
59
|
-
z-index:
|
|
59
|
+
z-index: 999999;
|
|
60
60
|
border-radius: 14rpx;
|
|
61
61
|
margin-left: 5%;
|
|
62
62
|
margin-right: 5%;
|
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
|
@@ -13,9 +13,10 @@ const APP = {
|
|
|
13
13
|
电话: 'android.permission.CALL_PHONE',
|
|
14
14
|
},
|
|
15
15
|
}
|
|
16
|
-
export function appAuth(code = '相册') {
|
|
16
|
+
export function appAuth(code = '相册', msg = '') {
|
|
17
17
|
return new Promise((resolve, reject) => {
|
|
18
18
|
const platform = uni.getSystemInfoSync().platform // ios/android
|
|
19
|
+
if (msg) contentEnum[platform][code] = msg
|
|
19
20
|
if (platform === 'ios') {
|
|
20
21
|
const permissionInfo = uni.getAppAuthorizeSetting()
|
|
21
22
|
const authStatus = permissionInfo[APP[platform][code]]
|