@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.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/docs/api/apis/core.md +189 -0
- package/docs/api/apis/index.md +82 -0
- package/docs/api/apis/request.md +369 -0
- package/docs/api/configs/api.md +32 -0
- package/docs/api/configs/app.md +43 -0
- package/docs/api/configs/brand.md +43 -0
- package/docs/api/configs/cdn.md +35 -0
- package/docs/api/configs/color.md +144 -0
- package/docs/api/configs/env.md +120 -0
- package/docs/api/configs/index.md +394 -0
- package/docs/api/configs/link.md +33 -0
- package/docs/api/configs/log.md +27 -0
- package/docs/api/configs/mp.md +34 -0
- package/docs/api/configs/navigate.md +27 -0
- package/docs/api/configs/page.md +32 -0
- package/docs/api/configs/path.md +27 -0
- package/docs/api/configs/storage.md +24 -0
- package/docs/api/configs/tabbar.md +29 -0
- package/docs/api/configs/toast.md +35 -0
- package/docs/api/configs/update.md +25 -0
- package/docs/api/configs/upload.md +45 -0
- package/docs/api/configs/ver.md +32 -0
- package/docs/api/configs/web.md +28 -0
- package/docs/api/hooks/index.md +182 -0
- package/docs/api/hooks/useI18n.md +27 -0
- package/docs/api/hooks/useOverlay.md +37 -0
- package/docs/api/hooks/usePopup.md +35 -0
- package/docs/api/hooks/useVersion.md +23 -0
- package/docs/api/index.md +269 -0
- package/docs/api/mixins/app.md +29 -0
- package/docs/api/mixins/badge.md +23 -0
- package/docs/api/mixins/debounce.md +32 -0
- package/docs/api/mixins/deep.md +29 -0
- package/docs/api/mixins/index.md +23 -0
- package/docs/api/mixins/login.md +22 -0
- package/docs/api/mixins/model.md +26 -0
- package/docs/api/mixins/redirect.md +26 -0
- package/docs/api/mixins/share.md +29 -0
- package/docs/api/mixins/show.md +27 -0
- package/docs/api/mixins/webview.md +27 -0
- package/docs/api/modules/app.md +30 -0
- package/docs/api/modules/dict.md +28 -0
- package/docs/api/modules/im.md +22 -0
- package/docs/api/modules/index.md +44 -0
- package/docs/api/modules/launch.md +26 -0
- package/docs/api/modules/location.md +25 -0
- package/docs/api/modules/login.md +35 -0
- package/docs/api/modules/network.md +26 -0
- package/docs/api/modules/system.md +29 -0
- package/docs/api/utils/audio.md +84 -0
- package/docs/api/utils/consts.md +201 -0
- package/docs/api/utils/cos.md +269 -0
- package/docs/api/utils/debounce.md +89 -0
- package/docs/api/utils/file.md +78 -0
- package/docs/api/utils/index.md +547 -0
- package/docs/api/utils/locale.md +32 -0
- package/docs/api/utils/message.md +81 -0
- package/docs/api/utils/navigate.md +267 -0
- package/docs/api/utils/pages.md +205 -0
- package/docs/api/utils/permission.md +28 -0
- package/docs/api/utils/permit.md +62 -0
- package/docs/api/utils/query.md +89 -0
- package/docs/api/utils/request.md +34 -0
- package/docs/api/utils/storage.md +145 -0
- package/docs/api/utils/subscribe.md +77 -0
- package/docs/api/utils/throttle.md +101 -0
- package/docs/api/utils/toast.md +164 -0
- package/docs/api/utils/uni.md +28 -0
- package/docs/api/utils/update.md +165 -0
- package/docs/components/g-back-button.md +76 -0
- package/docs/components/g-checkbox-list.md +101 -0
- package/docs/components/g-container.md +93 -0
- package/docs/components/g-data-list.md +106 -0
- package/docs/components/g-dot-text.md +79 -0
- package/docs/components/g-env.md +75 -0
- package/docs/components/g-float.md +83 -0
- package/docs/components/g-grid-image.md +91 -0
- package/docs/components/g-grid-swiper.md +99 -0
- package/docs/components/g-icon.md +106 -0
- package/docs/components/g-mask.md +82 -0
- package/docs/components/g-money.md +90 -0
- package/docs/components/g-more.md +78 -0
- package/docs/components/g-page-container.md +170 -0
- package/docs/components/g-permission-popup.md +117 -0
- package/docs/components/g-polyline-chat.md +102 -0
- package/docs/components/g-polyline-view.md +67 -0
- package/docs/components/g-popup.md +144 -0
- package/docs/components/g-refresh-view.md +118 -0
- package/docs/components/g-render-image.md +83 -0
- package/docs/components/g-search.md +120 -0
- package/docs/components/g-share-photo.md +77 -0
- package/docs/components/g-share-view.md +83 -0
- package/docs/components/g-share-weixin.md +81 -0
- package/docs/components/g-skeleton-view.md +71 -0
- package/docs/components/g-skeleton.md +64 -0
- package/docs/components/g-tag-editor.md +134 -0
- package/docs/components/g-timer.md +72 -0
- package/docs/components/g-trtc-room.md +116 -0
- package/docs/components/g-trtc-tui.md +84 -0
- package/docs/components/g-trtc.md +124 -0
- package/docs/components/g-upload.md +117 -0
- package/docs/components/g-waterfall.md +84 -0
- package/docs/components/index.md +109 -0
- package/docs/components/styles/base-styles.md +367 -0
- package/docs/components/styles/global-vars.md +150 -0
- package/docs/components/usage.md +112 -0
- package/docs/faq/index.md +78 -0
- package/docs/guide/getting-started.md +195 -0
- package/docs/guide/project-frame.md +297 -0
- package/docs/index.md +80 -0
- package/lib/apis/core.d.ts +12 -0
- package/lib/apis/core.js +13 -0
- package/lib/apis/index.d.ts +2 -0
- package/lib/apis/index.js +2 -0
- package/lib/apis/request.d.ts +4 -0
- package/lib/apis/request.js +27 -0
- package/lib/components/g-back-button/g-back-button.vue +141 -0
- package/lib/components/g-checkbox-list/g-checkbox-list.vue +156 -0
- package/lib/components/g-container/g-container.vue +159 -0
- package/lib/components/g-data-list/g-data-list.vue +192 -0
- package/lib/components/g-dot-text/g-dot-text.vue +114 -0
- package/lib/components/g-env/g-env.vue +123 -0
- package/lib/components/g-float/g-float.vue +131 -0
- package/lib/components/g-grid-image/g-grid-image.vue +84 -0
- package/lib/components/g-grid-swiper/g-grid-swiper.vue +224 -0
- package/lib/components/g-icon/g-icon.vue +72 -0
- package/lib/components/g-mask/g-mask.vue +126 -0
- package/lib/components/g-money/g-money.vue +174 -0
- package/lib/components/g-more/g-more.vue +68 -0
- package/lib/components/g-page-container/g-page-container.vue +470 -0
- package/lib/components/g-permission-popup/g-permission-popup.vue +80 -0
- package/lib/components/g-polyline-chat/g-polyline-chat.vue +255 -0
- package/lib/components/g-polyline-view/g-polyline-view.vue +104 -0
- package/lib/components/g-popup/g-popup.vue +449 -0
- package/lib/components/g-refresh-view/g-refresh-view.vue +213 -0
- package/lib/components/g-render-image/g-render-image.vue +222 -0
- package/lib/components/g-search/g-search.vue +274 -0
- package/lib/components/g-share-photo/g-share-photo.vue +75 -0
- package/lib/components/g-share-view/g-share-view.vue +157 -0
- package/lib/components/g-share-weixin/g-share-weixin.vue +106 -0
- package/lib/components/g-skeleton/g-skeleton.vue +55 -0
- package/lib/components/g-skeleton-view/g-skeleton-view.vue +78 -0
- package/lib/components/g-tag-editor/g-tag-editor.vue +482 -0
- package/lib/components/g-timer/g-timer.vue +61 -0
- package/lib/components/g-trtc/g-trtc.vue +347 -0
- package/lib/components/g-trtc-room/g-trtc-room.vue +524 -0
- package/lib/components/g-trtc-room/iconfont.scss +59 -0
- package/lib/components/g-trtc-tui/g-trtc-tui.vue +245 -0
- package/lib/components/g-upload/g-upload.vue +294 -0
- package/lib/components/g-waterfall/g-waterfall.vue +101 -0
- package/lib/configs/api.d.ts +7 -0
- package/lib/configs/api.js +6 -0
- package/lib/configs/app.d.ts +26 -0
- package/lib/configs/app.js +50 -0
- package/lib/configs/brand.d.ts +22 -0
- package/lib/configs/brand.js +26 -0
- package/lib/configs/cdn.d.ts +13 -0
- package/lib/configs/cdn.js +12 -0
- package/lib/configs/color.d.ts +62 -0
- package/lib/configs/color.js +66 -0
- package/lib/configs/env.d.ts +37 -0
- package/lib/configs/env.js +71 -0
- package/lib/configs/index.d.ts +170 -0
- package/lib/configs/index.js +82 -0
- package/lib/configs/link.d.ts +11 -0
- package/lib/configs/link.js +3 -0
- package/lib/configs/log.d.ts +9 -0
- package/lib/configs/log.js +8 -0
- package/lib/configs/mp.d.ts +15 -0
- package/lib/configs/mp.js +9 -0
- package/lib/configs/navigate.d.ts +17 -0
- package/lib/configs/navigate.js +5 -0
- package/lib/configs/page.d.ts +18 -0
- package/lib/configs/page.js +14 -0
- package/lib/configs/path.d.ts +11 -0
- package/lib/configs/path.js +10 -0
- package/lib/configs/storage.d.ts +7 -0
- package/lib/configs/storage.js +6 -0
- package/lib/configs/tabbar.d.ts +7 -0
- package/lib/configs/tabbar.js +6 -0
- package/lib/configs/toast.d.ts +18 -0
- package/lib/configs/toast.js +29 -0
- package/lib/configs/update.d.ts +45 -0
- package/lib/configs/update.js +6 -0
- package/lib/configs/upload.d.ts +30 -0
- package/lib/configs/upload.js +7 -0
- package/lib/configs/ver.d.ts +8 -0
- package/lib/configs/ver.js +28 -0
- package/lib/configs/web.d.ts +5 -0
- package/lib/configs/web.js +2 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.js +4 -0
- package/lib/hooks/useI18n.d.ts +2 -0
- package/lib/hooks/useI18n.js +19 -0
- package/lib/hooks/useOverlay.d.ts +1 -0
- package/lib/hooks/useOverlay.js +17 -0
- package/lib/hooks/usePopup.d.ts +1 -0
- package/lib/hooks/usePopup.js +14 -0
- package/lib/hooks/useVersion.d.ts +6 -0
- package/lib/hooks/useVersion.js +21 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +33 -0
- package/lib/mixins/app.d.ts +14 -0
- package/lib/mixins/app.js +105 -0
- package/lib/mixins/badge.d.ts +24 -0
- package/lib/mixins/badge.js +44 -0
- package/lib/mixins/debounce.d.ts +6 -0
- package/lib/mixins/debounce.js +11 -0
- package/lib/mixins/deep.d.ts +6 -0
- package/lib/mixins/deep.js +8 -0
- package/lib/mixins/index.d.ts +8 -0
- package/lib/mixins/index.js +8 -0
- package/lib/mixins/login.d.ts +4 -0
- package/lib/mixins/login.js +25 -0
- package/lib/mixins/model.d.ts +22 -0
- package/lib/mixins/model.js +29 -0
- package/lib/mixins/redirect.d.ts +8 -0
- package/lib/mixins/redirect.js +94 -0
- package/lib/mixins/share.d.ts +15 -0
- package/lib/mixins/share.js +55 -0
- package/lib/mixins/show.d.ts +9 -0
- package/lib/mixins/show.js +16 -0
- package/lib/mixins/webview.d.ts +26 -0
- package/lib/mixins/webview.js +225 -0
- package/lib/modules/app.d.ts +5 -0
- package/lib/modules/app.js +19 -0
- package/lib/modules/dict.d.ts +8 -0
- package/lib/modules/dict.js +43 -0
- package/lib/modules/im.d.ts +6 -0
- package/lib/modules/im.js +105 -0
- package/lib/modules/index.d.ts +8 -0
- package/lib/modules/index.js +8 -0
- package/lib/modules/launch.d.ts +5 -0
- package/lib/modules/launch.js +32 -0
- package/lib/modules/location.d.ts +5 -0
- package/lib/modules/location.js +57 -0
- package/lib/modules/login.d.ts +5 -0
- package/lib/modules/login.js +72 -0
- package/lib/modules/network.d.ts +5 -0
- package/lib/modules/network.js +39 -0
- package/lib/modules/system.d.ts +5 -0
- package/lib/modules/system.js +65 -0
- package/lib/styles/animate-vue.scss +3 -0
- package/lib/styles/animate.scss +27 -0
- package/lib/styles/bg-vue.scss +21 -0
- package/lib/styles/bg.scss +93 -0
- package/lib/styles/border.scss +218 -0
- package/lib/styles/flex-nvue.scss +64 -0
- package/lib/styles/flex-vue.scss +75 -0
- package/lib/styles/font.scss +59 -0
- package/lib/styles/index.scss +25 -0
- package/lib/styles/layout-nvue.scss +24 -0
- package/lib/styles/layout-vue.scss +30 -0
- package/lib/styles/layout.scss +76 -0
- package/lib/styles/opacity.scss +10 -0
- package/lib/styles/reset-vue.scss +46 -0
- package/lib/styles/shadow.scss +12 -0
- package/lib/styles/sizing-vue.scss +21 -0
- package/lib/styles/sizing.scss +21 -0
- package/lib/styles/spacing.scss +234 -0
- package/lib/styles/text-nvue.scss +21 -0
- package/lib/styles/text-vue.scss +70 -0
- package/lib/styles/text.scss +122 -0
- package/lib/styles/var.module.scss +29 -0
- package/lib/utils/audio.d.ts +14 -0
- package/lib/utils/audio.js +43 -0
- package/lib/utils/consts.d.ts +30 -0
- package/lib/utils/consts.js +52 -0
- package/lib/utils/cos.d.ts +15 -0
- package/lib/utils/cos.js +140 -0
- package/lib/utils/debounce.d.ts +2 -0
- package/lib/utils/debounce.js +30 -0
- package/lib/utils/file.d.ts +28 -0
- package/lib/utils/file.js +292 -0
- package/lib/utils/index.d.ts +166 -0
- package/lib/utils/index.js +485 -0
- package/lib/utils/locale.d.ts +6 -0
- package/lib/utils/locale.js +19 -0
- package/lib/utils/message.d.ts +9 -0
- package/lib/utils/message.js +63 -0
- package/lib/utils/navigate.d.ts +27 -0
- package/lib/utils/navigate.js +183 -0
- package/lib/utils/pages.d.ts +21 -0
- package/lib/utils/pages.js +79 -0
- package/lib/utils/permission.d.ts +16 -0
- package/lib/utils/permission.js +291 -0
- package/lib/utils/permit.d.ts +30 -0
- package/lib/utils/permit.js +181 -0
- package/lib/utils/query.d.ts +13 -0
- package/lib/utils/query.js +14 -0
- package/lib/utils/request.d.ts +8 -0
- package/lib/utils/request.js +126 -0
- package/lib/utils/storage.d.ts +53 -0
- package/lib/utils/storage.js +145 -0
- package/lib/utils/subscribe.d.ts +7 -0
- package/lib/utils/subscribe.js +94 -0
- package/lib/utils/throttle.d.ts +2 -0
- package/lib/utils/throttle.js +32 -0
- package/lib/utils/toast.d.ts +17 -0
- package/lib/utils/toast.js +66 -0
- package/lib/utils/uni.d.ts +1 -0
- package/lib/utils/uni.js +147 -0
- package/lib/utils/update.d.ts +9 -0
- package/lib/utils/update.js +376 -0
- package/package.json +49 -0
- package/types/index.d.ts +25 -0
- package/types/virtual.d.ts +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# 模块
|
|
2
|
+
|
|
3
|
+
模块发布路径为 `@zfqh/uniapp/lib/modules`。根入口没有直接导出这些模块;如果业务项目要复用,请深度引入 `@zfqh/uniapp/lib/modules/<name>` 或从 `@zfqh/uniapp/lib/modules` 取具名导出。
|
|
4
|
+
|
|
5
|
+
这些模块默认假设项目使用 Vuex 4,并且插件安装后会把 Vuex store 暴露到 `uni.$store`,请求、导航、webview 消息等普通模块会读取它。组件和 hooks 中读取 Vuex 时仍应使用 `useStore()` 或 `this.$store`。
|
|
6
|
+
|
|
7
|
+
## 基本使用
|
|
8
|
+
|
|
9
|
+
在业务项目的 `store/index.ts` 中引入模块并注册到 `createStore`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createStore } from 'vuex';
|
|
13
|
+
import { getDictData } from '@zfqh/uniapp/lib/apis';
|
|
14
|
+
import { app, dict, im, system } from '@zfqh/uniapp/lib/modules';
|
|
15
|
+
import login from './modules/login';
|
|
16
|
+
import setting from './modules/setting';
|
|
17
|
+
|
|
18
|
+
// 注入请求函数到 dict 模块
|
|
19
|
+
dict.request = ({ name: type }) => getDictData({ type });
|
|
20
|
+
|
|
21
|
+
// 注入请求函数到 im 模块(获取 IM userSig)
|
|
22
|
+
im.request = () => getImUserInfo();
|
|
23
|
+
|
|
24
|
+
const store = createStore({
|
|
25
|
+
modules: {
|
|
26
|
+
app,
|
|
27
|
+
dict,
|
|
28
|
+
im,
|
|
29
|
+
system,
|
|
30
|
+
login,
|
|
31
|
+
setting,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export default store;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
关键点:
|
|
39
|
+
|
|
40
|
+
- `dict.request` 必须在 `createStore` 之前赋值,它是 `getDictInfo` action 内部调用的数据获取函数。
|
|
41
|
+
- `getDictData` 已内置在 `@zfqh/uniapp/lib/apis`,直接导入即可,无需业务自行封装。
|
|
42
|
+
- `im` 模块同样有可注入的 `request` 属性,用于获取 IM userSig,模式与 `dict` 一致。
|
|
43
|
+
- `app` 模块读取 `config.app` 和 `config.brand` 作为初始 state,适合存储应用级信息,无需额外配置。
|
|
44
|
+
- `system` 模块无需额外配置,注册后即可通过 `store.state.system.info` 读取系统信息。
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# launch
|
|
2
|
+
|
|
3
|
+
启动参数模块。发布路径:`@zfqh/uniapp/lib/modules/launch`
|
|
4
|
+
|
|
5
|
+
| 项 | 说明 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `state.info` | 包含 id、path、query、referrerInfo、scene。 |
|
|
8
|
+
| `state.key` | 持久化的 launch id。 |
|
|
9
|
+
| `mutation setLaunchInfo(data)` | 规范化 scene/path 并记录启动参数。 |
|
|
10
|
+
| `mutation setLaunchId(data)` | 写入 launch 缓存。 |
|
|
11
|
+
|
|
12
|
+
## 基本使用
|
|
13
|
+
|
|
14
|
+
App.vue 启动时保存启动路径、scene 和 query,后续页面可读取邀请码、二维码参数或来源信息。
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// App.vue
|
|
18
|
+
onLaunch(e) {
|
|
19
|
+
store.commit('setLaunchInfo', e);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 读取启动参数
|
|
23
|
+
const launchInfo = store.state.launch.info;
|
|
24
|
+
console.log(launchInfo.scene); // 小程序场景值
|
|
25
|
+
console.log(launchInfo.query); // 启动 query
|
|
26
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# location
|
|
2
|
+
|
|
3
|
+
定位模块。发布路径:`@zfqh/uniapp/lib/modules/location`
|
|
4
|
+
|
|
5
|
+
| 项 | 说明 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `state.info` | 包含 name、address、longitude、latitude,并持久化。 |
|
|
8
|
+
| `action getLocationInfo(options)` | 申请 location 权限后调用 uni.getLocation,成功后写入城市和经纬度。 |
|
|
9
|
+
| `mutation setLocationInfo(data)` | 合并并缓存定位信息。 |
|
|
10
|
+
|
|
11
|
+
## 基本使用
|
|
12
|
+
|
|
13
|
+
需要按距离查找门店或设备时,先获取定位再发起业务请求。
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// 获取定位
|
|
17
|
+
await store.dispatch('getLocationInfo');
|
|
18
|
+
const location = store.state.location.info;
|
|
19
|
+
console.log(location.name, location.longitude, location.latitude);
|
|
20
|
+
|
|
21
|
+
const stores = await getNearbyStores({
|
|
22
|
+
longitude: location.longitude,
|
|
23
|
+
latitude: location.latitude,
|
|
24
|
+
});
|
|
25
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# login
|
|
2
|
+
|
|
3
|
+
登录模块。发布路径:`@zfqh/uniapp/lib/modules/login`
|
|
4
|
+
|
|
5
|
+
| 项 | 说明 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `state.info` | 登录信息,包含 token、refreshToken、expiresTime、phone、userId、tenantId、storeId 等。 |
|
|
8
|
+
| `getter isLogin` | Boolean(state.info.token)。 |
|
|
9
|
+
| `mutation setLoginInfo(data)` | 去掉 token 中 bearer 前缀后合并并缓存。 |
|
|
10
|
+
| `mutation resetState()` | 重置登录信息并删除缓存。 |
|
|
11
|
+
| `action logout(reLaunch)` | 节流退出;reLaunch 为 true 时重启到登录页,否则走 navigate 登录拦截。 |
|
|
12
|
+
|
|
13
|
+
## 基本使用
|
|
14
|
+
|
|
15
|
+
登录成功后写入 token、用户和租户信息;请求拦截器会从该模块注入请求头。
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
store.commit('setLoginInfo', {
|
|
19
|
+
token: loginResult.accessToken,
|
|
20
|
+
refreshToken: loginResult.refreshToken,
|
|
21
|
+
userId: loginResult.userId,
|
|
22
|
+
tenantId: loginResult.tenantId,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// 检查登录状态
|
|
26
|
+
const isLogin = store.getters.isLogin;
|
|
27
|
+
|
|
28
|
+
// 读取登录信息
|
|
29
|
+
const token = store.state.login.info.token;
|
|
30
|
+
const userId = store.state.login.info.userId;
|
|
31
|
+
const tenantId = store.state.login.info.tenantId;
|
|
32
|
+
|
|
33
|
+
// 退出登录
|
|
34
|
+
await store.dispatch('logout');
|
|
35
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# network
|
|
2
|
+
|
|
3
|
+
网络模块。发布路径:`@zfqh/uniapp/lib/modules/network`
|
|
4
|
+
|
|
5
|
+
| 项 | 说明 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `state.info.type` | 网络类型,默认 unknown。 |
|
|
8
|
+
| `getter isConnected` | type !== "none"。 |
|
|
9
|
+
| `action getNetworkInfo()` | 调用 uni.getNetworkType 并写入 type。 |
|
|
10
|
+
| `mutation setNetworkInfo(data)` | 合并网络信息。 |
|
|
11
|
+
|
|
12
|
+
## 基本使用
|
|
13
|
+
|
|
14
|
+
商户端离线体检流程可根据网络状态决定是否同步本地报告。
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
await store.dispatch('getNetworkInfo');
|
|
18
|
+
|
|
19
|
+
// 检查网络连接
|
|
20
|
+
const isConnected = store.getters.isConnected;
|
|
21
|
+
const networkType = store.state.network.info.type; // 'wifi', '4g', 'none' 等
|
|
22
|
+
|
|
23
|
+
if (isConnected) {
|
|
24
|
+
await syncOfflineReports();
|
|
25
|
+
}
|
|
26
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# system
|
|
2
|
+
|
|
3
|
+
系统信息模块。发布路径:`@zfqh/uniapp/lib/modules/system`
|
|
4
|
+
|
|
5
|
+
| 项 | 说明 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `state.info` | uni.getWindowInfo、getDeviceInfo、getAppBaseInfo 合并结果,并补充 deviceOrientation、titleHeight、topStatusBarHeight、topBarTitleHeight、uaEnv。 |
|
|
8
|
+
| `action getSystemInfo()` | 调用 uni.getSystemInfo 刷新系统信息。 |
|
|
9
|
+
| `mutation setSystemInfo(info)` | 合并系统信息。 |
|
|
10
|
+
|
|
11
|
+
## 基本使用
|
|
12
|
+
|
|
13
|
+
商户端波形、导航栏和设备适配页面可读取系统信息计算高度和平台能力。
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createStore } from 'vuex';
|
|
17
|
+
import { system } from '@zfqh/uniapp/lib/modules';
|
|
18
|
+
|
|
19
|
+
const store = createStore({
|
|
20
|
+
modules: {
|
|
21
|
+
system,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await store.dispatch('getSystemInfo');
|
|
26
|
+
|
|
27
|
+
const { safeAreaInsets, titleHeight, deviceOrientation } = store.state.system.info;
|
|
28
|
+
console.log(safeAreaInsets.bottom, titleHeight, deviceOrientation);
|
|
29
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# 音频
|
|
2
|
+
|
|
3
|
+
::: tip 工具模块
|
|
4
|
+
`@zfqh/uniapp/lib/utils/audio`
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
封装互斥播放、停止和销毁逻辑,适合语音消息、提示音、录音试听等场景。
|
|
8
|
+
|
|
9
|
+
## 平台兼容性
|
|
10
|
+
|
|
11
|
+
| App | H5 | 微信小程序 | 其他小程序 | WebView |
|
|
12
|
+
| --- | --- | --- | --- | --- |
|
|
13
|
+
| √ | √ | √ | 视平台 API 而定 | 视运行容器而定 |
|
|
14
|
+
|
|
15
|
+
## 基本使用
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Audio } from '@zfqh/uniapp';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 创建和播放
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Audio } from '@zfqh/uniapp';
|
|
25
|
+
|
|
26
|
+
// 创建音频实例
|
|
27
|
+
const audio = new Audio({
|
|
28
|
+
url: 'https://cdn.example.com/guide.mp3',
|
|
29
|
+
autoplay: false,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 播放(会自动停止上一个 Audio 实例)
|
|
33
|
+
audio.play();
|
|
34
|
+
|
|
35
|
+
// 暂停并重置到起点
|
|
36
|
+
audio.stop();
|
|
37
|
+
|
|
38
|
+
// 销毁实例(释放资源)
|
|
39
|
+
audio.destroy();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 单例互斥
|
|
43
|
+
|
|
44
|
+
`Audio` 类维护了一个静态 `instance` 引用。调用 `play()` 时会自动停止之前播放的 `Audio.instance`,确保同一时刻只有一个音频在播放。
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// 语音消息列表:点击播放时自动停止上一条
|
|
48
|
+
const audioList = messages.map((msg) => new Audio({ url: msg.audioUrl }));
|
|
49
|
+
|
|
50
|
+
function playMessage(index) {
|
|
51
|
+
audioList[index].play(); // 自动停止之前播放的音频
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 语音播报场景
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const guideAudio = new Audio({ url: 'https://cdn.example.com/guide.mp3' });
|
|
59
|
+
|
|
60
|
+
// 页面显示时播放引导语音
|
|
61
|
+
onShow(() => {
|
|
62
|
+
guideAudio.play();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 页面隐藏时停止
|
|
66
|
+
onHide(() => {
|
|
67
|
+
guideAudio.stop();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// 页面卸载时销毁
|
|
71
|
+
onUnload(() => {
|
|
72
|
+
guideAudio.destroy();
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## API
|
|
77
|
+
|
|
78
|
+
发布路径:`@zfqh/uniapp/lib/utils/audio`
|
|
79
|
+
|
|
80
|
+
| 名称 | 签名/声明 | 说明 |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| `AudioOptions` | `export interface AudioOptions {` | 音频实例配置,包含 url 和 autoplay。 |
|
|
83
|
+
| `Audio` | `export class Audio {` | 单例互斥音频类;play 时会停止上一个 Audio.instance,提供 play、stop、destroy。 |
|
|
84
|
+
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# 运行时常量
|
|
2
|
+
|
|
3
|
+
::: tip 工具模块
|
|
4
|
+
`@zfqh/uniapp/lib/utils/consts`
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
集中暴露系统信息、小程序胶囊、webview 环境、平台代码和语言常量。
|
|
8
|
+
|
|
9
|
+
## 平台兼容性
|
|
10
|
+
|
|
11
|
+
| App | H5 | 微信小程序 | 其他小程序 | WebView |
|
|
12
|
+
| --- | --- | --- | --- | --- |
|
|
13
|
+
| √ | √ | √ | 视平台 API 而定 | 视运行容器而定 |
|
|
14
|
+
|
|
15
|
+
## 基本使用
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { MENU_BUTTON, SYSTEM_INFO, WEBVIEW_ENV, IS_WEBVIEW_ENV, PLATFORM_CODE, MP_ENV_VERSION, LANGUAGE } from '@zfqh/uniapp';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
具体方法、参数语义和返回值以发布包类型为准;下方表格按 `@zfqh/uniapp/lib/utils/consts` 的导出整理。
|
|
22
|
+
|
|
23
|
+
## API
|
|
24
|
+
|
|
25
|
+
发布路径:`@zfqh/uniapp/lib/utils/consts`
|
|
26
|
+
|
|
27
|
+
| 名称 | 签名/声明 | 说明 |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `MENU_BUTTON` | `export const MENU_BUTTON = { height: 0, width: 0, top: 0, bottom: 0, left: 0 };` | 小程序胶囊按钮信息,来自 uni.getMenuButtonBoundingClientRect。 |
|
|
30
|
+
| `SYSTEM_INFO` | `export const SYSTEM_INFO = system.state.info;` | 系统、窗口、设备、App 基础信息的合并结果。 |
|
|
31
|
+
| `WEBVIEW_ENV` | `export const WEBVIEW_ENV = {` | H5/webview 容器环境识别结果,例如 h5、app、mp 等。 |
|
|
32
|
+
| `IS_WEBVIEW_ENV` | `export const IS_WEBVIEW_ENV = Object.values(WEBVIEW_ENV).some((ele) => ele === true);` | 是否运行在 webview 容器内。 |
|
|
33
|
+
| `PLATFORM_CODE` | `export const PLATFORM_CODE = (() => {` | 当前平台代码,用于 webview 参数和业务统计。 |
|
|
34
|
+
| `MP_ENV_VERSION` | `export enum MP_ENV_VERSION {` | 小程序环境版本枚举。 |
|
|
35
|
+
| `LANGUAGE` | `export const LANGUAGE = {` | 当前语言标识。 |
|
|
36
|
+
|
|
37
|
+
## SYSTEM_INFO 属性详情
|
|
38
|
+
|
|
39
|
+
`SYSTEM_INFO` 是 `uni.getWindowInfo()`、`uni.getDeviceInfo()`、`uni.getAppBaseInfo()` 的合并结果,并补充了计算属性。常用于自定义导航栏、响应式布局等平台适配场景。
|
|
40
|
+
|
|
41
|
+
### 窗口信息(来自 `uni.getWindowInfo()`)
|
|
42
|
+
|
|
43
|
+
| 属性 | 类型 | 说明 |
|
|
44
|
+
| --- | --- | --- |
|
|
45
|
+
| `windowWidth` | `number` | 可使用窗口宽度(px) |
|
|
46
|
+
| `windowHeight` | `number` | 可使用窗口高度(px) |
|
|
47
|
+
| `screenWidth` | `number` | 屏幕宽度(px) |
|
|
48
|
+
| `screenHeight` | `number` | 屏幕高度(px) |
|
|
49
|
+
| `pixelRatio` | `number` | 设备像素比 |
|
|
50
|
+
| `statusBarHeight` | `number` | 状态栏高度(px) |
|
|
51
|
+
| `safeArea` | `object` | 安全区域,含 `top`、`bottom`、`left`、`right`、`width`、`height` |
|
|
52
|
+
|
|
53
|
+
### 设备信息(来自 `uni.getDeviceInfo()`)
|
|
54
|
+
|
|
55
|
+
| 属性 | 类型 | 说明 |
|
|
56
|
+
| --- | --- | --- |
|
|
57
|
+
| `brand` | `string` | 设备品牌 |
|
|
58
|
+
| `model` | `string` | 设备型号 |
|
|
59
|
+
| `system` | `string` | 操作系统版本 |
|
|
60
|
+
| `platform` | `string` | 客户端平台(`ios`、`android`、`devtools` 等) |
|
|
61
|
+
| `deviceOrientation` | `string` | 设备方向(`portrait`、`landscape`) |
|
|
62
|
+
|
|
63
|
+
### 应用信息(来自 `uni.getAppBaseInfo()`)
|
|
64
|
+
|
|
65
|
+
| 属性 | 类型 | 说明 |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| `SDKVersion` | `string` | 客户端基础库版本 |
|
|
68
|
+
| `appName` | `string` | 应用名称 |
|
|
69
|
+
| `appVersion` | `string` | 应用版本名 |
|
|
70
|
+
| `appVersionCode` | `string` | 应用版本号 |
|
|
71
|
+
| `appLanguage` | `string` | 应用语言 |
|
|
72
|
+
|
|
73
|
+
### 计算属性
|
|
74
|
+
|
|
75
|
+
| 属性 | 类型 | 说明 |
|
|
76
|
+
| --- | --- | --- |
|
|
77
|
+
| `titleHeight` | `number` | 导航栏标题高度,默认 44(小程序端根据胶囊计算) |
|
|
78
|
+
| `topStatusBarHeight` | `number` | 状态栏高度(与 `statusBarHeight` 相同) |
|
|
79
|
+
| `topBarTitleHeight` | `number` | 状态栏 + 导航栏总高度 |
|
|
80
|
+
| `uaEnv` | `object` | 仅 H5:`{ weixin, alipay, browser, devtools }` 环境识别结果 |
|
|
81
|
+
|
|
82
|
+
### 常用场景
|
|
83
|
+
|
|
84
|
+
自定义导航栏高度计算:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { SYSTEM_INFO } from '@zfqh/uniapp';
|
|
88
|
+
|
|
89
|
+
// 状态栏高度
|
|
90
|
+
const statusBarHeight = SYSTEM_INFO.statusBarHeight;
|
|
91
|
+
|
|
92
|
+
// 导航栏总高度 = 状态栏 + 标题栏
|
|
93
|
+
const navBarHeight = SYSTEM_INFO.topBarTitleHeight;
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
响应式布局判断:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const screenWidth = SYSTEM_INFO.screenWidth;
|
|
100
|
+
const isSmallScreen = screenWidth < 375;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## WEBVIEW_ENV 使用示例
|
|
104
|
+
|
|
105
|
+
`WEBVIEW_ENV` 用于检测当前是否运行在 webview 容器中,以及具体是哪种容器环境。仅在 H5 平台有效。
|
|
106
|
+
|
|
107
|
+
| 属性 | 检测条件 | 说明 |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| `h5` | `platform` 为 `h5` 或 `web` 且 `window !== parent` | 在 H5 iframe 或 Electron webview 内 |
|
|
110
|
+
| `app` | `platform` 为 `app` | 在 App webview 内 |
|
|
111
|
+
| `mp` | `window.__wxjs_environment === 'miniprogram'` 或 `platform` 为 `mp` | 在微信小程序 webview 内 |
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { WEBVIEW_ENV, IS_WEBVIEW_ENV } from '@zfqh/uniapp';
|
|
115
|
+
|
|
116
|
+
// 判断是否在任意 webview 容器内
|
|
117
|
+
if (IS_WEBVIEW_ENV) {
|
|
118
|
+
// 在 webview 容器内运行
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 判断具体容器类型
|
|
122
|
+
if (WEBVIEW_ENV.app) {
|
|
123
|
+
// 在 App webview 内
|
|
124
|
+
} else if (WEBVIEW_ENV.mp) {
|
|
125
|
+
// 在小程序 webview 内
|
|
126
|
+
} else if (WEBVIEW_ENV.h5) {
|
|
127
|
+
// 在 H5 iframe 或 Electron webview 内
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
检测 Electron webview 需配合 `PLATFORM_CODE`:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { WEBVIEW_ENV, PLATFORM_CODE } from '@zfqh/uniapp';
|
|
135
|
+
|
|
136
|
+
if (WEBVIEW_ENV.h5 && PLATFORM_CODE === 'web') {
|
|
137
|
+
// 在 Electron webview 内
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## MENU_BUTTON 使用示例
|
|
142
|
+
|
|
143
|
+
小程序胶囊按钮信息,来自 `uni.getMenuButtonBoundingClientRect()`。常用于自定义导航栏高度计算。
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { MENU_BUTTON } from '@zfqh/uniapp';
|
|
147
|
+
|
|
148
|
+
// 自定义导航栏高度 = 胶囊底部 + (胶囊顶部 - 状态栏高度)
|
|
149
|
+
const navBarHeight = MENU_BUTTON.bottom + (MENU_BUTTON.top - statusBarHeight);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
| 属性 | 类型 | 说明 |
|
|
153
|
+
| --- | --- | --- |
|
|
154
|
+
| `height` | `number` | 胶囊高度(px) |
|
|
155
|
+
| `width` | `number` | 胶囊宽度(px) |
|
|
156
|
+
| `top` | `number` | 胶囊顶部距离视口顶部(px) |
|
|
157
|
+
| `bottom` | `number` | 胶囊底部距离视口顶部(px) |
|
|
158
|
+
| `left` | `number` | 胶囊左侧距离视口左侧(px) |
|
|
159
|
+
|
|
160
|
+
## PLATFORM_CODE 使用示例
|
|
161
|
+
|
|
162
|
+
当前平台代码,用于 webview 参数和业务统计。
|
|
163
|
+
|
|
164
|
+
| 值 | 条件 | 说明 |
|
|
165
|
+
| --- | --- | --- |
|
|
166
|
+
| `'mp'` | `#ifdef MP` | 小程序端 |
|
|
167
|
+
| `'web'` | `#ifdef H5` 且 `window.electron` 存在 | Electron 桌面端 |
|
|
168
|
+
| `'h5'` | `#ifdef H5` 且无 `window.electron` | 普通 H5 浏览器 |
|
|
169
|
+
| `'app'` | `#ifdef APP-PLUS` | App 端 |
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { PLATFORM_CODE } from '@zfqh/uniapp';
|
|
173
|
+
|
|
174
|
+
if (PLATFORM_CODE === 'web') {
|
|
175
|
+
// Electron 桌面端
|
|
176
|
+
} else if (PLATFORM_CODE === 'h5') {
|
|
177
|
+
// 普通 H5 浏览器
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## MP_ENV_VERSION 使用示例
|
|
182
|
+
|
|
183
|
+
小程序环境版本枚举。
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { MP_ENV_VERSION } from '@zfqh/uniapp';
|
|
187
|
+
|
|
188
|
+
if (config.mp.envVersion === MP_ENV_VERSION.develop) {
|
|
189
|
+
// 开发版
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## LANGUAGE 使用示例
|
|
194
|
+
|
|
195
|
+
当前语言标识,用于请求 header 和国际化。
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
import { LANGUAGE } from '@zfqh/uniapp';
|
|
199
|
+
|
|
200
|
+
headers['X-Language'] = LANGUAGE;
|
|
201
|
+
```
|