uni-auth 1.1.8 → 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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-auth",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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('authCode', code)
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,12 +8,13 @@
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('')
15
15
  const permissionListener = ref(null)
16
16
  const isPermissionAlertShow = ref(false)
17
+ const systemInfo = ref(uni.getSystemInfoSync())
17
18
  const props = defineProps({
18
19
  top: {
19
20
  type: String,
@@ -21,16 +22,15 @@ const props = defineProps({
21
22
  },
22
23
  })
23
24
  onMounted(() => {
24
- const systemInfo = uni.getSystemInfoSync()
25
- if (systemInfo.platform !== 'ios') {
25
+ if (systemInfo.value.platform !== 'ios') {
26
26
  permissionListener.value = uni.createRequestPermissionListener()
27
27
  permissionListener.value.onConfirm((e) => {
28
- type.value = uni.getStorageSync('authCode') || ''
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
  })
@@ -40,7 +40,9 @@ const safeH = computed(() => {
40
40
  return statusBarHeight + menuButtonHeight + 20 + 'px'
41
41
  })
42
42
  onUnmounted(() => {
43
- permissionListener.value.stop()
43
+ if (systemInfo.value.platform !== 'ios') {
44
+ permissionListener.value.stop()
45
+ }
44
46
  })
45
47
  // #endif
46
48
  </script>
@@ -54,7 +56,7 @@ onUnmounted(() => {
54
56
  min-height: 120rpx;
55
57
  background: #f2f2f2;
56
58
  box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
57
- z-index: 999;
59
+ z-index: 999999;
58
60
  border-radius: 14rpx;
59
61
  margin-left: 5%;
60
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]]