@zfqh/uniapp 0.2.27 → 0.2.29

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 CHANGED
@@ -3,6 +3,22 @@
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.29](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.2.28...@zfqh/uniapp@0.2.29) (2026-07-02)
7
+
8
+ **Note:** Version bump only for package @zfqh/uniapp
9
+
10
+
11
+
12
+
13
+
14
+ ## [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)
15
+
16
+ **Note:** Version bump only for package @zfqh/uniapp
17
+
18
+
19
+
20
+
21
+
6
22
  ## [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
23
 
8
24
  **Note:** Version bump only for package @zfqh/uniapp
@@ -27,16 +27,18 @@ import { checkVersion, installUpdate, restartApp } from '@zfqh/uniapp';
27
27
  检查指定应用是否有新版本可用。
28
28
 
29
29
  ```ts
30
- function checkVersion(appId: string): Promise<VersionInfo | null>
30
+ function checkVersion(appId: string): Promise<CheckVersionResult>
31
31
  ```
32
32
 
33
- - 返回 `VersionInfo` 表示有可用更新
34
- - 返回 `null` 表示已是最新版本或检查失败
33
+ - `code`: `0` 表示无更新或检查失败,`1` 表示有新版本可用
34
+ - `data.info`: 本地版本信息(`versionCode` 已归一化为 `number`)
35
+ - `data.latest`: 远端最新版本信息(`VersionInfo`),无数据时为 `undefined`
36
+ - `message`: 失败时的错误信息
35
37
 
36
38
  ```ts
37
- const versionInfo = await checkVersion('com.example.app');
38
- if (versionInfo) {
39
- console.log('发现新版本', versionInfo.name, versionInfo.version);
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: versionInfo.fileUrl || versionInfo.hotUpdateUrl,
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 info = await checkVersion(config.app.appId);
144
- if (!info) return;
165
+ const { code, data } = await checkVersion(config.app.appId);
166
+ if (code !== 1 || !data.latest) return;
145
167
 
146
- const url = info.hotUpdateUrl || info.fileUrl;
168
+ const url = data.latest.hotUpdateUrl || data.latest.fileUrl;
147
169
  if (!url) return;
148
170
 
149
171
  installUpdate({
@@ -15,6 +15,16 @@ export interface InstallOptions {
15
15
  message: string;
16
16
  }) => void;
17
17
  }
18
- export declare function checkVersion(appId: string, cb?: any): Promise<VersionInfo | null>;
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;
@@ -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 === app.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, cb) {
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
- data = await appGetProperty(appId);
52
- version = data.versionCode || 0;
54
+ info = await appGetProperty(appId);
55
+ version = Number(info.versionCode || 0);
53
56
  // #endif
54
57
  // #ifdef H5
55
- data = await h5GetProperty(appId);
56
- version = data.versionCode || 0;
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
- const lastVer = { ...res?.data };
71
- if (typeof cb === 'function') {
72
- cb(lastVer);
73
- }
74
- // #ifdef APP
75
- if (uni.$store?.state?.dict && platform === 'android' && appId === app.appId && env.key === 'prod') {
76
- await uni.$store.dispatch('getDictInfo', { name: 'group_relation', cache: true });
77
- if (uni.$store.state.dict.info.group_relation?.values?.includes(brand)) {
78
- lastVer.hotUpdateUrl = '';
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
- return null;
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.27",
3
+ "version": "0.2.29",
4
4
  "description": "uniapp公共模块",
5
5
  "author": "yinjiazeng@163.com",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "README.md"
28
28
  ],
29
29
  "dependencies": {
30
- "@gmcb/uv-ui": "0.3.3",
30
+ "@gmcb/uv-ui": "0.3.4",
31
31
  "@tencentcloud/chat-uikit-engine": "^2.3.2",
32
32
  "@tencentcloud/tui-core": "^2.3.2",
33
33
  "crypto-js": "^4.2.0",
@@ -46,5 +46,5 @@
46
46
  "@types/qs": "^6.9.16",
47
47
  "@types/url-parse": "^1.4.11"
48
48
  },
49
- "gitHead": "6bc8ded30fa266be58a4affc226f9b540b32b006"
49
+ "gitHead": "b490689211c85faf2324dce167666aed87f7a66a"
50
50
  }