uni-auth 1.2.0 → 1.2.2

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.2",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -4,6 +4,7 @@ export const contentEnum = {
4
4
  相册: `允许${appName}访问您的相册/相机权限来获取您的照片用于上传您的图片和相册等信息`,
5
5
  相机: `允许${appName}访问您的相册/相机权限及摄像头来方便用户拍摄上传图片等信息`,
6
6
  麦克风: `允许${appName}访问您的麦克风来获取您的声音用于录音等信息`,
7
+ 位置: `允许${appName}访问您的位置,用于为你提供推荐优质房源服务`,
7
8
  },
8
9
  android: {
9
10
  相册: `允许${appName}访问您的相册/相机,您可以上传/拍摄照片及视频;`,
@@ -15,8 +16,25 @@ export const contentEnum = {
15
16
  },
16
17
  }
17
18
 
19
+ export const APP = {
20
+ ios: {
21
+ 相册: 'albumAuthorized',
22
+ 相机: 'cameraAuthorized',
23
+ 麦克风: 'microphoneAuthorized',
24
+ 位置: 'locationAuthorized',
25
+ },
26
+ android: {
27
+ 相册: 'android.permission.WRITE_EXTERNAL_STORAGE',
28
+ 相机: 'android.permission.WRITE_EXTERNAL_STORAGE',
29
+ 麦克风: 'android.permission.RECORD_AUDIO',
30
+ 设备信息: 'android.permission.READ_PHONE_STATE',
31
+ 电话: 'android.permission.CALL_PHONE',
32
+ 位置: 'android.permission.ACCESS_FINE_LOCATION',
33
+ },
34
+ }
35
+
18
36
  export function hintOpenAuth(params = {}) {
19
- const { code, platform = 'android', content = '', isOpenAuth = false } = params || {}
37
+ const { platform = 'android', content = '', isOpenAuth = false } = params || {}
20
38
  return new Promise((resolve, reject) => {
21
39
  uni.showModal({
22
40
  content,
@@ -25,7 +43,6 @@ export function hintOpenAuth(params = {}) {
25
43
  confirmText: platform === 'ios' ? '下一步' : '同意',
26
44
  success: (res) => {
27
45
  if (!res.confirm) return resolve(false)
28
- uni.setStorageSync('applyAuthCode', code)
29
46
  resolve(true)
30
47
  isOpenAuth && uni.openAppAuthorizeSetting()
31
48
  },
@@ -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