uni-auth 1.2.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-auth",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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 { code, platform = 'android', content = '', isOpenAuth = false } = params || {}
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('applyAuthCode', code)
29
43
  resolve(true)
30
44
  isOpenAuth && uni.openAppAuthorizeSetting()
31
45
  },
@@ -1,8 +1,8 @@
1
1
  <template>
2
2
  <!-- #ifdef APP-PLUS -->
3
3
  <view class="auth-pop" :style="{ marginTop: safeH }" v-if="isPermissionAlertShow">
4
- <view class="title">{{ type }}权限使用说明</view>
5
- <view class="msg">{{ contentEnum['android'][type] }}</view>
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>
@@ -10,10 +10,10 @@
10
10
  <script setup>
11
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,12 +25,11 @@ 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('applyAuthCode') || ''
29
- if (type.value) isPermissionAlertShow.value = true
28
+ list.value = e.map((item) => getPermissionKeyByValue(item))
29
+ isPermissionAlertShow.value = true
30
30
  })
31
31
  permissionListener.value.onComplete((e) => {
32
32
  isPermissionAlertShow.value = false
33
- uni.removeStorageSync('applyAuthCode')
34
33
  })
35
34
  }
36
35
  })
@@ -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
 
@@ -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/util/app.js CHANGED
@@ -1,18 +1,5 @@
1
- import { hintOpenAuth, contentEnum } from '../common/index.js'
2
- const APP = {
3
- ios: {
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
- }
1
+ import { hintOpenAuth, contentEnum, APP } from '../common/index.js'
2
+
16
3
  export function appAuth(code = '相册', msg = '') {
17
4
  return new Promise((resolve, reject) => {
18
5
  const platform = uni.getSystemInfoSync().platform // ios/android