@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,267 @@
1
+ # 导航
2
+
3
+ ::: tip 工具模块
4
+ `@zfqh/uniapp/lib/utils/navigate`
5
+ :::
6
+
7
+ 统一处理页面跳转、登录拦截、tabBar、webview、自定义协议和重复点击节流。
8
+
9
+ ## 平台兼容性
10
+
11
+ | App | H5 | 微信小程序 | 其他小程序 | WebView |
12
+ | --- | --- | --- | --- | --- |
13
+ | √ | √ | √ | 视平台 API 而定 | 视运行容器而定 |
14
+
15
+ ## 基本使用
16
+
17
+ ```ts
18
+ import { navigate } from '@zfqh/uniapp';
19
+ ```
20
+
21
+ 导航工具脱离组件 setup 上下文,内部会通过 `uni.$store.getters.isLogin` 判断登录态。组件或 hooks 中判断登录态时请使用 `useStore()`。
22
+
23
+ ## 常用跳转
24
+
25
+ ```ts
26
+ // 字符串参数(默认 navigateTo)
27
+ navigate('/pages/user/profile');
28
+
29
+ // 带参数跳转
30
+ navigate.navigateTo({
31
+ url: '/pages/order/detail',
32
+ params: { id: 123 },
33
+ });
34
+
35
+ // 重定向(关闭当前页)
36
+ navigate.redirectTo('/pages/login/login');
37
+
38
+ // 重启到首页
39
+ navigate.reLaunch('/pages/index/index');
40
+
41
+ // 切换 tabBar 页
42
+ navigate.switchTab('/pages/index/index');
43
+
44
+ // 返回
45
+ navigate.back({ delta: 1 });
46
+ ```
47
+
48
+ ## 对象参数
49
+
50
+ ```ts
51
+ navigate.navigateTo({
52
+ url: '/pages/detail/detail',
53
+ params: { id: 1 }, // 拼接到 URL query
54
+ webviewParams: { title: '详情' }, // 传给 webview 页的参数
55
+ needLogin: true, // 强制要求登录
56
+ native: true, // 作为原生页面跳转
57
+ });
58
+ ```
59
+
60
+ ## 登录拦截
61
+
62
+ `navigate` 会自动检查目标页是否在 `config.page.needLoginPages` 中,如果未登录则跳转登录页。
63
+
64
+ ```ts
65
+ // 页面配置中声明需要登录的页面
66
+ defineConfig({
67
+ page: {
68
+ needLoginPages: ['/pages/user/profile', '/pages/order/list'],
69
+ },
70
+ });
71
+
72
+ // 跳转时自动拦截
73
+ navigate('/pages/user/profile'); // 未登录 → 跳登录页
74
+
75
+ // 单次跳转中显式声明
76
+ navigate.navigateTo({
77
+ url: '/pages/user/profile',
78
+ needLogin: true,
79
+ });
80
+ ```
81
+
82
+ 登录页路径来自 `getPage('login')`,通过 `config.path.login` 配置。
83
+
84
+ ## 自定义拦截器
85
+
86
+ ```ts
87
+ import { navigate } from '@zfqh/uniapp';
88
+
89
+ // 覆盖跳转拦截器
90
+ navigate.interceptor = (url, absoluteUrl) => {
91
+ if (absoluteUrl.includes('/pages/disabled/')) {
92
+ return '/pages/index/index'; // 重定向到首页
93
+ }
94
+ return url; // 正常跳转
95
+ };
96
+
97
+ // 返回非字符串可阻止跳转
98
+ navigate.interceptor = (url) => {
99
+ if (shouldBlock(url)) {
100
+ return false; // 阻止跳转
101
+ }
102
+ return url;
103
+ };
104
+ ```
105
+
106
+ ## navigateBack
107
+
108
+ `navigateBack` 支持 3 种页面间通信方式:
109
+
110
+ ```ts
111
+ import { navigateBack } from '@zfqh/uniapp';
112
+
113
+ // 调用上一页的指定方法
114
+ navigateBack({ method: 'refresh' });
115
+ navigateBack({ method: 'handleResult', data: { id: 1 } });
116
+
117
+ // 通过 uni.$emit 发送事件(上一页用 uni.$on 监听)
118
+ navigateBack({ emit: 'orderCreated', data: { orderId: '123' } });
119
+
120
+ // 普通返回
121
+ navigateBack({ delta: 2 });
122
+ ```
123
+
124
+ ## 自动处理
125
+
126
+ `navigate` 内部会自动处理以下情况:
127
+
128
+ - 相对路径转绝对路径
129
+ - `params` 拼接为 URL query
130
+ - tabBar 页面自动使用 `switchTab`
131
+ - HTTP URL 和自定义协议转 webview 页面
132
+ - webview 容器内使用 `uni.webView` 跳转
133
+ - 节流防止重复点击
134
+
135
+ ## API
136
+
137
+ 发布路径:`@zfqh/uniapp/lib/utils/navigate`
138
+
139
+ | 名称 | 签名/声明 | 说明 |
140
+ | --- | --- | --- |
141
+ | `navigate(urlOrOptions, type?)` | `default export member` | 统一跳转入口;支持字符串或对象参数,默认 type 为 navigateTo。 |
142
+ | `navigate.navigateTo(options)` | `default export member` | 按 navigateTo 跳转。 |
143
+ | `navigate.redirectTo(options)` | `default export member` | 按 redirectTo 跳转。 |
144
+ | `navigate.reLaunch(options)` | `default export member` | 按 reLaunch 跳转。 |
145
+ | `navigate.switchTab(options)` | `default export member` | 按 switchTab 跳转。 |
146
+ | `navigate.back(options)` | `default export member` | 调用 uni.navigateBack。 |
147
+ | `navigate.interceptor(url, absoluteUrl)` | `default export member` | 可覆盖的跳转拦截器;返回非字符串可阻止跳转。 |
148
+
149
+ ## navigate 使用指南
150
+
151
+ 根入口导出:
152
+
153
+ ```ts
154
+ import { navigate } from '@zfqh/uniapp';
155
+ ```
156
+
157
+ 基础使用:
158
+
159
+ ```ts
160
+ navigate('/pages/user/user');
161
+ navigate.navigateTo('/pages/user/user');
162
+ navigate.redirectTo('/pages/login/login');
163
+ navigate.reLaunch('/pages/index/index');
164
+ navigate.switchTab('/pages/index/index');
165
+ navigate.back({ delta: 1 });
166
+ ```
167
+
168
+ 对象参数:
169
+
170
+ ```ts
171
+ navigate.navigateTo({
172
+ url: '/pages/detail/detail',
173
+ params: { id: 1 },
174
+ webviewParams: { title: '详情' },
175
+ needLogin: true,
176
+ native: true,
177
+ });
178
+ ```
179
+
180
+ ## URL 处理
181
+
182
+ `navigate` 会处理:
183
+
184
+ - 相对路径转绝对路径。
185
+ - `params` 拼接为 query。
186
+ - tabBar 页面自动使用 `switchTab`。
187
+ - 自定义协议和 HTTP URL 转 webview 页面。
188
+ - webview 容器内使用 `uni.webView` 跳转。
189
+
190
+ ## 登录拦截
191
+
192
+ 登录判断依赖:
193
+
194
+ ```ts
195
+ uni.$store.getters.isLogin
196
+ ```
197
+
198
+ `navigate` 是普通工具模块,脱离组件 setup 上下文,所以读取 `uni.$store`。如果是在组件或 hooks 中判断登录态,请使用:
199
+
200
+ ```ts
201
+ import { computed } from 'vue';
202
+ import { useStore } from 'vuex';
203
+
204
+ const store = useStore();
205
+ const isLogin = computed(() => store.getters.isLogin);
206
+ ```
207
+
208
+ 需要登录的页面来源:
209
+
210
+ ```ts
211
+ defineConfig({
212
+ page: {
213
+ needLoginPages: ['/pages/user/user'],
214
+ },
215
+ });
216
+ ```
217
+
218
+ 也可以在单次跳转中声明:
219
+
220
+ ```ts
221
+ navigate('/pages/user/user', 'navigateTo');
222
+ navigate.navigateTo({
223
+ url: '/pages/user/user',
224
+ needLogin: true,
225
+ });
226
+ ```
227
+
228
+ 登录页路径来自 `getPage('login')`,通常通过页面别名配置提供。
229
+
230
+ ## 来源页策略
231
+
232
+ `navigate.referrerType` 控制未登录跳转登录页时如何携带来源:
233
+
234
+ | 值 | 行为 |
235
+ | --- | --- |
236
+ | `none` | 不携带来源。 |
237
+ | `target` | 登录后跳转目标页。 |
238
+ | `referrer` | 登录后回到来源页。 |
239
+ | `combine` | 登录后先回来源页,再根据 `__navigate` 跳目标页。 |
240
+
241
+ 配置:
242
+
243
+ ```ts
244
+ defineConfig({
245
+ navigate: {
246
+ loginType: 'navigateTo',
247
+ referrerType: 'combine',
248
+ },
249
+ });
250
+ ```
251
+
252
+ ## 跳转拦截器
253
+
254
+ 可以覆盖 `navigate.interceptor`:
255
+
256
+ ```ts
257
+ import { navigate } from '@zfqh/uniapp';
258
+
259
+ navigate.interceptor = (url, absoluteUrl) => {
260
+ if (absoluteUrl.includes('/pages/disabled/')) {
261
+ return '/pages/index/index';
262
+ }
263
+ return url;
264
+ };
265
+ ```
266
+
267
+ 返回非字符串会终止跳转。
@@ -0,0 +1,205 @@
1
+ # 页面配置
2
+
3
+ ::: tip 工具模块
4
+ `@zfqh/uniapp/lib/utils/pages`
5
+ :::
6
+
7
+ 根据页面配置生成 tabBar、原生页、登录页、不可重定向页等页面集合。
8
+
9
+ ## 平台兼容性
10
+
11
+ | App | H5 | 微信小程序 | 其他小程序 | WebView |
12
+ | --- | --- | --- | --- | --- |
13
+ | √ | √ | √ | 视平台 API 而定 | 视运行容器而定 |
14
+
15
+ ## 基本使用
16
+
17
+ ```ts
18
+ import { getPage, inPages, createPages } from '@zfqh/uniapp';
19
+ ```
20
+
21
+ ## createPages
22
+
23
+ 从 `pages.json` 生成页面集合配置,在 `defineConfig` 中使用:
24
+
25
+ ```ts
26
+ import { defineConfig, createPages } from '@zfqh/uniapp';
27
+ // #ifdef H5
28
+ import pages from 'virtual:remove-json-comments@/pages.json';
29
+ // #endif
30
+ // #ifndef H5
31
+ import pages from '@/pages.json';
32
+ // #endif
33
+
34
+ defineConfig({
35
+ page: createPages(pages),
36
+ path: {
37
+ index: '/pages/index/index',
38
+ login: '/pages/login/login',
39
+ webview: '/pages/webview/webview',
40
+ },
41
+ });
42
+ ```
43
+
44
+ `createPages` 会从 `pages.json` 中提取:
45
+
46
+ | 来源字段 | 生成配置 |
47
+ | --- | --- |
48
+ | `pages[].path` | `page.pages` |
49
+ | `subPackages[].root` + `pages[].path` | `page.pages` |
50
+ | `tabBar.list[].pagePath` | `page.tabBarPages` |
51
+ | 页面项 `native`(默认 `true`) | `native` 为 `false` 时从 `page.nativePages` 中排除 |
52
+ | 页面项 `needLogin: true` | `page.needLoginPages`(默认 `false`) |
53
+ | 页面项 `notRedirect: true` | `page.notRedirectPages`(默认 `false`) |
54
+
55
+ 在 `pages.json` 中声明:
56
+
57
+ ```json
58
+ {
59
+ "pages": [
60
+ { "path": "pages/index/index" },
61
+ { "path": "pages/user/profile", "needLogin": true },
62
+ { "path": "pages/login/login", "native": true }
63
+ ],
64
+ "globalStyle": {
65
+ "needLogin": false
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## native 与 webview 页面
71
+
72
+ `native` 字段控制页面在 App 和小程序端的打开方式,默认为 `true`(原生页面)。
73
+
74
+ 当 `navigate('/pages/some/page')` 时,`navigate` 会检查目标页是否在 `nativePages` 中:
75
+
76
+ - **在 `nativePages` 中**(默认) → 原生页面跳转(`uni.navigateTo`)
77
+ - **不在 `nativePages` 中**(`native: false`) → 通过 webview 承载页打开(跳转到 `config.path.webview`,URL 作为参数传入)
78
+
79
+ ### 推荐方式:条件编译
80
+
81
+ 如果某个页面只在 H5 端存在(App/小程序端通过 webview 打开),推荐使用条件编译在 `pages.json` 中排除该页面:
82
+
83
+ ```json
84
+ {
85
+ "pages": [
86
+ { "path": "pages/index/index" },
87
+ // #ifdef H5
88
+ {
89
+ "path": "pages/type/type",
90
+ "needLogin": false,
91
+ "style": {
92
+ "navigationBarTitleText": "皮肤健康深度测评",
93
+ "navigationStyle": "custom"
94
+ }
95
+ },
96
+ // #endif
97
+ ]
98
+ }
99
+ ```
100
+
101
+ 这样 App 和小程序端的 `pages.json` 中不包含该页面,`createPages` 生成的 `nativePages` 中也没有它。`navigate` 会自动将其作为 webview 页面打开。
102
+
103
+ ### 替代方式:native 字段
104
+
105
+ 也可以通过 `native: false` 显式标记某个页面为非原生页面:
106
+
107
+ ```json
108
+ {
109
+ "pages": [
110
+ { "path": "pages/index/index" },
111
+ { "path": "pages/webview/webview" },
112
+ { "path": "pages/h5-only/h5-only", "native": false }
113
+ ]
114
+ }
115
+ ```
116
+
117
+ - `native: true`(默认) — 原生页面,所有端均以原生方式跳转
118
+ - `native: false` — 非原生页面,App/小程序端通过 webview 打开
119
+ - `globalStyle.native` — 全局默认值,页面项的 `native` 会覆盖全局设置
120
+
121
+ 两种方式可以配合使用。推荐优先使用条件编译,效果更精确。
122
+
123
+ ## needLogin 登录拦截
124
+
125
+ `needLogin` 字段控制页面是否需要登录才能访问,默认为 `false`。
126
+
127
+ 当 `needLogin: true` 时,`navigate` 会检查 `uni.$store.getters.isLogin`,如果未登录则自动跳转到 `getPage('login')` 返回的登录页路径。
128
+
129
+ ```json
130
+ {
131
+ "pages": [
132
+ { "path": "pages/index/index" },
133
+ { "path": "pages/user/profile", "needLogin": true },
134
+ { "path": "pages/order/list", "needLogin": true }
135
+ ],
136
+ "globalStyle": {
137
+ "needLogin": false
138
+ }
139
+ }
140
+ ```
141
+
142
+ - `needLogin: true` — 需要登录,未登录时自动跳转登录页
143
+ - `needLogin: false`(默认) — 不需要登录
144
+ - `globalStyle.needLogin` — 全局默认值,页面项的 `needLogin` 会覆盖全局设置
145
+
146
+ 登录拦截需要配合 [login mixin](./../mixins/login) 使用。login mixin 会在页面 `onShow` 时检查当前页面是否在 `needLoginPages` 中,未登录则跳转登录页。
147
+
148
+ ## notRedirect 登录重定向控制
149
+
150
+ `notRedirect` 字段控制登录成功后是否重定向回来源页,默认为 `false`。
151
+
152
+ 当页面使用了 [redirect mixin](./../mixins/redirect) 时,登录成功后会自动跳转回 `path.referrer`(来源页)。如果某个页面在登录后不希望被重定向(例如登录后需要跳转到绑定手机号页面),可以设置 `notRedirect: true`。
153
+
154
+ ```json
155
+ {
156
+ "pages": [
157
+ { "path": "pages/index/index" },
158
+ { "path": "pages/login/login" },
159
+ { "path": "pages/bind-phone/bind-phone", "notRedirect": true }
160
+ ]
161
+ }
162
+ ```
163
+
164
+ - `notRedirect: true` — 登录跳转后不会重定向到来源页
165
+ - `notRedirect: false`(默认) — 登录跳转后自动重定向到来源页
166
+ - `globalStyle.notRedirect` — 全局默认值,页面项的 `notRedirect` 会覆盖全局设置
167
+
168
+ **典型场景**:用户登录后需要绑定手机号,跳转到绑定页面。如果绑定页未设置 `notRedirect: true`,进入绑定页后 redirect mixin 会自动跳回 referrer(来源页),导致绑定流程被打断。设置为 `true` 后,绑定页不会被重定向,用户可以正常完成绑定操作。
169
+
170
+ ## getPage
171
+
172
+ ```ts
173
+ import { getPage } from '@zfqh/uniapp';
174
+
175
+ // 获取配置的页面别名路径
176
+ const loginPath = getPage('login'); // '/pages/login/login'
177
+ const indexPath = getPage('index'); // '/pages/index/index'
178
+ const webviewPath = getPage('webview'); // '/pages/webview/webview'
179
+ ```
180
+
181
+ ## inPages
182
+
183
+ ```ts
184
+ import { inPages, config } from '@zfqh/uniapp';
185
+
186
+ // 判断页面是否需要登录
187
+ const needLogin = inPages(config.page.needLoginPages, '/pages/user/profile');
188
+
189
+ // 判断是否是 tabBar 页面
190
+ const isTab = inPages(config.page.tabBarPages, '/pages/index/index');
191
+
192
+ // 支持 ** 前缀匹配
193
+ inPages(['/pages/user/**'], '/pages/user/profile'); // true
194
+ ```
195
+
196
+ ## API
197
+
198
+ 发布路径:`@zfqh/uniapp/lib/utils/pages`
199
+
200
+ | 名称 | 签名/声明 | 说明 |
201
+ | --- | --- | --- |
202
+ | `getPage` | `export const getPage = (name: string) => {` | 按别名从 configs/path 获取页面路径。 |
203
+ | `inPages` | `export const inPages = (pages: string[], url: string \| { url: string; [key: string]: any }) => {` | 判断 url 是否命中页面数组,支持以 ** 结尾的前缀匹配。 |
204
+ | `createPages` | `export const createPages = (` | 从 pages.json 风格配置中生成 pages、tabBarPages、nativePages、needLoginPages、notRedirectPages。 |
205
+
@@ -0,0 +1,28 @@
1
+ # 权限补丁
2
+
3
+ ::: tip 工具模块
4
+ `@zfqh/uniapp/lib/utils/permission`
5
+ :::
6
+
7
+ 包含平台运行时补丁或内部实现,一般不直接调用。
8
+
9
+ ## 平台兼容性
10
+
11
+ | App | H5 | 微信小程序 | 其他小程序 | WebView |
12
+ | --- | --- | --- | --- | --- |
13
+ | √ | √ | √ | 视平台 API 而定 | 视运行容器而定 |
14
+
15
+ ## 基本使用
16
+
17
+ ```ts
18
+ import permission from '@zfqh/uniapp/lib/utils/permission';
19
+ ```
20
+
21
+ 具体方法、参数语义和返回值以发布包类型为准;下方表格按 `@zfqh/uniapp/lib/utils/permission` 的导出整理。
22
+
23
+ ## API
24
+
25
+ 发布路径:`@zfqh/uniapp/lib/utils/permission`
26
+
27
+ 该文件只包含运行时补丁或平台专用内部实现,没有具名导出。
28
+
@@ -0,0 +1,62 @@
1
+ # 权限申请
2
+
3
+ ::: tip 工具模块
4
+ `@zfqh/uniapp/lib/utils/permit`
5
+ :::
6
+
7
+ 统一申请 App/小程序权限,并在失败时引导用户打开授权设置。
8
+
9
+ ## 平台兼容性
10
+
11
+ | App | H5 | 微信小程序 | 其他小程序 | WebView |
12
+ | --- | --- | --- | --- | --- |
13
+ | √ | √ | √ | 视平台 API 而定 | 视运行容器而定 |
14
+
15
+ ## 基本使用
16
+
17
+ ```ts
18
+ import { openAuthorizeSetting, requestPermission } from '@zfqh/uniapp';
19
+ ```
20
+
21
+ 具体方法、参数语义和返回值以发布包类型为准;下方表格按 `@zfqh/uniapp/lib/utils/permit` 的导出整理。
22
+
23
+ ## API
24
+
25
+ 发布路径:`@zfqh/uniapp/lib/utils/permit`
26
+
27
+ | 名称 | 签名/声明 | 说明 |
28
+ | --- | --- | --- |
29
+ | `openAuthorizeSetting` | `export function openAuthorizeSetting(name: string) {` | 打开系统或应用授权设置页。 |
30
+ | `requestPermission` | `export async function requestPermission(name: keyof typeof permissionData, system = true) {` | 跨 App/小程序申请 location、storage、camera、record、bluetooth 权限,并在失败时弹出引导。 |
31
+
32
+ ## 支持的权限名称
33
+
34
+ | 权限 | 说明 | App 权限 ID |
35
+ | --- | --- | --- |
36
+ | `location` | 定位权限 | `ACCESS_FINE_LOCATION` |
37
+ | `storage` | 文件存储权限 | `WRITE_EXTERNAL_STORAGE` |
38
+ | `camera` | 相机权限 | `CAMERA` |
39
+ | `record` | 麦克风权限 | `RECORD_AUDIO` |
40
+ | `bluetooth` | 蓝牙权限 | `BLUETOOTH` / `BLUETOOTH_SCAN` + `BLUETOOTH_CONNECT`(Android 12+) |
41
+
42
+ ## 典型用法
43
+
44
+ 先申请权限,失败后引导用户到系统设置页手动开启:
45
+
46
+ ```ts
47
+ import { requestPermission, openAuthorizeSetting } from '@zfqh/uniapp';
48
+
49
+ async function takePhoto() {
50
+ const granted = await requestPermission('camera');
51
+ if (!granted) {
52
+ // 权限被拒绝,引导用户到设置页
53
+ openAuthorizeSetting('camera');
54
+ return;
55
+ }
56
+ // 权限已获取,执行拍照逻辑
57
+ uni.chooseImage({ ... });
58
+ }
59
+ ```
60
+
61
+ 小程序端 `requestPermission` 会调用 `uni.authorize`,App 端会通过 `plus.android.requestPermissions` 申请对应的系统权限。`system` 参数控制是否同时检测系统级开关(默认 `true`)。
62
+
@@ -0,0 +1,89 @@
1
+ # Query 解析
2
+
3
+ ::: tip 工具模块
4
+ `@zfqh/uniapp/lib/utils/query`
5
+ :::
6
+
7
+ 解析当前页面或 H5 地址栏 query,供渠道、来源和业务参数读取。
8
+
9
+ ## 平台兼容性
10
+
11
+ | App | H5 | 微信小程序 | 其他小程序 | WebView |
12
+ | --- | --- | --- | --- | --- |
13
+ | √ | √ | √ | 视平台 API 而定 | 视运行容器而定 |
14
+
15
+ ## 基本使用
16
+
17
+ ```ts
18
+ import { query } from '@zfqh/uniapp';
19
+ ```
20
+
21
+ ## query 对象
22
+
23
+ `query` 是默认导出的当前页面或 H5 URL 的 query 参数解析结果。
24
+
25
+ **H5 端**:解析 `location.search`(地址栏 query 字符串)。 **小程序端**:解析启动参数中的 query。
26
+
27
+ ```ts
28
+ import { query } from '@zfqh/uniapp';
29
+
30
+ // 访问 query 参数
31
+ console.log(query.token); // URL 中的 token 参数
32
+ console.log(query.channel); // 渠道参数
33
+ console.log(query.platform); // 平台参数
34
+ ```
35
+
36
+ ### 内置属性
37
+
38
+ | 属性 | 类型 | 说明 |
39
+ | --- | --- | --- |
40
+ | `platform` | `string` | 平台标识 |
41
+ | `token` | `string` | H5 端 URL 传入的 token |
42
+ | `primary` | `string` | 主题色覆盖 |
43
+ | `brand` | `string` | 品牌标识 |
44
+ | `app` | `string` | 应用标识 |
45
+ | `safeBottom` | `string \| number` | 安全区域底部高度 |
46
+ | `tabbar` | `string \| number` | tabbar 配置 |
47
+
48
+ 同时支持任意自定义 query 参数(`[key: string]: any`)。
49
+
50
+ ## parseQuery
51
+
52
+ ```ts
53
+ import { parseQuery } from '@zfqh/uniapp';
54
+ ```
55
+
56
+ `parseQuery(search: string): Record<string, string>`
57
+
58
+ 解析 URL query 字符串为对象。
59
+
60
+ ```ts
61
+ parseQuery('id=123&tab=detail'); // { id: '123', tab: 'detail' }
62
+ parseQuery('name=%E5%BC%A0%E4%B8%89'); // { name: '张三' }
63
+ ```
64
+
65
+ ## 配合导航使用
66
+
67
+ ```ts
68
+ import { query, navigate } from '@zfqh/uniapp';
69
+
70
+ // H5 端通过 URL 传入 token 自动登录
71
+ if (query.token) {
72
+ store.commit('setLoginInfo', { token: query.token });
73
+ }
74
+
75
+ // 根据渠道参数决定跳转目标
76
+ if (query.channel === 'promotion') {
77
+ navigate('/pages/activity/activity');
78
+ }
79
+ ```
80
+
81
+ ## API
82
+
83
+ 发布路径:`@zfqh/uniapp/lib/utils/query`
84
+
85
+ | 名称 | 签名/声明 | 说明 |
86
+ | --- | --- | --- |
87
+ | `parseQuery` | `export function parseQuery(search: string = '') {` | 解析 URL query 字符串。 |
88
+ | `query` | `default export member` | 默认导出当前页面或 H5 URL query 解析结果。 |
89
+
@@ -0,0 +1,34 @@
1
+ # 请求工厂
2
+
3
+ ::: tip 工具模块
4
+ `@zfqh/uniapp/lib/utils/request`
5
+ :::
6
+
7
+ 创建请求方法并安装通用拦截器,处理动态 URL、token、错误、401 退出登录。
8
+
9
+ ## 平台兼容性
10
+
11
+ | App | H5 | 微信小程序 | 其他小程序 | WebView |
12
+ | --- | --- | --- | --- | --- |
13
+ | √ | √ | √ | 视平台 API 而定 | 视运行容器而定 |
14
+
15
+ ## 基本使用
16
+
17
+ ```ts
18
+ import { formatURL, createInterceptors, createRequest } from '@zfqh/uniapp';
19
+ ```
20
+
21
+ 请求工具脱离组件 setup 上下文,拦截器内部会通过 `uni.$store` 读取 token 并处理 `401`。组件或 hooks 中读取 store 时请使用 `useStore()`。
22
+
23
+ 具体方法、参数语义和返回值以发布包类型为准;下方表格按 `@zfqh/uniapp/lib/utils/request` 的导出整理。
24
+
25
+ ## API
26
+
27
+ 发布路径:`@zfqh/uniapp/lib/utils/request`
28
+
29
+ | 名称 | 签名/声明 | 说明 |
30
+ | --- | --- | --- |
31
+ | `formatURL` | `export function formatURL(url, data) {` | 把 /:id 或 :id 动态片段替换为 data 中的值,并删除已消费字段。 |
32
+ | `createInterceptors` | `export function createInterceptors(req) {` | 给请求实例安装统一请求/响应拦截器,注入 token 并处理 code/401/toast/logout。 |
33
+ | `createRequest` | `export function createRequest(req, opts = {}) {` | 基于请求实例生成 GET、DELETE、POST、PUT 方法。 |
34
+