@zfqh/uniapp 0.2.27 → 0.2.28
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 +8 -0
- package/docs/api/utils/update.md +32 -10
- package/lib/utils/update.d.ts +11 -1
- package/lib/utils/update.js +36 -26
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.2.28](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.2.27...@zfqh/uniapp@0.2.28) (2026-07-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @zfqh/uniapp
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [0.2.27](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.2.26...@zfqh/uniapp@0.2.27) (2026-06-30)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @zfqh/uniapp
|
package/docs/api/utils/update.md
CHANGED
|
@@ -27,16 +27,18 @@ import { checkVersion, installUpdate, restartApp } from '@zfqh/uniapp';
|
|
|
27
27
|
检查指定应用是否有新版本可用。
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
function checkVersion(appId: string): Promise<
|
|
30
|
+
function checkVersion(appId: string): Promise<CheckVersionResult>
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
-
|
|
34
|
-
-
|
|
33
|
+
- `code`: `0` 表示无更新或检查失败,`1` 表示有新版本可用
|
|
34
|
+
- `data.info`: 本地版本信息(`versionCode` 已归一化为 `number`)
|
|
35
|
+
- `data.latest`: 远端最新版本信息(`VersionInfo`),无数据时为 `undefined`
|
|
36
|
+
- `message`: 失败时的错误信息
|
|
35
37
|
|
|
36
38
|
```ts
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
console.log('发现新版本',
|
|
39
|
+
const { code, data } = await checkVersion('com.example.app');
|
|
40
|
+
if (code === 1 && data.latest) {
|
|
41
|
+
console.log('发现新版本', data.latest.name, data.latest.version);
|
|
40
42
|
}
|
|
41
43
|
```
|
|
42
44
|
|
|
@@ -51,7 +53,7 @@ function installUpdate(options: InstallOptions): void
|
|
|
51
53
|
```ts
|
|
52
54
|
installUpdate({
|
|
53
55
|
appId: 'com.example.app',
|
|
54
|
-
url:
|
|
56
|
+
url: data.latest.fileUrl || data.latest.hotUpdateUrl,
|
|
55
57
|
progress(p) {
|
|
56
58
|
console.log(`下载进度: ${p}%`);
|
|
57
59
|
},
|
|
@@ -91,6 +93,26 @@ restartApp();
|
|
|
91
93
|
|
|
92
94
|
## 类型定义
|
|
93
95
|
|
|
96
|
+
### CheckVersionResult
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
interface CheckVersionResult {
|
|
100
|
+
code: number;
|
|
101
|
+
data: {
|
|
102
|
+
info: { versionCode: number; versionName: string };
|
|
103
|
+
latest: VersionInfo;
|
|
104
|
+
};
|
|
105
|
+
message: string;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
| 字段 | 说明 |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| `code` | `0` 无更新或失败,`1` 有新版本 |
|
|
112
|
+
| `data.info` | 本地版本信息 |
|
|
113
|
+
| `data.latest` | 远端最新版本信息 |
|
|
114
|
+
| `message` | 失败时的错误信息 |
|
|
115
|
+
|
|
94
116
|
### VersionInfo
|
|
95
117
|
|
|
96
118
|
```ts
|
|
@@ -140,10 +162,10 @@ import { checkVersion, installUpdate, restartApp } from '@zfqh/uniapp';
|
|
|
140
162
|
import { config } from '@zfqh/uniapp';
|
|
141
163
|
|
|
142
164
|
async function doUpdate() {
|
|
143
|
-
const
|
|
144
|
-
if (!
|
|
165
|
+
const { code, data } = await checkVersion(config.app.appId);
|
|
166
|
+
if (code !== 1 || !data.latest) return;
|
|
145
167
|
|
|
146
|
-
const url =
|
|
168
|
+
const url = data.latest.hotUpdateUrl || data.latest.fileUrl;
|
|
147
169
|
if (!url) return;
|
|
148
170
|
|
|
149
171
|
installUpdate({
|
package/lib/utils/update.d.ts
CHANGED
|
@@ -15,6 +15,16 @@ export interface InstallOptions {
|
|
|
15
15
|
message: string;
|
|
16
16
|
}) => void;
|
|
17
17
|
}
|
|
18
|
-
export declare function checkVersion(appId: string
|
|
18
|
+
export declare function checkVersion(appId: string): Promise<{
|
|
19
|
+
code: number;
|
|
20
|
+
data: {
|
|
21
|
+
info: {
|
|
22
|
+
versionCode: number;
|
|
23
|
+
versionName: string;
|
|
24
|
+
};
|
|
25
|
+
latest: VersionInfo;
|
|
26
|
+
};
|
|
27
|
+
message: string;
|
|
28
|
+
}>;
|
|
19
29
|
export declare function installUpdate(options: InstallOptions): void;
|
|
20
30
|
export declare function restartApp(): void;
|
package/lib/utils/update.js
CHANGED
|
@@ -34,27 +34,31 @@ function appGetProperty(appId) {
|
|
|
34
34
|
// #ifdef H5
|
|
35
35
|
function h5GetProperty(appId) {
|
|
36
36
|
return new Promise((resolve) => {
|
|
37
|
-
if (appId
|
|
38
|
-
resolve({ version: ver.name, versionCode: ver.code });
|
|
39
|
-
}
|
|
40
|
-
else if (window.electron) {
|
|
37
|
+
if (appId !== app.appId && window.electron) {
|
|
41
38
|
window.electron.webUtils.getProperty(appId, (manifest) => resolve(manifest || {}));
|
|
42
39
|
}
|
|
40
|
+
else {
|
|
41
|
+
resolve({ version: ver.name, versionCode: ver.code });
|
|
42
|
+
}
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
// #endif
|
|
46
|
-
export async function checkVersion(appId
|
|
46
|
+
export async function checkVersion(appId) {
|
|
47
|
+
let info;
|
|
48
|
+
let latest;
|
|
49
|
+
let code = 0;
|
|
50
|
+
let message = '';
|
|
47
51
|
try {
|
|
48
52
|
let version = 0;
|
|
49
|
-
let data = null;
|
|
50
53
|
// #ifdef APP
|
|
51
|
-
|
|
52
|
-
version =
|
|
54
|
+
info = await appGetProperty(appId);
|
|
55
|
+
version = Number(info.versionCode || 0);
|
|
53
56
|
// #endif
|
|
54
57
|
// #ifdef H5
|
|
55
|
-
|
|
56
|
-
version =
|
|
58
|
+
info = await h5GetProperty(appId);
|
|
59
|
+
version = Number(info.versionCode || 0);
|
|
57
60
|
// #endif
|
|
61
|
+
info.versionCode = version;
|
|
58
62
|
let type = 3;
|
|
59
63
|
let plat;
|
|
60
64
|
if (!IS_WEBVIEW_ENV && appId === app.appId) {
|
|
@@ -67,26 +71,32 @@ export async function checkVersion(appId, cb) {
|
|
|
67
71
|
type,
|
|
68
72
|
platform: plat,
|
|
69
73
|
}, { custom: { message: false } });
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
latest = res?.data;
|
|
75
|
+
if (latest) {
|
|
76
|
+
// #ifdef APP
|
|
77
|
+
if (uni.$store?.state?.dict && platform === 'android' && appId === app.appId && env.key === 'prod') {
|
|
78
|
+
await uni.$store.dispatch('getDictInfo', { name: 'group_relation', cache: true });
|
|
79
|
+
if (uni.$store.state.dict.info.group_relation?.values?.includes(brand)) {
|
|
80
|
+
latest.hotUpdateUrl = '';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// #endif
|
|
84
|
+
if (Number(latest.version) > Number(version)) {
|
|
85
|
+
code = 1;
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
|
-
// #endif
|
|
82
|
-
if (Number(lastVer.version) > Number(version)) {
|
|
83
|
-
return lastVer;
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
88
|
}
|
|
87
|
-
catch {
|
|
88
|
-
|
|
89
|
+
catch (e) {
|
|
90
|
+
message = e?.message || e?.data?.message || e?.data?.msg || '';
|
|
89
91
|
}
|
|
92
|
+
return {
|
|
93
|
+
code,
|
|
94
|
+
data: {
|
|
95
|
+
info,
|
|
96
|
+
latest,
|
|
97
|
+
},
|
|
98
|
+
message,
|
|
99
|
+
};
|
|
90
100
|
}
|
|
91
101
|
// #ifdef APP
|
|
92
102
|
function appInstall({ appId, url, progress, success, fail }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zfqh/uniapp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.28",
|
|
4
4
|
"description": "uniapp公共模块",
|
|
5
5
|
"author": "yinjiazeng@163.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/qs": "^6.9.16",
|
|
47
47
|
"@types/url-parse": "^1.4.11"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "40a5dcdb57439185a27c906c03a97f55f87de58a"
|
|
50
50
|
}
|