@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
@@ -1,18 +1,10 @@
1
1
  <template>
2
- <view>
3
- <form
4
- :class="
5
- classPrefix +
6
- ' ' + classPrefix + '--' + labelAlign +
7
- ' ' + classPrefix + '--' + (disabled ? 'disabled' : '') +
8
- ' ' + classPrefix + '--' + (readonly ? 'readonly' : '') +
9
- ' ' + tClass
10
- "
11
- :style="customStyle"
12
- >
13
- <slot />
14
- </form>
15
- </view>
2
+ <form
3
+ :class="classPrefix + ' ' + tClass"
4
+ :style="tools._style([customStyle])"
5
+ >
6
+ <slot />
7
+ </form>
16
8
  </template>
17
9
  <script>
18
10
 
@@ -21,6 +13,7 @@ import { prefix } from '../common/config';
21
13
  import props from './props';
22
14
  import { ParentMixin, RELATION_MAP } from '../common/relation';
23
15
  import { coalesce } from '../common/utils';
16
+ import tools from '../common/utils.wxs';
24
17
 
25
18
  const name = `${prefix}-form`;
26
19
 
@@ -29,257 +22,279 @@ const needValidate = (name, fields) => {
29
22
  return fields.indexOf(`${name}`) !== -1;
30
23
  };
31
24
 
32
- export default uniComponent({
33
- name,
34
- options: {
35
- styleIsolation: 'shared',
36
- },
37
- externalClasses: [
38
- `${prefix}-class`,
39
- ],
40
- mixins: [ParentMixin(RELATION_MAP.FormItem)],
41
- props: {
42
- ...props,
43
- },
44
- data() {
45
- return {
46
- prefix,
47
- classPrefix: name,
48
- children: [],
49
- formData: {},
50
- initialData: {},
51
- fields: [],
52
- };
53
- },
54
- created() {
55
- this.initFormData();
56
- },
57
-
58
- methods: {
59
- // 初始化表单数据
60
- initFormData() {
61
- const { data } = this;
62
- // 确保 data 不为 undefined 或 null
63
- const safeData = data || {};
64
- const formData = { ...safeData };
65
- const initialData = { ...safeData };
66
- const fields = Object.keys(safeData);
67
-
68
- this.formData = formData;
69
- this.initialData = initialData;
70
- this.fields = fields;
25
+ export default {
26
+ ...uniComponent({
27
+ name,
28
+ options: {
29
+ styleIsolation: 'shared',
71
30
  },
72
-
73
- // 注册子组件
74
- registerChild(child) {
75
- const { children } = this;
76
- if (!children.find(item => item.name === child.name)) {
77
- children.push(child);
78
- this.children = children;
79
- }
31
+ externalClasses: [
32
+ `${prefix}-class`,
33
+ ],
34
+ mixins: [ParentMixin(RELATION_MAP.FormItem)],
35
+ props: {
36
+ ...props,
80
37
  },
81
-
82
- // 注销子组件
83
- unregisterChild(childName) {
84
- const { children } = this;
85
- const index = children.findIndex(item => item.name === childName);
86
- if (index > -1) {
87
- children.splice(index, 1);
88
- this.children = children;
89
- }
38
+ data() {
39
+ return {
40
+ prefix,
41
+ classPrefix: name,
42
+ formData: {},
43
+ initialData: {},
44
+ fields: [],
45
+ tools,
46
+ };
90
47
  },
91
-
92
- // 更新表单数据
93
- updateFormData(name, value) {
94
- const { formData } = this;
95
- formData[name] = value;
96
- this.formData = formData;
48
+ created() {
49
+ this.children = [];
50
+ this.initFormData();
97
51
  },
98
52
 
99
- // 验证表单
100
- async validate(params = {}) {
101
- const { fields, trigger = 'all' } = params;
102
- const showErrorMessage = coalesce(params.showErrorMessage, this.showErrorMessage);
53
+ methods: {
54
+ // 初始化表单数据
55
+ initFormData() {
56
+ const { data } = this;
57
+ // 确保 data 不为 undefined 或 null
58
+ const safeData = data || {};
59
+ const formData = { ...safeData };
60
+ const initialData = { ...safeData };
61
+ const fields = Object.keys(safeData);
62
+
63
+ this.formData = formData;
64
+ this.initialData = initialData;
65
+ this.fields = fields;
66
+ },
67
+
68
+ // 注册子组件
69
+ registerChild(child) {
70
+ const { children } = this;
71
+ if (!children.find(item => item.name === child.name)) {
72
+ children.push(child);
73
+ this.children = children;
74
+ }
75
+ },
76
+
77
+ // 注销子组件
78
+ unregisterChild(childName) {
79
+ const { children } = this;
80
+ const index = children.findIndex(item => item.name === childName);
81
+ if (index > -1) {
82
+ children.splice(index, 1);
83
+ this.children = children;
84
+ }
85
+ },
86
+
87
+ // 更新表单数据
88
+ updateFormData(name, value) {
89
+ const { formData } = this;
90
+ formData[name] = value;
91
+ this.formData = formData;
92
+ },
93
+
94
+ // 验证表单
95
+ async validate(params = {}) {
96
+ const { fields, trigger = 'all' } = params;
97
+ const showErrorMessage = coalesce(params.showErrorMessage, this.showErrorMessage);
98
+
99
+ const { children } = this;
100
+ const { data } = this;
101
+ const validatePromises = children
102
+ .filter(child => needValidate(`${child.name}`, fields))
103
+ .map(child => child.validate(data, trigger, showErrorMessage));
104
+
105
+ try {
106
+ const results = await Promise.all(validatePromises);
107
+ const validateResult = this.formatValidateResult(results);
108
+
109
+ if (validateResult !== true) {
110
+ this.scrollToError(validateResult);
111
+ }
103
112
 
104
- const { children } = this;
105
- const { data } = this;
106
- const validatePromises = children
107
- .filter(child => needValidate(`${child.name}`, fields))
108
- .map(child => child.validate(data, trigger, showErrorMessage));
113
+ this.$emit('validate', {
114
+ validateResult,
115
+ });
109
116
 
110
- try {
111
- const results = await Promise.all(validatePromises);
112
- const validateResult = this.formatValidateResult(results);
117
+ return validateResult;
118
+ } catch (error) {
119
+ return false;
120
+ }
121
+ },
113
122
 
114
- this.$emit('validate', {
115
- validateResult,
116
- });
123
+ // 滚动到第一个校验不通过的字段
124
+ scrollToError(validateResult) {
125
+ const { scrollToFirstError } = this;
126
+ if (!scrollToFirstError) return;
117
127
 
118
- return validateResult;
119
- } catch (error) {
120
- return false;
121
- }
122
- },
128
+ const firstErrorKey = Object.keys(validateResult)[0];
129
+ if (!firstErrorKey) return;
123
130
 
124
- // 纯净验证(不显示错误信息)
125
- async validateOnly(params) {
126
- const { fields, trigger = 'all' } = params;
127
- const { children } = this;
131
+ const { children } = this;
132
+ const errorChild = children.find(child => child.name === firstErrorKey);
133
+ if (!errorChild) return;
128
134
 
129
- const validatePromises = children
130
- .filter((child) => {
131
- if (fields && fields.length > 0) {
132
- return fields.includes(child.name);
133
- }
134
- return true;
135
- })
136
- .map(child => child.validateOnly(trigger));
137
-
138
- try {
139
- const results = await Promise.all(validatePromises);
140
- return this.formatValidateResult(results);
141
- } catch (error) {
142
- return false;
143
- }
144
- },
135
+ errorChild.scrollIntoView(scrollToFirstError);
136
+ },
137
+
138
+ // 纯净验证(不显示错误信息)
139
+ async validateOnly(params) {
140
+ const { fields, trigger = 'all' } = params;
141
+ const { children } = this;
145
142
 
146
- // 格式化验证结果
147
- formatValidateResult(validateResultList) {
148
- const result = {};
149
- let hasError = false;
150
-
151
- validateResultList.forEach((item) => {
152
- if (item && typeof item === 'object') {
153
- Object.keys(item).forEach((key) => {
154
- if (item[key] !== true) {
155
- result[key] = item[key];
156
- hasError = true;
143
+ const validatePromises = children
144
+ .filter((child) => {
145
+ if (fields && fields.length > 0) {
146
+ return fields.includes(child.name);
157
147
  }
158
- });
148
+ return true;
149
+ })
150
+ .map(child => child.validateOnly(trigger));
151
+
152
+ try {
153
+ const results = await Promise.all(validatePromises);
154
+ return this.formatValidateResult(results);
155
+ } catch (error) {
156
+ return false;
159
157
  }
160
- });
158
+ },
159
+
160
+ // 格式化验证结果
161
+ formatValidateResult(validateResultList) {
162
+ const result = {};
163
+ let hasError = false;
164
+
165
+ validateResultList.forEach((item) => {
166
+ if (item && typeof item === 'object') {
167
+ Object.keys(item).forEach((key) => {
168
+ if (item[key] !== true) {
169
+ result[key] = item[key];
170
+ hasError = true;
171
+ }
172
+ });
173
+ }
174
+ });
161
175
 
162
- return hasError ? result : true;
163
- },
176
+ return hasError ? result : true;
177
+ },
164
178
 
165
- // 获取第一个错误信息
166
- getFirstError(validateResult) {
167
- if (validateResult === true) return '';
168
- const firstKey = Object.keys(validateResult)[0];
169
- if (!firstKey) return '';
179
+ // 获取第一个错误信息
180
+ getFirstError(validateResult) {
181
+ if (validateResult === true) return '';
182
+ const firstKey = Object.keys(validateResult)[0];
183
+ if (!firstKey) return '';
170
184
 
171
- const errorList = validateResult[firstKey];
172
- if (Array.isArray(errorList) && errorList.length > 0) {
173
- return errorList[0].message || '';
174
- }
185
+ const errorList = validateResult[firstKey];
186
+ if (Array.isArray(errorList) && errorList.length > 0) {
187
+ return errorList[0].message || '';
188
+ }
175
189
 
176
- return '';
177
- },
190
+ return '';
191
+ },
178
192
 
179
- // 提交表单
180
- async submit(options) {
181
- try {
182
- const validateResult = await this.validate({
183
- showErrorMessage: coalesce(options?.showErrorMessage, this.showErrorMessage),
184
- });
185
- const firstError = this.getFirstError(validateResult);
186
- this.$emit('submit', {
187
- validateResult,
188
- firstError,
193
+ // 提交表单
194
+ async submit(options) {
195
+ try {
196
+ const validateResult = await this.validate({
197
+ showErrorMessage: coalesce(options?.showErrorMessage, this.showErrorMessage),
198
+ });
199
+ const firstError = this.getFirstError(validateResult);
200
+ this.$emit('submit', {
201
+ validateResult,
202
+ firstError,
203
+ });
204
+
205
+ return validateResult;
206
+ } catch (error) {
207
+ return false;
208
+ }
209
+ },
210
+ // 获取表单提交信息
211
+ async getValidate() {
212
+ try {
213
+ const validateResult = await this.validate();
214
+ const firstError = this.getFirstError(validateResult);
215
+ // this.$emit('getFormData', {
216
+ // validateResult,
217
+ // firstError,
218
+ // });
219
+
220
+ return { validateResult, firstError };
221
+ } catch (error) {
222
+ return false;
223
+ }
224
+ },
225
+ // 重置表单
226
+ reset(params = {}) {
227
+ const { fields } = params;
228
+ const resetType = coalesce(params.resetType, this.resetType);
229
+ const { children, initialData, formData } = this;
230
+
231
+ children
232
+ .filter(child => needValidate(`${child.name}`, fields))
233
+ .forEach((child) => {
234
+ if (resetType === 'empty') {
235
+ this.updateFormData(child.name, this.getEmptyValue(child.name));
236
+ } else if (resetType === 'initial') {
237
+ this.updateFormData(child.name, initialData[child.name]);
238
+ }
239
+ child.resetField();
240
+ });
241
+
242
+ this.$emit('reset', {
243
+ formData,
189
244
  });
245
+ },
190
246
 
191
- return validateResult;
192
- } catch (error) {
193
- return false;
194
- }
195
- },
196
- // 获取表单提交信息
197
- async getValidate() {
198
- try {
199
- const validateResult = await this.validate();
200
- const firstError = this.getFirstError(validateResult);
201
- // this.$emit('getFormData', {
202
- // validateResult,
203
- // firstError,
204
- // });
205
-
206
- return { validateResult, firstError };
207
- } catch (error) {
208
- return false;
209
- }
210
- },
211
- // 重置表单
212
- reset(params = {}) {
213
- const { fields } = params;
214
- const resetType = coalesce(params.resetType, this.resetType);
215
- const { children, initialData, formData } = this;
216
-
217
- children
218
- .filter(child => needValidate(`${child.name}`, fields))
219
- .forEach((child) => {
220
- if (resetType === 'empty') {
221
- this.updateFormData(child.name, this.getEmptyValue(child.name));
222
- } else if (resetType === 'initial') {
223
- this.updateFormData(child.name, initialData[child.name]);
247
+ // 清空验证结果
248
+ clearValidate(fields) {
249
+ const { children } = this;
250
+
251
+ children.forEach((child) => {
252
+ if (!fields || fields.includes(child.name)) {
253
+ child.clearValidate();
224
254
  }
225
- child.resetField();
226
255
  });
256
+ },
227
257
 
228
- this.$emit('reset', {
229
- formData,
230
- });
231
- },
232
-
233
- // 清空验证结果
234
- clearValidate(fields) {
235
- const { children } = this;
258
+ // 设置验证信息
259
+ setValidateMessage(validateMessage) {
260
+ const { children } = this;
236
261
 
237
- children.forEach((child) => {
238
- if (!fields || fields.includes(child.name)) {
239
- child.clearValidate();
240
- }
241
- });
242
- },
262
+ children.forEach((child) => {
263
+ if (validateMessage[child.name]) {
264
+ child.setValidateMessage(validateMessage[child.name]);
265
+ }
266
+ });
267
+ },
243
268
 
244
- // 设置验证信息
245
- setValidateMessage(validateMessage) {
246
- const { children } = this;
269
+ // 获取空值
270
+ getEmptyValue(name) {
271
+ const { formData } = this;
272
+ const currentValue = formData[name];
247
273
 
248
- children.forEach((child) => {
249
- if (validateMessage[child.name]) {
250
- child.setValidateMessage(validateMessage[child.name]);
274
+ if (Array.isArray(currentValue)) {
275
+ return [];
251
276
  }
252
- });
253
- },
254
-
255
- // 获取空值
256
- getEmptyValue(name) {
257
- const { formData } = this;
258
- const currentValue = formData[name];
259
-
260
- if (Array.isArray(currentValue)) {
261
- return [];
262
- }
263
- if (typeof currentValue === 'object' && currentValue !== null) {
264
- return {};
265
- }
266
- if (typeof currentValue === 'number') {
267
- return 0;
268
- }
269
- return '';
270
- },
271
-
272
- // 表单提交事件处理
273
- onSubmit() {
274
- this.submit();
275
- },
276
-
277
- // 表单重置事件处理
278
- onReset() {
279
- this.reset();
277
+ if (typeof currentValue === 'object' && currentValue !== null) {
278
+ return {};
279
+ }
280
+ if (typeof currentValue === 'number') {
281
+ return 0;
282
+ }
283
+ return '';
284
+ },
285
+
286
+ // 表单提交事件处理
287
+ onSubmit() {
288
+ this.submit();
289
+ },
290
+
291
+ // 表单重置事件处理
292
+ onReset() {
293
+ this.reset();
294
+ },
280
295
  },
281
- },
282
- });
296
+ }),
297
+ };
283
298
 
284
299
  </script>
285
300
  <style scoped src="./form.css"></style>
@@ -8,25 +8,11 @@ import type { TdFormProps } from './type';
8
8
  export default {
9
9
  /** 是否在表单标签字段右侧显示冒号 */
10
10
  colon: Boolean,
11
- /** 表单内容对齐方式:左对齐、右对齐 */
12
- contentAlign: {
13
- type: String,
14
- default: 'left' as TdFormProps['contentAlign'],
15
- validator(val: TdFormProps['contentAlign']): boolean {
16
- if (!val) return true;
17
- return ['left', 'right'].includes(val);
18
- },
19
- },
20
11
  /** 表单数据 */
21
12
  data: {
22
13
  type: Object,
23
14
  default: () => ({}),
24
15
  },
25
- /** 是否禁用整个表单 */
26
- disabled: {
27
- type: Boolean,
28
- default: undefined,
29
- },
30
16
  /** 表单错误信息配置,示例:`{ idcard: '请输入正确的身份证号码', max: '字符长度不能超过 ${max}' }` */
31
17
  errorMessage: {
32
18
  type: Object,
@@ -45,15 +31,10 @@ export default {
45
31
  type: [String, Number],
46
32
  default: '81px' as TdFormProps['labelWidth'],
47
33
  },
48
- /** 是否整个表单只读 */
49
- readonly: {
50
- type: Boolean,
51
- default: undefined,
52
- },
53
34
  /** 是否显示必填符号(*),默认显示 */
54
35
  requiredMark: {
55
- type: Boolean,
56
- default: undefined,
36
+ type: [Boolean, null],
37
+ default: null as TdFormProps['requiredMark'],
57
38
  },
58
39
  /** 表单必填符号(*)显示位置 */
59
40
  requiredMarkPosition: {