@zfqh/uniapp-x 0.0.0-stage → 0.0.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/CHANGELOG.md +44 -0
- package/LICENSE +21 -0
- package/README.md +61 -3
- package/lib/apis/core.d.ts +18 -0
- package/lib/apis/core.js +19 -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 +57 -0
- package/lib/configs/api.d.ts +7 -0
- package/lib/configs/api.js +6 -0
- package/lib/configs/app.d.ts +20 -0
- package/lib/configs/app.js +18 -0
- package/lib/configs/cdn.d.ts +15 -0
- package/lib/configs/cdn.js +17 -0
- package/lib/configs/env.d.ts +37 -0
- package/lib/configs/env.js +71 -0
- package/lib/configs/index.d.ts +130 -0
- package/lib/configs/index.js +76 -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/updater.d.ts +15 -0
- package/lib/configs/updater.js +33 -0
- package/lib/configs/upload.d.ts +30 -0
- package/lib/configs/upload.js +19 -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 +11 -0
- package/lib/hooks/index.js +11 -0
- package/lib/hooks/useAppLifecycle.d.ts +8 -0
- package/lib/hooks/useAppLifecycle.js +87 -0
- package/lib/hooks/useBadge.d.ts +8 -0
- package/lib/hooks/useBadge.js +47 -0
- package/lib/hooks/useNeedLogin.d.ts +1 -0
- package/lib/hooks/useNeedLogin.js +27 -0
- package/lib/hooks/useOverlay.d.ts +1 -0
- package/lib/hooks/useOverlay.js +17 -0
- package/lib/hooks/usePageShow.d.ts +2 -0
- package/lib/hooks/usePageShow.js +16 -0
- package/lib/hooks/usePopup.d.ts +1 -0
- package/lib/hooks/usePopup.js +14 -0
- package/lib/hooks/useRedirect.d.ts +5 -0
- package/lib/hooks/useRedirect.js +92 -0
- package/lib/hooks/useReferrer.d.ts +1 -0
- package/lib/hooks/useReferrer.js +11 -0
- package/lib/hooks/useShare.d.ts +12 -0
- package/lib/hooks/useShare.js +49 -0
- package/lib/hooks/useVersion.d.ts +6 -0
- package/lib/hooks/useVersion.js +21 -0
- package/lib/hooks/useWebview.d.ts +14 -0
- package/lib/hooks/useWebview.js +294 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +26 -0
- package/lib/stores/app.d.ts +51 -0
- package/lib/stores/app.js +57 -0
- package/lib/stores/dict.d.ts +35 -0
- package/lib/stores/dict.js +42 -0
- package/lib/stores/im.d.ts +57 -0
- package/lib/stores/im.js +102 -0
- package/lib/stores/index.d.ts +12 -0
- package/lib/stores/index.js +17 -0
- package/lib/stores/launch.d.ts +42 -0
- package/lib/stores/launch.js +39 -0
- package/lib/stores/location.d.ts +35 -0
- package/lib/stores/location.js +58 -0
- package/lib/stores/login.d.ts +80 -0
- package/lib/stores/login.js +91 -0
- package/lib/stores/network.d.ts +26 -0
- package/lib/stores/network.js +45 -0
- package/lib/stores/pinia.d.ts +2 -0
- package/lib/stores/pinia.js +3 -0
- package/lib/stores/system.d.ts +39 -0
- package/lib/stores/system.js +36 -0
- package/lib/styles/index.scss +9 -0
- package/lib/styles/reset-vue.scss +15 -0
- package/lib/utils/audio.d.ts +14 -0
- package/lib/utils/audio.js +43 -0
- package/lib/utils/consts.d.ts +74 -0
- package/lib/utils/consts.js +110 -0
- package/lib/utils/cos.d.ts +17 -0
- package/lib/utils/cos.js +141 -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 +486 -0
- package/lib/utils/message.d.ts +1 -0
- package/lib/utils/message.js +55 -0
- package/lib/utils/navigate.d.ts +28 -0
- package/lib/utils/navigate.js +192 -0
- package/lib/utils/pages.d.ts +21 -0
- package/lib/utils/pages.js +83 -0
- package/lib/utils/permission.d.ts +17 -0
- package/lib/utils/permission.js +278 -0
- package/lib/utils/query.d.ts +20 -0
- package/lib/utils/query.js +51 -0
- package/lib/utils/request.d.ts +8 -0
- package/lib/utils/request.js +139 -0
- package/lib/utils/storage.d.ts +40 -0
- package/lib/utils/storage.js +128 -0
- package/lib/utils/subscribe.d.ts +7 -0
- package/lib/utils/subscribe.js +94 -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 +141 -0
- package/lib/utils/update.d.ts +41 -0
- package/lib/utils/update.js +322 -0
- package/lib/utils/url.d.ts +14 -0
- package/lib/utils/url.js +40 -0
- package/package.json +38 -4
- package/types/index.d.ts +78 -0
- package/types/virtual.d.ts +1 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import app from '../configs/app';
|
|
2
|
+
import env from '../configs/env';
|
|
3
|
+
import ver from '../configs/ver';
|
|
4
|
+
import updater from '../configs/updater';
|
|
5
|
+
import { SYSTEM_INFO, IS_WEBVIEW_ENV, TYPES } from './consts';
|
|
6
|
+
import { postMessage } from './index';
|
|
7
|
+
import { pinia } from '../stores/pinia';
|
|
8
|
+
import { useDictStore } from '../stores/dict';
|
|
9
|
+
const { platform, brand } = SYSTEM_INFO;
|
|
10
|
+
let _installMessageHandler = null;
|
|
11
|
+
function getSystemVersionInfo() {
|
|
12
|
+
return {
|
|
13
|
+
versionCode: Number(SYSTEM_INFO.appVersionCode || 0),
|
|
14
|
+
versionName: SYSTEM_INFO.appVersion || '',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function toVersionInfo(info) {
|
|
18
|
+
return {
|
|
19
|
+
versionCode: Number(info?.code ?? info?.versionCode ?? 0),
|
|
20
|
+
versionName: info?.name ?? info?.versionName ?? '',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function isUniMPSuccess(ret) {
|
|
24
|
+
return ret?.type === 'success' || Number(ret?.code) === 0;
|
|
25
|
+
}
|
|
26
|
+
/** 主应用 x 端安装包类型:优先显式 fileType,其次 URL 后缀 */
|
|
27
|
+
function resolveFileType(options) {
|
|
28
|
+
if (options.fileType === 'apk' || options.fileType === 'wgt')
|
|
29
|
+
return options.fileType;
|
|
30
|
+
const path = String(options.url || '')
|
|
31
|
+
.split(/[?#]/)[0]
|
|
32
|
+
.toLowerCase();
|
|
33
|
+
if (path.endsWith('.apk'))
|
|
34
|
+
return 'apk';
|
|
35
|
+
if (path.endsWith('.wgt'))
|
|
36
|
+
return 'wgt';
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
// #ifdef APP
|
|
40
|
+
function appGetProperty(appId, path) {
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
if (appId === app.appId) {
|
|
43
|
+
// #ifdef UNI-APP-X
|
|
44
|
+
resolve(getSystemVersionInfo());
|
|
45
|
+
// #endif
|
|
46
|
+
// #ifdef APP-PLUS
|
|
47
|
+
plus.runtime.getProperty(String(plus.runtime.appid), (res) => resolve(res));
|
|
48
|
+
// #endif
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// #ifdef UNI-APP-X
|
|
52
|
+
if (typeof uni.getUniMPVersion !== 'function') {
|
|
53
|
+
resolve({});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
uni.getUniMPVersion(appId, (ret) => {
|
|
58
|
+
if (isUniMPSuccess(ret) && ret.versionInfo) {
|
|
59
|
+
resolve(toVersionInfo(ret.versionInfo));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
resolve({});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
resolve({});
|
|
68
|
+
}
|
|
69
|
+
// #endif
|
|
70
|
+
// #ifdef APP-PLUS
|
|
71
|
+
plus.io.resolveLocalFileSystemURL(`_doc/${path ? path + '/' : ''}${appId}/manifest.json`, (entry) => {
|
|
72
|
+
entry.file((file) => {
|
|
73
|
+
const reader = new plus.io.FileReader();
|
|
74
|
+
reader.onloadend = (e) => {
|
|
75
|
+
try {
|
|
76
|
+
resolve(JSON.parse(e.target.result));
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
resolve({});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
reader.readAsText(file);
|
|
83
|
+
}, () => resolve({}));
|
|
84
|
+
}, () => resolve({}));
|
|
85
|
+
// #endif
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// #endif
|
|
90
|
+
// #ifdef H5
|
|
91
|
+
function h5GetProperty(appId, path) {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
if (appId !== app.appId && window.electron) {
|
|
94
|
+
window.electron.webUtils.getProperty(appId, path, (res) => resolve(res || {}));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
resolve({ version: ver.name, versionCode: ver.code });
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// #endif
|
|
102
|
+
export async function checkVersion(options) {
|
|
103
|
+
const { appId, versionCode = 0, versionName = '' } = options || {};
|
|
104
|
+
let info;
|
|
105
|
+
let latest;
|
|
106
|
+
let code = 0;
|
|
107
|
+
let message = '';
|
|
108
|
+
try {
|
|
109
|
+
let version = 0;
|
|
110
|
+
if (options?.versionCode != null) {
|
|
111
|
+
info = { versionCode, versionName };
|
|
112
|
+
version = Number(info.versionCode || 0);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// #ifdef APP
|
|
116
|
+
info = (await appGetProperty(appId, options.path));
|
|
117
|
+
version = Number(info.versionCode || 0);
|
|
118
|
+
// #endif
|
|
119
|
+
// #ifdef H5
|
|
120
|
+
info = (await h5GetProperty(appId, options.path));
|
|
121
|
+
version = Number(info.versionCode || 0);
|
|
122
|
+
// #endif
|
|
123
|
+
}
|
|
124
|
+
info.versionCode = version;
|
|
125
|
+
let type = 3;
|
|
126
|
+
let plat;
|
|
127
|
+
if (!IS_WEBVIEW_ENV && appId === app.appId) {
|
|
128
|
+
type = 1;
|
|
129
|
+
plat = { android: '1', ios: '2', harmony: '3', windows: '4', macos: '5' }[platform];
|
|
130
|
+
}
|
|
131
|
+
const res = await updater.request({
|
|
132
|
+
version,
|
|
133
|
+
appId,
|
|
134
|
+
type,
|
|
135
|
+
platform: plat,
|
|
136
|
+
});
|
|
137
|
+
latest = res?.data;
|
|
138
|
+
if (latest) {
|
|
139
|
+
// #ifdef APP
|
|
140
|
+
if (platform === 'android' && appId === app.appId && env.key === 'prod') {
|
|
141
|
+
const dictStore = useDictStore(pinia);
|
|
142
|
+
await dictStore.getDictInfo({ name: 'group_relation', cache: true });
|
|
143
|
+
if (dictStore.state.group_relation?.values?.includes(brand)) {
|
|
144
|
+
latest.hotUpdateUrl = '';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// #endif
|
|
148
|
+
if (Number(latest.version) > Number(version)) {
|
|
149
|
+
code = 1;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
message = e?.message || e?.data?.message || e?.data?.msg || '';
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
code,
|
|
158
|
+
data: {
|
|
159
|
+
info,
|
|
160
|
+
latest,
|
|
161
|
+
},
|
|
162
|
+
message,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// #ifdef APP
|
|
166
|
+
function appInstall({ appId, url, path, fileType, progress, success, fail }) {
|
|
167
|
+
let settled = false;
|
|
168
|
+
const successOnce = () => {
|
|
169
|
+
if (settled)
|
|
170
|
+
return;
|
|
171
|
+
settled = true;
|
|
172
|
+
success?.();
|
|
173
|
+
};
|
|
174
|
+
const failOnce = (message) => {
|
|
175
|
+
if (settled)
|
|
176
|
+
return;
|
|
177
|
+
settled = true;
|
|
178
|
+
fail?.({ message: message || 'install failed' });
|
|
179
|
+
};
|
|
180
|
+
const downloadTask = uni.downloadFile({
|
|
181
|
+
url,
|
|
182
|
+
success(res) {
|
|
183
|
+
if (res.statusCode !== 200)
|
|
184
|
+
return failOnce('download failed');
|
|
185
|
+
progress?.(100);
|
|
186
|
+
setTimeout(() => {
|
|
187
|
+
if (appId === app.appId) {
|
|
188
|
+
// 主应用
|
|
189
|
+
// #ifdef UNI-APP-X
|
|
190
|
+
const type = resolveFileType({ appId, url, path, fileType });
|
|
191
|
+
if (!type) {
|
|
192
|
+
failOnce('无法判断安装包类型,请指定 fileType');
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (type === 'wgt') {
|
|
196
|
+
if (typeof uni.installWgt !== 'function') {
|
|
197
|
+
failOnce('当前环境不支持 uni.installWgt');
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
uni.installWgt({
|
|
201
|
+
filePath: res.tempFilePath,
|
|
202
|
+
success: successOnce,
|
|
203
|
+
fail: (e) => failOnce(e?.errMsg || e?.message || 'installWgt failed'),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
if (typeof uni.installApk !== 'function') {
|
|
208
|
+
failOnce('当前环境不支持 uni.installApk');
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
uni.installApk({
|
|
212
|
+
filePath: res.tempFilePath,
|
|
213
|
+
success: successOnce,
|
|
214
|
+
fail: (e) => failOnce(e?.errMsg || e?.message || 'installApk failed'),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// #endif
|
|
218
|
+
// #ifdef APP-PLUS
|
|
219
|
+
plus.runtime.install(res.tempFilePath, { force: true }, successOnce, ((e) => failOnce(e?.message || String(e))));
|
|
220
|
+
// #endif
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// uni 小程序子应用
|
|
224
|
+
// #ifdef UNI-APP-X
|
|
225
|
+
if (typeof uni.installUniMP !== 'function') {
|
|
226
|
+
failOnce('当前宿主未注册 uni.installUniMP');
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
uni.installUniMP({ appid: appId, wgtFile: res.tempFilePath }, (ret) => {
|
|
230
|
+
if (isUniMPSuccess(ret)) {
|
|
231
|
+
successOnce();
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
failOnce(ret?.message || 'installUniMP failed');
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
// #endif
|
|
238
|
+
// #ifdef APP-PLUS
|
|
239
|
+
plus.io.resolveLocalFileSystemURL('_doc/', (docDir) => {
|
|
240
|
+
if (path) {
|
|
241
|
+
docDir.getDirectory(path, { create: true }, (subDir) => {
|
|
242
|
+
plus.zip.decompress(res.tempFilePath, subDir.fullPath, successOnce, ((e) => failOnce(e?.message || String(e))));
|
|
243
|
+
}, (e) => failOnce(e?.message || String(e)));
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
plus.zip.decompress(res.tempFilePath, docDir.fullPath, successOnce, ((e) => failOnce(e?.message || String(e))));
|
|
247
|
+
}
|
|
248
|
+
}, (e) => failOnce(e?.message || String(e)));
|
|
249
|
+
// #endif
|
|
250
|
+
}
|
|
251
|
+
}, 1000);
|
|
252
|
+
},
|
|
253
|
+
fail: (e) => failOnce(e?.errMsg || String(e)),
|
|
254
|
+
});
|
|
255
|
+
downloadTask.onProgressUpdate(({ progress: p }) => {
|
|
256
|
+
const value = Number.isFinite(p) ? Math.min(99, Math.max(0, Math.floor(p))) : 0;
|
|
257
|
+
progress?.(value);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
// #endif
|
|
261
|
+
// #ifdef H5
|
|
262
|
+
function h5Install(options) {
|
|
263
|
+
if (IS_WEBVIEW_ENV) {
|
|
264
|
+
postMessage({
|
|
265
|
+
type: TYPES.MESSAGE.APP_INSTALL,
|
|
266
|
+
payload: {
|
|
267
|
+
appId: options.appId,
|
|
268
|
+
url: options.url,
|
|
269
|
+
path: options.path,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
if (_installMessageHandler) {
|
|
273
|
+
uni.$off(TYPES.MESSAGE.WEBVIEW_MESSAGE, _installMessageHandler);
|
|
274
|
+
_installMessageHandler = null;
|
|
275
|
+
}
|
|
276
|
+
_installMessageHandler = (e) => {
|
|
277
|
+
if (e?.type === TYPES.MESSAGE.APP_INSTALL) {
|
|
278
|
+
if (e.payload?.progress != null) {
|
|
279
|
+
options.progress?.(e.payload.progress);
|
|
280
|
+
}
|
|
281
|
+
else if (e.payload?.success) {
|
|
282
|
+
options.success?.();
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
options.fail?.({ message: e.payload.message });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
uni.$on(TYPES.MESSAGE.WEBVIEW_MESSAGE, _installMessageHandler);
|
|
290
|
+
}
|
|
291
|
+
else if (window.electron) {
|
|
292
|
+
window.electron.webUtils.updateApp(options);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
// #endif
|
|
296
|
+
export function installUpdate(options) {
|
|
297
|
+
// #ifdef H5
|
|
298
|
+
h5Install(options);
|
|
299
|
+
// #endif
|
|
300
|
+
// #ifdef APP
|
|
301
|
+
appInstall(options);
|
|
302
|
+
// #endif
|
|
303
|
+
}
|
|
304
|
+
export function restartApp() {
|
|
305
|
+
// #ifdef H5
|
|
306
|
+
if (IS_WEBVIEW_ENV) {
|
|
307
|
+
postMessage({
|
|
308
|
+
type: TYPES.MESSAGE.APP_RESTART,
|
|
309
|
+
payload: {},
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
else if (window.electron) {
|
|
313
|
+
window.electron.ipcRenderer.send('relaunch');
|
|
314
|
+
}
|
|
315
|
+
// #endif
|
|
316
|
+
// #ifdef APP-PLUS
|
|
317
|
+
plus.runtime.restart();
|
|
318
|
+
// #endif
|
|
319
|
+
// #ifdef UNI-APP-X
|
|
320
|
+
getApp().restart?.();
|
|
321
|
+
// #endif
|
|
322
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轻量 URL 解析/重建,替代 url-parse 在 App 蒸汽模式下的 CJS 互操作问题。
|
|
3
|
+
* 仅覆盖 webview 场景需要的 origin/path/query/hash 操作。
|
|
4
|
+
*/
|
|
5
|
+
export declare class SimpleUrl {
|
|
6
|
+
base: string;
|
|
7
|
+
pathname: string;
|
|
8
|
+
query: Record<string, any>;
|
|
9
|
+
hash: string;
|
|
10
|
+
constructor(input: string, parseQueryFlag?: boolean);
|
|
11
|
+
set(key: 'query' | 'hash', value: any): this;
|
|
12
|
+
toString(): string;
|
|
13
|
+
}
|
|
14
|
+
export default SimpleUrl;
|
package/lib/utils/url.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { parseQuery, stringifyQuery } from './query';
|
|
2
|
+
/**
|
|
3
|
+
* 轻量 URL 解析/重建,替代 url-parse 在 App 蒸汽模式下的 CJS 互操作问题。
|
|
4
|
+
* 仅覆盖 webview 场景需要的 origin/path/query/hash 操作。
|
|
5
|
+
*/
|
|
6
|
+
export class SimpleUrl {
|
|
7
|
+
base = '';
|
|
8
|
+
pathname = '';
|
|
9
|
+
query = {};
|
|
10
|
+
hash = '';
|
|
11
|
+
constructor(input, parseQueryFlag = false) {
|
|
12
|
+
const value = String(input || '');
|
|
13
|
+
const match = value.match(/^((?:https?|file):\/\/[^/?#]+)([^?#]*)(\?[^#]*)?(#.*)?$/);
|
|
14
|
+
if (match) {
|
|
15
|
+
this.base = match[1];
|
|
16
|
+
this.pathname = match[2] || '';
|
|
17
|
+
if (parseQueryFlag && match[3]) {
|
|
18
|
+
this.query = parseQuery(match[3].substring(1));
|
|
19
|
+
}
|
|
20
|
+
this.hash = match[4] || '';
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.pathname = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
set(key, value) {
|
|
27
|
+
if (key === 'query') {
|
|
28
|
+
this.query = { ...(value || {}) };
|
|
29
|
+
}
|
|
30
|
+
else if (key === 'hash') {
|
|
31
|
+
this.hash = String(value || '');
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
toString() {
|
|
36
|
+
const queryString = stringifyQuery(this.query);
|
|
37
|
+
return `${this.base}${this.pathname}${queryString ? `?${queryString}` : ''}${this.hash}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export default SimpleUrl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zfqh/uniapp-x",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "uniapp x 公共模块",
|
|
5
|
+
"author": "yinjiazeng@163.com",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"tsc": "vue-tsc",
|
|
14
|
+
"tsc:dev": "vue-tsc --watch"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"uniapp",
|
|
18
|
+
"uniapp-x"
|
|
19
|
+
],
|
|
20
|
+
"files": [
|
|
21
|
+
"lib",
|
|
22
|
+
"types",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@zfqh/uview-x": "0.0.2",
|
|
28
|
+
"crypto-es": "^3.1.3",
|
|
29
|
+
"pinia": "2.1.7",
|
|
30
|
+
"qs": "^6.13.0",
|
|
31
|
+
"url-parse": "^1.5.10",
|
|
32
|
+
"vue": "3.4.21"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@dcloudio/types": "^3.4.19",
|
|
36
|
+
"@types/qs": "^6.9.16",
|
|
37
|
+
"@types/url-parse": "^1.4.11"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "abcec16d4c73e83cec02770a553cd89091e35cf3"
|
|
40
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// <reference path="./virtual.d.ts" />
|
|
2
|
+
|
|
3
|
+
import type { Uni as UniTypes } from '@dcloudio/types';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface UniMPResult {
|
|
7
|
+
type?: 'success' | 'fail' | string;
|
|
8
|
+
code?: number | string;
|
|
9
|
+
message?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface UniMPVersionInfo {
|
|
13
|
+
name?: string;
|
|
14
|
+
code?: number | string;
|
|
15
|
+
versionName?: string;
|
|
16
|
+
versionCode?: number | string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface UniMPVersionResult extends UniMPResult {
|
|
20
|
+
versionInfo?: UniMPVersionInfo;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface Uni extends UniTypes {
|
|
24
|
+
$uv: any;
|
|
25
|
+
webView: any;
|
|
26
|
+
showAppFromBackground: boolean;
|
|
27
|
+
getLocationCallback: {
|
|
28
|
+
[key: string]: (data: any) => void;
|
|
29
|
+
};
|
|
30
|
+
openLocationCallback: {
|
|
31
|
+
[key: string]: (data: any) => void;
|
|
32
|
+
};
|
|
33
|
+
requestPermission: (permission: 'location' | 'storage') => Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* uni-app x 安装 APK(官方 API,@dcloudio/types 暂未声明)
|
|
36
|
+
*/
|
|
37
|
+
installApk?: (options: {
|
|
38
|
+
filePath: string;
|
|
39
|
+
success?: (res: any) => void;
|
|
40
|
+
fail?: (err: any) => void;
|
|
41
|
+
complete?: (res: any) => void;
|
|
42
|
+
}) => void;
|
|
43
|
+
/**
|
|
44
|
+
* uni-app x 安装 WGT(官方 API,@dcloudio/types 暂未声明)
|
|
45
|
+
*/
|
|
46
|
+
installWgt?: (options: {
|
|
47
|
+
filePath: string;
|
|
48
|
+
ignoreVersion?: boolean;
|
|
49
|
+
success?: (res: any) => void;
|
|
50
|
+
fail?: (err: any) => void;
|
|
51
|
+
complete?: (res: any) => void;
|
|
52
|
+
}) => void;
|
|
53
|
+
/**
|
|
54
|
+
* 宿主注入的 uni 小程序安装方法
|
|
55
|
+
*/
|
|
56
|
+
installUniMP?: (options: { appid: string; wgtFile: string }, callback?: (result: UniMPResult) => void) => void;
|
|
57
|
+
/**
|
|
58
|
+
* 宿主注入的 uni 小程序版本读取方法
|
|
59
|
+
*/
|
|
60
|
+
getUniMPVersion?: (appid: string, callback: (result: UniMPVersionResult) => void) => void;
|
|
61
|
+
/**
|
|
62
|
+
* uni-app x 5.25+ 申请系统权限;@dcloudio/types 暂未声明,构建期补充
|
|
63
|
+
*/
|
|
64
|
+
requestSystemPermission?: (options: {
|
|
65
|
+
permissions: string[];
|
|
66
|
+
success?: (result: { grantedList: string[]; deniedList: string[]; doNotAskAgainList: string[] }) => void;
|
|
67
|
+
fail?: (result: { errCode: number; errMsg: string }) => void;
|
|
68
|
+
complete?: (result: any) => void;
|
|
69
|
+
}) => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface Window {
|
|
73
|
+
__wxjs_environment: string;
|
|
74
|
+
electron: any;
|
|
75
|
+
versionName: string;
|
|
76
|
+
versionCode: number;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'virtual:*';
|