@zfqh/uniapp 0.3.0 → 0.3.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 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.3.1](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.3.0...@zfqh/uniapp@0.3.1) (2026-07-08)
7
+
8
+ **Note:** Version bump only for package @zfqh/uniapp
9
+
10
+
11
+
12
+
13
+
6
14
  # [0.3.0](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.2.32...@zfqh/uniapp@0.3.0) (2026-07-07)
7
15
 
8
16
 
@@ -8,6 +8,7 @@ CDN 静态资源配置。发布路径:`@zfqh/uniapp/lib/configs/cdn`
8
8
  | `staticUrl` | `string` | `''` | 静态站点路径。 |
9
9
  | `ossUrl` | `string` | `''` | 阿里 OSS 资源路径。 |
10
10
  | `cosUrl` | `string` | `''` | 腾讯 COS 资源路径。 |
11
+ | `isAccelerate` | `boolean` | `false` | 是否启用 COS 全球加速,upload 配置会据此自动切换 region 为 `accelerate`。 |
11
12
 
12
13
  ## 基本使用
13
14
 
@@ -33,3 +34,18 @@ export function normalizeArticleImage(path: string) {
33
34
  return `${config.cdn.baseUrl}/${path.replace(/^\/+/, '')}`;
34
35
  }
35
36
  ```
37
+
38
+ ## COS 全球加速
39
+
40
+ 当项目使用腾讯云 COS 全球加速时,设置 `isAccelerate: true`,upload 配置会自动将 region 切换为 `accelerate`,updater 配置会将 prod 环境的 COS 链接转为 `acc-static` 域名:
41
+
42
+ ```ts
43
+ // env/.env.prod.ts
44
+ import { defineEnvConfig } from '@zfqh/uniapp';
45
+
46
+ export default defineEnvConfig({
47
+ cdn: {
48
+ isAccelerate: true,
49
+ },
50
+ });
51
+ ```
@@ -100,7 +100,7 @@ export default defineEnvConfig({
100
100
  | --- | --- | --- |
101
101
  | `env` | `configs/env.ts` | 当前环境信息,自动读取环境文件。 |
102
102
  | `api` | `configs/api.ts` | `baseUrl` 接口地址。 |
103
- | `cdn` | `configs/cdn.ts` | `baseUrl`、`staticUrl`、`ossUrl`、`cosUrl`。 |
103
+ | `cdn` | `configs/cdn.ts` | `baseUrl`、`staticUrl`、`ossUrl`、`cosUrl`、`isAccelerate`。 |
104
104
  | `log` | `configs/log.ts` | 请求/响应日志开关。 |
105
105
  | `mp` | `configs/mp.ts` | 小程序相关配置。 |
106
106
  | `app` | `configs/app.ts` | 应用 code、名称、主题色、AppId、渠道。 |
@@ -115,6 +115,7 @@ export default defineEnvConfig({
115
115
  | `toast` | `configs/toast.ts` | 自定义 Toast 适配。 |
116
116
  | `web` | `configs/web.ts` | Web 资源配置。 |
117
117
  | `storage` | `configs/storage.ts` | 本地存储 key 前缀。 |
118
+ | `updater` | `configs/updater.ts` | 版本检查请求函数,默认处理 APK 静态域名转换。 |
118
119
 
119
120
  ## app
120
121
 
@@ -0,0 +1,34 @@
1
+ # updater
2
+
3
+ 更新配置。发布路径:`@zfqh/uniapp/lib/configs/updater`
4
+
5
+ | 字段 | 类型 | 默认值 | 说明 |
6
+ | --- | --- | --- | --- |
7
+ | `request(params)` | `function` | 内置调用 `getLastVersion` | 版本检查请求;默认会将 `.apk` 的 COS 链接转为静态域名地址;当 `cdn.isAccelerate` 为 `true` 时处理所有 COS 链接,且 prod 环境使用 `acc-static` 域名。 |
8
+
9
+ `params` 参数:
10
+
11
+ | 字段 | 类型 | 说明 |
12
+ | --- | --- | --- |
13
+ | `version` | `number` | 当前版本号。 |
14
+ | `appId` | `string` | 应用 ID。 |
15
+ | `type` | `number` | 查询类型。 |
16
+ | `platform` | `string` | 平台标识。 |
17
+
18
+ ## 基本使用
19
+
20
+ 默认行为已满足大多数场景,无需额外配置。如需自定义版本检查逻辑,可覆盖 `request`:
21
+
22
+ ```ts
23
+ import { defineConfig } from '@zfqh/uniapp';
24
+
25
+ defineConfig({
26
+ updater: {
27
+ async request(params) {
28
+ // 自定义版本检查逻辑
29
+ const res = await myCustomApi(params);
30
+ return res;
31
+ },
32
+ },
33
+ });
34
+ ```
@@ -4,7 +4,7 @@
4
4
 
5
5
  | 字段 | 类型 | 默认值 | 说明 |
6
6
  | --- | --- | --- | --- |
7
- | `request(params)` | `function` | `Promise<null>` | 获取上传凭证;COS 上传会以 { mode: "cos" } 调用。 |
7
+ | `request(params)` | `function` | 内置调用 `getTencentToken` | 获取上传凭证;COS 上传会以 { mode: "cos" } 调用。 |
8
8
 
9
9
  COS 上传需要 `request` 返回:
10
10
 
@@ -20,25 +20,19 @@ COS 上传需要 `request` 返回:
20
20
 
21
21
  ## 基本使用
22
22
 
23
- 患者端和商户端上传图片时,通常从后端获取腾讯云临时密钥,并映射成 COS 工具需要的字段。
23
+ 默认已内置调用 `getTencentToken` 获取腾讯云临时密钥,通常无需额外配置。如需启用 COS 全球加速,在 cdn 配置中设置 `isAccelerate: true` 即可。
24
+
25
+ 仅当需要完全自定义请求逻辑时才需覆盖 `request`:
24
26
 
25
27
  ```ts
26
28
  import { defineConfig } from '@zfqh/uniapp';
27
- import { getTencentToken } from '@zfqh/uniapp/lib/apis';
28
29
 
29
30
  defineConfig({
30
31
  upload: {
31
32
  async request() {
32
- const { data } = await getTencentToken();
33
- return {
34
- secret_id: data.tmpSecretId,
35
- secret_key: data.tmpSecretKey,
36
- session_token: data.sessionToken,
37
- create_time: data.createTime,
38
- expire_time: data.expirationTime,
39
- bucket: data.bucket,
40
- region: data.region,
41
- };
33
+ // 自定义上传凭证逻辑
34
+ const res = await myCustomApi();
35
+ return res;
42
36
  },
43
37
  },
44
38
  });
@@ -8,6 +8,8 @@ declare const cdn: {
8
8
  ossUrl: string;
9
9
  /** 腾讯COS静态资源路径 */
10
10
  cosUrl: string;
11
+ /** 是否启用COS全球加速 */
12
+ isAccelerate: boolean;
11
13
  };
12
14
  export type CdnConfig = Partial<typeof cdn>;
13
15
  export default cdn;
@@ -8,5 +8,7 @@ const cdn = {
8
8
  ossUrl: '',
9
9
  /** 腾讯COS静态资源路径 */
10
10
  cosUrl: '',
11
+ /** 是否启用COS全球加速 */
12
+ isAccelerate: false,
11
13
  };
12
14
  export default cdn;
@@ -1,4 +1,5 @@
1
1
  import { ColorConfig } from './color';
2
+ import { CdnConfig } from './cdn';
2
3
  import { VerConfig } from './ver';
3
4
  import { AppConfig } from './app';
4
5
  import { TabbarConfig } from './tabbar';
@@ -6,6 +7,7 @@ import { PathConfig } from './path';
6
7
  import { PageConfig } from './page';
7
8
  import { LinkConfig } from './link';
8
9
  import { UploadConfig } from './upload';
10
+ import { UpdaterConfig } from './updater';
9
11
  import { NavigateConfig } from './navigate';
10
12
  import { ToastConfig } from './toast';
11
13
  import { DefineEnvConfig } from './env';
@@ -27,8 +29,12 @@ export interface DefineBaseConfig {
27
29
  navigate?: NavigateConfig;
28
30
  /** 上传配置 */
29
31
  upload?: UploadConfig;
32
+ /** 更新配置 */
33
+ updater?: UpdaterConfig;
30
34
  /** 版本配置 */
31
35
  ver?: VerConfig;
36
+ /** CDN配置 */
37
+ cdn?: CdnConfig;
32
38
  /** toast配置 */
33
39
  toast?: ToastConfig;
34
40
  /** 存储配置 */
@@ -52,6 +58,7 @@ declare const conf: {
52
58
  staticUrl: string;
53
59
  ossUrl: string;
54
60
  cosUrl: string;
61
+ isAccelerate: boolean;
55
62
  };
56
63
  /** 日志配置 */
57
64
  log: {
@@ -125,6 +132,8 @@ declare const conf: {
125
132
  };
126
133
  /** 上传配置 */
127
134
  upload: UploadConfig;
135
+ /** 更新配置 */
136
+ updater: UpdaterConfig;
128
137
  /** 导航配置 */
129
138
  navigate: {
130
139
  loginType: import("./navigate").NavigateType;
@@ -11,6 +11,7 @@ import path from './path';
11
11
  import page from './page';
12
12
  import link from './link';
13
13
  import upload from './upload';
14
+ import updater from './updater';
14
15
  import navigate from './navigate';
15
16
  import toast from './toast';
16
17
  import web from './web';
@@ -42,6 +43,8 @@ const conf = {
42
43
  page,
43
44
  /** 上传配置 */
44
45
  upload,
46
+ /** 更新配置 */
47
+ updater,
45
48
  /** 导航配置 */
46
49
  navigate,
47
50
  /** 版本配置 */
@@ -0,0 +1,15 @@
1
+ /** 更新配置参数 */
2
+ export type UpdateParams = {
3
+ version: number;
4
+ appId: string;
5
+ type: number;
6
+ platform?: string;
7
+ };
8
+ /** 更新配置 */
9
+ export type UpdaterConfig = {
10
+ /** 版本检查请求,客户端可根据业务自行覆盖 */
11
+ request: (params: UpdateParams) => Promise<any>;
12
+ };
13
+ /** 更新配置 */
14
+ declare const Updater: UpdaterConfig;
15
+ export default Updater;
@@ -0,0 +1,33 @@
1
+ import { getLastVersion } from '../apis/core';
2
+ import cdn from './cdn';
3
+ /** 将 COS 链接转为静态域名链接 */
4
+ function convertCosUrl(url) {
5
+ if (!url)
6
+ return url;
7
+ const isAccelerate = !!cdn.isAccelerate;
8
+ // 非加速模式仅处理 .apk
9
+ if (!isAccelerate && !/\.apk$/i.test(url))
10
+ return url;
11
+ const match = url.match(/^https?:\/\/([^.]+)\.cos\.[^.]+\.myqcloud\.com(\/.+)/);
12
+ if (!match)
13
+ return url;
14
+ const [, bucket, path] = match;
15
+ const envMatch = bucket.match(/^([a-z]+)[-_]/);
16
+ const envPrefix = envMatch ? envMatch[1] : '';
17
+ if (envPrefix) {
18
+ return `https://${envPrefix}-static.qihuang-ai.com${path}`;
19
+ }
20
+ return `https://${isAccelerate ? 'acc-' : ''}static.qihuang-ai.com${path}`;
21
+ }
22
+ /** 更新配置 */
23
+ const Updater = {
24
+ /** 版本检查请求,默认调用 getLastVersion 并处理 COS 链接 */
25
+ request: async (params) => {
26
+ const res = await getLastVersion(params, { custom: { message: false } });
27
+ if (res?.data?.fileUrl) {
28
+ res.data.fileUrl = convertCosUrl(res.data.fileUrl);
29
+ }
30
+ return res;
31
+ },
32
+ };
33
+ export default Updater;
@@ -1,7 +1,19 @@
1
- // 变量大写开头,否则小程序会报错,奇怪...
1
+ import { getTencentToken } from '../apis/core';
2
+ import cdn from './cdn';
2
3
  /** 上传配置 */
3
4
  const Upload = {
4
- /** 上传请求,例如获取Token */
5
- request: () => Promise.resolve(null),
5
+ /** 上传请求,默认调用 getTencentToken 获取腾讯云临时密钥 */
6
+ request: async () => {
7
+ const { data } = await getTencentToken();
8
+ return {
9
+ secret_id: data.tmpSecretId,
10
+ secret_key: data.tmpSecretKey,
11
+ session_token: data.sessionToken,
12
+ create_time: data.createTime,
13
+ expire_time: data.expirationTime,
14
+ bucket: data.bucket,
15
+ region: cdn.isAccelerate ? 'accelerate' : data.region,
16
+ };
17
+ },
6
18
  };
7
19
  export default Upload;
@@ -4,6 +4,7 @@ import { PLATFORM_CODE, IS_WEBVIEW_ENV, SYSTEM_INFO, TYPES } from '../utils/cons
4
4
  import app from '../configs/app';
5
5
  import { requestPermission } from '../utils/permit';
6
6
  import web from '../configs/web';
7
+ import cdn from '../configs/cdn';
7
8
  import link from '../configs/link';
8
9
  import path from '../configs/path';
9
10
  import { base64ToPath } from '../utils/file';
@@ -38,6 +39,7 @@ export default {
38
39
  safeTop: SYSTEM_INFO.safeAreaInsets.top,
39
40
  safeBottom: SYSTEM_INFO.safeAreaInsets.bottom,
40
41
  locale: uni.$i18n?.global?.locale,
42
+ accelerate: cdn.isAccelerate ? 1 : undefined,
41
43
  };
42
44
  if (query.primary) {
43
45
  if (String(query.primary).startsWith('#')) {
@@ -1,9 +1,9 @@
1
1
  import app from '../configs/app';
2
2
  import env from '../configs/env';
3
3
  import ver from '../configs/ver';
4
+ import updater from '../configs/updater';
4
5
  import { SYSTEM_INFO, IS_WEBVIEW_ENV, TYPES } from './consts';
5
6
  import { postMessage } from './index';
6
- import { getLastVersion } from '../apis/core';
7
7
  const { platform, brand } = SYSTEM_INFO;
8
8
  let _installMessageHandler = null;
9
9
  // #ifdef APP
@@ -66,12 +66,12 @@ export async function checkVersion(options) {
66
66
  type = 1;
67
67
  plat = { android: '1', ios: '2', harmony: '3', windows: '4', macos: '5' }[platform];
68
68
  }
69
- const res = await getLastVersion({
69
+ const res = await updater.request({
70
70
  version,
71
71
  appId,
72
72
  type,
73
73
  platform: plat,
74
- }, { custom: { message: false } });
74
+ });
75
75
  latest = res?.data;
76
76
  if (latest) {
77
77
  // #ifdef APP
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zfqh/uniapp",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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": "2527c90194ae48b8d23817b248f53cd6435fd3a0"
49
+ "gitHead": "e8db2e5a9fe9900f05fd763304bbd787f70a1fc1"
50
50
  }