@zfqh/uniapp 0.1.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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/docs/api/apis/core.md +189 -0
- package/docs/api/apis/index.md +82 -0
- package/docs/api/apis/request.md +369 -0
- package/docs/api/configs/api.md +32 -0
- package/docs/api/configs/app.md +43 -0
- package/docs/api/configs/brand.md +43 -0
- package/docs/api/configs/cdn.md +35 -0
- package/docs/api/configs/color.md +144 -0
- package/docs/api/configs/env.md +120 -0
- package/docs/api/configs/index.md +394 -0
- package/docs/api/configs/link.md +33 -0
- package/docs/api/configs/log.md +27 -0
- package/docs/api/configs/mp.md +34 -0
- package/docs/api/configs/navigate.md +27 -0
- package/docs/api/configs/page.md +32 -0
- package/docs/api/configs/path.md +27 -0
- package/docs/api/configs/storage.md +24 -0
- package/docs/api/configs/tabbar.md +29 -0
- package/docs/api/configs/toast.md +35 -0
- package/docs/api/configs/update.md +25 -0
- package/docs/api/configs/upload.md +45 -0
- package/docs/api/configs/ver.md +32 -0
- package/docs/api/configs/web.md +28 -0
- package/docs/api/hooks/index.md +182 -0
- package/docs/api/hooks/useI18n.md +27 -0
- package/docs/api/hooks/useOverlay.md +37 -0
- package/docs/api/hooks/usePopup.md +35 -0
- package/docs/api/hooks/useVersion.md +23 -0
- package/docs/api/index.md +269 -0
- package/docs/api/mixins/app.md +29 -0
- package/docs/api/mixins/badge.md +23 -0
- package/docs/api/mixins/debounce.md +32 -0
- package/docs/api/mixins/deep.md +29 -0
- package/docs/api/mixins/index.md +23 -0
- package/docs/api/mixins/login.md +22 -0
- package/docs/api/mixins/model.md +26 -0
- package/docs/api/mixins/redirect.md +26 -0
- package/docs/api/mixins/share.md +29 -0
- package/docs/api/mixins/show.md +27 -0
- package/docs/api/mixins/webview.md +27 -0
- package/docs/api/modules/app.md +30 -0
- package/docs/api/modules/dict.md +28 -0
- package/docs/api/modules/im.md +22 -0
- package/docs/api/modules/index.md +44 -0
- package/docs/api/modules/launch.md +26 -0
- package/docs/api/modules/location.md +25 -0
- package/docs/api/modules/login.md +35 -0
- package/docs/api/modules/network.md +26 -0
- package/docs/api/modules/system.md +29 -0
- package/docs/api/utils/audio.md +84 -0
- package/docs/api/utils/consts.md +201 -0
- package/docs/api/utils/cos.md +269 -0
- package/docs/api/utils/debounce.md +89 -0
- package/docs/api/utils/file.md +78 -0
- package/docs/api/utils/index.md +547 -0
- package/docs/api/utils/locale.md +32 -0
- package/docs/api/utils/message.md +81 -0
- package/docs/api/utils/navigate.md +267 -0
- package/docs/api/utils/pages.md +205 -0
- package/docs/api/utils/permission.md +28 -0
- package/docs/api/utils/permit.md +62 -0
- package/docs/api/utils/query.md +89 -0
- package/docs/api/utils/request.md +34 -0
- package/docs/api/utils/storage.md +145 -0
- package/docs/api/utils/subscribe.md +77 -0
- package/docs/api/utils/throttle.md +101 -0
- package/docs/api/utils/toast.md +164 -0
- package/docs/api/utils/uni.md +28 -0
- package/docs/api/utils/update.md +165 -0
- package/docs/components/g-back-button.md +76 -0
- package/docs/components/g-checkbox-list.md +101 -0
- package/docs/components/g-container.md +93 -0
- package/docs/components/g-data-list.md +106 -0
- package/docs/components/g-dot-text.md +79 -0
- package/docs/components/g-env.md +75 -0
- package/docs/components/g-float.md +83 -0
- package/docs/components/g-grid-image.md +91 -0
- package/docs/components/g-grid-swiper.md +99 -0
- package/docs/components/g-icon.md +106 -0
- package/docs/components/g-mask.md +82 -0
- package/docs/components/g-money.md +90 -0
- package/docs/components/g-more.md +78 -0
- package/docs/components/g-page-container.md +170 -0
- package/docs/components/g-permission-popup.md +117 -0
- package/docs/components/g-polyline-chat.md +102 -0
- package/docs/components/g-polyline-view.md +67 -0
- package/docs/components/g-popup.md +144 -0
- package/docs/components/g-refresh-view.md +118 -0
- package/docs/components/g-render-image.md +83 -0
- package/docs/components/g-search.md +120 -0
- package/docs/components/g-share-photo.md +77 -0
- package/docs/components/g-share-view.md +83 -0
- package/docs/components/g-share-weixin.md +81 -0
- package/docs/components/g-skeleton-view.md +71 -0
- package/docs/components/g-skeleton.md +64 -0
- package/docs/components/g-tag-editor.md +134 -0
- package/docs/components/g-timer.md +72 -0
- package/docs/components/g-trtc-room.md +116 -0
- package/docs/components/g-trtc-tui.md +84 -0
- package/docs/components/g-trtc.md +124 -0
- package/docs/components/g-upload.md +117 -0
- package/docs/components/g-waterfall.md +84 -0
- package/docs/components/index.md +109 -0
- package/docs/components/styles/base-styles.md +367 -0
- package/docs/components/styles/global-vars.md +150 -0
- package/docs/components/usage.md +112 -0
- package/docs/faq/index.md +78 -0
- package/docs/guide/getting-started.md +195 -0
- package/docs/guide/project-frame.md +297 -0
- package/docs/index.md +80 -0
- package/lib/apis/core.d.ts +12 -0
- package/lib/apis/core.js +13 -0
- package/lib/apis/index.d.ts +2 -0
- package/lib/apis/index.js +2 -0
- package/lib/apis/request.d.ts +4 -0
- package/lib/apis/request.js +27 -0
- package/lib/components/g-back-button/g-back-button.vue +141 -0
- package/lib/components/g-checkbox-list/g-checkbox-list.vue +156 -0
- package/lib/components/g-container/g-container.vue +159 -0
- package/lib/components/g-data-list/g-data-list.vue +192 -0
- package/lib/components/g-dot-text/g-dot-text.vue +114 -0
- package/lib/components/g-env/g-env.vue +123 -0
- package/lib/components/g-float/g-float.vue +131 -0
- package/lib/components/g-grid-image/g-grid-image.vue +84 -0
- package/lib/components/g-grid-swiper/g-grid-swiper.vue +224 -0
- package/lib/components/g-icon/g-icon.vue +72 -0
- package/lib/components/g-mask/g-mask.vue +126 -0
- package/lib/components/g-money/g-money.vue +174 -0
- package/lib/components/g-more/g-more.vue +68 -0
- package/lib/components/g-page-container/g-page-container.vue +470 -0
- package/lib/components/g-permission-popup/g-permission-popup.vue +80 -0
- package/lib/components/g-polyline-chat/g-polyline-chat.vue +255 -0
- package/lib/components/g-polyline-view/g-polyline-view.vue +104 -0
- package/lib/components/g-popup/g-popup.vue +449 -0
- package/lib/components/g-refresh-view/g-refresh-view.vue +213 -0
- package/lib/components/g-render-image/g-render-image.vue +222 -0
- package/lib/components/g-search/g-search.vue +274 -0
- package/lib/components/g-share-photo/g-share-photo.vue +75 -0
- package/lib/components/g-share-view/g-share-view.vue +157 -0
- package/lib/components/g-share-weixin/g-share-weixin.vue +106 -0
- package/lib/components/g-skeleton/g-skeleton.vue +55 -0
- package/lib/components/g-skeleton-view/g-skeleton-view.vue +78 -0
- package/lib/components/g-tag-editor/g-tag-editor.vue +482 -0
- package/lib/components/g-timer/g-timer.vue +61 -0
- package/lib/components/g-trtc/g-trtc.vue +347 -0
- package/lib/components/g-trtc-room/g-trtc-room.vue +524 -0
- package/lib/components/g-trtc-room/iconfont.scss +59 -0
- package/lib/components/g-trtc-tui/g-trtc-tui.vue +245 -0
- package/lib/components/g-upload/g-upload.vue +294 -0
- package/lib/components/g-waterfall/g-waterfall.vue +101 -0
- package/lib/configs/api.d.ts +7 -0
- package/lib/configs/api.js +6 -0
- package/lib/configs/app.d.ts +26 -0
- package/lib/configs/app.js +50 -0
- package/lib/configs/brand.d.ts +22 -0
- package/lib/configs/brand.js +26 -0
- package/lib/configs/cdn.d.ts +13 -0
- package/lib/configs/cdn.js +12 -0
- package/lib/configs/color.d.ts +62 -0
- package/lib/configs/color.js +66 -0
- package/lib/configs/env.d.ts +37 -0
- package/lib/configs/env.js +71 -0
- package/lib/configs/index.d.ts +170 -0
- package/lib/configs/index.js +82 -0
- package/lib/configs/link.d.ts +11 -0
- package/lib/configs/link.js +3 -0
- package/lib/configs/log.d.ts +9 -0
- package/lib/configs/log.js +8 -0
- package/lib/configs/mp.d.ts +15 -0
- package/lib/configs/mp.js +9 -0
- package/lib/configs/navigate.d.ts +17 -0
- package/lib/configs/navigate.js +5 -0
- package/lib/configs/page.d.ts +18 -0
- package/lib/configs/page.js +14 -0
- package/lib/configs/path.d.ts +11 -0
- package/lib/configs/path.js +10 -0
- package/lib/configs/storage.d.ts +7 -0
- package/lib/configs/storage.js +6 -0
- package/lib/configs/tabbar.d.ts +7 -0
- package/lib/configs/tabbar.js +6 -0
- package/lib/configs/toast.d.ts +18 -0
- package/lib/configs/toast.js +29 -0
- package/lib/configs/update.d.ts +45 -0
- package/lib/configs/update.js +6 -0
- package/lib/configs/upload.d.ts +30 -0
- package/lib/configs/upload.js +7 -0
- package/lib/configs/ver.d.ts +8 -0
- package/lib/configs/ver.js +28 -0
- package/lib/configs/web.d.ts +5 -0
- package/lib/configs/web.js +2 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.js +4 -0
- package/lib/hooks/useI18n.d.ts +2 -0
- package/lib/hooks/useI18n.js +19 -0
- package/lib/hooks/useOverlay.d.ts +1 -0
- package/lib/hooks/useOverlay.js +17 -0
- package/lib/hooks/usePopup.d.ts +1 -0
- package/lib/hooks/usePopup.js +14 -0
- package/lib/hooks/useVersion.d.ts +6 -0
- package/lib/hooks/useVersion.js +21 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +33 -0
- package/lib/mixins/app.d.ts +14 -0
- package/lib/mixins/app.js +105 -0
- package/lib/mixins/badge.d.ts +24 -0
- package/lib/mixins/badge.js +44 -0
- package/lib/mixins/debounce.d.ts +6 -0
- package/lib/mixins/debounce.js +11 -0
- package/lib/mixins/deep.d.ts +6 -0
- package/lib/mixins/deep.js +8 -0
- package/lib/mixins/index.d.ts +8 -0
- package/lib/mixins/index.js +8 -0
- package/lib/mixins/login.d.ts +4 -0
- package/lib/mixins/login.js +25 -0
- package/lib/mixins/model.d.ts +22 -0
- package/lib/mixins/model.js +29 -0
- package/lib/mixins/redirect.d.ts +8 -0
- package/lib/mixins/redirect.js +94 -0
- package/lib/mixins/share.d.ts +15 -0
- package/lib/mixins/share.js +55 -0
- package/lib/mixins/show.d.ts +9 -0
- package/lib/mixins/show.js +16 -0
- package/lib/mixins/webview.d.ts +26 -0
- package/lib/mixins/webview.js +225 -0
- package/lib/modules/app.d.ts +5 -0
- package/lib/modules/app.js +19 -0
- package/lib/modules/dict.d.ts +8 -0
- package/lib/modules/dict.js +43 -0
- package/lib/modules/im.d.ts +6 -0
- package/lib/modules/im.js +105 -0
- package/lib/modules/index.d.ts +8 -0
- package/lib/modules/index.js +8 -0
- package/lib/modules/launch.d.ts +5 -0
- package/lib/modules/launch.js +32 -0
- package/lib/modules/location.d.ts +5 -0
- package/lib/modules/location.js +57 -0
- package/lib/modules/login.d.ts +5 -0
- package/lib/modules/login.js +72 -0
- package/lib/modules/network.d.ts +5 -0
- package/lib/modules/network.js +39 -0
- package/lib/modules/system.d.ts +5 -0
- package/lib/modules/system.js +65 -0
- package/lib/styles/animate-vue.scss +3 -0
- package/lib/styles/animate.scss +27 -0
- package/lib/styles/bg-vue.scss +21 -0
- package/lib/styles/bg.scss +93 -0
- package/lib/styles/border.scss +218 -0
- package/lib/styles/flex-nvue.scss +64 -0
- package/lib/styles/flex-vue.scss +75 -0
- package/lib/styles/font.scss +59 -0
- package/lib/styles/index.scss +25 -0
- package/lib/styles/layout-nvue.scss +24 -0
- package/lib/styles/layout-vue.scss +30 -0
- package/lib/styles/layout.scss +76 -0
- package/lib/styles/opacity.scss +10 -0
- package/lib/styles/reset-vue.scss +46 -0
- package/lib/styles/shadow.scss +12 -0
- package/lib/styles/sizing-vue.scss +21 -0
- package/lib/styles/sizing.scss +21 -0
- package/lib/styles/spacing.scss +234 -0
- package/lib/styles/text-nvue.scss +21 -0
- package/lib/styles/text-vue.scss +70 -0
- package/lib/styles/text.scss +122 -0
- package/lib/styles/var.module.scss +29 -0
- package/lib/utils/audio.d.ts +14 -0
- package/lib/utils/audio.js +43 -0
- package/lib/utils/consts.d.ts +30 -0
- package/lib/utils/consts.js +52 -0
- package/lib/utils/cos.d.ts +15 -0
- package/lib/utils/cos.js +140 -0
- package/lib/utils/debounce.d.ts +2 -0
- package/lib/utils/debounce.js +30 -0
- package/lib/utils/file.d.ts +28 -0
- package/lib/utils/file.js +292 -0
- package/lib/utils/index.d.ts +166 -0
- package/lib/utils/index.js +485 -0
- package/lib/utils/locale.d.ts +6 -0
- package/lib/utils/locale.js +19 -0
- package/lib/utils/message.d.ts +9 -0
- package/lib/utils/message.js +63 -0
- package/lib/utils/navigate.d.ts +27 -0
- package/lib/utils/navigate.js +183 -0
- package/lib/utils/pages.d.ts +21 -0
- package/lib/utils/pages.js +79 -0
- package/lib/utils/permission.d.ts +16 -0
- package/lib/utils/permission.js +291 -0
- package/lib/utils/permit.d.ts +30 -0
- package/lib/utils/permit.js +181 -0
- package/lib/utils/query.d.ts +13 -0
- package/lib/utils/query.js +14 -0
- package/lib/utils/request.d.ts +8 -0
- package/lib/utils/request.js +126 -0
- package/lib/utils/storage.d.ts +53 -0
- package/lib/utils/storage.js +145 -0
- package/lib/utils/subscribe.d.ts +7 -0
- package/lib/utils/subscribe.js +94 -0
- package/lib/utils/throttle.d.ts +2 -0
- package/lib/utils/throttle.js +32 -0
- package/lib/utils/toast.d.ts +17 -0
- package/lib/utils/toast.js +66 -0
- package/lib/utils/uni.d.ts +1 -0
- package/lib/utils/uni.js +147 -0
- package/lib/utils/update.d.ts +9 -0
- package/lib/utils/update.js +376 -0
- package/package.json +49 -0
- package/types/index.d.ts +25 -0
- package/types/virtual.d.ts +1 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import color from '../configs/color';
|
|
2
|
+
import { SYSTEM_INFO } from './consts';
|
|
3
|
+
// #ifdef APP
|
|
4
|
+
import permission from './permission';
|
|
5
|
+
// #endif
|
|
6
|
+
const permissionData = {
|
|
7
|
+
location: {
|
|
8
|
+
// #ifdef APP
|
|
9
|
+
id: 'android.permission.ACCESS_FINE_LOCATION',
|
|
10
|
+
system: '检测到系统未开启定位',
|
|
11
|
+
// #endif
|
|
12
|
+
content: '我们需要获取您的定位权限,用于城市定位、地址获取、位置获取,发现附近设备等服务',
|
|
13
|
+
},
|
|
14
|
+
storage: {
|
|
15
|
+
// #ifdef APP
|
|
16
|
+
id: 'android.permission.WRITE_EXTERNAL_STORAGE',
|
|
17
|
+
system: '',
|
|
18
|
+
// #endif
|
|
19
|
+
content: '我们需要获取您的文件存储权限,用于设置头像、保存图片、上传文件、发布内容等服务',
|
|
20
|
+
},
|
|
21
|
+
camera: {
|
|
22
|
+
// #ifdef APP
|
|
23
|
+
id: 'android.permission.CAMERA',
|
|
24
|
+
system: '',
|
|
25
|
+
// #endif
|
|
26
|
+
content: '我们需要获取您的相机权限,用于拍摄照片、录制视频、视频通话、扫码识别、发布内容等服务',
|
|
27
|
+
},
|
|
28
|
+
record: {
|
|
29
|
+
// #ifdef APP
|
|
30
|
+
id: 'android.permission.RECORD_AUDIO',
|
|
31
|
+
system: '',
|
|
32
|
+
// #endif
|
|
33
|
+
content: '我们需要获取您的麦克风权限,用于录制语音、语音通话,发布内容等服务',
|
|
34
|
+
},
|
|
35
|
+
bluetooth: {
|
|
36
|
+
// #ifdef APP
|
|
37
|
+
id: plus?.android?.importClass('android.os.Build')?.['VERSION']?.['SDK_INT'] >= 31
|
|
38
|
+
? ['android.permission.BLUETOOTH_SCAN', 'android.permission.BLUETOOTH_CONNECT']
|
|
39
|
+
: 'android.permission.BLUETOOTH',
|
|
40
|
+
system: '检测到系统未开启蓝牙',
|
|
41
|
+
// #endif
|
|
42
|
+
content: '我们需要获取您的蓝牙权限,用于数据传输、设备配对、发现附近设备等服务',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
// #ifdef APP
|
|
46
|
+
const requestAndroidPermission = async (name) => {
|
|
47
|
+
const data = permissionData[name];
|
|
48
|
+
let res = null;
|
|
49
|
+
if (data) {
|
|
50
|
+
uni.showAppFromBackground = false;
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
// 500毫秒内permission.requestAndroidPermission未响应结果,说明系统弹出授权框,此时在顶部显示授权文案
|
|
53
|
+
if (res == null) {
|
|
54
|
+
uni.$emit('requestPermission', data);
|
|
55
|
+
}
|
|
56
|
+
}, 500);
|
|
57
|
+
res = await permission.requestAndroidPermission(data.id);
|
|
58
|
+
uni.$emit('requestPermission', null);
|
|
59
|
+
}
|
|
60
|
+
return res;
|
|
61
|
+
};
|
|
62
|
+
// #endif
|
|
63
|
+
// #ifdef MP
|
|
64
|
+
const requestMpPermission = async (scope) => {
|
|
65
|
+
return await new Promise((res) => {
|
|
66
|
+
uni.authorize({
|
|
67
|
+
scope,
|
|
68
|
+
success() {
|
|
69
|
+
res(1);
|
|
70
|
+
},
|
|
71
|
+
fail() {
|
|
72
|
+
res(0);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
// #endif
|
|
78
|
+
export function openAuthorizeSetting(name) {
|
|
79
|
+
// #ifdef APP
|
|
80
|
+
if (SYSTEM_INFO.platform == 'ios') {
|
|
81
|
+
plus.runtime.openURL('app-settings://');
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const main = plus.android.runtimeMainActivity();
|
|
85
|
+
const Intent = plus.android.importClass('android.content.Intent');
|
|
86
|
+
const Settings = plus.android.importClass('android.provider.Settings');
|
|
87
|
+
let intent = null;
|
|
88
|
+
if (name === 'location') {
|
|
89
|
+
intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
90
|
+
}
|
|
91
|
+
else if (name === 'bluetooth') {
|
|
92
|
+
intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
|
|
93
|
+
}
|
|
94
|
+
if (intent) {
|
|
95
|
+
main.startActivity(intent);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// #endif
|
|
99
|
+
// #ifdef MP
|
|
100
|
+
uni.openAppAuthorizeSetting();
|
|
101
|
+
// #endif
|
|
102
|
+
}
|
|
103
|
+
export async function requestPermission(name, system = true) {
|
|
104
|
+
let result = 1;
|
|
105
|
+
// #ifdef MP
|
|
106
|
+
switch (name) {
|
|
107
|
+
case 'location': {
|
|
108
|
+
result = await requestMpPermission('scope.userLocation');
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'storage': {
|
|
112
|
+
result = await requestMpPermission('scope.userLocation');
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case 'bluetooth': {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
default: {
|
|
119
|
+
result = await requestMpPermission(`scope.${name}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// #endif
|
|
123
|
+
// #ifdef APP
|
|
124
|
+
if (SYSTEM_INFO.platform === 'android') {
|
|
125
|
+
result = await requestAndroidPermission(name);
|
|
126
|
+
}
|
|
127
|
+
else if (SYSTEM_INFO.platform === 'ios') {
|
|
128
|
+
}
|
|
129
|
+
if (system && result > 0) {
|
|
130
|
+
switch (name) {
|
|
131
|
+
case 'location': {
|
|
132
|
+
const enabled = await permission.checkSystemEnableLocation();
|
|
133
|
+
if (!enabled) {
|
|
134
|
+
result = -2;
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case 'bluetooth': {
|
|
139
|
+
const enabled = await permission.checkSystemEnableBluetooth();
|
|
140
|
+
if (!enabled) {
|
|
141
|
+
result = -2;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// #endif
|
|
147
|
+
if (result <= 0) {
|
|
148
|
+
const { content, system } = permissionData[name];
|
|
149
|
+
uni.showModal({
|
|
150
|
+
title: '提示',
|
|
151
|
+
content: `${result === -2 ? system : `${content},检测到应用未开启权限`},是否开启?`,
|
|
152
|
+
confirmText: '去开启',
|
|
153
|
+
cancelText: '取消',
|
|
154
|
+
confirmColor: color.primary,
|
|
155
|
+
cancelColor: color.tipsColor,
|
|
156
|
+
success: (res) => {
|
|
157
|
+
if (res.confirm) {
|
|
158
|
+
try {
|
|
159
|
+
// #ifdef MP
|
|
160
|
+
uni.openSetting();
|
|
161
|
+
// #endif
|
|
162
|
+
// #ifdef APP
|
|
163
|
+
uni.showAppFromBackground = false;
|
|
164
|
+
// app开启权限,系统没有开启
|
|
165
|
+
if (result === -2) {
|
|
166
|
+
openAuthorizeSetting(name);
|
|
167
|
+
// 系统开启权限,app没有开启
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
uni.openAppAuthorizeSetting();
|
|
171
|
+
}
|
|
172
|
+
// #endif
|
|
173
|
+
}
|
|
174
|
+
catch (e) { }
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
return Promise.reject(0);
|
|
179
|
+
}
|
|
180
|
+
return Promise.resolve(1);
|
|
181
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Query {
|
|
2
|
+
platform?: string;
|
|
3
|
+
token?: string;
|
|
4
|
+
primary?: string;
|
|
5
|
+
brand?: string;
|
|
6
|
+
app?: string;
|
|
7
|
+
safeBottom?: string | number;
|
|
8
|
+
tabbar?: string | number;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
declare const query: Query;
|
|
12
|
+
export declare function parseQuery(search?: string): Query;
|
|
13
|
+
export default query;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const query = {};
|
|
2
|
+
export function parseQuery(search = '') {
|
|
3
|
+
search = decodeURIComponent(search);
|
|
4
|
+
const q = {};
|
|
5
|
+
search.split('&').forEach((value) => {
|
|
6
|
+
const [key, val] = value.split('=');
|
|
7
|
+
q[key] = val;
|
|
8
|
+
});
|
|
9
|
+
return q;
|
|
10
|
+
}
|
|
11
|
+
// #ifdef H5
|
|
12
|
+
Object.assign(query, parseQuery(location.search.substring(1)));
|
|
13
|
+
// #endif
|
|
14
|
+
export default query;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function formatURL(url: any, data: any): string;
|
|
2
|
+
export declare function createInterceptors(req: any): void;
|
|
3
|
+
export declare function createRequest(req: any, opts?: {}): {
|
|
4
|
+
GET: (url: any, data?: {}, options?: {}) => any;
|
|
5
|
+
DELETE: (url: any, data?: {}, options?: {}) => any;
|
|
6
|
+
POST: (url: any, data?: {}, options?: {}) => any;
|
|
7
|
+
PUT: (url: any, data?: {}, options?: {}) => any;
|
|
8
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import log from '../configs/log';
|
|
2
|
+
import toast from './toast';
|
|
3
|
+
import Throttle from './throttle';
|
|
4
|
+
const throttle = new Throttle();
|
|
5
|
+
export function formatURL(url, data) {
|
|
6
|
+
let newUrl = '';
|
|
7
|
+
// 匹配动态参数
|
|
8
|
+
if (/(\/?:\w+)/.test(url)) {
|
|
9
|
+
url.split(/(\/?:\w+)/).forEach((path) => {
|
|
10
|
+
if (/^\/?:/.test(path)) {
|
|
11
|
+
const index = path.startsWith('/:') ? 2 : 1;
|
|
12
|
+
const key = path.substr(index);
|
|
13
|
+
newUrl += data[key] !== undefined ? `${index === 2 ? '/' : ''}${data[key]}` : '';
|
|
14
|
+
delete data[key];
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
newUrl += path;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
newUrl = url;
|
|
23
|
+
}
|
|
24
|
+
return newUrl;
|
|
25
|
+
}
|
|
26
|
+
function responseReject(response) {
|
|
27
|
+
const { data, status, config } = response;
|
|
28
|
+
if (status === 401) {
|
|
29
|
+
const { reLogin, needLogin } = config?.custom || {};
|
|
30
|
+
if (reLogin !== false && needLogin !== false && uni.$store != null) {
|
|
31
|
+
throttle.exec(() => {
|
|
32
|
+
if (uni.$store.state.login?.info?.token != null) {
|
|
33
|
+
const { message, msg } = data;
|
|
34
|
+
if (message || msg) {
|
|
35
|
+
toast.message(message || msg);
|
|
36
|
+
}
|
|
37
|
+
uni.$store.dispatch('logout');
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
if (config?.custom?.message !== false) {
|
|
44
|
+
const { message, msg } = data;
|
|
45
|
+
if (message || msg) {
|
|
46
|
+
toast.message(message || msg);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return Promise.reject(response);
|
|
51
|
+
}
|
|
52
|
+
export function createInterceptors(req) {
|
|
53
|
+
req.interceptors.request.use((config) => {
|
|
54
|
+
if (log.request) {
|
|
55
|
+
console.log(`Request URL:${config.baseURL}${config.url}`);
|
|
56
|
+
console.log(config);
|
|
57
|
+
}
|
|
58
|
+
const header = {};
|
|
59
|
+
if (uni.$store) {
|
|
60
|
+
const loginInfo = uni.$store.state.login?.info;
|
|
61
|
+
const { token } = loginInfo || {};
|
|
62
|
+
if (token) {
|
|
63
|
+
header.Authorization = `Bearer ${token}`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
config.header = {
|
|
67
|
+
...header,
|
|
68
|
+
...config.header,
|
|
69
|
+
};
|
|
70
|
+
return config;
|
|
71
|
+
});
|
|
72
|
+
req.interceptors.response.use((response) => {
|
|
73
|
+
const { data, config } = response;
|
|
74
|
+
if (log.response) {
|
|
75
|
+
console.log(`Response URL:${config.baseURL}${config.url}`);
|
|
76
|
+
console.log(data);
|
|
77
|
+
}
|
|
78
|
+
if (data.code != 0) {
|
|
79
|
+
response.status = data.code;
|
|
80
|
+
return responseReject(response);
|
|
81
|
+
}
|
|
82
|
+
return data;
|
|
83
|
+
}, (error) => {
|
|
84
|
+
if (!error?.response) {
|
|
85
|
+
const { config, data, errMsg, status, statusCode } = error;
|
|
86
|
+
const code = data?.code || statusCode || status || 404;
|
|
87
|
+
const msg = data?.message || data?.msg || data?.error || errMsg;
|
|
88
|
+
error.response = {
|
|
89
|
+
config,
|
|
90
|
+
data: {
|
|
91
|
+
msg,
|
|
92
|
+
code,
|
|
93
|
+
},
|
|
94
|
+
status: code,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (log.response) {
|
|
98
|
+
console.log('Response Error:', error.response);
|
|
99
|
+
}
|
|
100
|
+
return responseReject(error.response);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export function createRequest(req, opts = {}) {
|
|
104
|
+
const GET = (url, data = {}, options = {}) => {
|
|
105
|
+
url = formatURL(url, data);
|
|
106
|
+
return req.get(url, { params: data, ...opts, ...options });
|
|
107
|
+
};
|
|
108
|
+
const DELETE = (url, data = {}, options = {}) => {
|
|
109
|
+
url = formatURL(url, data);
|
|
110
|
+
return req.delete(url, data, { ...opts, ...options });
|
|
111
|
+
};
|
|
112
|
+
const POST = (url, data = {}, options = {}) => {
|
|
113
|
+
url = formatURL(url, data);
|
|
114
|
+
return req.post(url, data, { ...opts, ...options });
|
|
115
|
+
};
|
|
116
|
+
const PUT = (url, data = {}, options = {}) => {
|
|
117
|
+
url = formatURL(url, data);
|
|
118
|
+
return req.put(url, data, { ...opts, ...options });
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
GET,
|
|
122
|
+
DELETE,
|
|
123
|
+
POST,
|
|
124
|
+
PUT,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 同步获取本地缓存
|
|
3
|
+
* @param name 键名
|
|
4
|
+
*/
|
|
5
|
+
export declare function getStorageSync(name: string): any;
|
|
6
|
+
/**
|
|
7
|
+
* 异步获取本地缓存
|
|
8
|
+
* @param name 键名
|
|
9
|
+
*/
|
|
10
|
+
export declare function getStorage(name: string): Promise<unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* 同步设置本地缓存
|
|
13
|
+
* @param name 键名
|
|
14
|
+
* @param data 值
|
|
15
|
+
*/
|
|
16
|
+
export declare function setStorageSync(name: string, data: any): void;
|
|
17
|
+
/**
|
|
18
|
+
* 异步设置本地缓存
|
|
19
|
+
* @param name 键名
|
|
20
|
+
* @param data 值
|
|
21
|
+
*/
|
|
22
|
+
export declare function setStorage(name: string, data: any): Promise<unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* 同步删除本地缓存
|
|
25
|
+
* @param name 键名
|
|
26
|
+
*/
|
|
27
|
+
export declare function removeStorageSync(name: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* 异步删除本地缓存
|
|
30
|
+
* @param name 键名
|
|
31
|
+
*/
|
|
32
|
+
export declare function removeStorage(name: string): Promise<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* 同步删除全部本地缓存
|
|
35
|
+
*/
|
|
36
|
+
export declare function clearStorageSync(): void;
|
|
37
|
+
/**
|
|
38
|
+
* 异步删除全部本地缓存
|
|
39
|
+
*/
|
|
40
|
+
export declare function clearStorage(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* 设置缓存Key
|
|
43
|
+
*/
|
|
44
|
+
export declare function setStorageKeys<T>(data: T): T;
|
|
45
|
+
export interface StorageKeys {
|
|
46
|
+
query: string;
|
|
47
|
+
login: string;
|
|
48
|
+
user: string;
|
|
49
|
+
open: string;
|
|
50
|
+
launch: string;
|
|
51
|
+
location: string;
|
|
52
|
+
}
|
|
53
|
+
export declare const storageKeys: StorageKeys;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import env from '../configs/env';
|
|
2
|
+
import storage from '../configs/storage';
|
|
3
|
+
const getKey = (name) => {
|
|
4
|
+
const key = [];
|
|
5
|
+
if (storage.prefix) {
|
|
6
|
+
key.push(storage.prefix);
|
|
7
|
+
}
|
|
8
|
+
if (env.name !== 'prod') {
|
|
9
|
+
key.push(env.name);
|
|
10
|
+
}
|
|
11
|
+
if (name) {
|
|
12
|
+
key.push(name);
|
|
13
|
+
}
|
|
14
|
+
return key.join('_').toUpperCase();
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 同步获取本地缓存
|
|
18
|
+
* @param name 键名
|
|
19
|
+
*/
|
|
20
|
+
export function getStorageSync(name) {
|
|
21
|
+
try {
|
|
22
|
+
const key = getKey(name);
|
|
23
|
+
return uni.getStorageSync(key);
|
|
24
|
+
}
|
|
25
|
+
catch (e) { }
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 异步获取本地缓存
|
|
29
|
+
* @param name 键名
|
|
30
|
+
*/
|
|
31
|
+
export function getStorage(name) {
|
|
32
|
+
const key = getKey(name);
|
|
33
|
+
return new Promise((res, rej) => {
|
|
34
|
+
uni.getStorage({
|
|
35
|
+
key,
|
|
36
|
+
success(e) {
|
|
37
|
+
res(e);
|
|
38
|
+
},
|
|
39
|
+
fail(e) {
|
|
40
|
+
rej(e);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 同步设置本地缓存
|
|
47
|
+
* @param name 键名
|
|
48
|
+
* @param data 值
|
|
49
|
+
*/
|
|
50
|
+
export function setStorageSync(name, data) {
|
|
51
|
+
try {
|
|
52
|
+
const key = getKey(name);
|
|
53
|
+
uni.setStorageSync(key, data);
|
|
54
|
+
}
|
|
55
|
+
catch (e) { }
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 异步设置本地缓存
|
|
59
|
+
* @param name 键名
|
|
60
|
+
* @param data 值
|
|
61
|
+
*/
|
|
62
|
+
export function setStorage(name, data) {
|
|
63
|
+
const key = getKey(name);
|
|
64
|
+
return new Promise((res, rej) => {
|
|
65
|
+
uni.setStorage({
|
|
66
|
+
key,
|
|
67
|
+
data,
|
|
68
|
+
success(e) {
|
|
69
|
+
res(e);
|
|
70
|
+
},
|
|
71
|
+
fail(e) {
|
|
72
|
+
rej(e);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 同步删除本地缓存
|
|
79
|
+
* @param name 键名
|
|
80
|
+
*/
|
|
81
|
+
export function removeStorageSync(name) {
|
|
82
|
+
try {
|
|
83
|
+
const key = getKey(name);
|
|
84
|
+
uni.removeStorageSync(key);
|
|
85
|
+
}
|
|
86
|
+
catch (e) { }
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 异步删除本地缓存
|
|
90
|
+
* @param name 键名
|
|
91
|
+
*/
|
|
92
|
+
export function removeStorage(name) {
|
|
93
|
+
const key = getKey(name);
|
|
94
|
+
return new Promise((res, rej) => {
|
|
95
|
+
uni.removeStorage({
|
|
96
|
+
key,
|
|
97
|
+
success(e) {
|
|
98
|
+
res(e);
|
|
99
|
+
},
|
|
100
|
+
fail(e) {
|
|
101
|
+
rej(e);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 同步删除全部本地缓存
|
|
108
|
+
*/
|
|
109
|
+
export function clearStorageSync() {
|
|
110
|
+
try {
|
|
111
|
+
uni.clearStorageSync();
|
|
112
|
+
}
|
|
113
|
+
catch (e) { }
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 异步删除全部本地缓存
|
|
117
|
+
*/
|
|
118
|
+
export function clearStorage() {
|
|
119
|
+
return new Promise((res, rej) => {
|
|
120
|
+
try {
|
|
121
|
+
uni.clearStorage();
|
|
122
|
+
res();
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
rej(e);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 设置缓存Key
|
|
131
|
+
*/
|
|
132
|
+
export function setStorageKeys(data) {
|
|
133
|
+
Object.keys(data).forEach((key) => {
|
|
134
|
+
data[key] = key;
|
|
135
|
+
});
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
export const storageKeys = setStorageKeys({
|
|
139
|
+
query: '',
|
|
140
|
+
login: '',
|
|
141
|
+
user: '',
|
|
142
|
+
open: '',
|
|
143
|
+
launch: '',
|
|
144
|
+
location: '',
|
|
145
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type SubscribeCallback = (key: string) => void;
|
|
2
|
+
interface SubscribeTemplate {
|
|
3
|
+
title: string;
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function subscribeMessage(data?: string[] | SubscribeTemplate[], acceptCallback?: SubscribeCallback, rejectCallback?: SubscribeCallback): Promise<number>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import color from '../configs/color';
|
|
2
|
+
// 订阅消息
|
|
3
|
+
export function subscribeMessage(data = [], acceptCallback, rejectCallback) {
|
|
4
|
+
const tmplIds = data
|
|
5
|
+
?.map((id) => {
|
|
6
|
+
if (typeof id === 'string') {
|
|
7
|
+
return id;
|
|
8
|
+
}
|
|
9
|
+
return id?.id;
|
|
10
|
+
})
|
|
11
|
+
?.filter((e) => !!e);
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
// #ifdef MP-WEIXIN
|
|
14
|
+
uni.getSetting({
|
|
15
|
+
withSubscriptions: true,
|
|
16
|
+
success(res) {
|
|
17
|
+
let content = '';
|
|
18
|
+
let list = [];
|
|
19
|
+
if (!res.subscriptionsSetting?.mainSwitch) {
|
|
20
|
+
content = '消息通知权限已关闭,不开启将无法收到系统推送消息,请前往通知管理勾选“接收通知”开启?';
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const settings = res.subscriptionsSetting?.itemSettings;
|
|
24
|
+
if (settings) {
|
|
25
|
+
list = data?.filter((e) => {
|
|
26
|
+
if (e && typeof e === 'object') {
|
|
27
|
+
return e['id'] && e['title'] && settings[e['id']] === 'reject';
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
});
|
|
31
|
+
if (list?.length) {
|
|
32
|
+
content = `${list.map((e) => `“${e['title']}”`).join('')}权限已关闭,不开启将无法收到系统推送消息,请前往通知管理选择“接收并提醒”开启?`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (content) {
|
|
37
|
+
uni.showModal({
|
|
38
|
+
content,
|
|
39
|
+
confirmColor: color.primary,
|
|
40
|
+
confirmText: '去开启',
|
|
41
|
+
cancelText: '暂不开启',
|
|
42
|
+
success({ confirm }) {
|
|
43
|
+
if (confirm) {
|
|
44
|
+
uni.openSetting();
|
|
45
|
+
if (list?.length) {
|
|
46
|
+
resolve(0);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
reject();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
resolve(0);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
fail() {
|
|
57
|
+
resolve(0);
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else if (tmplIds?.length) {
|
|
62
|
+
uni.requestSubscribeMessage({
|
|
63
|
+
tmplIds,
|
|
64
|
+
success(e) {
|
|
65
|
+
Object.keys(e).forEach((key) => {
|
|
66
|
+
const val = e[key];
|
|
67
|
+
if (val === 'accept' && typeof acceptCallback === 'function') {
|
|
68
|
+
acceptCallback(key);
|
|
69
|
+
}
|
|
70
|
+
if (val === 'reject' && typeof rejectCallback === 'function') {
|
|
71
|
+
rejectCallback(key);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
resolve(1);
|
|
75
|
+
},
|
|
76
|
+
fail() {
|
|
77
|
+
resolve(0);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
resolve(0);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
fail() {
|
|
86
|
+
resolve(0);
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
// #endif
|
|
90
|
+
// #ifndef MP-WEIXIN
|
|
91
|
+
resolve(0);
|
|
92
|
+
// #endif
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default function Throttle() {
|
|
2
|
+
this.throttling = false;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* @function 节流
|
|
6
|
+
* @param {Function} func 要执行的回调函数
|
|
7
|
+
* @param {Number} wait 延时的时间
|
|
8
|
+
* @param {Boolean} immediate 是否立即执行
|
|
9
|
+
*/
|
|
10
|
+
Throttle.prototype.exec = function (func, wait = 500, immediate = true) {
|
|
11
|
+
if (immediate) {
|
|
12
|
+
if (!this.throttling) {
|
|
13
|
+
this.throttling = true;
|
|
14
|
+
// 如果是立即执行,则在wait毫秒内开始时执行
|
|
15
|
+
typeof func === 'function' && func();
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
this.throttling = false;
|
|
18
|
+
}, wait);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (!this.throttling) {
|
|
23
|
+
this.throttling = true;
|
|
24
|
+
// 如果是非立即执行,则在wait毫秒内的结束处执行
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
this.throttling = false;
|
|
27
|
+
typeof func === 'function' && func();
|
|
28
|
+
}, wait);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const throttle = new Throttle();
|