@zfqh/uniapp-x 0.0.0-stage → 0.0.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.
Files changed (130) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +21 -0
  3. package/README.md +61 -3
  4. package/lib/apis/core.d.ts +18 -0
  5. package/lib/apis/core.js +19 -0
  6. package/lib/apis/index.d.ts +2 -0
  7. package/lib/apis/index.js +2 -0
  8. package/lib/apis/request.d.ts +4 -0
  9. package/lib/apis/request.js +57 -0
  10. package/lib/configs/api.d.ts +7 -0
  11. package/lib/configs/api.js +6 -0
  12. package/lib/configs/app.d.ts +20 -0
  13. package/lib/configs/app.js +18 -0
  14. package/lib/configs/cdn.d.ts +15 -0
  15. package/lib/configs/cdn.js +17 -0
  16. package/lib/configs/env.d.ts +37 -0
  17. package/lib/configs/env.js +71 -0
  18. package/lib/configs/index.d.ts +130 -0
  19. package/lib/configs/index.js +76 -0
  20. package/lib/configs/link.d.ts +11 -0
  21. package/lib/configs/link.js +3 -0
  22. package/lib/configs/log.d.ts +9 -0
  23. package/lib/configs/log.js +8 -0
  24. package/lib/configs/mp.d.ts +15 -0
  25. package/lib/configs/mp.js +9 -0
  26. package/lib/configs/navigate.d.ts +17 -0
  27. package/lib/configs/navigate.js +5 -0
  28. package/lib/configs/page.d.ts +18 -0
  29. package/lib/configs/page.js +14 -0
  30. package/lib/configs/path.d.ts +11 -0
  31. package/lib/configs/path.js +10 -0
  32. package/lib/configs/storage.d.ts +7 -0
  33. package/lib/configs/storage.js +6 -0
  34. package/lib/configs/tabbar.d.ts +7 -0
  35. package/lib/configs/tabbar.js +6 -0
  36. package/lib/configs/toast.d.ts +18 -0
  37. package/lib/configs/toast.js +29 -0
  38. package/lib/configs/updater.d.ts +15 -0
  39. package/lib/configs/updater.js +33 -0
  40. package/lib/configs/upload.d.ts +30 -0
  41. package/lib/configs/upload.js +19 -0
  42. package/lib/configs/ver.d.ts +8 -0
  43. package/lib/configs/ver.js +28 -0
  44. package/lib/configs/web.d.ts +5 -0
  45. package/lib/configs/web.js +2 -0
  46. package/lib/hooks/index.d.ts +11 -0
  47. package/lib/hooks/index.js +11 -0
  48. package/lib/hooks/useAppLifecycle.d.ts +8 -0
  49. package/lib/hooks/useAppLifecycle.js +87 -0
  50. package/lib/hooks/useBadge.d.ts +8 -0
  51. package/lib/hooks/useBadge.js +47 -0
  52. package/lib/hooks/useNeedLogin.d.ts +1 -0
  53. package/lib/hooks/useNeedLogin.js +27 -0
  54. package/lib/hooks/useOverlay.d.ts +1 -0
  55. package/lib/hooks/useOverlay.js +17 -0
  56. package/lib/hooks/usePageShow.d.ts +2 -0
  57. package/lib/hooks/usePageShow.js +16 -0
  58. package/lib/hooks/usePopup.d.ts +1 -0
  59. package/lib/hooks/usePopup.js +14 -0
  60. package/lib/hooks/useRedirect.d.ts +5 -0
  61. package/lib/hooks/useRedirect.js +92 -0
  62. package/lib/hooks/useReferrer.d.ts +1 -0
  63. package/lib/hooks/useReferrer.js +11 -0
  64. package/lib/hooks/useShare.d.ts +12 -0
  65. package/lib/hooks/useShare.js +49 -0
  66. package/lib/hooks/useVersion.d.ts +6 -0
  67. package/lib/hooks/useVersion.js +21 -0
  68. package/lib/hooks/useWebview.d.ts +14 -0
  69. package/lib/hooks/useWebview.js +294 -0
  70. package/lib/index.d.ts +27 -0
  71. package/lib/index.js +26 -0
  72. package/lib/stores/app.d.ts +51 -0
  73. package/lib/stores/app.js +57 -0
  74. package/lib/stores/dict.d.ts +35 -0
  75. package/lib/stores/dict.js +42 -0
  76. package/lib/stores/im.d.ts +57 -0
  77. package/lib/stores/im.js +102 -0
  78. package/lib/stores/index.d.ts +12 -0
  79. package/lib/stores/index.js +17 -0
  80. package/lib/stores/launch.d.ts +42 -0
  81. package/lib/stores/launch.js +39 -0
  82. package/lib/stores/location.d.ts +35 -0
  83. package/lib/stores/location.js +58 -0
  84. package/lib/stores/login.d.ts +80 -0
  85. package/lib/stores/login.js +91 -0
  86. package/lib/stores/network.d.ts +26 -0
  87. package/lib/stores/network.js +45 -0
  88. package/lib/stores/pinia.d.ts +2 -0
  89. package/lib/stores/pinia.js +3 -0
  90. package/lib/stores/system.d.ts +39 -0
  91. package/lib/stores/system.js +36 -0
  92. package/lib/styles/index.scss +9 -0
  93. package/lib/styles/reset-vue.scss +15 -0
  94. package/lib/utils/audio.d.ts +14 -0
  95. package/lib/utils/audio.js +43 -0
  96. package/lib/utils/consts.d.ts +74 -0
  97. package/lib/utils/consts.js +110 -0
  98. package/lib/utils/cos.d.ts +17 -0
  99. package/lib/utils/cos.js +141 -0
  100. package/lib/utils/file.d.ts +28 -0
  101. package/lib/utils/file.js +292 -0
  102. package/lib/utils/index.d.ts +166 -0
  103. package/lib/utils/index.js +486 -0
  104. package/lib/utils/message.d.ts +1 -0
  105. package/lib/utils/message.js +55 -0
  106. package/lib/utils/navigate.d.ts +28 -0
  107. package/lib/utils/navigate.js +192 -0
  108. package/lib/utils/pages.d.ts +21 -0
  109. package/lib/utils/pages.js +83 -0
  110. package/lib/utils/permission.d.ts +17 -0
  111. package/lib/utils/permission.js +278 -0
  112. package/lib/utils/query.d.ts +20 -0
  113. package/lib/utils/query.js +51 -0
  114. package/lib/utils/request.d.ts +8 -0
  115. package/lib/utils/request.js +139 -0
  116. package/lib/utils/storage.d.ts +40 -0
  117. package/lib/utils/storage.js +128 -0
  118. package/lib/utils/subscribe.d.ts +7 -0
  119. package/lib/utils/subscribe.js +94 -0
  120. package/lib/utils/toast.d.ts +17 -0
  121. package/lib/utils/toast.js +66 -0
  122. package/lib/utils/uni.d.ts +1 -0
  123. package/lib/utils/uni.js +141 -0
  124. package/lib/utils/update.d.ts +41 -0
  125. package/lib/utils/update.js +322 -0
  126. package/lib/utils/url.d.ts +14 -0
  127. package/lib/utils/url.js +40 -0
  128. package/package.json +38 -4
  129. package/types/index.d.ts +78 -0
  130. package/types/virtual.d.ts +1 -0
@@ -0,0 +1,139 @@
1
+ import throttle from '@zfqh/uview-x/utils/throttle';
2
+ import log from '../configs/log';
3
+ import toast from './toast';
4
+ import { pinia } from '../stores/pinia';
5
+ import { useLoginStore } from '../stores/login';
6
+ export function formatURL(url, data) {
7
+ let newUrl = '';
8
+ // 匹配动态参数
9
+ if (/(\/?:\w+)/.test(url)) {
10
+ url.split(/(\/?:\w+)/).forEach((path) => {
11
+ if (/^\/?:/.test(path)) {
12
+ const index = path.startsWith('/:') ? 2 : 1;
13
+ const key = path.substr(index);
14
+ newUrl += data[key] !== undefined ? `${index === 2 ? '/' : ''}${data[key]}` : '';
15
+ delete data[key];
16
+ }
17
+ else {
18
+ newUrl += path;
19
+ }
20
+ });
21
+ }
22
+ else {
23
+ newUrl = url;
24
+ }
25
+ return newUrl;
26
+ }
27
+ function responseReject(response) {
28
+ const { data, status, config } = response;
29
+ if (status === 401) {
30
+ const { reLogin, needLogin } = config?.custom || {};
31
+ const loginStore = useLoginStore(pinia);
32
+ if (reLogin !== false && needLogin !== false && loginStore.state.accessToken != null) {
33
+ throttle(() => {
34
+ if (loginStore.state.accessToken != null) {
35
+ const { message, msg } = data;
36
+ if (message || msg) {
37
+ toast.message(message || msg);
38
+ }
39
+ loginStore.logout();
40
+ }
41
+ });
42
+ }
43
+ }
44
+ else {
45
+ if (config?.custom?.message !== false) {
46
+ const { message, msg } = data;
47
+ if (message || msg) {
48
+ toast.message(message || msg);
49
+ }
50
+ }
51
+ }
52
+ return Promise.reject(response);
53
+ }
54
+ export function createInterceptors(req) {
55
+ req.interceptors.request.use((config) => {
56
+ if (log.request) {
57
+ console.log(`Request URL:${config.baseURL}${config.url}`);
58
+ console.log(config);
59
+ }
60
+ const header = {};
61
+ const loginState = useLoginStore(pinia).state;
62
+ const { accessToken } = loginState || {};
63
+ if (accessToken) {
64
+ header.Authorization = `Bearer ${accessToken}`;
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
+ let opts = _opts;
105
+ const GET = (url, data = {}, options = {}) => {
106
+ if (typeof opts === 'function') {
107
+ opts = _opts();
108
+ }
109
+ url = formatURL(url, data);
110
+ return req.get(url, { params: data, ...opts, ...options });
111
+ };
112
+ const DELETE = (url, data = {}, options = {}) => {
113
+ if (typeof opts === 'function') {
114
+ opts = _opts();
115
+ }
116
+ url = formatURL(url, data);
117
+ return req.delete(url, data, { ...opts, ...options });
118
+ };
119
+ const POST = (url, data = {}, options = {}) => {
120
+ if (typeof opts === 'function') {
121
+ opts = _opts();
122
+ }
123
+ url = formatURL(url, data);
124
+ return req.post(url, data, { ...opts, ...options });
125
+ };
126
+ const PUT = (url, data = {}, options = {}) => {
127
+ if (typeof opts === 'function') {
128
+ opts = _opts();
129
+ }
130
+ url = formatURL(url, data);
131
+ return req.put(url, data, { ...opts, ...options });
132
+ };
133
+ return {
134
+ GET,
135
+ DELETE,
136
+ POST,
137
+ PUT,
138
+ };
139
+ }
@@ -0,0 +1,40 @@
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>;
@@ -0,0 +1,128 @@
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
+ }
@@ -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 { config } from '@zfqh/uview-x';
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: config.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,17 @@
1
+ export declare const loading: (title?: string | UniNamespace.ShowLoadingOptions, options?: UniNamespace.ShowLoadingOptions) => void;
2
+ export declare const message: (title?: string | UniNamespace.ShowToastOptions, options?: UniNamespace.ShowToastOptions) => Promise<void>;
3
+ export declare const close: () => void;
4
+ export declare const hideToast: () => void;
5
+ export declare const hideLoading: () => void;
6
+ declare const toast: {
7
+ loading: (title?: string | UniNamespace.ShowLoadingOptions, options?: UniNamespace.ShowLoadingOptions) => void;
8
+ message: (title?: string | UniNamespace.ShowToastOptions, options?: UniNamespace.ShowToastOptions) => Promise<void>;
9
+ success: (title?: string | UniNamespace.ShowToastOptions, options?: UniNamespace.ShowToastOptions) => Promise<void>;
10
+ error: (title?: string | UniNamespace.ShowToastOptions, options?: UniNamespace.ShowToastOptions) => Promise<void>;
11
+ fail: (title?: string | UniNamespace.ShowToastOptions, options?: UniNamespace.ShowToastOptions) => Promise<void>;
12
+ exception: (title?: string | UniNamespace.ShowToastOptions, options?: UniNamespace.ShowToastOptions) => Promise<void>;
13
+ close: () => void;
14
+ hideToast: () => void;
15
+ hideLoading: () => void;
16
+ };
17
+ export default toast;
@@ -0,0 +1,66 @@
1
+ import toastConfig from '../configs/toast';
2
+ export const loading = (title = '', options = {}) => {
3
+ if (typeof title === 'object') {
4
+ options = title;
5
+ title = options.title || '';
6
+ }
7
+ uni.showLoading(Object.assign({
8
+ title: title || '',
9
+ }, options));
10
+ };
11
+ export const message = (title = '', options = {}) => {
12
+ if (typeof title === 'object') {
13
+ options = title;
14
+ title = options.title || '';
15
+ }
16
+ options = Object.assign({
17
+ title: title || '',
18
+ icon: 'none',
19
+ duration: 2000,
20
+ }, options);
21
+ return new Promise((res) => {
22
+ if (options.title) {
23
+ setTimeout(() => {
24
+ if (toastConfig.custom === true) {
25
+ if (toastConfig.show(options) !== false) {
26
+ return;
27
+ }
28
+ }
29
+ uni.showToast(options);
30
+ });
31
+ setTimeout(() => {
32
+ res();
33
+ }, options.duration || 2000);
34
+ }
35
+ else {
36
+ res();
37
+ }
38
+ });
39
+ };
40
+ export const close = () => {
41
+ if (toastConfig.custom === true) {
42
+ if (toastConfig.hide() !== false) {
43
+ return;
44
+ }
45
+ }
46
+ uni.hideToast();
47
+ };
48
+ export const hideToast = close;
49
+ export const hideLoading = () => uni.hideLoading();
50
+ const toast = {
51
+ loading,
52
+ message,
53
+ success: message,
54
+ error: message,
55
+ fail: message,
56
+ exception: message,
57
+ close,
58
+ hideToast,
59
+ hideLoading,
60
+ };
61
+ ['success', 'error', 'fail', 'exception'].forEach((icon) => {
62
+ toast[icon] = (title, options = {}) => {
63
+ return message(title, { ...options, icon });
64
+ };
65
+ });
66
+ export default toast;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,141 @@
1
+ // #ifdef H5
2
+ import { config } from '@zfqh/uview-x';
3
+ import { colorGradient } from '@zfqh/uview-x/utils/colorGradient';
4
+ // #endif
5
+ import mp from '../configs/mp';
6
+ import { IS_WEBVIEW_ENV } from './consts';
7
+ import query from './query';
8
+ // #ifndef H5
9
+ uni.webView = uni;
10
+ if (!uni.webView.postMessage) {
11
+ uni.webView.postMessage = () => { };
12
+ }
13
+ // #endif
14
+ // #ifdef H5
15
+ // H5下没有该方法,做兼容处理
16
+ uni.hideShareMenu = () => { };
17
+ uni.showShareMenu = () => { };
18
+ // 解决Tree Shaking导致程序报错
19
+ const scanCode = uni.scanCode;
20
+ const chooseImage = uni.chooseImage;
21
+ const chooseVideo = uni.chooseVideo;
22
+ const chooseFile = uni.chooseFile;
23
+ const navigateTo = uni.navigateTo;
24
+ const redirectTo = uni.redirectTo;
25
+ const switchTab = uni.switchTab;
26
+ const reLaunch = uni.reLaunch;
27
+ uni.scanCode = scanCode;
28
+ uni.chooseImage = chooseImage;
29
+ uni.chooseVideo = chooseVideo;
30
+ uni.chooseFile = chooseFile;
31
+ uni.navigateTo = navigateTo;
32
+ uni.redirectTo = redirectTo;
33
+ uni.switchTab = switchTab;
34
+ uni.reLaunch = reLaunch;
35
+ // #endif
36
+ const navigateBack = uni.navigateBack;
37
+ const navigateToMiniProgram = uni.navigateToMiniProgram;
38
+ const openEmbeddedMiniProgram = uni.openEmbeddedMiniProgram;
39
+ uni.navigateBack = (options = {}) => {
40
+ let { delta = 1 } = options;
41
+ if (delta < 1) {
42
+ delta = 1;
43
+ }
44
+ const pages = getCurrentPages();
45
+ const length = pages.length;
46
+ if (IS_WEBVIEW_ENV && length === 1) {
47
+ // webview内没有上页,则触发原生返回
48
+ uni.webView?.navigateBack(options);
49
+ }
50
+ else {
51
+ navigateBack(options);
52
+ }
53
+ };
54
+ uni.navigateToMiniProgram = (options) => {
55
+ // #ifdef MP
56
+ navigateToMiniProgram({
57
+ envVersion: mp.envVersion,
58
+ ...options,
59
+ });
60
+ // #endif
61
+ };
62
+ uni.openEmbeddedMiniProgram = (options) => {
63
+ // #ifdef MP
64
+ openEmbeddedMiniProgram({
65
+ envVersion: mp.envVersion,
66
+ allowFullScreen: true,
67
+ ...options,
68
+ });
69
+ // #endif
70
+ };
71
+ // 应用是否从后台唤起,在App.onShow中建议使用if (uni.showAppFromBackground) { /* do something */ }
72
+ uni.showAppFromBackground = true;
73
+ // 调用API将appShowFromBackground设置为false,防止App.vue非必要的执行onShow
74
+ [
75
+ // #ifdef MP
76
+ 'previewImage',
77
+ 'openLocation',
78
+ 'chooseLocation',
79
+ 'chooseAddress',
80
+ 'chooseMessageFile',
81
+ 'openSetting',
82
+ // #endif
83
+ // #ifndef APP
84
+ 'scanCode',
85
+ // #endif
86
+ 'chooseImage',
87
+ 'chooseVideo',
88
+ 'chooseFile',
89
+ ].forEach((key) => {
90
+ const func = uni[key];
91
+ uni[key] = (options = {}) => {
92
+ uni.showAppFromBackground = false;
93
+ return func(options);
94
+ };
95
+ });
96
+ // #ifdef H5
97
+ if (query) {
98
+ const safeTop = Number(query.safeTop);
99
+ const safeBottom = Number(query.safeBottom);
100
+ if (safeTop > 0 || safeBottom > 0) {
101
+ const node = document.createElement('style');
102
+ node.type = 'text/css';
103
+ const styles = [];
104
+ if (safeTop > 0) {
105
+ styles.push(`.uv-safe-area-inset-top { padding-top: ${safeTop}px; }`);
106
+ document.documentElement.style.setProperty('--status-bar-height', `${safeTop}px`);
107
+ }
108
+ if (safeBottom > 0) {
109
+ styles.push(`.uv-safe-area-inset-bottom { padding-bottom: ${safeBottom}px; }`);
110
+ }
111
+ node.innerText = styles.join('\n');
112
+ document.body.append(node);
113
+ }
114
+ // 隐藏子应用tabbar,不传或者为空字符表示显式子应用tabbar
115
+ if (query.tabbar != null && query.tabbar !== '') {
116
+ const node = document.createElement('style');
117
+ node.type = 'text/css';
118
+ node.innerText = `
119
+ .uni-tabbar-bottom { display: none }
120
+ `.trim();
121
+ document.body.append(node);
122
+ window.addEventListener('load', () => {
123
+ document.documentElement.style.setProperty('--window-bottom', '0px');
124
+ });
125
+ }
126
+ // 更新主题色
127
+ const primary = query.primary ? `#${query.primary}`.replace(/^#+/, '#') : '';
128
+ if (primary) {
129
+ const colors = colorGradient(primary, '#fff', 10);
130
+ document.documentElement.style.setProperty('--primary', (config.color.primary = colors[0]));
131
+ document.documentElement.style.setProperty('--primary-light', (config.color.primaryLight = colors[9]));
132
+ document.documentElement.style.setProperty('--primary-disabled', (config.color.primaryDisabled = colors[6]));
133
+ document.documentElement.style.setProperty('--primary-dark', (config.color.primaryDark = colors[4]));
134
+ }
135
+ }
136
+ // const resizeCallback = () => {
137
+ // document.documentElement.style.setProperty('--window-height', `${window.innerHeight}px`);
138
+ // };
139
+ // resizeCallback();
140
+ // window.addEventListener('resize', resizeCallback);
141
+ // #endif
@@ -0,0 +1,41 @@
1
+ export interface VersionInfo {
2
+ name: string;
3
+ version: string | number;
4
+ comment: string;
5
+ status: number;
6
+ hotUpdateUrl: string;
7
+ fileUrl: string;
8
+ }
9
+ export interface InstallOptions {
10
+ appId: string;
11
+ url: string;
12
+ path?: string;
13
+ /** 主应用 uni-app x 安装包类型;未传时按 URL 后缀推断 */
14
+ fileType?: 'apk' | 'wgt';
15
+ progress?: (p: number) => void;
16
+ success?: () => void;
17
+ fail?: (error: {
18
+ message: string;
19
+ }) => void;
20
+ }
21
+ export interface CheckVersionOptions {
22
+ appId: string;
23
+ path?: string;
24
+ /** 指定本地版本号,传入后跳过本地 manifest 读取(重试场景) */
25
+ versionCode?: number;
26
+ /** 指定本地版本名称,与 versionCode 配套 */
27
+ versionName?: string;
28
+ }
29
+ export declare function checkVersion(options: CheckVersionOptions): Promise<{
30
+ code: number;
31
+ data: {
32
+ info: {
33
+ versionCode: number;
34
+ versionName: string;
35
+ };
36
+ latest: VersionInfo;
37
+ };
38
+ message: string;
39
+ }>;
40
+ export declare function installUpdate(options: InstallOptions): void;
41
+ export declare function restartApp(): void;