@tdesign/uniapp 0.7.2 → 0.8.0
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 +31 -0
- package/README.md +32 -2
- package/dist/action-sheet/README.md +1 -1
- package/dist/action-sheet/action-sheet.vue +158 -150
- package/dist/action-sheet/props.ts +2 -2
- package/dist/action-sheet/type.ts +1 -1
- package/dist/avatar/avatar.vue +89 -87
- package/dist/avatar-group/avatar-group.vue +69 -67
- package/dist/back-top/back-top.vue +60 -58
- package/dist/badge/badge.vue +69 -59
- package/dist/button/button.vue +121 -116
- package/dist/button/props.ts +2 -2
- package/dist/button/type.ts +1 -1
- package/dist/calendar/calendar-header.vue +4 -4
- package/dist/calendar/calendar.vue +308 -297
- package/dist/calendar/template.vue +1 -1
- package/dist/cascader/README.en-US.md +2 -1
- package/dist/cascader/README.md +2 -1
- package/dist/cascader/cascader.vue +340 -328
- package/dist/cascader/props.ts +6 -1
- package/dist/cascader/type.ts +6 -0
- package/dist/cell/cell.vue +127 -121
- package/dist/cell-group/cell-group.vue +32 -30
- package/dist/check-tag/check-tag.vue +73 -71
- package/dist/checkbox/README.en-US.md +6 -6
- package/dist/checkbox/README.md +5 -5
- package/dist/checkbox/checkbox.vue +127 -127
- package/dist/checkbox/props.ts +6 -6
- package/dist/checkbox/type.ts +6 -4
- package/dist/checkbox-group/checkbox-group.vue +175 -173
- package/dist/checkbox-group/props.ts +6 -6
- package/dist/checkbox-group/type.ts +6 -4
- package/dist/col/col.vue +26 -24
- package/dist/collapse/collapse.vue +83 -81
- package/dist/collapse-panel/collapse-panel.vue +121 -119
- package/dist/collapse-panel/props.ts +4 -4
- package/dist/collapse-panel/type.ts +2 -2
- package/dist/color-picker/README.md +1 -1
- package/dist/color-picker/color-picker.vue +324 -322
- package/dist/color-picker/props.ts +2 -2
- package/dist/color-picker/template.vue +14 -10
- package/dist/common/common.ts +1 -0
- package/dist/common/style/theme/index.css +57 -61
- package/dist/common/utils.js +7 -2
- package/dist/common/validator.js +172 -0
- package/dist/config-provider/README.en-US.md +184 -0
- package/dist/config-provider/README.md +234 -0
- package/dist/config-provider/config-provider.vue +105 -0
- package/dist/config-provider/config-store.js +70 -0
- package/dist/config-provider/props.ts +16 -0
- package/dist/config-provider/reactive-state.js +39 -0
- package/dist/config-provider/type.ts +401 -0
- package/dist/config-provider/use-config.js +29 -0
- package/dist/config-provider/utils.js +29 -0
- package/dist/count-down/count-down.vue +98 -97
- package/dist/date-time-picker/date-time-picker.vue +410 -395
- package/dist/demo/demo.vue +1 -0
- package/dist/dialog/dialog.vue +176 -173
- package/dist/divider/divider.vue +38 -36
- package/dist/draggable/draggable.vue +60 -58
- package/dist/drawer/README.md +1 -1
- package/dist/drawer/drawer.vue +48 -46
- package/dist/dropdown-item/dropdown-item.vue +209 -207
- package/dist/dropdown-item/props.ts +4 -4
- package/dist/dropdown-item/type.ts +3 -3
- package/dist/dropdown-menu/dropdown-menu.vue +93 -99
- package/dist/empty/empty.vue +43 -42
- package/dist/fab/fab.vue +88 -86
- package/dist/footer/footer.vue +36 -34
- package/dist/form/README.en-US.md +17 -24
- package/dist/form/README.md +18 -25
- package/dist/form/form.css +1 -166
- package/dist/form/form.vue +251 -236
- package/dist/form/props.ts +2 -21
- package/dist/form/type.ts +7 -70
- package/dist/form-item/README.en-US.md +4 -5
- package/dist/form-item/README.md +4 -5
- package/dist/form-item/form-item.css +69 -96
- package/dist/form-item/form-item.vue +315 -336
- package/dist/form-item/form-model.ts +125 -173
- package/dist/form-item/props.ts +4 -17
- package/dist/form-item/type.ts +43 -1
- package/dist/grid/grid.vue +53 -51
- package/dist/grid-item/grid-item.vue +121 -119
- package/dist/guide/README.md +1 -1
- package/dist/guide/guide.vue +281 -277
- package/dist/icon/README.md +2 -4
- package/dist/icon/icon.vue +78 -76
- package/dist/image/README.md +1 -1
- package/dist/image/image.vue +103 -101
- package/dist/image-viewer/image-viewer.vue +160 -158
- package/dist/image-viewer/props.ts +2 -2
- package/dist/image-viewer/type.ts +1 -1
- package/dist/index.js +3 -0
- package/dist/indexes/indexes.vue +264 -267
- package/dist/indexes-anchor/indexes-anchor.vue +41 -41
- package/dist/input/input.vue +192 -192
- package/dist/input/props.ts +6 -6
- package/dist/input/type.ts +3 -3
- package/dist/link/link.vue +73 -71
- package/dist/loading/loading.vue +59 -59
- package/dist/locale/ar_KW.ts +157 -0
- package/dist/locale/en_US.ts +146 -0
- package/dist/locale/it_IT.ts +145 -0
- package/dist/locale/ja_JP.ts +132 -0
- package/dist/locale/ko_KR.ts +132 -0
- package/dist/locale/ru_RU.ts +157 -0
- package/dist/locale/zh_CN.ts +133 -0
- package/dist/locale/zh_TW.ts +132 -0
- package/dist/message/message.vue +181 -173
- package/dist/message/props.ts +2 -2
- package/dist/message/type.ts +1 -1
- package/dist/message-item/message-item.vue +192 -184
- package/dist/mixins/using-config.js +39 -0
- package/dist/navbar/navbar.vue +201 -199
- package/dist/notice-bar/notice-bar.vue +175 -171
- package/dist/notice-bar/props.ts +2 -2
- package/dist/notice-bar/type.ts +1 -1
- package/dist/npm/dayjs/esm/locale/ar.js +81 -0
- package/dist/npm/dayjs/esm/locale/it.js +39 -0
- package/dist/overlay/overlay.vue +50 -48
- package/dist/picker/picker.vue +168 -161
- package/dist/picker-item/picker-item.vue +269 -269
- package/dist/popover/README.md +1 -1
- package/dist/popover/popover.vue +262 -261
- package/dist/popover/props.ts +4 -4
- package/dist/popover/type.ts +2 -2
- package/dist/popup/popup.vue +46 -45
- package/dist/progress/README.md +1 -1
- package/dist/progress/progress.vue +76 -76
- package/dist/pull-down-refresh/props.ts +2 -2
- package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
- package/dist/pull-down-refresh/type.ts +1 -1
- package/dist/qrcode/README.md +1 -1
- package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
- package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
- package/dist/qrcode/qrcode.vue +93 -87
- package/dist/radio/props.ts +6 -6
- package/dist/radio/radio.vue +118 -120
- package/dist/radio/type.ts +3 -3
- package/dist/radio-group/props.ts +4 -4
- package/dist/radio-group/radio-group.vue +136 -134
- package/dist/radio-group/type.ts +4 -4
- package/dist/rate/computed.js +2 -2
- package/dist/rate/props.ts +4 -4
- package/dist/rate/rate.vue +155 -154
- package/dist/rate/type.ts +2 -2
- package/dist/result/result.vue +41 -39
- package/dist/row/row.vue +38 -36
- package/dist/scroll-view/scroll-view.vue +24 -22
- package/dist/search/props.ts +2 -2
- package/dist/search/search.vue +127 -125
- package/dist/search/type.ts +1 -1
- package/dist/side-bar/side-bar.vue +57 -55
- package/dist/side-bar-item/side-bar-item.vue +86 -86
- package/dist/skeleton/skeleton.vue +126 -124
- package/dist/slider/README.md +1 -1
- package/dist/slider/props.ts +2 -2
- package/dist/slider/slider.vue +457 -457
- package/dist/slider/type.ts +1 -1
- package/dist/step-item/step-item.vue +77 -75
- package/dist/stepper/props.ts +2 -2
- package/dist/stepper/stepper.vue +168 -149
- package/dist/stepper/type.ts +1 -1
- package/dist/steps/props.ts +2 -2
- package/dist/steps/steps.vue +83 -81
- package/dist/steps/type.ts +1 -1
- package/dist/sticky/sticky.vue +104 -102
- package/dist/swipe-cell/swipe-cell.vue +91 -89
- package/dist/swiper/README.md +1 -1
- package/dist/swiper/swiper.vue +91 -89
- package/dist/swiper-nav/swiper-nav.vue +38 -36
- package/dist/switch/props.ts +2 -2
- package/dist/switch/switch.vue +62 -62
- package/dist/switch/type.ts +1 -1
- package/dist/tab-bar/tab-bar.vue +88 -86
- package/dist/tab-bar-item/tab-bar-item.vue +85 -82
- package/dist/tab-panel/tab-panel.vue +66 -64
- package/dist/tabs/tabs.vue +294 -287
- package/dist/tag/tag.vue +79 -77
- package/dist/textarea/props.ts +6 -6
- package/dist/textarea/textarea.vue +127 -126
- package/dist/textarea/type.ts +3 -3
- package/dist/toast/toast.vue +107 -106
- package/dist/transition/transition.vue +30 -28
- package/dist/tree-select/tree-select.vue +151 -151
- package/dist/types/config-provider.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/popover.d.ts +7 -0
- package/dist/upload/README.en-US.md +13 -14
- package/dist/upload/README.md +11 -12
- package/dist/upload/props.ts +2 -4
- package/dist/upload/type.ts +12 -11
- package/dist/upload/upload.css +1 -1
- package/dist/upload/upload.vue +672 -512
- package/dist/watermark/watermark.vue +151 -149
- package/global.d.ts +2 -0
- package/package.json +16 -2
- package/dist/form/form-item-props.ts +0 -56
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ConfigProvider 全局特性配置
|
|
3
|
+
description: 全局特性配置包含各个组件的文本语言配置及其他通用配置,可以减少重复的通用配置。
|
|
4
|
+
spline: explain
|
|
5
|
+
isComponent: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## 引入
|
|
10
|
+
|
|
11
|
+
可在 `main.ts` 或在需要使用的页面或组件中引入。
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import TConfigProvider from '@tdesign/uniapp/config-provider/config-provider.vue';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 代码演示
|
|
18
|
+
|
|
19
|
+
### 国际化配置
|
|
20
|
+
|
|
21
|
+
TDesign 支持国际化/多语言配置,目前支持的语言包括:
|
|
22
|
+
|
|
23
|
+
| 语言 | 对应文件 |
|
|
24
|
+
| -------- | -------- |
|
|
25
|
+
| 简体中文 | `zh_CN` |
|
|
26
|
+
| 繁体中文 | `zh_TW` |
|
|
27
|
+
| 英语 | `en_US` |
|
|
28
|
+
| 韩语 | `ko_KR` |
|
|
29
|
+
| 日语 | `ja_JP` |
|
|
30
|
+
| 俄语 | `ru_RU` |
|
|
31
|
+
| 意大利语 | `it_IT` |
|
|
32
|
+
| 阿拉伯语 | `ar_KW` |
|
|
33
|
+
|
|
34
|
+
如果你想贡献更多语言包,欢迎参考 [如何新增语言包](https://github.com/Tencent/tdesign-common/blob/develop/js/global-config/locale/CONTRIBUTING.md) 发起 PR。
|
|
35
|
+
|
|
36
|
+
### 01 配置示例
|
|
37
|
+
|
|
38
|
+
### Upload
|
|
39
|
+
|
|
40
|
+
{{ upload-en }}
|
|
41
|
+
|
|
42
|
+
### Chat
|
|
43
|
+
|
|
44
|
+
[@tdesign/uniapp-chat](https://tdesign.tencent.com/uniapp-chat) 组件与 `@tdesign-uniapp` 复用 `config-provider`。
|
|
45
|
+
|
|
46
|
+
{{ chat-en }}
|
|
47
|
+
|
|
48
|
+
### 其他组件
|
|
49
|
+
|
|
50
|
+
{{ other-en }}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
### ConfigProvider Props
|
|
56
|
+
|
|
57
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
58
|
+
-- | -- | -- | -- | --
|
|
59
|
+
custom-style | Object | - | 自定义样式 | N
|
|
60
|
+
global-config | Object | - | 全局配置。TS 类型:`GlobalConfigProvider` | N
|
|
61
|
+
theme-vars | Object | - | 全局配置 | N
|
|
62
|
+
|
|
63
|
+
### GlobalConfigProvider
|
|
64
|
+
|
|
65
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
66
|
+
-- | -- | -- | -- | --
|
|
67
|
+
action-sheet | Object | - | 动作面板全局配置。TS 类型:`ActionSheetConfig` | N
|
|
68
|
+
calendar | Object | - | 日历组件全局配置。TS 类型:`CalendarConfig` | N
|
|
69
|
+
cascader | Object | - | 级联选择器全局配置。TS 类型:`CascaderConfig` | N
|
|
70
|
+
class-prefix | String | t | CSS 类名前缀 | N
|
|
71
|
+
date-time-picker | Object | - | 时间选择器全局配置。TS 类型:`DateTimePickerConfig` | N
|
|
72
|
+
dropdown-menu | Object | - | 下拉菜单全局配置。TS 类型:`DropdownMenuConfig` | N
|
|
73
|
+
guide | Object | - | 引导全局配置。TS 类型:`GuideConfig` | N
|
|
74
|
+
picker | Object | - | 选择器全局配置。TS 类型:`PickerConfig` | N
|
|
75
|
+
pull-down-refresh | Object | - | 下拉刷新全局配置。TS 类型:`PullDownRefreshConfig` | N
|
|
76
|
+
qrcode | Object | - | 二维码全局配置。TS 类型:`QRCodeConfig` | N
|
|
77
|
+
rate | Object | - | 评分全局配置。TS 类型:`RateConfig` | N
|
|
78
|
+
tab-bar | Object | - | 标签栏全局配置。TS 类型:`TabBarConfig` | N
|
|
79
|
+
upload | Object | - | 上传组件全局配置。TS 类型:`UploadConfig` | N
|
|
80
|
+
|
|
81
|
+
### ActionSheetConfig
|
|
82
|
+
|
|
83
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
84
|
+
-- | -- | -- | -- | --
|
|
85
|
+
cancel | String | - | 语言配置,“取消” 按钮描述文本 | N
|
|
86
|
+
|
|
87
|
+
### AttachmentsConfig
|
|
88
|
+
|
|
89
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
90
|
+
-- | -- | -- | -- | --
|
|
91
|
+
status | Object | - | 语言配置,附件上传状态描述文本。TS 类型:`{ pending: string; fail: string; }` | N
|
|
92
|
+
|
|
93
|
+
### CalendarConfig
|
|
94
|
+
|
|
95
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
96
|
+
-- | -- | -- | -- | --
|
|
97
|
+
confirm | String | - | 语言配置,“确定” 按钮描述文本 | N
|
|
98
|
+
month-title | String | - | 语言配置,日期月面板标题描述文本。示例:“{year} / {month}” | N
|
|
99
|
+
months | Array | - | 月文本描述,默认值:['1 月', '2 月', '3 月', '4 月', '5 月', '6 月', '7 月', '8 月', '9 月', '10 月', '11 月', '12 月']。TS 类型:`string[]` | N
|
|
100
|
+
title | String | - | 语言配置,组件标题“请选择日期”描述文本 | N
|
|
101
|
+
weekdays | Array | - | 星期文本描述,默认值:['日', '一', '二', '三', '四', '五', '六']。TS 类型:`string[]` | N
|
|
102
|
+
|
|
103
|
+
### CascaderConfig
|
|
104
|
+
|
|
105
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
106
|
+
-- | -- | -- | -- | --
|
|
107
|
+
placeholder | String | - | 语言配置,未选中时的提示文案“选择选项”描述文本 | N
|
|
108
|
+
title | String | - | 语言配置,组件标题“选择地址”描述文本 | N
|
|
109
|
+
|
|
110
|
+
### ChatActionbarConfig
|
|
111
|
+
|
|
112
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
113
|
+
-- | -- | -- | -- | --
|
|
114
|
+
action-bar | Object | - | 语言配置,对话操作栏描述文本。TS 类型:`{ replay: string; copy: string; good: string; bad: string; share: string; quote: string; }` | N
|
|
115
|
+
|
|
116
|
+
### ChatSenderConfig
|
|
117
|
+
|
|
118
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
119
|
+
-- | -- | -- | -- | --
|
|
120
|
+
placeholder | String | - | 语言配置,占位符描述文本 | N
|
|
121
|
+
send-text | String | - | 语言配置,发送按钮描述文本 | N
|
|
122
|
+
stop-text | String | - | 语言配置,停止发送按钮描述文本 | N
|
|
123
|
+
|
|
124
|
+
### ChatThinkingConfig
|
|
125
|
+
|
|
126
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
127
|
+
-- | -- | -- | -- | --
|
|
128
|
+
status | Object | - | 语言配置,思考状态描述文本。TS 类型:`{ pending: string; complete: string; stop: string; }` | N
|
|
129
|
+
|
|
130
|
+
### DateTimePickerConfig
|
|
131
|
+
|
|
132
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
133
|
+
-- | -- | -- | -- | --
|
|
134
|
+
cancel | String | - | 语言配置,“取消”按钮描述文本 | N
|
|
135
|
+
confirm | String | - | 语言配置,“确定”按钮描述文本 | N
|
|
136
|
+
date-label | String | - | 语言配置,“日” 描述文本 | N
|
|
137
|
+
format | String | 'YYYY-MM-DD HH:mm:ss' | 日期格式化规则 | N
|
|
138
|
+
hour-label | String | - | 语言配置,“时” 描述文本 | N
|
|
139
|
+
minute-label | String | - | 语言配置,“分” 描述文本 | N
|
|
140
|
+
month-label | String | - | 语言配置,“月” 描述文本 | N
|
|
141
|
+
second-label | String | - | 语言配置,“秒” 描述文本 | N
|
|
142
|
+
title | String | - | 语言配置,组件标题“选择时间”描述文本 | N
|
|
143
|
+
year-label | String | - | 语言配置,“年” 描述文本 | N
|
|
144
|
+
|
|
145
|
+
### DropdownMenuConfig
|
|
146
|
+
|
|
147
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
148
|
+
-- | -- | -- | -- | --
|
|
149
|
+
confirm | String | - | 语言配置,“确定” 按钮描述文本 | N
|
|
150
|
+
reset | String | - | 语言配置,“重置” 按钮描述文本 | N
|
|
151
|
+
|
|
152
|
+
### FormConfig
|
|
153
|
+
|
|
154
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
155
|
+
-- | -- | -- | -- | --
|
|
156
|
+
colon-text | String | - | 字段旁边的冒号,中文为“:” | N
|
|
157
|
+
error-message | Object | - | 表单错误信息配置,示例:`{ idcard: '请输入正确的身份证号码', max: '字符长度不能超过 ${max}' }`。TS 类型:`FormErrorMessage`,[Form API Documents](./form?tab=api)。[详细类型定义](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/config-provider/type.ts) | N
|
|
158
|
+
required-mark | Boolean | true | 是否显示必填符号(*),默认显示 | N
|
|
159
|
+
required-mark-position | String | left | 表单必填符号(*)显示位置。可选项:left/right | N
|
|
160
|
+
|
|
161
|
+
### GuideConfig
|
|
162
|
+
|
|
163
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
164
|
+
-- | -- | -- | -- | --
|
|
165
|
+
back | String | - | 语言配置, “返回” 描述文本 | N
|
|
166
|
+
finish | String | - | 语言配置, “完成” 描述文本 | N
|
|
167
|
+
next | String | - | 语言配置, “下一步” 描述文本 | N
|
|
168
|
+
skip | String | - | 语言配置, “跳过” 描述文本 | N
|
|
169
|
+
|
|
170
|
+
### ImageConfig
|
|
171
|
+
|
|
172
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
173
|
+
-- | -- | -- | -- | --
|
|
174
|
+
error-text | String | - | 图片加载失败显示的文本,中文默认为“图片无法显示” | N
|
|
175
|
+
loading-text | String | - | 图片加载中显示的文本,中文默认为“图片加载中” | N
|
|
176
|
+
replace-image-src | Function | - | 统一替换图片 `src` 地址,参数为组件的全部属性,返回值为新的图片地址。TS 类型:`(params: ImageProps) => string`,[Image API Documents](./image?tab=api)。[详细类型定义](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/config-provider/type.ts) | N
|
|
177
|
+
|
|
178
|
+
### InputConfig
|
|
179
|
+
|
|
180
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
181
|
+
-- | -- | -- | -- | --
|
|
182
|
+
placeholder | String | - | 语言配置,“请输入”占位符描述文本 | N
|
|
183
|
+
|
|
184
|
+
### PickerConfig
|
|
185
|
+
|
|
186
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
187
|
+
-- | -- | -- | -- | --
|
|
188
|
+
cancel | String | - | 语言配置,“取消” 按钮描述文本 | N
|
|
189
|
+
confirm | String | - | 语言配置,“确认” 按钮描述文本 | N
|
|
190
|
+
|
|
191
|
+
### PullDownRefreshConfig
|
|
192
|
+
|
|
193
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
194
|
+
-- | -- | -- | -- | --
|
|
195
|
+
loading-texts | Array | - | 提示文本描述,默认值:['下拉刷新', '松手刷新', '正在刷新', '刷新完成']。TS 类型:`string[]` | N
|
|
196
|
+
|
|
197
|
+
### QRCodeConfig
|
|
198
|
+
|
|
199
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
200
|
+
-- | -- | -- | -- | --
|
|
201
|
+
expired-text | String | - | 语言配置,“二维码过期”描述文本 | N
|
|
202
|
+
refresh-text | String | - | 语言配置,“点击刷新”描述文本 | N
|
|
203
|
+
scanned-text | String | - | 语言配置,“已扫描”描述文本 | N
|
|
204
|
+
|
|
205
|
+
### RateConfig
|
|
206
|
+
|
|
207
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
208
|
+
-- | -- | -- | -- | --
|
|
209
|
+
no-value-text | String | - | 语言配置,“未评分”描述文本 | N
|
|
210
|
+
value-text | String | - | 语言配置,评分值描述文本。示例:“{value} 分” | N
|
|
211
|
+
|
|
212
|
+
### TabBarConfig
|
|
213
|
+
|
|
214
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
215
|
+
-- | -- | -- | -- | --
|
|
216
|
+
have-more-news-aria-label | String | - | 语言配置,“有n+条新的消息”描述文本。示例:“有 {value}+ 条消息” | N
|
|
217
|
+
have-news-aria-label | String | - | 语言配置,“有n条新的消息”描述文本。示例:“有 {value} 条消息” | N
|
|
218
|
+
more-news-aria-label | String | - | 语言配置,“有很多消息”描述文本 | N
|
|
219
|
+
news-aria-label | String | - | 语言配置,“有新的消息”描述文本 | N
|
|
220
|
+
|
|
221
|
+
### UploadConfig
|
|
222
|
+
|
|
223
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
224
|
+
-- | -- | -- | -- | --
|
|
225
|
+
progress | Object | - | 语言配置,上传进度相关。示例:{ uploadText: '上传中', waitingText: '待上传', 'failText': '上传失败', successText: '上传成功' }。TS 类型:`UploadConfigProgress` | N
|
|
226
|
+
|
|
227
|
+
### UploadConfigProgress
|
|
228
|
+
|
|
229
|
+
名称 | 类型 | 默认值 | 描述 | 必传
|
|
230
|
+
-- | -- | -- | -- | --
|
|
231
|
+
fail-text | String | - | 语言配置,“上传失败”文本描述 | N
|
|
232
|
+
success-text | String | - | 语言配置,“上传成功”文本描述 | N
|
|
233
|
+
uploading-text | String | - | 语言配置,“上传中”文本描述 | N
|
|
234
|
+
waiting-text | String | - | 语言配置,“待上传”文本描述 | N
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
:class="'' + `${classPrefix} ${tClass}`"
|
|
4
|
+
:style="'' + `${tools._style([customStyle, cssVars])}`"
|
|
5
|
+
>
|
|
6
|
+
<slot />
|
|
7
|
+
</view>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
import { prefix } from '../common/config';
|
|
12
|
+
import props from './props';
|
|
13
|
+
import { uniComponent } from '../common/src/index';
|
|
14
|
+
import tools from '../common/utils.wxs';
|
|
15
|
+
import { configStore } from './config-store';
|
|
16
|
+
import themeVarsToCSS from './utils';
|
|
17
|
+
|
|
18
|
+
const componentName = 'config-provider';
|
|
19
|
+
const name = `${prefix}-${componentName}`;
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
...uniComponent({
|
|
23
|
+
name,
|
|
24
|
+
externalClasses: [
|
|
25
|
+
`${prefix}-class`,
|
|
26
|
+
],
|
|
27
|
+
options: {
|
|
28
|
+
styleIsolation: 'shared',
|
|
29
|
+
},
|
|
30
|
+
props: {
|
|
31
|
+
...props,
|
|
32
|
+
},
|
|
33
|
+
data() {
|
|
34
|
+
return {
|
|
35
|
+
prefix,
|
|
36
|
+
tools,
|
|
37
|
+
classPrefix: name,
|
|
38
|
+
cssVars: {},
|
|
39
|
+
iComponentId: null,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
watch: {
|
|
43
|
+
themeVars: {
|
|
44
|
+
handler() {
|
|
45
|
+
this.updateConfig();
|
|
46
|
+
},
|
|
47
|
+
deep: true,
|
|
48
|
+
},
|
|
49
|
+
globalConfig: {
|
|
50
|
+
handler() {
|
|
51
|
+
this.updateConfig();
|
|
52
|
+
},
|
|
53
|
+
deep: true,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
mounted() {
|
|
57
|
+
this.iComponentId = `${Date.now()}-${Math.random().toString(36)
|
|
58
|
+
.slice(2)}`;
|
|
59
|
+
this.initStore();
|
|
60
|
+
this.updateConfig();
|
|
61
|
+
},
|
|
62
|
+
beforeUnmount() {
|
|
63
|
+
if (this.iUnsubscribeLocale) {
|
|
64
|
+
this.iUnsubscribeLocale();
|
|
65
|
+
}
|
|
66
|
+
if (this.iComponentId) {
|
|
67
|
+
configStore.resetPageState(this.iComponentId);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
methods: {
|
|
71
|
+
/**
|
|
72
|
+
* 初始化 Store 并订阅状态变化
|
|
73
|
+
*/
|
|
74
|
+
initStore() {
|
|
75
|
+
this.iUnsubscribeLocale = configStore.currentLocale.subscribe(() => {});
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 更新配置
|
|
80
|
+
*/
|
|
81
|
+
updateConfig() {
|
|
82
|
+
const { themeVars, globalConfig } = this;
|
|
83
|
+
|
|
84
|
+
// 切换语言包
|
|
85
|
+
if (globalConfig) {
|
|
86
|
+
configStore.switchLocale(globalConfig, this.iComponentId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 更新主题变量
|
|
90
|
+
if (themeVars) {
|
|
91
|
+
configStore.updateThemeVars(themeVars);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 应用主题变量
|
|
95
|
+
this.applyTheme();
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
applyTheme() {
|
|
99
|
+
const { themeVars } = this;
|
|
100
|
+
this.cssVars = themeVarsToCSS(themeVars || {});
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
</script>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import ReactiveState from './reactive-state';
|
|
2
|
+
|
|
3
|
+
class ConfigStore {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.currentLocale = new ReactiveState({});
|
|
6
|
+
this.themeVars = new ReactiveState({});
|
|
7
|
+
this.pageInitFlags = new Map();
|
|
8
|
+
this.cleanupCallbacks = new Map();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
deepEqual(a, b) {
|
|
12
|
+
if (a === b) return true;
|
|
13
|
+
if (typeof a !== typeof b) return false;
|
|
14
|
+
if (a == null || b == null) return a === b;
|
|
15
|
+
if (typeof a !== 'object') return false;
|
|
16
|
+
const keysA = Object.keys(a);
|
|
17
|
+
const keysB = Object.keys(b);
|
|
18
|
+
if (keysA.length !== keysB.length) return false;
|
|
19
|
+
try {
|
|
20
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return keysA.every(key => this.deepEqual(a[key], b[key]));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
switchLocale(locale, componentId) {
|
|
27
|
+
if (!componentId) return;
|
|
28
|
+
const pageInitFlag = this.getOrInitPageFlag(componentId);
|
|
29
|
+
if (!pageInitFlag.locale) {
|
|
30
|
+
pageInitFlag.locale = true;
|
|
31
|
+
this.currentLocale.value = locale;
|
|
32
|
+
} else {
|
|
33
|
+
const isEmptyLocale = !locale || Object.keys(locale).length === 0;
|
|
34
|
+
const isCurrentEmpty = Object.keys(this.currentLocale.value).length === 0;
|
|
35
|
+
if (isEmptyLocale !== isCurrentEmpty || !this.deepEqual(locale, this.currentLocale.value)) {
|
|
36
|
+
this.currentLocale.value = locale;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
updateThemeVars(vars) {
|
|
42
|
+
this.themeVars.value = { ...this.themeVars.value, ...vars };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getOrInitPageFlag(componentId) {
|
|
46
|
+
if (!this.pageInitFlags.has(componentId)) {
|
|
47
|
+
this.pageInitFlags.set(componentId, { theme: false, locale: false });
|
|
48
|
+
}
|
|
49
|
+
return this.pageInitFlags.get(componentId);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
resetPageState(componentId) {
|
|
53
|
+
if (componentId) {
|
|
54
|
+
this.pageInitFlags.delete(componentId);
|
|
55
|
+
const cleanup = this.cleanupCallbacks.get(componentId);
|
|
56
|
+
if (cleanup) {
|
|
57
|
+
try {
|
|
58
|
+
cleanup();
|
|
59
|
+
} catch (e) { /* ignore */ }
|
|
60
|
+
this.cleanupCallbacks.delete(componentId);
|
|
61
|
+
}
|
|
62
|
+
const hasOtherLocaleProvider = Array.from(this.pageInitFlags.values()).some(flag => flag.locale);
|
|
63
|
+
if (!hasOtherLocaleProvider) {
|
|
64
|
+
this.currentLocale.value = {};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const configStore = new ConfigStore();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 响应式状态基类
|
|
3
|
+
* 使用简易的发布-订阅模式实现响应式更新
|
|
4
|
+
*/
|
|
5
|
+
export default class ReactiveState {
|
|
6
|
+
constructor(initialValue) {
|
|
7
|
+
this.iValue = initialValue;
|
|
8
|
+
this.iListeners = new Set();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get value() {
|
|
12
|
+
return this.iValue;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
set value(newValue) {
|
|
16
|
+
if (this.iValue !== newValue) {
|
|
17
|
+
this.iValue = newValue;
|
|
18
|
+
this.notify();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
subscribe(listener) {
|
|
23
|
+
this.iListeners.add(listener);
|
|
24
|
+
listener(this.iValue);
|
|
25
|
+
return () => {
|
|
26
|
+
this.iListeners.delete(listener);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
notify() {
|
|
31
|
+
this.iListeners.forEach((listener) => {
|
|
32
|
+
try {
|
|
33
|
+
listener(this.iValue);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
// ignore
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|