@zfqh/uniapp 0.1.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 (310) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -0
  4. package/docs/api/apis/core.md +189 -0
  5. package/docs/api/apis/index.md +82 -0
  6. package/docs/api/apis/request.md +369 -0
  7. package/docs/api/configs/api.md +32 -0
  8. package/docs/api/configs/app.md +43 -0
  9. package/docs/api/configs/brand.md +43 -0
  10. package/docs/api/configs/cdn.md +35 -0
  11. package/docs/api/configs/color.md +144 -0
  12. package/docs/api/configs/env.md +120 -0
  13. package/docs/api/configs/index.md +394 -0
  14. package/docs/api/configs/link.md +33 -0
  15. package/docs/api/configs/log.md +27 -0
  16. package/docs/api/configs/mp.md +34 -0
  17. package/docs/api/configs/navigate.md +27 -0
  18. package/docs/api/configs/page.md +32 -0
  19. package/docs/api/configs/path.md +27 -0
  20. package/docs/api/configs/storage.md +24 -0
  21. package/docs/api/configs/tabbar.md +29 -0
  22. package/docs/api/configs/toast.md +35 -0
  23. package/docs/api/configs/update.md +25 -0
  24. package/docs/api/configs/upload.md +45 -0
  25. package/docs/api/configs/ver.md +32 -0
  26. package/docs/api/configs/web.md +28 -0
  27. package/docs/api/hooks/index.md +182 -0
  28. package/docs/api/hooks/useI18n.md +27 -0
  29. package/docs/api/hooks/useOverlay.md +37 -0
  30. package/docs/api/hooks/usePopup.md +35 -0
  31. package/docs/api/hooks/useVersion.md +23 -0
  32. package/docs/api/index.md +269 -0
  33. package/docs/api/mixins/app.md +29 -0
  34. package/docs/api/mixins/badge.md +23 -0
  35. package/docs/api/mixins/debounce.md +32 -0
  36. package/docs/api/mixins/deep.md +29 -0
  37. package/docs/api/mixins/index.md +23 -0
  38. package/docs/api/mixins/login.md +22 -0
  39. package/docs/api/mixins/model.md +26 -0
  40. package/docs/api/mixins/redirect.md +26 -0
  41. package/docs/api/mixins/share.md +29 -0
  42. package/docs/api/mixins/show.md +27 -0
  43. package/docs/api/mixins/webview.md +27 -0
  44. package/docs/api/modules/app.md +30 -0
  45. package/docs/api/modules/dict.md +28 -0
  46. package/docs/api/modules/im.md +22 -0
  47. package/docs/api/modules/index.md +44 -0
  48. package/docs/api/modules/launch.md +26 -0
  49. package/docs/api/modules/location.md +25 -0
  50. package/docs/api/modules/login.md +35 -0
  51. package/docs/api/modules/network.md +26 -0
  52. package/docs/api/modules/system.md +29 -0
  53. package/docs/api/utils/audio.md +84 -0
  54. package/docs/api/utils/consts.md +201 -0
  55. package/docs/api/utils/cos.md +269 -0
  56. package/docs/api/utils/debounce.md +89 -0
  57. package/docs/api/utils/file.md +78 -0
  58. package/docs/api/utils/index.md +547 -0
  59. package/docs/api/utils/locale.md +32 -0
  60. package/docs/api/utils/message.md +81 -0
  61. package/docs/api/utils/navigate.md +267 -0
  62. package/docs/api/utils/pages.md +205 -0
  63. package/docs/api/utils/permission.md +28 -0
  64. package/docs/api/utils/permit.md +62 -0
  65. package/docs/api/utils/query.md +89 -0
  66. package/docs/api/utils/request.md +34 -0
  67. package/docs/api/utils/storage.md +145 -0
  68. package/docs/api/utils/subscribe.md +77 -0
  69. package/docs/api/utils/throttle.md +101 -0
  70. package/docs/api/utils/toast.md +164 -0
  71. package/docs/api/utils/uni.md +28 -0
  72. package/docs/api/utils/update.md +165 -0
  73. package/docs/components/g-back-button.md +76 -0
  74. package/docs/components/g-checkbox-list.md +101 -0
  75. package/docs/components/g-container.md +93 -0
  76. package/docs/components/g-data-list.md +106 -0
  77. package/docs/components/g-dot-text.md +79 -0
  78. package/docs/components/g-env.md +75 -0
  79. package/docs/components/g-float.md +83 -0
  80. package/docs/components/g-grid-image.md +91 -0
  81. package/docs/components/g-grid-swiper.md +99 -0
  82. package/docs/components/g-icon.md +106 -0
  83. package/docs/components/g-mask.md +82 -0
  84. package/docs/components/g-money.md +90 -0
  85. package/docs/components/g-more.md +78 -0
  86. package/docs/components/g-page-container.md +170 -0
  87. package/docs/components/g-permission-popup.md +117 -0
  88. package/docs/components/g-polyline-chat.md +102 -0
  89. package/docs/components/g-polyline-view.md +67 -0
  90. package/docs/components/g-popup.md +144 -0
  91. package/docs/components/g-refresh-view.md +118 -0
  92. package/docs/components/g-render-image.md +83 -0
  93. package/docs/components/g-search.md +120 -0
  94. package/docs/components/g-share-photo.md +77 -0
  95. package/docs/components/g-share-view.md +83 -0
  96. package/docs/components/g-share-weixin.md +81 -0
  97. package/docs/components/g-skeleton-view.md +71 -0
  98. package/docs/components/g-skeleton.md +64 -0
  99. package/docs/components/g-tag-editor.md +134 -0
  100. package/docs/components/g-timer.md +72 -0
  101. package/docs/components/g-trtc-room.md +116 -0
  102. package/docs/components/g-trtc-tui.md +84 -0
  103. package/docs/components/g-trtc.md +124 -0
  104. package/docs/components/g-upload.md +117 -0
  105. package/docs/components/g-waterfall.md +84 -0
  106. package/docs/components/index.md +109 -0
  107. package/docs/components/styles/base-styles.md +367 -0
  108. package/docs/components/styles/global-vars.md +150 -0
  109. package/docs/components/usage.md +112 -0
  110. package/docs/faq/index.md +78 -0
  111. package/docs/guide/getting-started.md +195 -0
  112. package/docs/guide/project-frame.md +297 -0
  113. package/docs/index.md +80 -0
  114. package/lib/apis/core.d.ts +12 -0
  115. package/lib/apis/core.js +13 -0
  116. package/lib/apis/index.d.ts +2 -0
  117. package/lib/apis/index.js +2 -0
  118. package/lib/apis/request.d.ts +4 -0
  119. package/lib/apis/request.js +27 -0
  120. package/lib/components/g-back-button/g-back-button.vue +141 -0
  121. package/lib/components/g-checkbox-list/g-checkbox-list.vue +156 -0
  122. package/lib/components/g-container/g-container.vue +159 -0
  123. package/lib/components/g-data-list/g-data-list.vue +192 -0
  124. package/lib/components/g-dot-text/g-dot-text.vue +114 -0
  125. package/lib/components/g-env/g-env.vue +123 -0
  126. package/lib/components/g-float/g-float.vue +131 -0
  127. package/lib/components/g-grid-image/g-grid-image.vue +84 -0
  128. package/lib/components/g-grid-swiper/g-grid-swiper.vue +224 -0
  129. package/lib/components/g-icon/g-icon.vue +72 -0
  130. package/lib/components/g-mask/g-mask.vue +126 -0
  131. package/lib/components/g-money/g-money.vue +174 -0
  132. package/lib/components/g-more/g-more.vue +68 -0
  133. package/lib/components/g-page-container/g-page-container.vue +470 -0
  134. package/lib/components/g-permission-popup/g-permission-popup.vue +80 -0
  135. package/lib/components/g-polyline-chat/g-polyline-chat.vue +255 -0
  136. package/lib/components/g-polyline-view/g-polyline-view.vue +104 -0
  137. package/lib/components/g-popup/g-popup.vue +449 -0
  138. package/lib/components/g-refresh-view/g-refresh-view.vue +213 -0
  139. package/lib/components/g-render-image/g-render-image.vue +222 -0
  140. package/lib/components/g-search/g-search.vue +274 -0
  141. package/lib/components/g-share-photo/g-share-photo.vue +75 -0
  142. package/lib/components/g-share-view/g-share-view.vue +157 -0
  143. package/lib/components/g-share-weixin/g-share-weixin.vue +106 -0
  144. package/lib/components/g-skeleton/g-skeleton.vue +55 -0
  145. package/lib/components/g-skeleton-view/g-skeleton-view.vue +78 -0
  146. package/lib/components/g-tag-editor/g-tag-editor.vue +482 -0
  147. package/lib/components/g-timer/g-timer.vue +61 -0
  148. package/lib/components/g-trtc/g-trtc.vue +347 -0
  149. package/lib/components/g-trtc-room/g-trtc-room.vue +524 -0
  150. package/lib/components/g-trtc-room/iconfont.scss +59 -0
  151. package/lib/components/g-trtc-tui/g-trtc-tui.vue +245 -0
  152. package/lib/components/g-upload/g-upload.vue +294 -0
  153. package/lib/components/g-waterfall/g-waterfall.vue +101 -0
  154. package/lib/configs/api.d.ts +7 -0
  155. package/lib/configs/api.js +6 -0
  156. package/lib/configs/app.d.ts +26 -0
  157. package/lib/configs/app.js +50 -0
  158. package/lib/configs/brand.d.ts +22 -0
  159. package/lib/configs/brand.js +26 -0
  160. package/lib/configs/cdn.d.ts +13 -0
  161. package/lib/configs/cdn.js +12 -0
  162. package/lib/configs/color.d.ts +62 -0
  163. package/lib/configs/color.js +66 -0
  164. package/lib/configs/env.d.ts +37 -0
  165. package/lib/configs/env.js +71 -0
  166. package/lib/configs/index.d.ts +170 -0
  167. package/lib/configs/index.js +82 -0
  168. package/lib/configs/link.d.ts +11 -0
  169. package/lib/configs/link.js +3 -0
  170. package/lib/configs/log.d.ts +9 -0
  171. package/lib/configs/log.js +8 -0
  172. package/lib/configs/mp.d.ts +15 -0
  173. package/lib/configs/mp.js +9 -0
  174. package/lib/configs/navigate.d.ts +17 -0
  175. package/lib/configs/navigate.js +5 -0
  176. package/lib/configs/page.d.ts +18 -0
  177. package/lib/configs/page.js +14 -0
  178. package/lib/configs/path.d.ts +11 -0
  179. package/lib/configs/path.js +10 -0
  180. package/lib/configs/storage.d.ts +7 -0
  181. package/lib/configs/storage.js +6 -0
  182. package/lib/configs/tabbar.d.ts +7 -0
  183. package/lib/configs/tabbar.js +6 -0
  184. package/lib/configs/toast.d.ts +18 -0
  185. package/lib/configs/toast.js +29 -0
  186. package/lib/configs/update.d.ts +45 -0
  187. package/lib/configs/update.js +6 -0
  188. package/lib/configs/upload.d.ts +30 -0
  189. package/lib/configs/upload.js +7 -0
  190. package/lib/configs/ver.d.ts +8 -0
  191. package/lib/configs/ver.js +28 -0
  192. package/lib/configs/web.d.ts +5 -0
  193. package/lib/configs/web.js +2 -0
  194. package/lib/hooks/index.d.ts +4 -0
  195. package/lib/hooks/index.js +4 -0
  196. package/lib/hooks/useI18n.d.ts +2 -0
  197. package/lib/hooks/useI18n.js +19 -0
  198. package/lib/hooks/useOverlay.d.ts +1 -0
  199. package/lib/hooks/useOverlay.js +17 -0
  200. package/lib/hooks/usePopup.d.ts +1 -0
  201. package/lib/hooks/usePopup.js +14 -0
  202. package/lib/hooks/useVersion.d.ts +6 -0
  203. package/lib/hooks/useVersion.js +21 -0
  204. package/lib/index.d.ts +26 -0
  205. package/lib/index.js +33 -0
  206. package/lib/mixins/app.d.ts +14 -0
  207. package/lib/mixins/app.js +105 -0
  208. package/lib/mixins/badge.d.ts +24 -0
  209. package/lib/mixins/badge.js +44 -0
  210. package/lib/mixins/debounce.d.ts +6 -0
  211. package/lib/mixins/debounce.js +11 -0
  212. package/lib/mixins/deep.d.ts +6 -0
  213. package/lib/mixins/deep.js +8 -0
  214. package/lib/mixins/index.d.ts +8 -0
  215. package/lib/mixins/index.js +8 -0
  216. package/lib/mixins/login.d.ts +4 -0
  217. package/lib/mixins/login.js +25 -0
  218. package/lib/mixins/model.d.ts +22 -0
  219. package/lib/mixins/model.js +29 -0
  220. package/lib/mixins/redirect.d.ts +8 -0
  221. package/lib/mixins/redirect.js +94 -0
  222. package/lib/mixins/share.d.ts +15 -0
  223. package/lib/mixins/share.js +55 -0
  224. package/lib/mixins/show.d.ts +9 -0
  225. package/lib/mixins/show.js +16 -0
  226. package/lib/mixins/webview.d.ts +26 -0
  227. package/lib/mixins/webview.js +225 -0
  228. package/lib/modules/app.d.ts +5 -0
  229. package/lib/modules/app.js +19 -0
  230. package/lib/modules/dict.d.ts +8 -0
  231. package/lib/modules/dict.js +43 -0
  232. package/lib/modules/im.d.ts +6 -0
  233. package/lib/modules/im.js +105 -0
  234. package/lib/modules/index.d.ts +8 -0
  235. package/lib/modules/index.js +8 -0
  236. package/lib/modules/launch.d.ts +5 -0
  237. package/lib/modules/launch.js +32 -0
  238. package/lib/modules/location.d.ts +5 -0
  239. package/lib/modules/location.js +57 -0
  240. package/lib/modules/login.d.ts +5 -0
  241. package/lib/modules/login.js +72 -0
  242. package/lib/modules/network.d.ts +5 -0
  243. package/lib/modules/network.js +39 -0
  244. package/lib/modules/system.d.ts +5 -0
  245. package/lib/modules/system.js +65 -0
  246. package/lib/styles/animate-vue.scss +3 -0
  247. package/lib/styles/animate.scss +27 -0
  248. package/lib/styles/bg-vue.scss +21 -0
  249. package/lib/styles/bg.scss +93 -0
  250. package/lib/styles/border.scss +218 -0
  251. package/lib/styles/flex-nvue.scss +64 -0
  252. package/lib/styles/flex-vue.scss +75 -0
  253. package/lib/styles/font.scss +59 -0
  254. package/lib/styles/index.scss +25 -0
  255. package/lib/styles/layout-nvue.scss +24 -0
  256. package/lib/styles/layout-vue.scss +30 -0
  257. package/lib/styles/layout.scss +76 -0
  258. package/lib/styles/opacity.scss +10 -0
  259. package/lib/styles/reset-vue.scss +46 -0
  260. package/lib/styles/shadow.scss +12 -0
  261. package/lib/styles/sizing-vue.scss +21 -0
  262. package/lib/styles/sizing.scss +21 -0
  263. package/lib/styles/spacing.scss +234 -0
  264. package/lib/styles/text-nvue.scss +21 -0
  265. package/lib/styles/text-vue.scss +70 -0
  266. package/lib/styles/text.scss +122 -0
  267. package/lib/styles/var.module.scss +29 -0
  268. package/lib/utils/audio.d.ts +14 -0
  269. package/lib/utils/audio.js +43 -0
  270. package/lib/utils/consts.d.ts +30 -0
  271. package/lib/utils/consts.js +52 -0
  272. package/lib/utils/cos.d.ts +15 -0
  273. package/lib/utils/cos.js +140 -0
  274. package/lib/utils/debounce.d.ts +2 -0
  275. package/lib/utils/debounce.js +30 -0
  276. package/lib/utils/file.d.ts +28 -0
  277. package/lib/utils/file.js +292 -0
  278. package/lib/utils/index.d.ts +166 -0
  279. package/lib/utils/index.js +485 -0
  280. package/lib/utils/locale.d.ts +6 -0
  281. package/lib/utils/locale.js +19 -0
  282. package/lib/utils/message.d.ts +9 -0
  283. package/lib/utils/message.js +63 -0
  284. package/lib/utils/navigate.d.ts +27 -0
  285. package/lib/utils/navigate.js +183 -0
  286. package/lib/utils/pages.d.ts +21 -0
  287. package/lib/utils/pages.js +79 -0
  288. package/lib/utils/permission.d.ts +16 -0
  289. package/lib/utils/permission.js +291 -0
  290. package/lib/utils/permit.d.ts +30 -0
  291. package/lib/utils/permit.js +181 -0
  292. package/lib/utils/query.d.ts +13 -0
  293. package/lib/utils/query.js +14 -0
  294. package/lib/utils/request.d.ts +8 -0
  295. package/lib/utils/request.js +126 -0
  296. package/lib/utils/storage.d.ts +53 -0
  297. package/lib/utils/storage.js +145 -0
  298. package/lib/utils/subscribe.d.ts +7 -0
  299. package/lib/utils/subscribe.js +94 -0
  300. package/lib/utils/throttle.d.ts +2 -0
  301. package/lib/utils/throttle.js +32 -0
  302. package/lib/utils/toast.d.ts +17 -0
  303. package/lib/utils/toast.js +66 -0
  304. package/lib/utils/uni.d.ts +1 -0
  305. package/lib/utils/uni.js +147 -0
  306. package/lib/utils/update.d.ts +9 -0
  307. package/lib/utils/update.js +376 -0
  308. package/package.json +49 -0
  309. package/types/index.d.ts +25 -0
  310. package/types/virtual.d.ts +1 -0
@@ -0,0 +1,120 @@
1
+ # env
2
+
3
+ 环境配置。发布路径:`@zfqh/uniapp/lib/configs/env`
4
+
5
+ | 字段 | 类型 | 默认值 | 说明 |
6
+ | --- | --- | --- | --- |
7
+ | `env.name` | `string` | `dev/prod/local` | 当前环境显示名。 |
8
+ | `env.key` | `string` | `''` | 从 `.env.<key>.ts` 文件名推导的环境 key。 |
9
+ | `env.store` | `string` | `-` | 非小程序端本地缓存的环境覆盖值。 |
10
+ | `env.set(e)` | `function` | `-` | 切换环境并重新合并环境配置。 |
11
+
12
+ ---
13
+
14
+ ## 环境配置
15
+
16
+ 环境配置由 `@zfqh/uniapp/lib/configs/env` 管理。它通过 Vite 的 `import.meta.glob('@env/.env.*.*')` 自动发现环境文件。
17
+
18
+ ## 文件命名
19
+
20
+ 支持以下命名:
21
+
22
+ ```text
23
+ env/.env.dev.ts
24
+ env/.env.sit.ts
25
+ env/.env.uat.ts
26
+ env/.env.pre.ts
27
+ env/.env.prod.ts
28
+ env/.env.local.ts
29
+ ```
30
+
31
+ 也支持 `.js`、`.mjs`、`.mts` 等扩展名,只要匹配 `.env.<name>.<ext>`。
32
+
33
+ ## 示例
34
+
35
+ ```ts
36
+ import { defineEnvConfig } from '@zfqh/uniapp';
37
+
38
+ export default defineEnvConfig({
39
+ env: {
40
+ name: '开发环境',
41
+ },
42
+ ver: {
43
+ code: 999,
44
+ },
45
+ api: {
46
+ baseUrl: 'https://dev-api.example.com',
47
+ },
48
+ cdn: {
49
+ baseUrl: 'https://cdn.example.com',
50
+ cosUrl: 'https://example.cos.ap-nanjing.myqcloud.com',
51
+ },
52
+ web: {
53
+ patient: 'https://dev-patient.example.com',
54
+ doctor: 'https://dev-doctor.example.com',
55
+ },
56
+ log: {
57
+ request: true,
58
+ response: true,
59
+ },
60
+ mp: {
61
+ envVersion: 'develop',
62
+ },
63
+ });
64
+ ```
65
+
66
+ 环境文件中的 `env.name` 如果未设置,会使用文件名中的环境名;同时会自动补充 `env.key`。
67
+
68
+ ## 字段说明
69
+
70
+ | 字段 | 说明 |
71
+ | --- | --- |
72
+ | `env.name` | 环境显示名。 |
73
+ | `ver.code` | 资源版本号,用于更新检测和错误上报。 |
74
+ | `api.baseUrl` | 接口请求基础地址。 |
75
+ | `cdn.baseUrl` | 静态资源基础路径。 |
76
+ | `cdn.cosUrl` | 腾讯 COS 资源路径。 |
77
+ | `web` | Web 资源配置,键值对映射自定义协议到静态站点入口(如 `patient`、`doctor`)。 |
78
+ | `log.request` / `log.response` | 请求/响应日志开关。 |
79
+ | `mp.envVersion` | 小程序版本环境(`release`、`develop`、`trial`)。 |
80
+
81
+ 完整字段参考 [配置概览](./)。
82
+
83
+ ## 选择规则
84
+
85
+ 运行时选择环境的逻辑:
86
+
87
+ | 场景 | 选择规则 |
88
+ | --- | --- |
89
+ | 生产构建,且 `BUILD_ENV` 存在于环境文件列表 | 使用 `BUILD_ENV`。 |
90
+ | 生产构建,其他情况 | 使用 `prod`。 |
91
+ | 非生产构建,且存在 `local` | 使用 `local`。 |
92
+ | 非生产构建,其他情况 | 使用 `dev`。 |
93
+
94
+ 非小程序端还支持 `env.set(name)` 写入本地存储,下次会优先使用存储中的环境名。
95
+
96
+ ```ts
97
+ import { config } from '@zfqh/uniapp';
98
+
99
+ config.env.set('sit');
100
+ ```
101
+
102
+ ## 与 @gmcb/vite 配合
103
+
104
+ `@gmcb/vite` 会配置:
105
+
106
+ ```ts
107
+ resolve: {
108
+ alias: {
109
+ '@env': join(process.env.VITE_ROOT_DIR, './env'),
110
+ },
111
+ }
112
+ ```
113
+
114
+ 如果业务项目的 `env` 目录不在默认位置,需要在构建命令里设置 `VITE_ROOT_DIR` 或自行配置别名。
115
+
116
+ ## 生产构建注意
117
+
118
+ `@gmcb/vite` 的 `cleanEnv()` 插件会在生产构建时清理非当前环境配置,避免多环境信息进入产物。
119
+
120
+ 因此推荐通过 `gmcb build -e sit` 或 `BUILD_ENV=sit` 明确构建目标环境。
@@ -0,0 +1,394 @@
1
+ # 配置
2
+
3
+ `defineConfig` 会把传入配置深度合并到包内默认配置对象上;`defineEnvConfig` 用于 `@env/.env.<env>.ts` 环境文件。配置对象会被请求、导航、上传、更新、组件和 mixin 共同读取。
4
+
5
+ ## 基本使用
6
+
7
+ ```ts
8
+ import { defineConfig, createPages } from '@zfqh/uniapp';
9
+ import { app } from '@zfqh/uniapp/lib/configs/app';
10
+ import { brand } from '@zfqh/uniapp/lib/configs/brand';
11
+ // #ifdef H5
12
+ import pages from 'virtual:remove-json-comments@/pages.json';
13
+ // #endif
14
+ // #ifndef H5
15
+ import pages from '@/pages.json';
16
+ // #endif
17
+
18
+ defineConfig({
19
+ app: app.patient,
20
+ brand: brand.zfqh,
21
+ page: createPages(pages),
22
+ path: {
23
+ index: '/pages/index/index',
24
+ login: '/pages/public/login/login',
25
+ webview: '/pages/public/webview/webview',
26
+ },
27
+ });
28
+ ```
29
+
30
+ `defineConfig` 会修改包内部单例配置,业务配置文件只要被入口导入执行即可生效。内置 `app`、`brand` 预设不从根入口导出,需要从 `@zfqh/uniapp/lib/configs/app`、`@zfqh/uniapp/lib/configs/brand` 深度引用。
31
+
32
+ ## defineEnvConfig
33
+
34
+ ```ts
35
+ // @env/.env.dev.ts
36
+ import { defineEnvConfig } from '@zfqh/uniapp';
37
+
38
+ export default defineEnvConfig({
39
+ env: { name: '开发环境' },
40
+ api: { baseUrl: 'https://dev-api.example.com' },
41
+ });
42
+ ```
43
+
44
+ ---
45
+
46
+ ## 配置系统
47
+
48
+ 配置系统发布路径为 `@zfqh/uniapp/lib/configs`。根入口导出:
49
+
50
+ ```ts
51
+ import { defineConfig, defineEnvConfig, config } from '@zfqh/uniapp';
52
+ ```
53
+
54
+ ## defineConfig
55
+
56
+ `defineConfig` 用于合并基础配置:
57
+
58
+ ```ts
59
+ import { defineConfig, createPages } from '@zfqh/uniapp';
60
+ import { app } from '@zfqh/uniapp/lib/configs/app';
61
+ import { brand } from '@zfqh/uniapp/lib/configs/brand';
62
+ // #ifdef H5
63
+ import pages from 'virtual:remove-json-comments@/pages.json';
64
+ // #endif
65
+ // #ifndef H5
66
+ import pages from '@/pages.json';
67
+ // #endif
68
+
69
+ defineConfig({
70
+ app: app.patient,
71
+ brand: brand.zfqh,
72
+ page: createPages(pages),
73
+ path: {
74
+ index: '/pages/index/index',
75
+ login: '/pages/public/login/login',
76
+ webview: '/pages/public/webview/webview',
77
+ },
78
+ });
79
+ ```
80
+
81
+ 实现上使用 `deepMerge` 合并默认配置。传入字段为 `null` 或 `undefined` 时不会覆盖已有值。
82
+
83
+ 实际业务项目里,通常会在 `config.js` 或 `src/config.js` 中直接调用 `defineConfig(...)`。`defineConfig` 会修改并返回内部单例配置对象,配置文件只要被入口导入执行即可,不强制要求 `export default`。
84
+
85
+ ## defineEnvConfig
86
+
87
+ `defineEnvConfig` 用于声明 `@env/.env.<env>.ts` 文件:
88
+
89
+ ```ts
90
+ import { defineEnvConfig } from '@zfqh/uniapp';
91
+
92
+ export default defineEnvConfig({
93
+ api: {
94
+ baseUrl: 'https://api.example.com',
95
+ },
96
+ });
97
+ ```
98
+
99
+ ## 配置项总览
100
+
101
+ | 配置项 | 文件 | 说明 |
102
+ | --- | --- | --- |
103
+ | `env` | `configs/env.ts` | 当前环境信息,自动读取环境文件。 |
104
+ | `api` | `configs/api.ts` | `baseUrl` 接口地址。 |
105
+ | `cdn` | `configs/cdn.ts` | `baseUrl`、`staticUrl`、`ossUrl`、`cosUrl`。 |
106
+ | `log` | `configs/log.ts` | 请求/响应日志开关。 |
107
+ | `mp` | `configs/mp.ts` | 小程序相关配置。 |
108
+ | `app` | `configs/app.ts` | 应用 code、名称、主题色、AppId、渠道。 |
109
+ | `brand` | `configs/brand.ts` | 品牌 code、名称、资源等。 |
110
+ | `tabbar` | `configs/tabbar.ts` | tabbar 相关配置。 |
111
+ | `path` | `configs/path.ts` | 页面别名配置。 |
112
+ | `link` | `configs/link.ts` | 外部链接配置。 |
113
+ | `page` | `configs/page.ts` | 页面集合、tabBar、原生页、登录页集合。 |
114
+ | `update` | `configs/update.ts` | App 更新请求函数。 |
115
+ | `upload` | `configs/upload.ts` | 上传临时凭证请求函数。 |
116
+ | `navigate` | `configs/navigate.ts` | 登录跳转方式和来源页策略。 |
117
+ | `ver` | `configs/ver.ts` | 当前版本号和版本名。 |
118
+ | `toast` | `configs/toast.ts` | 自定义 Toast 适配。 |
119
+ | `web` | `configs/web.ts` | Web 资源配置。 |
120
+ | `storage` | `configs/storage.ts` | 本地存储 key 前缀。 |
121
+
122
+ ## app
123
+
124
+ ```ts
125
+ import { defineConfig } from '@zfqh/uniapp';
126
+ import { app } from '@zfqh/uniapp/lib/configs/app';
127
+
128
+ defineConfig({
129
+ app: app.patient,
130
+ });
131
+ ```
132
+
133
+ 内置预设包含 `patient`、`doctor`、`merchant` 三类应用配置。预设不从根入口导出,需要从深度路径引用:
134
+
135
+ ```ts
136
+ import { app } from '@zfqh/uniapp/lib/configs/app';
137
+ ```
138
+
139
+ 也可以在预设基础上覆盖字段:
140
+
141
+ ```ts
142
+ defineConfig({
143
+ app: {
144
+ ...app.merchant,
145
+ name: '自定义门店端',
146
+ },
147
+ });
148
+ ```
149
+
150
+ ## brand
151
+
152
+ ```ts
153
+ import { brand } from '@zfqh/uniapp/lib/configs/brand';
154
+
155
+ defineConfig({
156
+ brand: brand.zfqh,
157
+ });
158
+ ```
159
+
160
+ 内置品牌预设当前包含 `brand.zfqh`。如需项目自定义品牌,可覆盖 `code`、`name`、`telephone`、`company`、`primary`。
161
+
162
+ ## color
163
+
164
+ 门店端等项目可覆盖主题色:
165
+
166
+ ```ts
167
+ defineConfig({
168
+ color: {
169
+ primary: '#451709',
170
+ primaryDark: '#451709',
171
+ primaryDisabled: '#D5B9B0',
172
+ primaryLight: '#E8D8C9',
173
+ },
174
+ });
175
+ ```
176
+
177
+ ## page
178
+
179
+ ```ts
180
+ import { createPages } from '@zfqh/uniapp';
181
+ // #ifdef H5
182
+ import pages from 'virtual:remove-json-comments@/pages.json';
183
+ // #endif
184
+ // #ifndef H5
185
+ import pages from '@/pages.json';
186
+ // #endif
187
+
188
+ defineConfig({
189
+ page: createPages(pages),
190
+ path: {
191
+ index: '/pages/index/index',
192
+ login: '/pages/public/login/login',
193
+ webview: '/pages/public/webview/webview',
194
+ },
195
+ });
196
+ ```
197
+
198
+ `navigate` 会读取这些集合来判断是否需要登录、是否 tabBar、是否应作为原生页面跳转。
199
+
200
+ `createPages(pages)` 会读取 `pages.json` 中的:
201
+
202
+ | 来源字段 | 生成配置 |
203
+ | --- | --- |
204
+ | `pages[].path` | `page.pages` |
205
+ | `subPackages[].root` + `pages[].path` | `page.pages` |
206
+ | `tabBar.list[].pagePath` | `page.tabBarPages` |
207
+ | 页面项 `native` | `page.nativePages` |
208
+ | 页面项 `needLogin` | `page.needLoginPages` |
209
+ | 页面项 `notRedirect` | `page.notRedirectPages` |
210
+ | `global.native/needLogin/notRedirect` | 页面项默认值 |
211
+
212
+ 如果 H5 端直接导入带注释的 `pages.json` 会失败,可参考业务项目使用 `virtual:remove-json-comments@/pages.json`。
213
+
214
+ ## navigate
215
+
216
+ ```ts
217
+ defineConfig({
218
+ navigate: {
219
+ loginType: 'navigateTo',
220
+ referrerType: 'target',
221
+ },
222
+ });
223
+ ```
224
+
225
+ | 字段 | 可选值 | 说明 |
226
+ | --- | --- | --- |
227
+ | `loginType` | `navigateTo`、`reLaunch`、`redirectTo` | 未登录时跳转登录页的方法。 |
228
+ | `referrerType` | `none`、`target`、`referrer`、`combine` | 登录后回跳策略。 |
229
+
230
+ ## toast
231
+
232
+ 默认使用 `uni.showToast`。如果业务有自定义 Toast 组件,可开启:
233
+
234
+ ```ts
235
+ defineConfig({
236
+ toast: {
237
+ custom: true,
238
+ show(options) {
239
+ const page = getCurrentPages().pop() as any;
240
+ page?.$vm?.$refs?.toast?.show({
241
+ type: options.icon,
242
+ message: options.title,
243
+ });
244
+ return true;
245
+ },
246
+ hide() {
247
+ const page = getCurrentPages().pop() as any;
248
+ page?.$vm?.$refs?.toast?.hide();
249
+ return true;
250
+ },
251
+ },
252
+ });
253
+ ```
254
+
255
+ `show` 或 `hide` 返回 `false` 时会回退到 uni 原生 Toast。
256
+
257
+ ## upload
258
+
259
+ COS 上传依赖 `upload.request` 获取临时凭证:
260
+
261
+ ```ts
262
+ import { getTencentToken } from '@zfqh/uniapp/lib/apis';
263
+
264
+ defineConfig({
265
+ upload: {
266
+ async request() {
267
+ const { data } = await getTencentToken();
268
+ return {
269
+ secret_id: data.tmpSecretId,
270
+ secret_key: data.tmpSecretKey,
271
+ session_token: data.sessionToken,
272
+ create_time: data.createTime,
273
+ expire_time: data.expirationTime,
274
+ bucket: data.bucket,
275
+ region: data.region,
276
+ };
277
+ },
278
+ },
279
+ });
280
+ ```
281
+
282
+ 如果业务需要腾讯云全球加速,可以按项目状态动态改写 `region`:
283
+
284
+ ```ts
285
+ import { getTencentToken } from '@zfqh/uniapp/lib/apis';
286
+ import store from '@/store';
287
+
288
+ defineConfig({
289
+ upload: {
290
+ async request() {
291
+ const { data } = await getTencentToken();
292
+ return {
293
+ secret_id: data.tmpSecretId,
294
+ secret_key: data.tmpSecretKey,
295
+ session_token: data.sessionToken,
296
+ create_time: data.createTime,
297
+ expire_time: data.expirationTime,
298
+ bucket: data.bucket,
299
+ region: store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
300
+ };
301
+ },
302
+ },
303
+ });
304
+ ```
305
+
306
+ `getTencentToken` 是 `@zfqh/uniapp/lib/apis` 内置的 COS 临时密钥接口,对应 `/app-api/infra/file/getTencentToken`。如果业务项目使用自己的接口,可替换请求函数,但需要返回下方字段。
307
+
308
+ 返回数据需要包含:
309
+
310
+ ```ts
311
+ {
312
+ secret_id: string;
313
+ secret_key: string;
314
+ session_token: string;
315
+ bucket: string;
316
+ region: string;
317
+ create_time?: number;
318
+ expire_time?: number;
319
+ }
320
+ ```
321
+
322
+ ## update
323
+
324
+ App 更新能力依赖 `update.request`:
325
+
326
+ ```ts
327
+ defineConfig({
328
+ update: {
329
+ request(data) {
330
+ return POST('/app-api/system/app/version/latest', data);
331
+ },
332
+ },
333
+ });
334
+ ```
335
+
336
+ 返回数据可包含 `hot_update`、`force_update`、`wgt_url`、`apk_url`、`ipa_url`、`exe_url`、`dmg_url` 等字段。
337
+
338
+ ## storage
339
+
340
+ ```ts
341
+ defineConfig({
342
+ storage: {
343
+ prefix: 'zfqh',
344
+ },
345
+ });
346
+ ```
347
+
348
+ `storageKeys` 会基于此前缀生成统一 key。
349
+
350
+ ## 在业务代码中访问 config
351
+
352
+ `config` 是运行时单例对象,业务代码可以直接导入访问所有配置:
353
+
354
+ ```ts
355
+ import { config } from '@zfqh/uniapp';
356
+
357
+ // API 地址
358
+ console.log(config.api.baseUrl); // 'https://dev-api.example.com'
359
+
360
+ // CDN 资源
361
+ console.log(config.cdn.staticUrl); // 'https://cdn.example.com/static'
362
+ console.log(config.cdn.cosUrl); // 'https://bucket.cos.ap-nanjing.myqcloud.com'
363
+
364
+ // Web 资源
365
+ console.log(config.web.patient); // 'https://patient.example.com'
366
+ console.log(config.web.doctor); // 'https://doctor.example.com'
367
+
368
+ // 环境信息
369
+ console.log(config.env.name); // '开发环境'
370
+ console.log(config.env.key); // 'dev'
371
+
372
+ // 版本信息
373
+ console.log(config.ver.code); // 999
374
+ console.log(config.ver.name); // '1.0.0'
375
+
376
+ // 应用配置
377
+ console.log(config.app.name); // '智赋岐黄'
378
+ console.log(config.app.channel); // 3
379
+
380
+ // 品牌配置
381
+ console.log(config.brand.code); // 'zfqh'
382
+ console.log(config.brand.name); // '智赋岐黄'
383
+ ```
384
+
385
+ ### 运行时切换环境
386
+
387
+ 非小程序端支持运行时切换环境:
388
+
389
+ ```ts
390
+ import { config } from '@zfqh/uniapp';
391
+
392
+ // 切换到 sit 环境(会重新合并环境配置)
393
+ config.env.set('sit');
394
+ ```
@@ -0,0 +1,33 @@
1
+ # link
2
+
3
+ 链接配置。发布路径:`@zfqh/uniapp/lib/configs/link`
4
+
5
+ | 字段 | 类型 | 默认值 | 说明 |
6
+ | --- | --- | --- | --- |
7
+ | `[key].url` | `string` | `-` | 链接地址。 |
8
+ | `[key].title` | `string` | `-` | 链接标题。 |
9
+
10
+ ## 基本使用
11
+
12
+ 把协议、帮助中心等固定外链放入 `link` 配置,页面跳转时用统一 key 获取地址。
13
+
14
+ ```ts
15
+ import { defineConfig, config, navigate } from '@zfqh/uniapp';
16
+
17
+ defineConfig({
18
+ link: {
19
+ privacy: {
20
+ title: '隐私政策',
21
+ url: 'https://static.example.com/privacy.html',
22
+ },
23
+ },
24
+ });
25
+
26
+ export function openPrivacy() {
27
+ const item = config.link.privacy;
28
+ navigate('/pages/webview/webview', {
29
+ title: item.title,
30
+ url: item.url,
31
+ });
32
+ }
33
+ ```
@@ -0,0 +1,27 @@
1
+ # log
2
+
3
+ 日志配置。发布路径:`@zfqh/uniapp/lib/configs/log`
4
+
5
+ | 字段 | 类型 | 默认值 | 说明 |
6
+ | --- | --- | --- | --- |
7
+ | `request` | `boolean` | `false` | 是否打印请求日志。 |
8
+ | `response` | `boolean` | `false` | 是否打印响应日志。 |
9
+
10
+ ## 基本使用
11
+
12
+ 开发和联调环境可以打开请求日志,生产环境建议关闭。
13
+
14
+ ```ts
15
+ // env/.env.dev.ts
16
+ import { defineEnvConfig } from '@zfqh/uniapp';
17
+
18
+ export default defineEnvConfig({
19
+ env: {
20
+ name: 'dev',
21
+ },
22
+ log: {
23
+ request: true,
24
+ response: true,
25
+ },
26
+ });
27
+ ```
@@ -0,0 +1,34 @@
1
+ # mp
2
+
3
+ 小程序配置。发布路径:`@zfqh/uniapp/lib/configs/mp`
4
+
5
+ | 字段 | 类型 | 默认值 | 说明 |
6
+ | --- | --- | --- | --- |
7
+ | `envVersion` | `release/develop/trial` | `release` | 小程序版本环境。 |
8
+ | `envType` | `number` | `0` | 小程序环境数值标识。 |
9
+
10
+ ## 基本使用
11
+
12
+ 需要跳转微信小程序或区分体验版/正式版时,在环境配置中声明小程序版本。
13
+
14
+ ```ts
15
+ // env/.env.sit.ts
16
+ import { defineEnvConfig } from '@zfqh/uniapp';
17
+
18
+ export default defineEnvConfig({
19
+ mp: {
20
+ envVersion: 'trial',
21
+ envType: 1,
22
+ },
23
+ });
24
+ ```
25
+
26
+ ```ts
27
+ import { config } from '@zfqh/uniapp';
28
+
29
+ uni.navigateToMiniProgram({
30
+ appId: 'wx0000000000000000',
31
+ path: 'pages/index/index',
32
+ envVersion: config.mp.envVersion,
33
+ });
34
+ ```
@@ -0,0 +1,27 @@
1
+ # navigate
2
+
3
+ 导航配置。发布路径:`@zfqh/uniapp/lib/configs/navigate`
4
+
5
+ | 字段 | 类型 | 默认值 | 说明 |
6
+ | --- | --- | --- | --- |
7
+ | `loginType` | `navigateTo/reLaunch/redirectTo` | `navigateTo` | 未登录时进入登录页的跳转方式。 |
8
+ | `referrerType` | `none/target/referrer/combine` | `target` | 登录后回跳目标的构造策略。 |
9
+
10
+ ## 基本使用
11
+
12
+ 登录保护页面跳转登录页时,`navigate` 会读取这里的配置决定使用哪种跳转方式以及如何携带来源页。
13
+
14
+ ```ts
15
+ import { defineConfig, navigate } from '@zfqh/uniapp';
16
+
17
+ defineConfig({
18
+ navigate: {
19
+ loginType: 'navigateTo',
20
+ referrerType: 'combine',
21
+ },
22
+ });
23
+
24
+ export function goOrderDetail(id: string) {
25
+ navigate('/pages/order/detail', { id });
26
+ }
27
+ ```
@@ -0,0 +1,32 @@
1
+ # page
2
+
3
+ 页面集合配置。发布路径:`@zfqh/uniapp/lib/configs/page`
4
+
5
+ 推荐使用 `createPages(pagesJson)` 从 `pages.json` 生成。H5 端如果 `pages.json` 带注释,可使用 `virtual:remove-json-comments@/pages.json` 导入,非 H5 端直接导入 `@/pages.json`。
6
+
7
+ | 字段 | 类型 | 默认值 | 说明 |
8
+ | --- | --- | --- | --- |
9
+ | `pages` | `string[]` | `[]` | 全部页面。 |
10
+ | `tabBarPages` | `string[]` | `[]` | tabBar 页面,命中后 navigateTo/redirectTo 会转为 switchTab。 |
11
+ | `nativePages` | `string[]` | `[]` | 原生页面集合。 |
12
+ | `needLoginPages` | `string[]` | `[]` | 需要登录的页面集合。 |
13
+ | `notRedirectPages` | `string[]` | `[]` | 登录后不做 referrer 重定向的页面。 |
14
+
15
+ ## 基本使用
16
+
17
+ 患者端项目用 `createPages(pages)` 从 `pages.json` 生成页面集合,供 `navigate`、登录守卫和 tabBar 跳转判断使用。
18
+
19
+ ```ts
20
+ // config.ts
21
+ import { defineConfig, createPages } from '@zfqh/uniapp';
22
+ // #ifdef H5
23
+ import pages from 'virtual:remove-json-comments@/pages.json';
24
+ // #endif
25
+ // #ifndef H5
26
+ import pages from '@/pages.json';
27
+ // #endif
28
+
29
+ defineConfig({
30
+ page: createPages(pages),
31
+ });
32
+ ```
@@ -0,0 +1,27 @@
1
+ # path
2
+
3
+ 页面别名配置。发布路径:`@zfqh/uniapp/lib/configs/path`
4
+
5
+ | 字段 | 类型 | 默认值 | 说明 |
6
+ | --- | --- | --- | --- |
7
+ | `index` | `string` | `/pages/index/index` | 首页路径。 |
8
+ | `login` | `string` | `/pages/login/login` | 登录页路径。 |
9
+ | `webview` | `string` | `/pages/webview/webview` | webview 承载页路径。 |
10
+
11
+ ## 基本使用
12
+
13
+ 业务项目需要根据自身页面结构配置首页、登录页和 WebView 承载页。
14
+
15
+ ```ts
16
+ import { defineConfig } from '@zfqh/uniapp';
17
+
18
+ defineConfig({
19
+ path: {
20
+ index: '/pages/home/home',
21
+ login: '/pages/login/login',
22
+ webview: '/pages/webview/webview',
23
+ },
24
+ });
25
+ ```
26
+
27
+ `navigate` 登录拦截、`webview` mixin 和登录重定向都会读取这些路径。