@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.
Files changed (199) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +32 -2
  3. package/dist/action-sheet/README.md +1 -1
  4. package/dist/action-sheet/action-sheet.vue +158 -150
  5. package/dist/action-sheet/props.ts +2 -2
  6. package/dist/action-sheet/type.ts +1 -1
  7. package/dist/avatar/avatar.vue +89 -87
  8. package/dist/avatar-group/avatar-group.vue +69 -67
  9. package/dist/back-top/back-top.vue +60 -58
  10. package/dist/badge/badge.vue +69 -59
  11. package/dist/button/button.vue +121 -116
  12. package/dist/button/props.ts +2 -2
  13. package/dist/button/type.ts +1 -1
  14. package/dist/calendar/calendar-header.vue +4 -4
  15. package/dist/calendar/calendar.vue +308 -297
  16. package/dist/calendar/template.vue +1 -1
  17. package/dist/cascader/README.en-US.md +2 -1
  18. package/dist/cascader/README.md +2 -1
  19. package/dist/cascader/cascader.vue +340 -328
  20. package/dist/cascader/props.ts +6 -1
  21. package/dist/cascader/type.ts +6 -0
  22. package/dist/cell/cell.vue +127 -121
  23. package/dist/cell-group/cell-group.vue +32 -30
  24. package/dist/check-tag/check-tag.vue +73 -71
  25. package/dist/checkbox/README.en-US.md +6 -6
  26. package/dist/checkbox/README.md +5 -5
  27. package/dist/checkbox/checkbox.vue +127 -127
  28. package/dist/checkbox/props.ts +6 -6
  29. package/dist/checkbox/type.ts +6 -4
  30. package/dist/checkbox-group/checkbox-group.vue +175 -173
  31. package/dist/checkbox-group/props.ts +6 -6
  32. package/dist/checkbox-group/type.ts +6 -4
  33. package/dist/col/col.vue +26 -24
  34. package/dist/collapse/collapse.vue +83 -81
  35. package/dist/collapse-panel/collapse-panel.vue +121 -119
  36. package/dist/collapse-panel/props.ts +4 -4
  37. package/dist/collapse-panel/type.ts +2 -2
  38. package/dist/color-picker/README.md +1 -1
  39. package/dist/color-picker/color-picker.vue +324 -322
  40. package/dist/color-picker/props.ts +2 -2
  41. package/dist/color-picker/template.vue +14 -10
  42. package/dist/common/common.ts +1 -0
  43. package/dist/common/style/theme/index.css +57 -61
  44. package/dist/common/utils.js +7 -2
  45. package/dist/common/validator.js +172 -0
  46. package/dist/config-provider/README.en-US.md +184 -0
  47. package/dist/config-provider/README.md +234 -0
  48. package/dist/config-provider/config-provider.vue +105 -0
  49. package/dist/config-provider/config-store.js +70 -0
  50. package/dist/config-provider/props.ts +16 -0
  51. package/dist/config-provider/reactive-state.js +39 -0
  52. package/dist/config-provider/type.ts +401 -0
  53. package/dist/config-provider/use-config.js +29 -0
  54. package/dist/config-provider/utils.js +29 -0
  55. package/dist/count-down/count-down.vue +98 -97
  56. package/dist/date-time-picker/date-time-picker.vue +410 -395
  57. package/dist/demo/demo.vue +1 -0
  58. package/dist/dialog/dialog.vue +176 -173
  59. package/dist/divider/divider.vue +38 -36
  60. package/dist/draggable/draggable.vue +60 -58
  61. package/dist/drawer/README.md +1 -1
  62. package/dist/drawer/drawer.vue +48 -46
  63. package/dist/dropdown-item/dropdown-item.vue +209 -207
  64. package/dist/dropdown-item/props.ts +4 -4
  65. package/dist/dropdown-item/type.ts +3 -3
  66. package/dist/dropdown-menu/dropdown-menu.vue +93 -99
  67. package/dist/empty/empty.vue +43 -42
  68. package/dist/fab/fab.vue +88 -86
  69. package/dist/footer/footer.vue +36 -34
  70. package/dist/form/README.en-US.md +17 -24
  71. package/dist/form/README.md +18 -25
  72. package/dist/form/form.css +1 -166
  73. package/dist/form/form.vue +251 -236
  74. package/dist/form/props.ts +2 -21
  75. package/dist/form/type.ts +7 -70
  76. package/dist/form-item/README.en-US.md +4 -5
  77. package/dist/form-item/README.md +4 -5
  78. package/dist/form-item/form-item.css +69 -96
  79. package/dist/form-item/form-item.vue +315 -336
  80. package/dist/form-item/form-model.ts +125 -173
  81. package/dist/form-item/props.ts +4 -17
  82. package/dist/form-item/type.ts +43 -1
  83. package/dist/grid/grid.vue +53 -51
  84. package/dist/grid-item/grid-item.vue +121 -119
  85. package/dist/guide/README.md +1 -1
  86. package/dist/guide/guide.vue +281 -277
  87. package/dist/icon/README.md +2 -4
  88. package/dist/icon/icon.vue +78 -76
  89. package/dist/image/README.md +1 -1
  90. package/dist/image/image.vue +103 -101
  91. package/dist/image-viewer/image-viewer.vue +160 -158
  92. package/dist/image-viewer/props.ts +2 -2
  93. package/dist/image-viewer/type.ts +1 -1
  94. package/dist/index.js +3 -0
  95. package/dist/indexes/indexes.vue +264 -267
  96. package/dist/indexes-anchor/indexes-anchor.vue +41 -41
  97. package/dist/input/input.vue +192 -192
  98. package/dist/input/props.ts +6 -6
  99. package/dist/input/type.ts +3 -3
  100. package/dist/link/link.vue +73 -71
  101. package/dist/loading/loading.vue +59 -59
  102. package/dist/locale/ar_KW.ts +157 -0
  103. package/dist/locale/en_US.ts +146 -0
  104. package/dist/locale/it_IT.ts +145 -0
  105. package/dist/locale/ja_JP.ts +132 -0
  106. package/dist/locale/ko_KR.ts +132 -0
  107. package/dist/locale/ru_RU.ts +157 -0
  108. package/dist/locale/zh_CN.ts +133 -0
  109. package/dist/locale/zh_TW.ts +132 -0
  110. package/dist/message/message.vue +181 -173
  111. package/dist/message/props.ts +2 -2
  112. package/dist/message/type.ts +1 -1
  113. package/dist/message-item/message-item.vue +192 -184
  114. package/dist/mixins/using-config.js +39 -0
  115. package/dist/navbar/navbar.vue +201 -199
  116. package/dist/notice-bar/notice-bar.vue +175 -171
  117. package/dist/notice-bar/props.ts +2 -2
  118. package/dist/notice-bar/type.ts +1 -1
  119. package/dist/npm/dayjs/esm/locale/ar.js +81 -0
  120. package/dist/npm/dayjs/esm/locale/it.js +39 -0
  121. package/dist/overlay/overlay.vue +50 -48
  122. package/dist/picker/picker.vue +168 -161
  123. package/dist/picker-item/picker-item.vue +269 -269
  124. package/dist/popover/README.md +1 -1
  125. package/dist/popover/popover.vue +262 -261
  126. package/dist/popover/props.ts +4 -4
  127. package/dist/popover/type.ts +2 -2
  128. package/dist/popup/popup.vue +46 -45
  129. package/dist/progress/README.md +1 -1
  130. package/dist/progress/progress.vue +76 -76
  131. package/dist/pull-down-refresh/props.ts +2 -2
  132. package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
  133. package/dist/pull-down-refresh/type.ts +1 -1
  134. package/dist/qrcode/README.md +1 -1
  135. package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
  136. package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
  137. package/dist/qrcode/qrcode.vue +93 -87
  138. package/dist/radio/props.ts +6 -6
  139. package/dist/radio/radio.vue +118 -120
  140. package/dist/radio/type.ts +3 -3
  141. package/dist/radio-group/props.ts +4 -4
  142. package/dist/radio-group/radio-group.vue +136 -134
  143. package/dist/radio-group/type.ts +4 -4
  144. package/dist/rate/computed.js +2 -2
  145. package/dist/rate/props.ts +4 -4
  146. package/dist/rate/rate.vue +155 -154
  147. package/dist/rate/type.ts +2 -2
  148. package/dist/result/result.vue +41 -39
  149. package/dist/row/row.vue +38 -36
  150. package/dist/scroll-view/scroll-view.vue +24 -22
  151. package/dist/search/props.ts +2 -2
  152. package/dist/search/search.vue +127 -125
  153. package/dist/search/type.ts +1 -1
  154. package/dist/side-bar/side-bar.vue +57 -55
  155. package/dist/side-bar-item/side-bar-item.vue +86 -86
  156. package/dist/skeleton/skeleton.vue +126 -124
  157. package/dist/slider/README.md +1 -1
  158. package/dist/slider/props.ts +2 -2
  159. package/dist/slider/slider.vue +457 -457
  160. package/dist/slider/type.ts +1 -1
  161. package/dist/step-item/step-item.vue +77 -75
  162. package/dist/stepper/props.ts +2 -2
  163. package/dist/stepper/stepper.vue +168 -149
  164. package/dist/stepper/type.ts +1 -1
  165. package/dist/steps/props.ts +2 -2
  166. package/dist/steps/steps.vue +83 -81
  167. package/dist/steps/type.ts +1 -1
  168. package/dist/sticky/sticky.vue +104 -102
  169. package/dist/swipe-cell/swipe-cell.vue +91 -89
  170. package/dist/swiper/README.md +1 -1
  171. package/dist/swiper/swiper.vue +91 -89
  172. package/dist/swiper-nav/swiper-nav.vue +38 -36
  173. package/dist/switch/props.ts +2 -2
  174. package/dist/switch/switch.vue +62 -62
  175. package/dist/switch/type.ts +1 -1
  176. package/dist/tab-bar/tab-bar.vue +88 -86
  177. package/dist/tab-bar-item/tab-bar-item.vue +85 -82
  178. package/dist/tab-panel/tab-panel.vue +66 -64
  179. package/dist/tabs/tabs.vue +294 -287
  180. package/dist/tag/tag.vue +79 -77
  181. package/dist/textarea/props.ts +6 -6
  182. package/dist/textarea/textarea.vue +127 -126
  183. package/dist/textarea/type.ts +3 -3
  184. package/dist/toast/toast.vue +107 -106
  185. package/dist/transition/transition.vue +30 -28
  186. package/dist/tree-select/tree-select.vue +151 -151
  187. package/dist/types/config-provider.d.ts +7 -0
  188. package/dist/types/index.d.ts +2 -0
  189. package/dist/types/popover.d.ts +7 -0
  190. package/dist/upload/README.en-US.md +13 -14
  191. package/dist/upload/README.md +11 -12
  192. package/dist/upload/props.ts +2 -4
  193. package/dist/upload/type.ts +12 -11
  194. package/dist/upload/upload.css +1 -1
  195. package/dist/upload/upload.vue +672 -512
  196. package/dist/watermark/watermark.vue +151 -149
  197. package/global.d.ts +2 -0
  198. package/package.json +16 -2
  199. 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,16 @@
1
+ /* eslint-disable */
2
+
3
+ /**
4
+ * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
5
+ * */
6
+
7
+ export default {
8
+ /** 全局配置 */
9
+ globalConfig: {
10
+ type: Object,
11
+ },
12
+ /** 全局配置 */
13
+ themeVars: {
14
+ type: Object,
15
+ },
16
+ };
@@ -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
+ }