@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,297 @@
1
+ # 项目框架
2
+
3
+ 本章梳理在业务 uni-app 项目中完整接入 `@zfqh/uniapp` 的项目结构、配置入口和初始化顺序。
4
+
5
+ ## 示例项目结构
6
+
7
+ 仓库内提供两类示例,用来对应业务项目常见的两种组织方式。
8
+
9
+ ### 含 src 的项目
10
+
11
+ 源码集中在 `src/` 下,适合 TypeScript 和标准 Vite 项目结构。
12
+
13
+ ```text
14
+ uniapp/
15
+ src/
16
+ App.vue
17
+ main.ts
18
+ pages.json
19
+ manifest.json
20
+ config.ts
21
+ env/
22
+ store/
23
+ utils/
24
+ pages/
25
+ components/
26
+ styles/
27
+ uni.build.json
28
+ package.json
29
+ ```
30
+
31
+ ### 不含 src 的项目
32
+
33
+ 页面、配置、store 等目录位于项目根目录,适合传统 HBuilderX / uni-app 项目结构。
34
+
35
+ ```text
36
+ uniapp/
37
+ App.vue
38
+ main.js
39
+ pages.json
40
+ manifest.json
41
+ config.js
42
+ locale/
43
+ store/
44
+ pages/
45
+ static/
46
+ uni.scss
47
+ uni.build.json
48
+ package.json
49
+ ```
50
+
51
+ 两种结构都可以接入 `@zfqh/uniapp`,关键是保证配置文件先执行、store 先注册、easycom 指向构建产物组件路径。
52
+
53
+ `@zfqh/uniapp` 默认通过 `@env` 别名扫描环境文件。使用 `@gmcb/vite` 时,`@env` 会指向 `${process.env.VITE_ROOT_DIR}/env`。
54
+
55
+ ## 配置入口
56
+
57
+ 建议在 `src/config.js` 中集中调用 `defineConfig`,并在 `main.ts` 或应用启动入口中导入执行:
58
+
59
+ ```ts
60
+ import './config';
61
+ ```
62
+
63
+ 患者端常见写法:
64
+
65
+ ```ts
66
+ import { defineConfig, createPages } from '@zfqh/uniapp';
67
+ import { app } from '@zfqh/uniapp/lib/configs/app';
68
+ import { brand } from '@zfqh/uniapp/lib/configs/brand';
69
+ // #ifdef H5
70
+ import pages from 'virtual:remove-json-comments@/pages.json';
71
+ // #endif
72
+ // #ifndef H5
73
+ import pages from '@/pages.json';
74
+ // #endif
75
+ import { getTencentToken } from '@zfqh/uniapp/lib/apis';
76
+
77
+ defineConfig({
78
+ app: app.patient,
79
+ brand: brand.zfqh,
80
+ page: createPages(pages),
81
+ path: {
82
+ index: '/pages/index/index',
83
+ login: '/pages/public/login/login',
84
+ webview: '/pages/public/webview/webview',
85
+ },
86
+ tabbar: {
87
+ badgeIndex: 1,
88
+ },
89
+ upload: {
90
+ async request() {
91
+ const { data } = await getTencentToken();
92
+ return {
93
+ secret_id: data.tmpSecretId,
94
+ secret_key: data.tmpSecretKey,
95
+ session_token: data.sessionToken,
96
+ create_time: data.createTime,
97
+ expire_time: data.expirationTime,
98
+ bucket: data.bucket,
99
+ region: data.region,
100
+ };
101
+ },
102
+ },
103
+ });
104
+ ```
105
+
106
+ 门店端可复用 `app.merchant`,并覆盖主题色或上传 region:
107
+
108
+ ```ts
109
+ import { defineConfig } from '@zfqh/uniapp';
110
+ import { app } from '@zfqh/uniapp/lib/configs/app';
111
+ import { brand } from '@zfqh/uniapp/lib/configs/brand';
112
+ import { getTencentToken } from '@zfqh/uniapp/lib/apis';
113
+ import store from '@/store';
114
+
115
+ defineConfig({
116
+ app: app.merchant,
117
+ brand: brand.zfqh,
118
+ path: {
119
+ index: '/pages/home/home',
120
+ webview: '/pages/webview/webview',
121
+ },
122
+ color: {
123
+ primary: '#451709',
124
+ primaryDark: '#451709',
125
+ primaryDisabled: '#D5B9B0',
126
+ primaryLight: '#E8D8C9',
127
+ },
128
+ upload: {
129
+ async request() {
130
+ const { data } = await getTencentToken();
131
+ return {
132
+ secret_id: data.tmpSecretId,
133
+ secret_key: data.tmpSecretKey,
134
+ session_token: data.sessionToken,
135
+ create_time: data.createTime,
136
+ expire_time: data.expirationTime,
137
+ bucket: data.bucket,
138
+ region: store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
139
+ };
140
+ },
141
+ },
142
+ });
143
+ ```
144
+
145
+ 配置要点:
146
+
147
+ - `defineConfig` 修改的是包内部单例配置,配置文件被导入执行即可生效。
148
+ - `app`、`brand` 预设需要从 `@zfqh/uniapp/lib/configs/...` 深度引用。
149
+ - 推荐用 `createPages(pages)` 从 `pages.json` 自动生成页面集合,减少手写 `needLoginPages`、`tabBarPages` 的维护成本。
150
+ - `path.index`、`path.login`、`path.webview` 分别影响首页、登录拦截和 webview 承载页。
151
+ - `upload.request` 需要把后端字段映射成 COS 上传工具需要的字段名。
152
+ - 内置 COS 临时密钥接口为 `@zfqh/uniapp/lib/apis` 的 `getTencentToken`;如后端接口不同,可以替换请求函数,但返回给 `upload.request` 的字段名需要保持一致。
153
+
154
+ ## Vite 配置
155
+
156
+ ```ts
157
+ import { defineConfig } from '@gmcb/vite';
158
+ import uni from '@dcloudio/vite-plugin-uni';
159
+
160
+ export default defineConfig({
161
+ plugins: [uni()],
162
+ });
163
+ ```
164
+
165
+ 如果不使用 `@gmcb/vite`,需要自行保证 `@env` 别名可用:
166
+
167
+ ```ts
168
+ import { defineConfig } from 'vite';
169
+ import uni from '@dcloudio/vite-plugin-uni';
170
+ import { resolve } from 'path';
171
+
172
+ export default defineConfig({
173
+ plugins: [uni()],
174
+ resolve: {
175
+ alias: {
176
+ '@env': resolve(__dirname, 'src/env'),
177
+ },
178
+ },
179
+ });
180
+ ```
181
+
182
+ ## TypeScript 配置
183
+
184
+ 在 `tsconfig.json` 的 `compilerOptions.types` 中添加类型声明,使深度引用路径(如 `@zfqh/uniapp/lib/configs/app`)获得类型提示:
185
+
186
+ ```json
187
+ {
188
+ "compilerOptions": {
189
+ "types": ["@zfqh/uniapp/types"]
190
+ }
191
+ }
192
+ ```
193
+
194
+ ## Store 约定
195
+
196
+ 多个工具会读取下面这些状态:
197
+
198
+ | 路径 | 用途 |
199
+ | --- | --- |
200
+ | `uni.$store.state.login.info.token` | 请求拦截器注入 `Authorization`。 |
201
+ | `uni.$store.state.login.info.tenantId` | 业务请求注入 `Tenant-Id`。 |
202
+ | `uni.$store.state.system.info.appLanguage` | 业务请求注入 `X-Language`。 |
203
+ | `uni.$store.state.system.info.appVersion` | 非 App 环境下读取版本名。 |
204
+ | `uni.$store.state.system.info.appVersionCode` | 非 App 环境下读取版本号。 |
205
+ | `uni.$store.getters.isLogin` | 导航登录拦截判断。 |
206
+ | `uni.$store.dispatch('logout')` | `401` 时触发退出登录。 |
207
+
208
+ 推荐在注册插件前完成:
209
+
210
+ ```ts
211
+ app.use(store);
212
+ app.use(uniapp);
213
+ ```
214
+
215
+ ## Store 使用位置
216
+
217
+ `@zfqh/uniapp` 同时服务组件、hooks 和普通运行时模块,不同上下文使用 store 的方式不同:
218
+
219
+ | 场景 | 推荐用法 | 说明 |
220
+ | --- | --- | --- |
221
+ | Vue 组件的 Composition API / `<script setup>` | `import { useStore } from 'vuex'` 后调用 `const store = useStore()` | 组件实例处于 Vue 上下文内,应使用 Vuex 官方组合式 API,便于类型推导、测试和组件复用。 |
222
+ | 自定义 hooks / composables | `import { useStore } from 'vuex'` 后在 hook 内调用 `useStore()` | hooks 同样运行在组件 setup 上下文里,不要直接读取全局 `uni.$store`。 |
223
+ | Options API 组件 | `this.$store` | 组件实例已注入 `$store` 时可使用实例属性;现有 `g-*` 组件源码也采用这种方式读取部分系统状态。 |
224
+ | 请求、导航、toast、权限、webview 消息等普通 TS 模块 | `uni.$store` | 这些模块不在 Vue setup 上下文中,无法调用 `useStore()`,因此通过插件挂载到 `uni.$store` 的全局 store 读取登录态和全局状态。 |
225
+
226
+ 组件或 hooks 中推荐写法:
227
+
228
+ ```ts
229
+ import { computed } from 'vue';
230
+ import { useStore } from 'vuex';
231
+
232
+ export function useLoginInfo() {
233
+ const store = useStore();
234
+ const loginInfo = computed(() => store.state.login.info);
235
+ const isLogin = computed(() => store.getters.isLogin);
236
+
237
+ return {
238
+ loginInfo,
239
+ isLogin,
240
+ };
241
+ }
242
+ ```
243
+
244
+ 普通模块中推荐写法:
245
+
246
+ ```ts
247
+ export function getToken() {
248
+ return uni.$store?.state?.login?.info?.token;
249
+ }
250
+ ```
251
+
252
+ `uni.$store` 是为了让脱离组件树的工具函数能够访问 store,不建议在组件 setup 或 hooks 中把它作为首选入口。
253
+
254
+ ## 样式接入
255
+
256
+ `@zfqh/uniapp` 提供一套 UnoCSS 风格的工具样式类,需要在项目全局样式中导入一次:
257
+
258
+ ```scss
259
+ /* App.vue 的 <style> 块 */
260
+ @import '@zfqh/uniapp/lib/styles/index.scss';
261
+ ```
262
+
263
+ 此入口同时引入 `@gmcb/uv-ui/index.scss`,无需再单独导入 uv-ui 基础样式。
264
+
265
+ ### 覆盖 SCSS 主题变量
266
+
267
+ 如果项目通过 `defineConfig({ color })` 覆盖了主题色,建议同步覆盖 SCSS 变量,确保 uv-ui 组件和工具类使用一致的颜色。在 `uni.scss` 中先导入 `@gmcb/uv-ui/theme.scss` 默认变量,再声明同名变量覆盖:
268
+
269
+ ```scss
270
+ /* uni.scss */
271
+ @import '@gmcb/uv-ui/theme.scss';
272
+
273
+ // 覆盖主题变量(与 defineConfig color 保持一致)
274
+ $uv-primary: #451709;
275
+ $uv-primary-dark: #451709;
276
+ $uv-primary-light: #D5B9B0;
277
+ $uv-primary-disabled: #E8D8C9;
278
+ ```
279
+
280
+ 后续样式会读取覆盖后的 `$uv-*` 变量。样式编写优先使用这些变量,非必要不要硬编码颜色。
281
+
282
+ `@zfqh/uniapp` 自身的 `g-*` 组件样式随组件一起构建,通常通过 easycom 使用即可。
283
+
284
+ 工具类的完整参考见 [工具样式类](../components/styles/base-styles.md)。
285
+
286
+ ## 运行时顺序
287
+
288
+ 推荐初始化顺序:
289
+
290
+ 1. 创建 Vue app。
291
+ 2. 注册 store,并设置 `app.config.globalProperties.$store`。
292
+ 3. 注册 `@gmcb/uv-ui`。
293
+ 4. 注册 `@zfqh/uniapp`。
294
+ 5. 初始化业务配置、路由守卫或业务模块。
295
+
296
+ 顺序错误最常见的表现是请求不带 token、导航无法判断登录态、`401` 无法自动退出。
297
+
package/docs/index.md ADDED
@@ -0,0 +1,80 @@
1
+ # @zfqh/uniapp
2
+
3
+ `@zfqh/uniapp` 是面向 uni-app Vue 3 项目的公共能力包,包含配置系统、环境配置、请求封装、导航提示、COS 上传、应用更新、hooks、工具函数、Vuex modules、mixins、`g-*` 公共组件和工具样式类。
4
+
5
+ ## 快速入口
6
+
7
+ | 入口 | 说明 |
8
+ | --- | --- |
9
+ | [快速开始](./guide/getting-started.md) | 安装依赖、注册插件、配置 easycom,并跑通最小示例。 |
10
+ | [项目框架](./guide/project-frame.md) | 梳理含 `src` 与不含 `src` 的项目结构、Vite、store、pages、样式和初始化顺序。 |
11
+ | [组件](./components/index.md) | 查看组件概览、容器组件、样式变量、基础样式类和全部 `g-*` 组件。 |
12
+ | [API](./api/index.md) | 查看根入口导出、深度引用、工具、配置、hooks、mixins、modules 和接口。 |
13
+ | [常见问题](./faq/index.md) | 处理 easycom、store、请求、平台能力、构建等接入问题。 |
14
+
15
+ ## 安装与注册
16
+
17
+ ```bash
18
+ npm i @zfqh/uniapp @gmcb/uv-ui
19
+ ```
20
+
21
+ ```ts
22
+ import { createSSRApp } from 'vue';
23
+ import store from './store';
24
+ import Uniapp from '@zfqh/uniapp';
25
+
26
+ export function createApp() {
27
+ const app = createSSRApp(App);
28
+
29
+ app.use(store);
30
+ app.use(Uniapp);
31
+
32
+ return {
33
+ app,
34
+ };
35
+ }
36
+ ```
37
+
38
+ ## easycom
39
+
40
+ ```json
41
+ {
42
+ "easycom": {
43
+ "autoscan": true,
44
+ "custom": {
45
+ "^g-(.*)": "@zfqh/uniapp/lib/components/g-$1/g-$1.vue"
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ 配置后可直接使用公共组件:
52
+
53
+ ```vue
54
+ <template>
55
+ <g-page-container title="订单列表">
56
+ <g-search v-model="keyword" placeholder="搜索订单" @search="loadData" />
57
+ <g-data-list ref="listRef" :request="getOrderList">
58
+ <template #default="{ list }">
59
+ <view v-for="item in list" :key="item.id">{{ item.title }}</view>
60
+ </template>
61
+ </g-data-list>
62
+ </g-page-container>
63
+ </template>
64
+ ```
65
+
66
+ ## 文档结构
67
+
68
+ | 分类 | 文档 |
69
+ | --- | --- |
70
+ | 指南 | [快速开始](./guide/getting-started.md)、[项目框架](./guide/project-frame.md) |
71
+ | 组件 | [组件概览](./components/index.md)、[组件接入](./components/usage.md)、[全局变量](./components/styles/global-vars.md)、[基础样式类](./components/styles/base-styles.md) |
72
+ | API | [API 概览](./api/index.md)、[工具](./api/utils/index.md)、[配置](./api/configs/index.md)、[Hooks](./api/hooks/index.md)、[混入](./api/mixins/index.md)、[模块](./api/modules/index.md)、[接口](./api/apis/index.md) |
73
+ | 常见问题 | [常见问题](./faq/index.md) |
74
+
75
+ ## 使用约定
76
+
77
+ - 项目需要提供符合约定的 Vuex store:请求读取 `uni.$store.state.login.info.token`,导航读取 `uni.$store.getters.isLogin`,`401` 会触发 `uni.$store.dispatch('logout')`。
78
+ - Store 入口按上下文区分:组件和 hooks 的 Composition API 中使用 `import { useStore } from 'vuex'`,Options API 组件中使用 `this.$store`,请求、导航、权限、webview 消息等普通模块中使用 `uni.$store`。
79
+ - 多环境配置推荐使用 `@env/.env.<env>.ts`,并通过 `defineEnvConfig` 输出配置。
80
+ - 根入口未导出的 `apis`、`modules`、`mixins` 请按 [深度引用](./api/index.md#深度引用) 从构建产物路径引入。
@@ -0,0 +1,12 @@
1
+ /** 发送短信验证码 */
2
+ export declare const sendSmsCode: (...args: any[]) => any;
3
+ /** 获取腾讯上传临时Token */
4
+ export declare const getTencentToken: (...args: any[]) => any;
5
+ /** 获取最新版本 */
6
+ export declare const getLastVersion: (...args: any[]) => any;
7
+ /** 获取cos签名后的地址 */
8
+ export declare const getCosUrls: (...args: any[]) => any;
9
+ /** 刷新token */
10
+ export declare const postRefreshToken: (...args: any[]) => any;
11
+ /** 获取字典数据 */
12
+ export declare const getDictData: (...args: any[]) => any;
@@ -0,0 +1,13 @@
1
+ import { GET, POST } from './request';
2
+ /** 发送短信验证码 */
3
+ export const sendSmsCode = (...args) => POST('/admin-api/system/auth/send-checkCode', ...args);
4
+ /** 获取腾讯上传临时Token */
5
+ export const getTencentToken = (...args) => GET('/app-api/infra/file/getTencentToken', ...args);
6
+ /** 获取最新版本 */
7
+ export const getLastVersion = (...args) => POST('/app-api/system/app/version/get-last-version', ...args);
8
+ /** 获取cos签名后的地址 */
9
+ export const getCosUrls = (...args) => POST('/app-api/infra/cos/getUrls', ...args);
10
+ /** 刷新token */
11
+ export const postRefreshToken = (...args) => POST('/app-api/robot/store/auth/refreshToken?refreshToken=:refreshToken', ...args);
12
+ /** 获取字典数据 */
13
+ export const getDictData = (...args) => GET('/app-api/system/dict-data/type', ...args);
@@ -0,0 +1,2 @@
1
+ export * from './request';
2
+ export * from './core';
@@ -0,0 +1,2 @@
1
+ export * from './request';
2
+ export * from './core';
@@ -0,0 +1,4 @@
1
+ declare const request: any;
2
+ declare const GET: (url: any, data?: {}, options?: {}) => any, POST: (url: any, data?: {}, options?: {}) => any, PUT: (url: any, data?: {}, options?: {}) => any, DELETE: (url: any, data?: {}, options?: {}) => any;
3
+ export { GET, POST, PUT, DELETE };
4
+ export default request;
@@ -0,0 +1,27 @@
1
+ import api from '../configs/api';
2
+ import app from '../configs/app';
3
+ import { createRequest, createInterceptors } from '../utils/request';
4
+ import { LANGUAGE } from '../utils/consts';
5
+ import query from '../utils/query';
6
+ const request = uni.$uv.http;
7
+ request.interceptors.request.use((conf) => {
8
+ const store = uni.$store;
9
+ if (store) {
10
+ const { tenantId } = store.state.login?.info || {};
11
+ const { appLanguage } = store.state.system?.info || {};
12
+ const header = {
13
+ 'X-Language': LANGUAGE[appLanguage],
14
+ 'Tenant-Id': tenantId || 1,
15
+ Channel: query.channel || app.channel,
16
+ };
17
+ conf.header = {
18
+ ...header,
19
+ ...conf.header,
20
+ };
21
+ }
22
+ return conf;
23
+ });
24
+ createInterceptors(request);
25
+ const { GET, POST, PUT, DELETE } = createRequest(request, { baseURL: api.baseUrl });
26
+ export { GET, POST, PUT, DELETE };
27
+ export default request;
@@ -0,0 +1,141 @@
1
+ <template>
2
+ <view class="back-button" :style="[_customStyle]">
3
+ <view class="flex justify-center" @click="goBack" :class="[showHome ? '' : 'back']">
4
+ <g-icon v-if="showIcon" :type="type" :font="iconFont" :name="iconName" :size="iconSize || 18" :color="color" />
5
+ <uv-icon v-else :name="iconName" :size="iconSize || 22" :color="color" />
6
+ </view>
7
+ <view v-if="showHome" class="flex justify-center" @click="goHome">
8
+ <g-icon
9
+ v-if="showIcon"
10
+ :type="type"
11
+ :font="iconFont"
12
+ :name="homeIconName"
13
+ :size="homeIconSize || 32"
14
+ :color="color"
15
+ />
16
+ <uv-icon v-else :name="homeIconName" :size="homeIconSize || 32" :color="color" />
17
+ </view>
18
+ </view>
19
+ </template>
20
+
21
+ <script>
22
+ import { MENU_BUTTON } from '../../utils/consts';
23
+ import { getPage } from '../../utils/pages';
24
+
25
+ export default {
26
+ props: {
27
+ showLine: {
28
+ type: Boolean,
29
+ default: true,
30
+ },
31
+ showHome: {
32
+ type: Boolean,
33
+ default: true,
34
+ },
35
+ iconType: {
36
+ type: String,
37
+ default: '',
38
+ },
39
+ iconFont: {
40
+ type: String,
41
+ default: '',
42
+ },
43
+ iconName: {
44
+ type: String,
45
+ default: 'arrow-left',
46
+ },
47
+ homeIconName: {
48
+ type: String,
49
+ default: 'home-fill',
50
+ },
51
+ iconSize: {
52
+ type: [String, Number],
53
+ default: 0,
54
+ },
55
+ homeIconSize: {
56
+ type: [String, Number],
57
+ default: 0,
58
+ },
59
+ fixed: {
60
+ type: Boolean,
61
+ default: true,
62
+ },
63
+ color: {
64
+ type: String,
65
+ default: '#fff',
66
+ },
67
+ customStyle: {
68
+ type: Object,
69
+ default: () => ({}),
70
+ },
71
+ },
72
+ computed: {
73
+ systemInfo() {
74
+ return this.$store.state.system.info;
75
+ },
76
+ _customStyle() {
77
+ const style = {};
78
+ if (this.showLine && this.showHome) {
79
+ style.border = '1px solid rgba(0, 0, 0, 0.08)';
80
+ }
81
+ if (MENU_BUTTON.height) {
82
+ style.height = `${MENU_BUTTON.height}px`;
83
+ }
84
+ if (this.fixed) {
85
+ style.position = 'fixed';
86
+ style.top = `${this.systemInfo.topStatusBarHeight + 8}px`;
87
+ style.left = '24rpx';
88
+ }
89
+ return Object.assign(style, this.customStyle);
90
+ },
91
+ showIcon({ iconFont, iconType }) {
92
+ return Boolean(iconFont || iconType);
93
+ },
94
+ type({ iconType }) {
95
+ return iconType || 'iconfont';
96
+ },
97
+ },
98
+ methods: {
99
+ goBack() {
100
+ uni.navigateBack();
101
+ },
102
+ goHome() {
103
+ uni.reLaunch({
104
+ url: getPage('index'),
105
+ });
106
+ },
107
+ },
108
+ };
109
+ </script>
110
+
111
+ <style lang="scss" scoped>
112
+ .back-button {
113
+ border-radius: 200rpx;
114
+ height: 64rpx;
115
+ display: inline-flex;
116
+ justify-content: center;
117
+ align-items: center;
118
+ position: relative;
119
+ z-index: 99;
120
+ & > view {
121
+ height: 100%;
122
+ width: 87rpx;
123
+ position: relative;
124
+ &.back {
125
+ width: auto;
126
+ }
127
+ & + view {
128
+ &::before {
129
+ position: absolute;
130
+ top: 50%;
131
+ transform: translateY(-50%);
132
+ left: 0;
133
+ content: '';
134
+ width: 1px;
135
+ height: 36rpx;
136
+ background-color: rgba(0, 0, 0, 0.2);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ </style>