@zfqh/uniapp 0.1.2 → 0.1.4
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 +20 -11
- package/docs/api/apis/index.md +1 -1
- package/docs/api/apis/request.md +9 -9
- package/docs/api/configs/index.md +1 -2
- package/docs/api/hooks/index.md +4 -4
- package/docs/api/index.md +8 -3
- package/docs/api/mixins/app.md +1 -2
- package/docs/api/modules/app.md +0 -2
- package/docs/api/modules/index.md +1 -1
- package/docs/api/utils/cos.md +1 -2
- package/docs/api/utils/index.md +1 -1
- package/docs/api/utils/locale.md +40 -4
- package/docs/api/utils/navigate.md +3 -3
- package/docs/api/utils/pages.md +1 -1
- package/docs/api/utils/request.md +1 -1
- package/docs/components/index.md +1 -1
- package/docs/components/styles/base-styles.md +239 -239
- package/docs/components/usage.md +1 -1
- package/docs/faq/index.md +5 -6
- package/docs/guide/getting-started.md +3 -4
- package/docs/guide/project-frame.md +10 -21
- package/docs/index.md +2 -2
- package/lib/hooks/useI18n.js +1 -7
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -2
- package/lib/styles/bg.scss +1 -1
- package/lib/styles/flex.scss +8 -8
- package/lib/styles/index.scss +3 -3
- package/lib/styles/layout.scss +14 -14
- package/lib/styles/reset-vue.scss +2 -2
- package/lib/styles/text-nvue.scss +1 -1
- package/lib/styles/text.scss +1 -1
- package/lib/utils/locale.d.ts +3 -4
- package/lib/utils/locale.js +6 -15
- package/package.json +3 -3
- package/types/index.d.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [0.1.
|
|
6
|
+
## [0.1.4](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.1.2...@zfqh/uniapp@0.1.4) (2026-06-02)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @zfqh/uniapp
|
|
9
9
|
|
|
@@ -11,14 +11,23 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
|
|
15
|
+
## [0.1.2](http://10.10.10.16/caoben/front-end/compare/@zfqh/uniapp@0.1.1...@zfqh/uniapp@0.1.2) (2026-06-01)
|
|
16
|
+
|
|
17
|
+
**Note:** Version bump only for package @zfqh/uniapp
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## 0.1.1 (2026-05-31)
|
|
24
|
+
|
|
25
|
+
**Note:** Version bump only for package @zfqh/uniapp
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## [0.1.0](http://10.10.200.92:8090/gmcb/front-end/compare/@zfqh/uniapp@0.1.0) (2026-05-31)
|
|
32
|
+
|
|
24
33
|
**Note:** Version bump only for package @zfqh/uniapp
|
package/docs/api/apis/index.md
CHANGED
|
@@ -28,7 +28,7 @@ import { getTencentToken, getDictData } from '@zfqh/uniapp/lib/apis/core';
|
|
|
28
28
|
- `GET` 会把 data 作为 query params。
|
|
29
29
|
- `POST`、`PUT`、`DELETE` 会把 data 作为请求体或方法参数传给底层请求实例。
|
|
30
30
|
- URL 中的 `:id`、`/:id` 会由 `formatURL` 使用 data 同名字段替换,并从 data 中删除该字段。
|
|
31
|
-
- 响应拦截器要求后端成功码为 `code == 0`;失败时会按配置弹 toast,并在 401 时触发 `
|
|
31
|
+
- 响应拦截器要求后端成功码为 `code == 0`;失败时会按配置弹 toast,并在 401 时触发 `store.dispatch('logout')`。
|
|
32
32
|
|
|
33
33
|
## 接口清单
|
|
34
34
|
|
package/docs/api/apis/request.md
CHANGED
|
@@ -26,9 +26,9 @@ const request = uni.$uv.http;
|
|
|
26
26
|
|
|
27
27
|
| Header | 来源 | 默认值 |
|
|
28
28
|
| --- | --- | --- |
|
|
29
|
-
| `Authorization` | `
|
|
30
|
-
| `Tenant-Id` | `
|
|
31
|
-
| `X-Language` | `
|
|
29
|
+
| `Authorization` | `store.state.login.info.token` | 无 |
|
|
30
|
+
| `Tenant-Id` | `store.state.login.info.tenantId` | `1` |
|
|
31
|
+
| `X-Language` | `store.state.system.info.appLanguage` 映射到 `LANGUAGE` | 无 |
|
|
32
32
|
| `Channel` | `query.channel` 或 `config.app.channel` | `config.app.channel` |
|
|
33
33
|
|
|
34
34
|
业务请求的 `baseURL` 来自 `config.api.baseUrl`。
|
|
@@ -274,7 +274,7 @@ GET('/app-api/demo/check', {}, {
|
|
|
274
274
|
| 阶段 | 行为 |
|
|
275
275
|
| --- | --- |
|
|
276
276
|
| request | 当 `log.request` 为 true 时打印请求 URL 和配置。 |
|
|
277
|
-
| request | 如果存在 `
|
|
277
|
+
| request | 如果存在 `store.state.login.info.token`,注入 `Authorization: Bearer <token>`。 |
|
|
278
278
|
| response | 当 `log.response` 为 true 时打印响应数据。 |
|
|
279
279
|
| response | 当 `data.code != 0` 时将其作为错误响应处理。 |
|
|
280
280
|
| error | 补齐非标准错误的 `response`、`status`、`data.msg`。 |
|
|
@@ -283,11 +283,11 @@ GET('/app-api/demo/check', {}, {
|
|
|
283
283
|
`401` 处理依赖:
|
|
284
284
|
|
|
285
285
|
```ts
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
store.state.login.info.token
|
|
287
|
+
store.dispatch('logout')
|
|
288
288
|
```
|
|
289
289
|
|
|
290
|
-
请求拦截器属于普通 TS 模块,不在 Vue 组件 setup
|
|
290
|
+
请求拦截器属于普通 TS 模块,不在 Vue 组件 setup 上下文中,因此直接引入 store 实例。如果是在组件或 hooks 中读取同一份登录态,请使用:
|
|
291
291
|
|
|
292
292
|
```ts
|
|
293
293
|
import { useStore } from 'vuex';
|
|
@@ -322,8 +322,8 @@ const request = uni.$uv.http;
|
|
|
322
322
|
|
|
323
323
|
| Header | 来源 |
|
|
324
324
|
| --- | --- |
|
|
325
|
-
| `Tenant-Id` | `
|
|
326
|
-
| `X-Language` | `
|
|
325
|
+
| `Tenant-Id` | `store.state.login.info.tenantId`,默认 `1`。 |
|
|
326
|
+
| `X-Language` | `store.state.system.info.appLanguage` 映射到 `LANGUAGE`。 |
|
|
327
327
|
| `Channel` | `query.channel`,没有 query 渠道时回退到 `config.app.channel`。 |
|
|
328
328
|
|
|
329
329
|
业务请求的 `baseURL` 来自:
|
|
@@ -283,7 +283,6 @@ defineConfig({
|
|
|
283
283
|
|
|
284
284
|
```ts
|
|
285
285
|
import { getTencentToken } from '@zfqh/uniapp/lib/apis';
|
|
286
|
-
import store from '@/store';
|
|
287
286
|
|
|
288
287
|
defineConfig({
|
|
289
288
|
upload: {
|
|
@@ -296,7 +295,7 @@ defineConfig({
|
|
|
296
295
|
create_time: data.createTime,
|
|
297
296
|
expire_time: data.expirationTime,
|
|
298
297
|
bucket: data.bucket,
|
|
299
|
-
region: store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
|
|
298
|
+
region: uni.$store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
|
|
300
299
|
};
|
|
301
300
|
},
|
|
302
301
|
},
|
package/docs/api/hooks/index.md
CHANGED
|
@@ -10,7 +10,7 @@ import { useStore } from 'vuex';
|
|
|
10
10
|
const store = useStore();
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
`uni.$store
|
|
13
|
+
普通 TS 模块中使用 `uni.$store`。
|
|
14
14
|
|
|
15
15
|
| Hook | 说明 |
|
|
16
16
|
| --- | --- |
|
|
@@ -44,7 +44,7 @@ import { useOverlay, usePopup, useVersion, useI18n } from '@zfqh/uniapp';
|
|
|
44
44
|
|
|
45
45
|
## Store 用法
|
|
46
46
|
|
|
47
|
-
Hooks 运行在组件 setup 上下文中,需要读取 Vuex 时请使用 `useStore()
|
|
47
|
+
Hooks 运行在组件 setup 上下文中,需要读取 Vuex 时请使用 `useStore()`:
|
|
48
48
|
|
|
49
49
|
```ts
|
|
50
50
|
import { computed } from 'vue';
|
|
@@ -57,7 +57,7 @@ export function useUserName() {
|
|
|
57
57
|
}
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
`uni.$store
|
|
60
|
+
普通 TS 模块中使用 `uni.$store`。完整约定见 [Store 使用位置](./../../guide/project-frame#store-使用位置)。
|
|
61
61
|
|
|
62
62
|
## useOverlay
|
|
63
63
|
|
|
@@ -172,7 +172,7 @@ const { t, locale } = useI18n();
|
|
|
172
172
|
|
|
173
173
|
| 平台 | 行为 |
|
|
174
174
|
| --- | --- |
|
|
175
|
-
| APP-NVUE | 使用内部 `inject('t')` 和 `
|
|
175
|
+
| APP-NVUE | 使用内部 `inject('t')` 和 `getLocaleMessage`。 |
|
|
176
176
|
| 其他平台 | 透传 `vue-i18n` 的 `useI18n`。 |
|
|
177
177
|
|
|
178
178
|
```vue
|
package/docs/api/index.md
CHANGED
|
@@ -21,14 +21,19 @@ app.use(uniapp);
|
|
|
21
21
|
安装逻辑:
|
|
22
22
|
|
|
23
23
|
- 小程序端混入 `deep`。
|
|
24
|
-
- 将 `app.config.globalProperties.$store` 挂到 `uni.$store`。
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
Store 使用入口请按上下文区分:
|
|
27
26
|
|
|
28
27
|
```ts
|
|
28
|
+
// Composition API / <script setup>
|
|
29
29
|
import { useStore } from 'vuex';
|
|
30
|
-
|
|
31
30
|
const store = useStore();
|
|
31
|
+
|
|
32
|
+
// Options API 组件
|
|
33
|
+
this.$store
|
|
34
|
+
|
|
35
|
+
// 普通 TS 模块
|
|
36
|
+
uni.$store
|
|
32
37
|
```
|
|
33
38
|
|
|
34
39
|
## Hooks
|
package/docs/api/mixins/app.md
CHANGED
|
@@ -16,13 +16,12 @@ App.vue 全局生命周期 mixin。发布路径:`@zfqh/uniapp/lib/mixins/app`
|
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import app from '@zfqh/uniapp/lib/mixins/app';
|
|
19
|
-
import store from '@/store';
|
|
20
19
|
|
|
21
20
|
export default {
|
|
22
21
|
mixins: [app],
|
|
23
22
|
onLaunch() {
|
|
24
23
|
if (store.getters.isLogin) {
|
|
25
|
-
store.dispatch('getInfo');
|
|
24
|
+
this.$store.dispatch('getInfo');
|
|
26
25
|
}
|
|
27
26
|
},
|
|
28
27
|
};
|
package/docs/api/modules/app.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
模块发布路径为 `@zfqh/uniapp/lib/modules`。根入口没有直接导出这些模块;如果业务项目要复用,请深度引入 `@zfqh/uniapp/lib/modules/<name>` 或从 `@zfqh/uniapp/lib/modules` 取具名导出。
|
|
4
4
|
|
|
5
|
-
这些模块默认假设项目使用 Vuex 4
|
|
5
|
+
这些模块默认假设项目使用 Vuex 4。请求、导航、webview 消息等普通模块会从 store 中读取状态。组件和 hooks 中读取 Vuex 时仍应使用 `useStore()` 或 `this.$store`。
|
|
6
6
|
|
|
7
7
|
## 基本使用
|
|
8
8
|
|
package/docs/api/utils/cos.md
CHANGED
|
@@ -205,7 +205,6 @@ defineConfig({
|
|
|
205
205
|
|
|
206
206
|
```ts
|
|
207
207
|
import { getTencentToken } from '@zfqh/uniapp/lib/apis';
|
|
208
|
-
import store from '@/store';
|
|
209
208
|
|
|
210
209
|
defineConfig({
|
|
211
210
|
upload: {
|
|
@@ -218,7 +217,7 @@ defineConfig({
|
|
|
218
217
|
create_time: data.createTime,
|
|
219
218
|
expire_time: data.expirationTime,
|
|
220
219
|
bucket: data.bucket,
|
|
221
|
-
region: store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
|
|
220
|
+
region: uni.$store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
|
|
222
221
|
};
|
|
223
222
|
},
|
|
224
223
|
},
|
package/docs/api/utils/index.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
| [cos](./cos) | 腾讯云 COS 上传与图片压缩 URL。 |
|
|
13
13
|
| [debounce](./debounce) | 防抖类和默认实例。 |
|
|
14
14
|
| [file](./file) | URL、dataURL、base64、File、本地路径互转。 |
|
|
15
|
-
| [locale](./locale) |
|
|
15
|
+
| [locale](./locale) | 当前语言、回退语言、vue-i18n 实例创建和 nvue 文案读取。 |
|
|
16
16
|
| [message](./message) | webview 与宿主环境通信的消息类型常量。 |
|
|
17
17
|
| [navigate](./navigate) | 页面跳转、登录拦截、tabBar、webview、自定义协议。 |
|
|
18
18
|
| [pages](./pages) | 根据页面配置生成页面集合。 |
|
package/docs/api/utils/locale.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
`@zfqh/uniapp/lib/utils/locale`
|
|
5
5
|
:::
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
提供当前语言、回退语言、vue-i18n 实例创建和 nvue 可用的简易文案读取方法。
|
|
8
8
|
|
|
9
9
|
## 平台兼容性
|
|
10
10
|
|
|
@@ -15,11 +15,47 @@
|
|
|
15
15
|
## 基本使用
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import { defaultLocale, fallbackLocale,
|
|
18
|
+
import { defaultLocale, fallbackLocale, createI18n, getLocaleMessage } from '@zfqh/uniapp';
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
具体方法、参数语义和返回值以发布包类型为准;下方表格按 `@zfqh/uniapp/lib/utils/locale` 的导出整理。
|
|
22
22
|
|
|
23
|
+
## 创建 vue-i18n 实例
|
|
24
|
+
|
|
25
|
+
在 `locale/index.js` 中调用 `createI18n` 创建实例并导出:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { createI18n, defaultLocale, fallbackLocale } from '@zfqh/uniapp';
|
|
29
|
+
import messages from './messages';
|
|
30
|
+
|
|
31
|
+
export const i18n = createI18n({
|
|
32
|
+
locale: defaultLocale,
|
|
33
|
+
fallbackLocale,
|
|
34
|
+
messages,
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`messages.js` 按语言键组织翻译文件:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import zhHans from './zh-Hans.json';
|
|
42
|
+
import en from './en.json';
|
|
43
|
+
|
|
44
|
+
export default {
|
|
45
|
+
'zh-Hans': zhHans,
|
|
46
|
+
en,
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
实例创建后可在 App 启动时注册:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
import { i18n } from './locale';
|
|
54
|
+
|
|
55
|
+
const app = createApp(App);
|
|
56
|
+
app.use(i18n);
|
|
57
|
+
```
|
|
58
|
+
|
|
23
59
|
## API
|
|
24
60
|
|
|
25
61
|
发布路径:`@zfqh/uniapp/lib/utils/locale`
|
|
@@ -28,5 +64,5 @@ import { defaultLocale, fallbackLocale, showLocale } from '@zfqh/uniapp';
|
|
|
28
64
|
| --- | --- | --- |
|
|
29
65
|
| `defaultLocale` | `export const defaultLocale = uni.getLocale();` | 默认语言。 |
|
|
30
66
|
| `fallbackLocale` | `export const fallbackLocale = 'zh-Hans';` | 回退语言。 |
|
|
31
|
-
| `
|
|
32
|
-
|
|
67
|
+
| `createI18n` | `export function createI18n(opts: I18nOptions)` | 创建 vue-i18n 实例,返回实例。 |
|
|
68
|
+
| `getLocaleMessage` | `export function getLocaleMessage(key: string): string` | 通过 key 获取当前语言文案,nvue 场景下的简易 i18n 文案读取。未匹配时返回 key 本身。 |
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { navigate } from '@zfqh/uniapp';
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
导航工具脱离组件 setup 上下文,内部会通过 `
|
|
21
|
+
导航工具脱离组件 setup 上下文,内部会通过 `store.getters.isLogin` 判断登录态。组件或 hooks 中判断登录态时请使用 `useStore()`。
|
|
22
22
|
|
|
23
23
|
## 常用跳转
|
|
24
24
|
|
|
@@ -192,10 +192,10 @@ navigate.navigateTo({
|
|
|
192
192
|
登录判断依赖:
|
|
193
193
|
|
|
194
194
|
```ts
|
|
195
|
-
|
|
195
|
+
store.getters.isLogin
|
|
196
196
|
```
|
|
197
197
|
|
|
198
|
-
`navigate` 是普通工具模块,脱离组件 setup
|
|
198
|
+
`navigate` 是普通工具模块,脱离组件 setup 上下文,所以直接引入 store 实例。如果是在组件或 hooks 中判断登录态,请使用:
|
|
199
199
|
|
|
200
200
|
```ts
|
|
201
201
|
import { computed } from 'vue';
|
package/docs/api/utils/pages.md
CHANGED
|
@@ -124,7 +124,7 @@ defineConfig({
|
|
|
124
124
|
|
|
125
125
|
`needLogin` 字段控制页面是否需要登录才能访问,默认为 `false`。
|
|
126
126
|
|
|
127
|
-
当 `needLogin: true` 时,`navigate` 会检查 `
|
|
127
|
+
当 `needLogin: true` 时,`navigate` 会检查 `store.getters.isLogin`,如果未登录则自动跳转到 `getPage('login')` 返回的登录页路径。
|
|
128
128
|
|
|
129
129
|
```json
|
|
130
130
|
{
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { formatURL, createInterceptors, createRequest } from '@zfqh/uniapp';
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
请求工具脱离组件 setup
|
|
21
|
+
请求工具脱离组件 setup 上下文,拦截器内部会从 store 中读取 token 并处理 `401`。组件或 hooks 中读取 store 时请使用 `useStore()`。
|
|
22
22
|
|
|
23
23
|
具体方法、参数语义和返回值以发布包类型为准;下方表格按 `@zfqh/uniapp/lib/utils/request` 的导出整理。
|
|
24
24
|
|
package/docs/components/index.md
CHANGED
|
@@ -41,7 +41,7 @@ import { useStore } from 'vuex';
|
|
|
41
41
|
const store = useStore();
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
Options API 组件可使用 `this.$store
|
|
44
|
+
Options API 组件可使用 `this.$store`。普通 TS 模块中使用 `uni.$store`。
|
|
45
45
|
|
|
46
46
|
## 组件分类
|
|
47
47
|
|
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
# 工具样式类
|
|
2
|
-
|
|
3
|
-
`@zfqh/uniapp` 内置一组静态 SCSS 工具类,仅覆盖 **平台差异类** 和 **使用 `$uv-*` SCSS 变量的语义色类**。间距、尺寸、字号、圆角、透明度、阴影等通用原子类需要配合 `@gmcb/vite` 提供的 unocss 插件在构建时动态生成,两者命名风格与 UnoCSS / Tailwind CSS 一致。
|
|
4
|
-
|
|
5
|
-
## 前置依赖
|
|
6
|
-
|
|
7
|
-
使用完整原子类能力前,需要在项目的 `vite.config.js` 中注册 unocss 插件,并传入 `blockList` 避免与内置静态类冲突:
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
import { defineConfig } from '@gmcb/vite';
|
|
11
|
-
import { unocss } from '@gmcb/vite/lib/plugins';
|
|
12
|
-
import { blockList } from '@gmcb/vite/lib/unocss';
|
|
13
|
-
|
|
14
|
-
export default defineConfig({
|
|
15
|
-
plugins: [
|
|
16
|
-
uni(),
|
|
17
|
-
unocss({
|
|
18
|
-
blockList,
|
|
19
|
-
}),
|
|
20
|
-
],
|
|
21
|
-
});
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
`blockList` 已预置全部内置静态类名,unocss 插件不会为这些类名生成重复 CSS。
|
|
25
|
-
|
|
26
|
-
## 引入方式
|
|
27
|
-
|
|
28
|
-
在项目全局样式中导入一次即可。放在 `App.vue` 的 `<style>` 块:
|
|
29
|
-
|
|
30
|
-
```scss
|
|
31
|
-
@import '@zfqh/uniapp/lib/styles/index.scss';
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
此入口同时导入 `@gmcb/uv-ui/index.scss`,无需再单独导入 uv-ui 基础样式。
|
|
35
|
-
|
|
36
|
-
## 内置原子类
|
|
37
|
-
|
|
38
|
-
### Flex 布局
|
|
39
|
-
|
|
40
|
-
| 类名 | 效果 |
|
|
41
|
-
| --- | --- |
|
|
42
|
-
| `.flex` | flex 行布局 |
|
|
43
|
-
| `.flex-inline` | inline-flex 行布局 |
|
|
44
|
-
| `.flex-row` / `.flex-row-reverse` | 行方向 |
|
|
45
|
-
| `.flex-col` / `.flex-col-reverse` | 列方向 |
|
|
46
|
-
| `.flex-wrap` / `.flex-nowrap` / `.flex-wrap-reverse` | 换行控制 |
|
|
47
|
-
| `.flex-0` ~ `.flex-8` | `flex: 0` ~ `flex: 8` |
|
|
48
|
-
| `.flex-none` | `flex: 0` |
|
|
49
|
-
| `.items-start` / `.items-end` / `.items-center` / `.items-stretch` / `.items-baseline` | align-items |
|
|
50
|
-
| `.justify-start` / `.justify-end` / `.justify-center` / `.justify-between` / `.justify-around` | justify-content |
|
|
51
|
-
|
|
52
|
-
::: info 平台差异
|
|
53
|
-
- H5 平台下这些类包裹在 `page` 选择器内。
|
|
54
|
-
- `.flex` / `.flex-inline` 的 `display: flex` / `display: inline-flex` 仅在非 APP-NVUE 平台生效,nvue 端省略 display 属性(Weex 默认 flex 布局)。
|
|
55
|
-
:::
|
|
56
|
-
|
|
57
|
-
### 背景色
|
|
58
|
-
|
|
59
|
-
`.bg-{color}` 系列,颜色值读取 `$uv-*` SCSS 变量,跟随主题配置:
|
|
60
|
-
|
|
61
|
-
| 色组 | 可用类名 |
|
|
62
|
-
| --- | --- |
|
|
63
|
-
| primary | `.bg-primary`、`.bg-primary-dark`、`.bg-primary-light`、`.bg-primary-disabled` |
|
|
64
|
-
| warning | `.bg-warning`、`.bg-warning-dark`、`.bg-warning-light`、`.bg-warning-disabled` |
|
|
65
|
-
| success | `.bg-success`、`.bg-success-dark`、`.bg-success-light`、`.bg-success-disabled` |
|
|
66
|
-
| error | `.bg-error`、`.bg-error-dark`、`.bg-error-light`、`.bg-error-disabled` |
|
|
67
|
-
| info | `.bg-info`、`.bg-info-dark`、`.bg-info-light`、`.bg-info-disabled` |
|
|
68
|
-
|
|
69
|
-
基础背景:
|
|
70
|
-
|
|
71
|
-
| 类名 | SCSS 变量 | 说明 |
|
|
72
|
-
| --- | --- | --- |
|
|
73
|
-
| `.bg` | `$uv-bg-color` | 页面背景色 |
|
|
74
|
-
| `.bg-light` | `$uv-bg-light-color` | 浅色背景 |
|
|
75
|
-
| `.bg-disabled` | `$uv-disabled-color` | 禁用态背景 |
|
|
76
|
-
| `.bg-border` | `$uv-border-color` | 边框色背景 |
|
|
77
|
-
|
|
78
|
-
### 文字颜色
|
|
79
|
-
|
|
80
|
-
`.text-{color}` 系列,颜色值读取 `$uv-*` SCSS 变量:
|
|
81
|
-
|
|
82
|
-
| 色组 | 可用类名 |
|
|
83
|
-
| --- | --- |
|
|
84
|
-
| primary | `.text-primary`、`.text-primary-dark`、`.text-primary-light`、`.text-primary-disabled` |
|
|
85
|
-
| warning | `.text-warning`、`.text-warning-dark`、`.text-warning-light`、`.text-warning-disabled` |
|
|
86
|
-
| success | `.text-success`、`.text-success-dark`、`.text-success-light`、`.text-success-disabled` |
|
|
87
|
-
| error | `.text-error`、`.text-error-dark`、`.text-error-light`、`.text-error-disabled` |
|
|
88
|
-
| info | `.text-info`、`.text-info-dark`、`.text-info-light`、`.text-info-disabled` |
|
|
89
|
-
|
|
90
|
-
UI 语义色:
|
|
91
|
-
|
|
92
|
-
| 类名 | SCSS 变量 | 说明 |
|
|
93
|
-
| --- | --- | --- |
|
|
94
|
-
| `.text-main` | `$uv-main-color` | 主要文字 |
|
|
95
|
-
| `.text-content` | `$uv-content-color` | 正文文字 |
|
|
96
|
-
| `.text-tips` | `$uv-tips-color` | 辅助提示 |
|
|
97
|
-
| `.text-light` | `$uv-light-color` | 占位/水印 |
|
|
98
|
-
| `.text-border` | `$uv-border-color` | 边框色文字 |
|
|
99
|
-
| `.text-disabled` | `$uv-disabled-color` | 禁用态文字 |
|
|
100
|
-
|
|
101
|
-
### 边框
|
|
102
|
-
|
|
103
|
-
| 类名 | 效果 |
|
|
104
|
-
| --- | --- |
|
|
105
|
-
| `.border` | 1px solid 边框色(`$uv-border-color`) |
|
|
106
|
-
| `.border-half` | 0.5px solid 边框色 |
|
|
107
|
-
| `.border-t` / `.border-r` / `.border-b` / `.border-l` | 单边 1px solid 边框色 |
|
|
108
|
-
| `.border-x` / `.border-y` | 双轴 1px solid 边框色 |
|
|
109
|
-
|
|
110
|
-
语义色边框:
|
|
111
|
-
|
|
112
|
-
| 类名 | SCSS 变量 |
|
|
113
|
-
| --- | --- |
|
|
114
|
-
| `.border-primary` | `$uv-primary` |
|
|
115
|
-
| `.border-warning` | `$uv-warning` |
|
|
116
|
-
| `.border-success` | `$uv-success` |
|
|
117
|
-
| `.border-error` | `$uv-error` |
|
|
118
|
-
| `.border-info` | `$uv-info` |
|
|
119
|
-
|
|
120
|
-
### 定位
|
|
121
|
-
|
|
122
|
-
| 类名 | 效果 |
|
|
123
|
-
| --- | --- |
|
|
124
|
-
| `.relative` | position: relative |
|
|
125
|
-
| `.absolute` | position: absolute |
|
|
126
|
-
| `.fixed` | position: fixed |
|
|
127
|
-
| `.sticky` | position: sticky |
|
|
128
|
-
|
|
129
|
-
::: info 平台差异
|
|
130
|
-
H5 平台下这些类包裹在 `page` 选择器内,其他平台直接使用。
|
|
131
|
-
:::
|
|
132
|
-
|
|
133
|
-
### 文本截断
|
|
134
|
-
|
|
135
|
-
**非 nvue 平台**(`text-vue.scss`):
|
|
136
|
-
|
|
137
|
-
| 类名 | 效果 |
|
|
138
|
-
| --- | --- |
|
|
139
|
-
| `.truncate` | 单行截断(overflow ellipsis + nowrap) |
|
|
140
|
-
| `.line-clamp-1` ~ `.line-clamp-5` | 多行截断(`-webkit-line-clamp`) |
|
|
141
|
-
|
|
142
|
-
**nvue 平台**(`text-nvue.scss`):
|
|
143
|
-
|
|
144
|
-
| 类名 | 效果 |
|
|
145
|
-
| --- | --- |
|
|
146
|
-
| `.truncate` | 单行截断(Weex `lines: 1`) |
|
|
147
|
-
| `.line-clamp-1` ~ `.line-clamp-5` | 多行截断(Weex `lines: n`) |
|
|
148
|
-
|
|
149
|
-
### 全局重置
|
|
150
|
-
|
|
151
|
-
`reset-vue.scss` 在非 nvue 平台自动生效,不属于原子类,作用:
|
|
152
|
-
|
|
153
|
-
- 设置 `:root` 下的 `--window-bottom`、`--window-top`(非 H5)、`--window-height`、`--window-width` CSS 自定义属性。
|
|
154
|
-
- `page` 元素宽高 100%、`font-family: Microsoft YaHei`、颜色取 `$uv-main-color`、flex 列布局。
|
|
155
|
-
- `view`、`text`、`image` 设置 `box-sizing: border-box`。
|
|
156
|
-
- 修复 `.uni-scroll-view-refresher` 背景透明。
|
|
157
|
-
- 调整 `.ql-editor.ql-blank:before` 占位文字样式。
|
|
158
|
-
- 调整 `.uv-toast` 默认样式。
|
|
159
|
-
|
|
160
|
-
除上述内置类外,其余原子类(间距、尺寸、字号、字重、行高、对齐、基础背景色、边框宽度/样式、圆角、overflow、top/right/bottom/left/inset/z-index、透明度、阴影、transform-origin、transition 等)均由 `@gmcb/vite` 的 unocss 插件在构建时根据模板扫描动态生成,命名风格与 UnoCSS / Tailwind CSS 一致,支持 `px` 和 `rpx` 两种单位。
|
|
161
|
-
|
|
162
|
-
`blockList` 已预置全部内置静态类名,unocss 插件不会为这些类名生成重复 CSS。
|
|
163
|
-
|
|
164
|
-
## 常用组合示例
|
|
165
|
-
|
|
166
|
-
卡片布局:
|
|
167
|
-
|
|
168
|
-
```html
|
|
169
|
-
<view class="flex flex-col p-16px bg-white rounded-8px shadow-sm">
|
|
170
|
-
<text class="text-32px font-semibold text-main">标题</text>
|
|
171
|
-
<text class="text-24px text-tips mt-8px">描述内容</text>
|
|
172
|
-
</view>
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
居加载中状态:
|
|
176
|
-
|
|
177
|
-
```html
|
|
178
|
-
<view class="flex justify-center items-center h-200px">
|
|
179
|
-
<text class="text-28px text-tips">加载中...</text>
|
|
180
|
-
</view>
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
列表项(头像 + 文字):
|
|
184
|
-
|
|
185
|
-
```html
|
|
186
|
-
<view class="flex items-center px-16px py-12px">
|
|
187
|
-
<image class="w-80rpx h-80rpx rounded-full" :src="avatar" />
|
|
188
|
-
<view class="flex-1 ml-12px">
|
|
189
|
-
<text class="text-28px text-main truncate">用户名</text>
|
|
190
|
-
<text class="text-24px text-tips">副标题</text>
|
|
191
|
-
</view>
|
|
192
|
-
</view>
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
吸顶导航栏:
|
|
196
|
-
|
|
197
|
-
```html
|
|
198
|
-
<view class="sticky top-0 bg-light px-16px py-12px">
|
|
199
|
-
<text class="text-32px font-bold text-main">页面标题</text>
|
|
200
|
-
</view>
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
表单区域:
|
|
204
|
-
|
|
205
|
-
```html
|
|
206
|
-
<view class="flex flex-col px-16px py-12px bg-white mt-8px">
|
|
207
|
-
<view class="flex justify-between items-center py-12px border-b">
|
|
208
|
-
<text class="text-28px text-main">标签</text>
|
|
209
|
-
<text class="text-28px text-content">值</text>
|
|
210
|
-
</view>
|
|
211
|
-
</view>
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
两列等分布局:
|
|
215
|
-
|
|
216
|
-
```html
|
|
217
|
-
<view class="flex flex-wrap">
|
|
218
|
-
<view class="w-full flex" v-for="group in groups" :key="group.id">
|
|
219
|
-
<view class="flex-1 p-8px" v-for="item in group.items" :key="item.id">
|
|
220
|
-
<view class="bg-white rounded-8px p-16px">{{ item.name }}</view>
|
|
221
|
-
</view>
|
|
222
|
-
</view>
|
|
223
|
-
</view>
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
底部固定操作栏:
|
|
227
|
-
|
|
228
|
-
```html
|
|
229
|
-
<view class="fixed bottom-0 left-0 right-0 bg-white px-16px py-12px z-5">
|
|
230
|
-
<view class="flex">
|
|
231
|
-
<view class="flex-1 mr-8px bg-error rounded-8px py-12px text-center">
|
|
232
|
-
<text class="text-white text-28px font-medium">取消</text>
|
|
233
|
-
</view>
|
|
234
|
-
<view class="flex-1 bg-primary rounded-8px py-12px text-center">
|
|
235
|
-
<text class="text-white text-28px font-medium">确认</text>
|
|
236
|
-
</view>
|
|
237
|
-
</view>
|
|
238
|
-
</view>
|
|
239
|
-
```
|
|
1
|
+
# 工具样式类
|
|
2
|
+
|
|
3
|
+
`@zfqh/uniapp` 内置一组静态 SCSS 工具类,仅覆盖 **平台差异类** 和 **使用 `$uv-*` SCSS 变量的语义色类**。间距、尺寸、字号、圆角、透明度、阴影等通用原子类需要配合 `@gmcb/vite` 提供的 unocss 插件在构建时动态生成,两者命名风格与 UnoCSS / Tailwind CSS 一致。
|
|
4
|
+
|
|
5
|
+
## 前置依赖
|
|
6
|
+
|
|
7
|
+
使用完整原子类能力前,需要在项目的 `vite.config.js` 中注册 unocss 插件,并传入 `blockList` 避免与内置静态类冲突:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import { defineConfig } from '@gmcb/vite';
|
|
11
|
+
import { unocss } from '@gmcb/vite/lib/plugins';
|
|
12
|
+
import { blockList } from '@gmcb/vite/lib/unocss';
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
plugins: [
|
|
16
|
+
uni(),
|
|
17
|
+
unocss({
|
|
18
|
+
blockList,
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`blockList` 已预置全部内置静态类名,unocss 插件不会为这些类名生成重复 CSS。
|
|
25
|
+
|
|
26
|
+
## 引入方式
|
|
27
|
+
|
|
28
|
+
在项目全局样式中导入一次即可。放在 `App.vue` 的 `<style>` 块:
|
|
29
|
+
|
|
30
|
+
```scss
|
|
31
|
+
@import '@zfqh/uniapp/lib/styles/index.scss';
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
此入口同时导入 `@gmcb/uv-ui/index.scss`,无需再单独导入 uv-ui 基础样式。
|
|
35
|
+
|
|
36
|
+
## 内置原子类
|
|
37
|
+
|
|
38
|
+
### Flex 布局
|
|
39
|
+
|
|
40
|
+
| 类名 | 效果 |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `.flex` | flex 行布局 |
|
|
43
|
+
| `.flex-inline` | inline-flex 行布局 |
|
|
44
|
+
| `.flex-row` / `.flex-row-reverse` | 行方向 |
|
|
45
|
+
| `.flex-col` / `.flex-col-reverse` | 列方向 |
|
|
46
|
+
| `.flex-wrap` / `.flex-nowrap` / `.flex-wrap-reverse` | 换行控制 |
|
|
47
|
+
| `.flex-0` ~ `.flex-8` | `flex: 0` ~ `flex: 8` |
|
|
48
|
+
| `.flex-none` | `flex: 0` |
|
|
49
|
+
| `.items-start` / `.items-end` / `.items-center` / `.items-stretch` / `.items-baseline` | align-items |
|
|
50
|
+
| `.justify-start` / `.justify-end` / `.justify-center` / `.justify-between` / `.justify-around` | justify-content |
|
|
51
|
+
|
|
52
|
+
::: info 平台差异
|
|
53
|
+
- H5 平台下这些类包裹在 `page` 选择器内。
|
|
54
|
+
- `.flex` / `.flex-inline` 的 `display: flex` / `display: inline-flex` 仅在非 APP-NVUE 平台生效,nvue 端省略 display 属性(Weex 默认 flex 布局)。
|
|
55
|
+
:::
|
|
56
|
+
|
|
57
|
+
### 背景色
|
|
58
|
+
|
|
59
|
+
`.bg-{color}` 系列,颜色值读取 `$uv-*` SCSS 变量,跟随主题配置:
|
|
60
|
+
|
|
61
|
+
| 色组 | 可用类名 |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| primary | `.bg-primary`、`.bg-primary-dark`、`.bg-primary-light`、`.bg-primary-disabled` |
|
|
64
|
+
| warning | `.bg-warning`、`.bg-warning-dark`、`.bg-warning-light`、`.bg-warning-disabled` |
|
|
65
|
+
| success | `.bg-success`、`.bg-success-dark`、`.bg-success-light`、`.bg-success-disabled` |
|
|
66
|
+
| error | `.bg-error`、`.bg-error-dark`、`.bg-error-light`、`.bg-error-disabled` |
|
|
67
|
+
| info | `.bg-info`、`.bg-info-dark`、`.bg-info-light`、`.bg-info-disabled` |
|
|
68
|
+
|
|
69
|
+
基础背景:
|
|
70
|
+
|
|
71
|
+
| 类名 | SCSS 变量 | 说明 |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| `.bg` | `$uv-bg-color` | 页面背景色 |
|
|
74
|
+
| `.bg-light` | `$uv-bg-light-color` | 浅色背景 |
|
|
75
|
+
| `.bg-disabled` | `$uv-disabled-color` | 禁用态背景 |
|
|
76
|
+
| `.bg-border` | `$uv-border-color` | 边框色背景 |
|
|
77
|
+
|
|
78
|
+
### 文字颜色
|
|
79
|
+
|
|
80
|
+
`.text-{color}` 系列,颜色值读取 `$uv-*` SCSS 变量:
|
|
81
|
+
|
|
82
|
+
| 色组 | 可用类名 |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| primary | `.text-primary`、`.text-primary-dark`、`.text-primary-light`、`.text-primary-disabled` |
|
|
85
|
+
| warning | `.text-warning`、`.text-warning-dark`、`.text-warning-light`、`.text-warning-disabled` |
|
|
86
|
+
| success | `.text-success`、`.text-success-dark`、`.text-success-light`、`.text-success-disabled` |
|
|
87
|
+
| error | `.text-error`、`.text-error-dark`、`.text-error-light`、`.text-error-disabled` |
|
|
88
|
+
| info | `.text-info`、`.text-info-dark`、`.text-info-light`、`.text-info-disabled` |
|
|
89
|
+
|
|
90
|
+
UI 语义色:
|
|
91
|
+
|
|
92
|
+
| 类名 | SCSS 变量 | 说明 |
|
|
93
|
+
| --- | --- | --- |
|
|
94
|
+
| `.text-main` | `$uv-main-color` | 主要文字 |
|
|
95
|
+
| `.text-content` | `$uv-content-color` | 正文文字 |
|
|
96
|
+
| `.text-tips` | `$uv-tips-color` | 辅助提示 |
|
|
97
|
+
| `.text-light` | `$uv-light-color` | 占位/水印 |
|
|
98
|
+
| `.text-border` | `$uv-border-color` | 边框色文字 |
|
|
99
|
+
| `.text-disabled` | `$uv-disabled-color` | 禁用态文字 |
|
|
100
|
+
|
|
101
|
+
### 边框
|
|
102
|
+
|
|
103
|
+
| 类名 | 效果 |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `.border` | 1px solid 边框色(`$uv-border-color`) |
|
|
106
|
+
| `.border-half` | 0.5px solid 边框色 |
|
|
107
|
+
| `.border-t` / `.border-r` / `.border-b` / `.border-l` | 单边 1px solid 边框色 |
|
|
108
|
+
| `.border-x` / `.border-y` | 双轴 1px solid 边框色 |
|
|
109
|
+
|
|
110
|
+
语义色边框:
|
|
111
|
+
|
|
112
|
+
| 类名 | SCSS 变量 |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `.border-primary` | `$uv-primary` |
|
|
115
|
+
| `.border-warning` | `$uv-warning` |
|
|
116
|
+
| `.border-success` | `$uv-success` |
|
|
117
|
+
| `.border-error` | `$uv-error` |
|
|
118
|
+
| `.border-info` | `$uv-info` |
|
|
119
|
+
|
|
120
|
+
### 定位
|
|
121
|
+
|
|
122
|
+
| 类名 | 效果 |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| `.relative` | position: relative |
|
|
125
|
+
| `.absolute` | position: absolute |
|
|
126
|
+
| `.fixed` | position: fixed |
|
|
127
|
+
| `.sticky` | position: sticky |
|
|
128
|
+
|
|
129
|
+
::: info 平台差异
|
|
130
|
+
H5 平台下这些类包裹在 `page` 选择器内,其他平台直接使用。
|
|
131
|
+
:::
|
|
132
|
+
|
|
133
|
+
### 文本截断
|
|
134
|
+
|
|
135
|
+
**非 nvue 平台**(`text-vue.scss`):
|
|
136
|
+
|
|
137
|
+
| 类名 | 效果 |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| `.truncate` | 单行截断(overflow ellipsis + nowrap) |
|
|
140
|
+
| `.line-clamp-1` ~ `.line-clamp-5` | 多行截断(`-webkit-line-clamp`) |
|
|
141
|
+
|
|
142
|
+
**nvue 平台**(`text-nvue.scss`):
|
|
143
|
+
|
|
144
|
+
| 类名 | 效果 |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| `.truncate` | 单行截断(Weex `lines: 1`) |
|
|
147
|
+
| `.line-clamp-1` ~ `.line-clamp-5` | 多行截断(Weex `lines: n`) |
|
|
148
|
+
|
|
149
|
+
### 全局重置
|
|
150
|
+
|
|
151
|
+
`reset-vue.scss` 在非 nvue 平台自动生效,不属于原子类,作用:
|
|
152
|
+
|
|
153
|
+
- 设置 `:root` 下的 `--window-bottom`、`--window-top`(非 H5)、`--window-height`、`--window-width` CSS 自定义属性。
|
|
154
|
+
- `page` 元素宽高 100%、`font-family: Microsoft YaHei`、颜色取 `$uv-main-color`、flex 列布局。
|
|
155
|
+
- `view`、`text`、`image` 设置 `box-sizing: border-box`。
|
|
156
|
+
- 修复 `.uni-scroll-view-refresher` 背景透明。
|
|
157
|
+
- 调整 `.ql-editor.ql-blank:before` 占位文字样式。
|
|
158
|
+
- 调整 `.uv-toast` 默认样式。
|
|
159
|
+
|
|
160
|
+
除上述内置类外,其余原子类(间距、尺寸、字号、字重、行高、对齐、基础背景色、边框宽度/样式、圆角、overflow、top/right/bottom/left/inset/z-index、透明度、阴影、transform-origin、transition 等)均由 `@gmcb/vite` 的 unocss 插件在构建时根据模板扫描动态生成,命名风格与 UnoCSS / Tailwind CSS 一致,支持 `px` 和 `rpx` 两种单位。
|
|
161
|
+
|
|
162
|
+
`blockList` 已预置全部内置静态类名,unocss 插件不会为这些类名生成重复 CSS。
|
|
163
|
+
|
|
164
|
+
## 常用组合示例
|
|
165
|
+
|
|
166
|
+
卡片布局:
|
|
167
|
+
|
|
168
|
+
```html
|
|
169
|
+
<view class="flex flex-col p-16px bg-white rounded-8px shadow-sm">
|
|
170
|
+
<text class="text-32px font-semibold text-main">标题</text>
|
|
171
|
+
<text class="text-24px text-tips mt-8px">描述内容</text>
|
|
172
|
+
</view>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
居加载中状态:
|
|
176
|
+
|
|
177
|
+
```html
|
|
178
|
+
<view class="flex justify-center items-center h-200px">
|
|
179
|
+
<text class="text-28px text-tips">加载中...</text>
|
|
180
|
+
</view>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
列表项(头像 + 文字):
|
|
184
|
+
|
|
185
|
+
```html
|
|
186
|
+
<view class="flex items-center px-16px py-12px">
|
|
187
|
+
<image class="w-80rpx h-80rpx rounded-full" :src="avatar" />
|
|
188
|
+
<view class="flex-1 ml-12px">
|
|
189
|
+
<text class="text-28px text-main truncate">用户名</text>
|
|
190
|
+
<text class="text-24px text-tips">副标题</text>
|
|
191
|
+
</view>
|
|
192
|
+
</view>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
吸顶导航栏:
|
|
196
|
+
|
|
197
|
+
```html
|
|
198
|
+
<view class="sticky top-0 bg-light px-16px py-12px">
|
|
199
|
+
<text class="text-32px font-bold text-main">页面标题</text>
|
|
200
|
+
</view>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
表单区域:
|
|
204
|
+
|
|
205
|
+
```html
|
|
206
|
+
<view class="flex flex-col px-16px py-12px bg-white mt-8px">
|
|
207
|
+
<view class="flex justify-between items-center py-12px border-b">
|
|
208
|
+
<text class="text-28px text-main">标签</text>
|
|
209
|
+
<text class="text-28px text-content">值</text>
|
|
210
|
+
</view>
|
|
211
|
+
</view>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
两列等分布局:
|
|
215
|
+
|
|
216
|
+
```html
|
|
217
|
+
<view class="flex flex-wrap">
|
|
218
|
+
<view class="w-full flex" v-for="group in groups" :key="group.id">
|
|
219
|
+
<view class="flex-1 p-8px" v-for="item in group.items" :key="item.id">
|
|
220
|
+
<view class="bg-white rounded-8px p-16px">{{ item.name }}</view>
|
|
221
|
+
</view>
|
|
222
|
+
</view>
|
|
223
|
+
</view>
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
底部固定操作栏:
|
|
227
|
+
|
|
228
|
+
```html
|
|
229
|
+
<view class="fixed bottom-0 left-0 right-0 bg-white px-16px py-12px z-5">
|
|
230
|
+
<view class="flex">
|
|
231
|
+
<view class="flex-1 mr-8px bg-error rounded-8px py-12px text-center">
|
|
232
|
+
<text class="text-white text-28px font-medium">取消</text>
|
|
233
|
+
</view>
|
|
234
|
+
<view class="flex-1 bg-primary rounded-8px py-12px text-center">
|
|
235
|
+
<text class="text-white text-28px font-medium">确认</text>
|
|
236
|
+
</view>
|
|
237
|
+
</view>
|
|
238
|
+
</view>
|
|
239
|
+
```
|
package/docs/components/usage.md
CHANGED
|
@@ -58,7 +58,7 @@ const isLogin = computed(() => store.getters.isLogin);
|
|
|
58
58
|
</script>
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
如果组件仍使用 Options API,可使用 `this.$store
|
|
61
|
+
如果组件仍使用 Options API,可使用 `this.$store`。脱离组件上下文的普通 TS 模块中使用 `uni.$store`。
|
|
62
62
|
|
|
63
63
|
## 页面骨架示例
|
|
64
64
|
|
package/docs/faq/index.md
CHANGED
|
@@ -5,16 +5,15 @@
|
|
|
5
5
|
检查:
|
|
6
6
|
|
|
7
7
|
1. 是否先注册 store,再注册 `@zfqh/uniapp`。
|
|
8
|
-
2.
|
|
9
|
-
3. token 是否位于 `uni.$store.state.login.info.token`。
|
|
8
|
+
2. token 是否位于 `store.state.login.info.token`。
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
请求拦截器属于普通 TS 模块,内部会从 store 中读取状态。组件或 hooks 内读取同一份状态时应使用 `useStore()`。
|
|
12
11
|
|
|
13
12
|
## 401 后没有退出登录
|
|
14
13
|
|
|
15
14
|
检查:
|
|
16
15
|
|
|
17
|
-
1. `
|
|
16
|
+
1. `store.state.login.info.token` 是否存在。
|
|
18
17
|
2. store 是否实现 `dispatch('logout')`。
|
|
19
18
|
3. 请求配置是否设置了 `custom.reLogin: false` 或 `custom.needLogin: false`。
|
|
20
19
|
|
|
@@ -31,12 +30,12 @@
|
|
|
31
30
|
|
|
32
31
|
检查:
|
|
33
32
|
|
|
34
|
-
1. `
|
|
33
|
+
1. `store.getters.isLogin` 是否正确。
|
|
35
34
|
2. `page.needLoginPages` 是否包含目标页。
|
|
36
35
|
3. `getPage('login')` 是否能返回登录页路径。
|
|
37
36
|
4. 当前跳转是否显式传入 `needLogin: false`。
|
|
38
37
|
|
|
39
|
-
`navigate` 内部读取 `
|
|
38
|
+
`navigate` 内部读取 `store.getters.isLogin`。如果页面组件里自己判断登录态,请使用 `import { useStore } from 'vuex'`。
|
|
40
39
|
|
|
41
40
|
## tabBar 页面 navigateTo 失败
|
|
42
41
|
|
|
@@ -34,14 +34,14 @@ export function createApp() {
|
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
请求、导航、权限、登录等能力会读取 store 状态,所以请先挂载 store,再注册本插件。
|
|
38
38
|
|
|
39
39
|
Store 使用入口请按上下文区分:
|
|
40
40
|
|
|
41
41
|
- 组件的 Composition API 或 `<script setup>` 中使用 `import { useStore } from 'vuex'`。
|
|
42
42
|
- 自定义 hooks / composables 中也使用 `useStore()`。
|
|
43
43
|
- Options API 组件中可使用 `this.$store`。
|
|
44
|
-
-
|
|
44
|
+
- 普通 TS 模块中使用 `uni.$store`。
|
|
45
45
|
|
|
46
46
|
详见 [Store 使用位置](./project-frame.md#store-使用位置)。
|
|
47
47
|
|
|
@@ -124,7 +124,6 @@ import { defineConfig } from '@zfqh/uniapp';
|
|
|
124
124
|
import { app } from '@zfqh/uniapp/lib/configs/app';
|
|
125
125
|
import { brand } from '@zfqh/uniapp/lib/configs/brand';
|
|
126
126
|
import { getTencentToken } from '@zfqh/uniapp/lib/apis';
|
|
127
|
-
import store from '@/store';
|
|
128
127
|
|
|
129
128
|
defineConfig({
|
|
130
129
|
app: app.merchant,
|
|
@@ -149,7 +148,7 @@ defineConfig({
|
|
|
149
148
|
create_time: data.createTime,
|
|
150
149
|
expire_time: data.expirationTime,
|
|
151
150
|
bucket: data.bucket,
|
|
152
|
-
region: store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
|
|
151
|
+
region: uni.$store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
|
|
153
152
|
};
|
|
154
153
|
},
|
|
155
154
|
},
|
|
@@ -110,7 +110,6 @@ import { defineConfig } from '@zfqh/uniapp';
|
|
|
110
110
|
import { app } from '@zfqh/uniapp/lib/configs/app';
|
|
111
111
|
import { brand } from '@zfqh/uniapp/lib/configs/brand';
|
|
112
112
|
import { getTencentToken } from '@zfqh/uniapp/lib/apis';
|
|
113
|
-
import store from '@/store';
|
|
114
113
|
|
|
115
114
|
defineConfig({
|
|
116
115
|
app: app.merchant,
|
|
@@ -135,7 +134,7 @@ defineConfig({
|
|
|
135
134
|
create_time: data.createTime,
|
|
136
135
|
expire_time: data.expirationTime,
|
|
137
136
|
bucket: data.bucket,
|
|
138
|
-
region: store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
|
|
137
|
+
region: uni.$store.state.storeConfig.isGlobalAccelerate ? 'accelerate' : data.region,
|
|
139
138
|
};
|
|
140
139
|
},
|
|
141
140
|
},
|
|
@@ -197,13 +196,13 @@ export default defineConfig({
|
|
|
197
196
|
|
|
198
197
|
| 路径 | 用途 |
|
|
199
198
|
| --- | --- |
|
|
200
|
-
| `
|
|
201
|
-
| `
|
|
202
|
-
| `
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
| `
|
|
206
|
-
| `
|
|
199
|
+
| `store.state.login.info.token` | 请求拦截器注入 `Authorization`。 |
|
|
200
|
+
| `store.state.login.info.tenantId` | 业务请求注入 `Tenant-Id`。 |
|
|
201
|
+
| `store.state.system.info.appLanguage` | 业务请求注入 `X-Language`。 |
|
|
202
|
+
| `store.state.system.info.appVersion` | 非 App 环境下读取版本名。 |
|
|
203
|
+
| `store.state.system.info.appVersionCode` | 非 App 环境下读取版本号。 |
|
|
204
|
+
| `store.getters.isLogin` | 导航登录拦截判断。 |
|
|
205
|
+
| `store.dispatch('logout')` | `401` 时触发退出登录。 |
|
|
207
206
|
|
|
208
207
|
推荐在注册插件前完成:
|
|
209
208
|
|
|
@@ -219,9 +218,9 @@ app.use(uniapp);
|
|
|
219
218
|
| 场景 | 推荐用法 | 说明 |
|
|
220
219
|
| --- | --- | --- |
|
|
221
220
|
| 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
|
|
221
|
+
| 自定义 hooks / composables | `import { useStore } from 'vuex'` 后在 hook 内调用 `useStore()` | hooks 同样运行在组件 setup 上下文里。 |
|
|
223
222
|
| Options API 组件 | `this.$store` | 组件实例已注入 `$store` 时可使用实例属性;现有 `g-*` 组件源码也采用这种方式读取部分系统状态。 |
|
|
224
|
-
| 请求、导航、toast、权限、webview 消息等普通 TS 模块 | `uni.$store` | 这些模块不在 Vue setup 上下文中,无法调用 `useStore()
|
|
223
|
+
| 请求、导航、toast、权限、webview 消息等普通 TS 模块 | `uni.$store` | 这些模块不在 Vue setup 上下文中,无法调用 `useStore()`,因此直接引入 store 实例读取登录态和全局状态。 |
|
|
225
224
|
|
|
226
225
|
组件或 hooks 中推荐写法:
|
|
227
226
|
|
|
@@ -241,16 +240,6 @@ export function useLoginInfo() {
|
|
|
241
240
|
}
|
|
242
241
|
```
|
|
243
242
|
|
|
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
243
|
## 样式接入
|
|
255
244
|
|
|
256
245
|
`@zfqh/uniapp` 内置的静态样式仅覆盖平台差异类和使用 `$uv-*` SCSS 变量的语义色类,间距、尺寸、字号、圆角、透明度、阴影等通用原子类由 `@gmcb/vite` 的 unocss 插件在构建时动态生成。
|
package/docs/index.md
CHANGED
|
@@ -74,7 +74,7 @@ export function createApp() {
|
|
|
74
74
|
|
|
75
75
|
## 使用约定
|
|
76
76
|
|
|
77
|
-
- 项目需要提供符合约定的 Vuex store:请求读取 `
|
|
78
|
-
- Store
|
|
77
|
+
- 项目需要提供符合约定的 Vuex store:请求读取 `store.state.login.info.token`,导航读取 `store.getters.isLogin`,`401` 会触发 `store.dispatch('logout')`。
|
|
78
|
+
- Store 入口按上下文区分:组件的 Composition API 中使用 `import { useStore } from 'vuex'`,Options API 组件中使用 `this.$store`,普通 TS 模块中使用 `uni.$store`。
|
|
79
79
|
- 多环境配置推荐使用 `@env/.env.<env>.ts`,并通过 `defineEnvConfig` 输出配置。
|
|
80
80
|
- 根入口未导出的 `apis`、`modules`、`mixins` 请按 [深度引用](./api/index.md#深度引用) 从构建产物路径引入。
|
package/lib/hooks/useI18n.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
// #ifdef APP-NVUE
|
|
2
|
-
import { ref, inject } from 'vue';
|
|
3
|
-
import { showLocale, defaultLocale } from '../utils/locale';
|
|
4
|
-
// #endif
|
|
5
1
|
// #ifndef APP-NVUE
|
|
6
2
|
import { useI18n as vueUseI18n } from 'vue-i18n';
|
|
7
3
|
// #endif
|
|
8
4
|
let _useI18n;
|
|
9
5
|
// #ifdef APP-NVUE
|
|
10
6
|
_useI18n = function () {
|
|
11
|
-
|
|
12
|
-
const t = inject('t', showLocale);
|
|
13
|
-
return { t, locale };
|
|
7
|
+
return uni.$i18n.global;
|
|
14
8
|
};
|
|
15
9
|
// #endif
|
|
16
10
|
// #ifndef APP-NVUE
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import cos from './utils/cos';
|
|
|
6
6
|
import './utils/uni';
|
|
7
7
|
export * from './hooks';
|
|
8
8
|
export * from './utils';
|
|
9
|
+
export * from './utils/locale';
|
|
9
10
|
export * from './utils/file';
|
|
10
11
|
export * from './utils/storage';
|
|
11
12
|
export * from './utils/pages';
|
|
@@ -25,8 +26,6 @@ const install = (app) => {
|
|
|
25
26
|
// #ifdef MP
|
|
26
27
|
app.mixin(deep);
|
|
27
28
|
// #endif
|
|
28
|
-
const { $store } = app.config.globalProperties;
|
|
29
|
-
uni.$store = $store;
|
|
30
29
|
};
|
|
31
30
|
export default {
|
|
32
31
|
install,
|
package/lib/styles/bg.scss
CHANGED
package/lib/styles/flex.scss
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/* #ifdef H5 */
|
|
2
|
-
page {
|
|
1
|
+
/* #ifdef H5 */
|
|
2
|
+
page {
|
|
3
3
|
/* #endif */
|
|
4
|
-
.flex {
|
|
4
|
+
.flex {
|
|
5
5
|
/* #ifndef APP-NVUE */
|
|
6
|
-
display: flex;
|
|
6
|
+
display: flex;
|
|
7
7
|
/* #endif */
|
|
8
8
|
flex-direction: row;
|
|
9
9
|
}
|
|
10
|
-
.flex-inline {
|
|
10
|
+
.flex-inline {
|
|
11
11
|
/* #ifndef APP-NVUE */
|
|
12
|
-
display: inline-flex;
|
|
12
|
+
display: inline-flex;
|
|
13
13
|
/* #endif */
|
|
14
14
|
flex-direction: row;
|
|
15
15
|
}
|
|
@@ -72,7 +72,7 @@ page {
|
|
|
72
72
|
.justify-around {
|
|
73
73
|
justify-content: space-around;
|
|
74
74
|
}
|
|
75
|
-
/* #ifdef H5 */
|
|
76
|
-
}
|
|
75
|
+
/* #ifdef H5 */
|
|
76
|
+
}
|
|
77
77
|
/* #endif */
|
|
78
78
|
|
package/lib/styles/index.scss
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
@import '@gmcb/uv-ui/index.scss';
|
|
2
2
|
@import './border.scss';
|
|
3
3
|
@import './bg.scss';
|
|
4
|
-
@import './text.scss';
|
|
4
|
+
@import './text.scss';
|
|
5
5
|
@import './layout.scss';
|
|
6
6
|
@import './flex.scss';
|
|
7
7
|
/* #ifndef APP-NVUE */
|
|
8
|
-
@import './reset-vue.scss';
|
|
8
|
+
@import './reset-vue.scss';
|
|
9
9
|
@import './text-vue.scss';
|
|
10
10
|
/* #endif */
|
|
11
11
|
/* #ifdef APP-NVUE */
|
|
12
|
-
@import './text-nvue.scss';
|
|
12
|
+
@import './text-nvue.scss';
|
|
13
13
|
/* #endif */
|
package/lib/styles/layout.scss
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/* #ifdef H5 */
|
|
2
|
-
page {
|
|
1
|
+
/* #ifdef H5 */
|
|
2
|
+
page {
|
|
3
3
|
/* #endif */
|
|
4
|
-
.relative {
|
|
5
|
-
position: relative;
|
|
6
|
-
}
|
|
7
|
-
.absolute {
|
|
8
|
-
position: absolute;
|
|
9
|
-
}
|
|
10
|
-
.fixed {
|
|
11
|
-
position: fixed;
|
|
12
|
-
}
|
|
13
|
-
.sticky {
|
|
14
|
-
position: sticky;
|
|
15
|
-
}
|
|
4
|
+
.relative {
|
|
5
|
+
position: relative;
|
|
6
|
+
}
|
|
7
|
+
.absolute {
|
|
8
|
+
position: absolute;
|
|
9
|
+
}
|
|
10
|
+
.fixed {
|
|
11
|
+
position: fixed;
|
|
12
|
+
}
|
|
13
|
+
.sticky {
|
|
14
|
+
position: sticky;
|
|
15
|
+
}
|
|
16
16
|
/* #ifdef H5 */
|
|
17
17
|
}
|
|
18
18
|
/* #endif */
|
package/lib/styles/text.scss
CHANGED
package/lib/utils/locale.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { I18nOptions } from 'vue-i18n';
|
|
1
2
|
export declare const defaultLocale: string;
|
|
2
3
|
export declare const fallbackLocale = "zh-Hans";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export declare function showLocale(key: any, values: any): any;
|
|
4
|
+
export declare function createI18n(opts: I18nOptions): import("vue-i18n").I18n<import("vue-i18n").LocaleMessages<import("vue-i18n").VueMessageType>, import("vue-i18n").IntlDateTimeFormats, import("vue-i18n").IntlNumberFormats, boolean>;
|
|
5
|
+
export declare function getLocaleMessage(key: string): string;
|
package/lib/utils/locale.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
+
import { createI18n as _createI18n } from 'vue-i18n';
|
|
1
2
|
export const defaultLocale = uni.getLocale();
|
|
2
3
|
export const fallbackLocale = 'zh-Hans';
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
let out = str;
|
|
8
|
-
for (const k of Object.keys(values)) {
|
|
9
|
-
out = out.split(`{${k}}`).join(String(values[k]));
|
|
10
|
-
}
|
|
11
|
-
return out;
|
|
4
|
+
export function createI18n(opts) {
|
|
5
|
+
const i18n = _createI18n(opts);
|
|
6
|
+
return (uni.$i18n = i18n);
|
|
12
7
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
export function showLocale(key, values) {
|
|
17
|
-
const raw = uni.$messages[uni.getLocale()]?.[key] || uni.$messages[fallbackLocale]?.[key] || key;
|
|
18
|
-
return applyNamedPlaceholders(raw, values);
|
|
8
|
+
export function getLocaleMessage(key) {
|
|
9
|
+
return uni.$i18n?.global?.t(key) || key;
|
|
19
10
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zfqh/uniapp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "uniapp公共模块",
|
|
5
5
|
"author": "yinjiazeng@163.com",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
9
|
-
"homepage": "https://git.keeprisk.cn/zfqh/front-end/tree/master/packages/uniapp
|
|
9
|
+
"homepage": "https://git.keeprisk.cn/zfqh/front-end/tree/master/packages/zfqh-uniapp",
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"@types/qs": "^6.9.16",
|
|
46
46
|
"@types/url-parse": "^1.4.11"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "466e3167167162d5976a7d39111f1d2309707542"
|
|
49
49
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/// <reference path="./virtual.d.ts" />
|
|
2
2
|
|
|
3
3
|
import type { Uni as UniTypes } from '@dcloudio/types';
|
|
4
|
+
import type { Store } from 'vuex';
|
|
5
|
+
import type { I18n } from 'vue-i18n';
|
|
4
6
|
import color from '../lib/configs/color';
|
|
5
7
|
|
|
6
8
|
declare global {
|
|
7
9
|
interface Uni extends UniTypes {
|
|
8
|
-
$store:
|
|
9
|
-
$
|
|
10
|
+
$store: Store;
|
|
11
|
+
$i18n: I18n;
|
|
10
12
|
$uv: any;
|
|
11
13
|
webView: any;
|
|
12
14
|
showAppFromBackground: boolean;
|