uni-auth 1.0.2 → 1.0.4

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.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -0,0 +1,34 @@
1
+ const appName = uni.getSystemInfoSync().appName // 获取应用名称
2
+ export const contentEnum = {
3
+ ios: {
4
+ 相册: `允许${appName}访问您的相册/相机权限来获取您的照片用于上传您的图片和相册等信息`,
5
+ 相机: `允许${appName}访问您的相册/相机权限及摄像头来方便用户拍摄上传图片等信息`,
6
+ 麦克风: `允许${appName}访问您的麦克风来获取您的声音用于录音等信息`,
7
+ },
8
+ android: {
9
+ 相册: `允许${appName}访问您的相册/相机,您可以上传/拍摄照片及视频;`,
10
+ 相机: `允许${appName}访问您的相册/相机,您可以上传/拍摄照片及视频`,
11
+ 麦克风: `允许${appName}访问您的麦克风来获取您的声音用于录音等信息`,
12
+ 设备信息: `允许${appName}访问您设备的唯一标识,用于数据统计和分析`,
13
+ 电话: `允许${appName}访问您设备的电话,用于联系客服`,
14
+ 位置: `允许${appName}访问您的位置,用于为你提供下单配送服务`,
15
+ },
16
+ }
17
+
18
+ export function hintOpenAuth(params = {}) {
19
+ const { code, platform = 'android', content = '', isOpenAuth = false } = params || {}
20
+ return new Promise((resolve, reject) => {
21
+ uni.showModal({
22
+ content: content,
23
+ showCancel: platform !== 'ios',
24
+ cancelText: '拒绝',
25
+ confirmText: platform === 'ios' ? '下一步' : '同意',
26
+ success: (res) => {
27
+ if (!res.confirm) return resolve(false)
28
+ uni.setStorageSync('authCode', code)
29
+ resolve(true)
30
+ isOpenAuth && uni.openAppAuthorizeSetting()
31
+ },
32
+ })
33
+ })
34
+ }
@@ -0,0 +1,63 @@
1
+ <template>
2
+ <view class="auth-pop" v-if="isPermissionAlertShow">
3
+ <view class="title">{{ type }}权限使用说明</view>
4
+ <view class="msg">{{ contentEnum['android'][type] }}</view>
5
+ </view>
6
+ </template>
7
+
8
+ <script setup>
9
+ import { onMounted, onUnmounted, ref } from 'vue'
10
+ import { contentEnum } from '../common/index.js'
11
+ const type = ref('')
12
+ const permissionListener = ref(null)
13
+ const isPermissionAlertShow = ref(false)
14
+ onMounted(() => {
15
+ type.value = uni.getStorageSync('authCode') || ''
16
+ uni.removeStorageSync('authCode')
17
+ if (!type.value) return
18
+ permissionListener.value = uni.createRequestPermissionListener()
19
+ permissionListener.value.onConfirm((e) => {
20
+ isPermissionAlertShow.value = true
21
+ })
22
+ permissionListener.value.onComplete((e) => {
23
+ isPermissionAlertShow.value = false
24
+ })
25
+ })
26
+ onUnmounted(() => {
27
+ permissionListener.value.stop()
28
+ })
29
+ </script>
30
+
31
+ <style scoped>
32
+ .auth-pop {
33
+ position: fixed;
34
+ top: 0;
35
+ left: 0;
36
+ width: 90%;
37
+ min-height: 120rpx;
38
+ background: #f2f2f2;
39
+ box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
40
+ z-index: 999;
41
+ border-radius: 14rpx;
42
+ margin: 100rpx 5% 0;
43
+ animation: identifier 1s ease-in-out;
44
+ padding: 20rpx 30rpx;
45
+ box-sizing: border-box;
46
+ }
47
+ @keyframes identifier {
48
+ 0% {
49
+ transform: translateY(-300rpx);
50
+ }
51
+ 100% {
52
+ transform: translateY(0);
53
+ }
54
+ }
55
+ .title {
56
+ font-weight: 600;
57
+ font-size: 26rpx;
58
+ }
59
+ .msg {
60
+ font-size: 24rpx;
61
+ letter-spacing: 2rpx;
62
+ }
63
+ </style>
package/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export { appAuth } from './util/app.js'
2
- export { wxAuth } from './util/wx.js'
1
+ import { appAuth } from './util/app.js'
2
+ import { wxAuth } from './util/wx.js'
3
+ export { default as AuthPop } from './components/AuthPop.vue'
3
4
 
4
5
  export async function ifUserAuth(code) {
5
6
  // #ifdef APP-PLUS
package/src/util/app.js CHANGED
@@ -1,21 +1,4 @@
1
- import { hintOpenAuth } from './common.js'
2
-
3
- const appName = uni.getSystemInfoSync().appName // 获取应用名称
4
- const MESSAGE = {
5
- ios: {
6
- 相册: `允许${appName}访问您的相册/相机权限来获取您的照片用于上传您的图片和相册等信息`,
7
- 相机: `允许${appName}访问您的相册/相机权限及摄像头来方便用户拍摄上传图片等信息`,
8
- 麦克风: `允许${appName}访问您的麦克风来获取您的声音用于录音等信息`,
9
- },
10
- android: {
11
- 相册: `允许${appName}访问您的相册/相机,您可以上传/拍摄照片及视频;`,
12
- 相机: `允许${appName}访问您的相册/相机,您可以上传/拍摄照片及视频`,
13
- 麦克风: `允许${appName}访问您的麦克风来获取您的声音用于录音等信息`,
14
- 设备信息: `允许${appName}访问您设备的唯一标识,用于数据统计和分析`,
15
- 电话: `允许${appName}访问您设备的电话,用于联系客服`,
16
- 位置: `允许${appName}访问您的位置,用于为你提供下单配送服务`,
17
- },
18
- }
1
+ import { hintOpenAuth, contentEnum } from '../common/index.js'
19
2
 
20
3
  export function appAuth(code = '相册') {
21
4
  return new Promise((resolve, reject) => {
@@ -28,10 +11,10 @@ export function appAuth(code = '相册') {
28
11
  resolve(true)
29
12
  break
30
13
  case 'not determined':
31
- hintOpenAuth({ code, platform, content: MESSAGE[platform][code] }).then((res) => resolve(res))
14
+ hintOpenAuth({ code, platform, content: contentEnum[platform][code] }).then((res) => resolve(res))
32
15
  break
33
16
  case 'denied':
34
- hintOpenAuth({ code, platform, content: MESSAGE[platform][code] }).then((res) => resolve(res))
17
+ hintOpenAuth({ code, platform, content: contentEnum[platform][code] }).then((res) => resolve(res))
35
18
  break
36
19
  default:
37
20
  break
@@ -48,7 +31,7 @@ export function appAuth(code = '相册') {
48
31
  // case 'undetermined': //未请求授权
49
32
  // case 'unknown': //无法查询权限
50
33
  default:
51
- hintOpenAuth({ code, platform, content: MESSAGE[platform][code] }).then((res) => {
34
+ hintOpenAuth({ code, platform, content: contentEnum[platform][code] }).then((res) => {
52
35
  if (!res) return resolve(res)
53
36
  else {
54
37
  //granted通过/deniedPresent临时拒绝/deniedAlways永久拒绝
package/src/util/wx.js CHANGED
@@ -1,4 +1,4 @@
1
- import { hintOpenAuth } from './common.js'
1
+ import { hintOpenAuth } from '../common/index.js'
2
2
 
3
3
  const weixin = {
4
4
  相册: 'scope.writePhotosAlbum',
@@ -1,16 +0,0 @@
1
- export function hintOpenAuth(params = {}) {
2
- const { code, platform = 'android', content = '', isOpenAuth = false } = params || {}
3
- return new Promise((resolve, reject) => {
4
- uni.showModal({
5
- content: content,
6
- showCancel: platform !== 'ios',
7
- cancelText: '拒绝',
8
- confirmText: platform === 'ios' ? '下一步' : '同意',
9
- success: (res) => {
10
- if (!res.confirm) return resolve(false)
11
- resolve(true)
12
- isOpenAuth && uni.openAppAuthorizeSetting()
13
- },
14
- })
15
- })
16
- }