@ebiz/designer-components 0.1.78 → 0.1.80

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 (219) hide show
  1. package/README.md +29 -29
  2. package/dist/designer-components.css +1 -1
  3. package/dist/index.mjs +20746 -20703
  4. package/package.json +1 -1
  5. package/src/App.vue +26 -26
  6. package/src/apiService/SIMPLE_DATA_SERVICE.md +284 -284
  7. package/src/apiService/mockDataService.js +115 -115
  8. package/src/apiService/simpleDataService.js +299 -299
  9. package/src/assets/base.css +86 -86
  10. package/src/assets/logo.svg +1 -1
  11. package/src/components/Button.vue +149 -149
  12. package/src/components/DataContainer.vue +40 -40
  13. package/src/components/EbizApproval.vue +335 -335
  14. package/src/components/EbizApprovalForm.vue +507 -507
  15. package/src/components/EbizAutoForm.vue +596 -596
  16. package/src/components/EbizAvatar.vue +115 -115
  17. package/src/components/EbizCheckbox.vue +93 -93
  18. package/src/components/EbizCheckboxGroup.vue +69 -69
  19. package/src/components/EbizDepartmentSelector.vue +149 -149
  20. package/src/components/EbizDescriptions.vue +340 -340
  21. package/src/components/EbizDescriptionsItem.vue +47 -47
  22. package/src/components/EbizDetailBlock.vue +81 -81
  23. package/src/components/EbizDetailItem.vue +559 -559
  24. package/src/components/EbizDetailView.md +438 -438
  25. package/src/components/EbizDetailView.vue +355 -355
  26. package/src/components/EbizDialog.vue +260 -260
  27. package/src/components/EbizDiv.vue +40 -40
  28. package/src/components/EbizDivider.vue +96 -96
  29. package/src/components/EbizDropdown.vue +135 -135
  30. package/src/components/EbizDropdownItem.vue +85 -85
  31. package/src/components/EbizEmployeeInfo.vue +138 -138
  32. package/src/components/EbizEmployeeSelector.vue +1159 -1159
  33. package/src/components/EbizFileList.vue +466 -466
  34. package/src/components/EbizMap.vue +541 -541
  35. package/src/components/EbizMeetingRoomSelector.vue +664 -664
  36. package/src/components/EbizMobileMeetingRoomSelector.vue +727 -727
  37. package/src/components/EbizOkrTree.vue +99 -99
  38. package/src/components/EbizPageHeader.vue +95 -95
  39. package/src/components/EbizPagination.vue +162 -162
  40. package/src/components/EbizPdfViewer.vue +540 -540
  41. package/src/components/EbizPopconfirm.vue +47 -47
  42. package/src/components/EbizQrCode.vue +73 -73
  43. package/src/components/EbizRadio.vue +86 -86
  44. package/src/components/EbizRadioGroup.vue +83 -83
  45. package/src/components/EbizRemoteSelect.vue +232 -232
  46. package/src/components/EbizRichTextEditor.vue +275 -275
  47. package/src/components/EbizRouteBreadcrumb.vue +46 -46
  48. package/src/components/EbizSApprovalProcess.vue +1429 -1429
  49. package/src/components/EbizSelect.vue +85 -85
  50. package/src/components/EbizSpace.vue +100 -100
  51. package/src/components/EbizStatistic.vue +149 -149
  52. package/src/components/EbizStatsCard.vue +113 -113
  53. package/src/components/EbizSwiper.vue +113 -113
  54. package/src/components/EbizSwiperItem.vue +13 -13
  55. package/src/components/EbizSwitch.vue +85 -85
  56. package/src/components/EbizTabHeader.vue +132 -132
  57. package/src/components/EbizTabPanel.vue +22 -22
  58. package/src/components/EbizTable.vue +469 -469
  59. package/src/components/EbizTableColumn.vue +116 -116
  60. package/src/components/EbizTableSort.vue +179 -179
  61. package/src/components/EbizTabs.vue +142 -142
  62. package/src/components/EbizTdesignButtonDialog.vue +332 -332
  63. package/src/components/EbizTdesignLoading.vue +107 -107
  64. package/src/components/EbizTimePicker.vue +143 -143
  65. package/src/components/EbizTitle.vue +91 -91
  66. package/src/components/EbizTree.vue +141 -141
  67. package/src/components/EbizTreeMergeTable.vue +1494 -1494
  68. package/src/components/EbizTreeSelector.vue +418 -418
  69. package/src/components/EbizVideo.vue +553 -553
  70. package/src/components/EbizVxeTable.vue +290 -290
  71. package/src/components/Form.vue +28 -28
  72. package/src/components/Home.vue +7 -7
  73. package/src/components/MyComponent.vue +39 -39
  74. package/src/components/Table.vue +45 -45
  75. package/src/components/TdesignAlert.vue +115 -115
  76. package/src/components/TdesignButton.vue +135 -135
  77. package/src/components/TdesignCalendar/index.vue +145 -145
  78. package/src/components/TdesignCard.vue +195 -195
  79. package/src/components/TdesignCol.vue +101 -101
  80. package/src/components/TdesignCollapse.vue +142 -142
  81. package/src/components/TdesignCollapsePanel.vue +79 -79
  82. package/src/components/TdesignDatePicker.vue +124 -124
  83. package/src/components/TdesignDescriptions.vue +74 -74
  84. package/src/components/TdesignDescriptionsItem.vue +50 -50
  85. package/src/components/TdesignDialog.vue +225 -225
  86. package/src/components/TdesignForm.vue +138 -138
  87. package/src/components/TdesignFormItem.vue +105 -105
  88. package/src/components/TdesignGrid.vue +55 -55
  89. package/src/components/TdesignIcon.vue +67 -67
  90. package/src/components/TdesignImage.vue +162 -162
  91. package/src/components/TdesignImageViewer.vue +200 -200
  92. package/src/components/TdesignInput.vue +242 -242
  93. package/src/components/TdesignSelect.vue +446 -446
  94. package/src/components/TdesignTag.vue +117 -117
  95. package/src/components/TdesignTextarea.vue +142 -142
  96. package/src/components/TdesignTimeline.vue +58 -58
  97. package/src/components/TdesignTimelineItem.vue +71 -71
  98. package/src/components/TdesignUpload.vue +414 -414
  99. package/src/components/TdesignWatermark.vue +107 -107
  100. package/src/components/ebiz-form/components/cascader.vue +61 -61
  101. package/src/components/ebiz-form/components/checkbox.vue +37 -37
  102. package/src/components/ebiz-form/components/city.vue +137 -137
  103. package/src/components/ebiz-form/components/date-panel.vue +52 -52
  104. package/src/components/ebiz-form/components/date-range-panel.vue +52 -52
  105. package/src/components/ebiz-form/components/date-range.vue +56 -56
  106. package/src/components/ebiz-form/components/date.vue +52 -52
  107. package/src/components/ebiz-form/components/editor-multi-language.vue +47 -47
  108. package/src/components/ebiz-form/components/editor.vue +78 -78
  109. package/src/components/ebiz-form/components/file-multi-language.vue +52 -52
  110. package/src/components/ebiz-form/components/file.vue +149 -149
  111. package/src/components/ebiz-form/components/images-multi-language.vue +52 -52
  112. package/src/components/ebiz-form/components/images.vue +129 -129
  113. package/src/components/ebiz-form/components/img-multi-language.vue +51 -51
  114. package/src/components/ebiz-form/components/img.vue +129 -129
  115. package/src/components/ebiz-form/components/number.vue +50 -50
  116. package/src/components/ebiz-form/components/radio.vue +28 -28
  117. package/src/components/ebiz-form/components/select.vue +119 -119
  118. package/src/components/ebiz-form/components/switch.vue +23 -23
  119. package/src/components/ebiz-form/components/text-multi-language.vue +47 -47
  120. package/src/components/ebiz-form/components/text.vue +52 -52
  121. package/src/components/ebiz-form/components/textarea-multi-language.vue +48 -48
  122. package/src/components/ebiz-form/components/textarea.vue +29 -29
  123. package/src/components/ebiz-form/components/video-multi-language.vue +51 -51
  124. package/src/components/ebiz-form/components/video.vue +97 -97
  125. package/src/components/ebiz-form/index.vue +157 -157
  126. package/src/components/examples/PopconfirmExample.vue +149 -149
  127. package/src/components/icons/IconCommunity.vue +7 -7
  128. package/src/components/icons/IconDocumentation.vue +7 -7
  129. package/src/components/icons/IconEcosystem.vue +7 -7
  130. package/src/components/icons/IconSupport.vue +7 -7
  131. package/src/components/icons/IconTooling.vue +19 -19
  132. package/src/components/mItems/UserInfo.vue +342 -342
  133. package/src/components/senior/EbizSData/index.vue +273 -273
  134. package/src/components/senior/EbizSDialog/index.vue +770 -772
  135. package/src/components/senior/EbizSForm/README.md +157 -157
  136. package/src/components/senior/EbizSForm/index.vue +667 -667
  137. package/src/components/senior/EbizSForm/item.vue +971 -971
  138. package/src/components/senior/EbizSForm/mItems/DateTimePicker.vue +51 -51
  139. package/src/components/senior/EbizSForm/mItems/Picker.vue +63 -63
  140. package/src/index.js +255 -255
  141. package/src/main.js +55 -55
  142. package/src/router/index.js +415 -415
  143. package/src/utils/formatCode.js +24 -24
  144. package/src/utils/generateImportStatement.js +52 -52
  145. package/src/utils/hasJsx.js +25 -25
  146. package/src/utils/index.js +166 -166
  147. package/src/utils/mergeOptions.js +29 -29
  148. package/src/utils/parseRequiredBlocks.js +18 -18
  149. package/src/utils/vue-sfc-validator.js +155 -155
  150. package/src/views/Button.vue +23 -23
  151. package/src/views/CheckboxDemo.vue +104 -104
  152. package/src/views/DataContainer.vue +19 -19
  153. package/src/views/DialogDemo.vue +125 -125
  154. package/src/views/EbizApprovalDemo.vue +87 -87
  155. package/src/views/EbizApprovalFormDemo.vue +207 -207
  156. package/src/views/EbizAutoFormDemo.vue +129 -129
  157. package/src/views/EbizAvatar.vue +223 -223
  158. package/src/views/EbizDepartmentSelectorDemo.vue +169 -169
  159. package/src/views/EbizDetailBlockDemo.vue +30 -30
  160. package/src/views/EbizDetailViewDemo.vue +412 -412
  161. package/src/views/EbizEmployeeInfo.vue +249 -249
  162. package/src/views/EbizEmployeeSelector.vue +85 -85
  163. package/src/views/EbizFileListDemo.vue +339 -339
  164. package/src/views/EbizMap.vue +201 -201
  165. package/src/views/EbizMeetingRoomSelectorDemo.vue +293 -293
  166. package/src/views/EbizMobileMeetingRoomSelectorDemo.vue +566 -566
  167. package/src/views/EbizRadioDemo.vue +151 -151
  168. package/src/views/EbizSDataDemo.vue +136 -136
  169. package/src/views/EbizSDialogDemo.vue +303 -303
  170. package/src/views/EbizSForm/index.vue +351 -351
  171. package/src/views/EbizSFormDemo.vue +420 -420
  172. package/src/views/EbizSpace.vue +185 -185
  173. package/src/views/EbizSwiper.vue +157 -157
  174. package/src/views/EbizTdesignButtonDialogExample.vue +437 -437
  175. package/src/views/Form.vue +19 -19
  176. package/src/views/GridDemo.vue +238 -238
  177. package/src/views/Home.vue +153 -153
  178. package/src/views/Mindmap.vue +17 -17
  179. package/src/views/MyComponent.vue +19 -19
  180. package/src/views/OkrTree.vue +19 -19
  181. package/src/views/PageHeaderDemo.vue +104 -104
  182. package/src/views/PaginationDemo.vue +96 -96
  183. package/src/views/PdfViewerDemo.vue +433 -433
  184. package/src/views/PermissionBoxDemo.vue +85 -85
  185. package/src/views/PopconfirmDemo.vue +80 -80
  186. package/src/views/RemoteSelect.vue +350 -350
  187. package/src/views/StatisticDemo.vue +190 -190
  188. package/src/views/SwitchDemo.vue +79 -79
  189. package/src/views/Table.vue +19 -19
  190. package/src/views/TableDemo.vue +334 -334
  191. package/src/views/TableSortDemo.vue +143 -143
  192. package/src/views/TableView.vue +68 -68
  193. package/src/views/TabsDemo.vue +282 -282
  194. package/src/views/TagDemo.vue +101 -101
  195. package/src/views/TdesignAlert.vue +98 -98
  196. package/src/views/TdesignButton.vue +190 -190
  197. package/src/views/TdesignCalendar.vue +94 -94
  198. package/src/views/TdesignCard.vue +296 -296
  199. package/src/views/TdesignCollapse.vue +293 -293
  200. package/src/views/TdesignDatePicker.vue +187 -187
  201. package/src/views/TdesignDescriptions.vue +101 -101
  202. package/src/views/TdesignForm.vue +248 -248
  203. package/src/views/TdesignIcon.vue +203 -203
  204. package/src/views/TdesignImage.vue +215 -215
  205. package/src/views/TdesignImageViewer.vue +198 -198
  206. package/src/views/TdesignInput.vue +252 -252
  207. package/src/views/TdesignSelect.vue +473 -473
  208. package/src/views/TdesignSwiper.vue +157 -157
  209. package/src/views/TextareaDemo.vue +93 -93
  210. package/src/views/TimePickerDemo.vue +146 -146
  211. package/src/views/TimelineDemo.vue +160 -160
  212. package/src/views/Title.vue +19 -19
  213. package/src/views/TreeDemo.vue +254 -254
  214. package/src/views/TreeMergeTableDemo.vue +239 -239
  215. package/src/views/TreeSelectorDemo.vue +245 -245
  216. package/src/views/UploadDemo.vue +128 -128
  217. package/src/views/VideoDemo.vue +245 -245
  218. package/src/views/VxeTableDemo.vue +279 -279
  219. package/src/views/WatermarkDemo.vue +85 -85
@@ -1,668 +1,668 @@
1
- <template>
2
- <t-form ref="formRef" :class="['ebiz-s-form', className]" :colon="colon" :data="localFormData" :disabled="disabled"
3
- :label-align="labelAlign" :label-width="labelWidth" :layout="layout" :reset-type="resetType"
4
- :reset-on-semi-controlled="resetOnSemiControlled" :rules="formRules" :scroll-to-first-error="scrollToFirstError"
5
- :show-error-message="showErrorMessage" :status-icon="statusIcon" :style="customStyle" @reset="handleReset"
6
- @submit="handleSubmit" @validate="handleValidate">
7
-
8
- <slot :formData="localFormData"></slot>
9
-
10
- <ebiz-s-form-item label=" ">
11
- <slot name="buttons">
12
- <t-space>
13
- <t-button v-if="showCancelButton" :theme="cancelButtonTheme" type="reset" :loading="loading"
14
- :disabled="loading || disabled">{{
15
- cancelButtonText
16
- }}</t-button>
17
- <t-button v-if="showSubmitButton" theme="primary" :loading="loading" :disabled="loading || disabled"
18
- type="submit">{{
19
- submitButtonText }}</t-button>
20
- </t-space>
21
- </slot>
22
- </ebiz-s-form-item>
23
- </t-form>
24
- </template>
25
-
26
- <script>
27
- /**
28
- * @displayName PC端表单
29
- * @description PC端表单组件,基于TDesign Form封装,支持表单验证、API提交等功能
30
- * @category 表单组件
31
- * @name EbizSForm
32
- */
33
- export default {
34
- name: "EbizSForm"
35
- }
36
- </script>
37
-
38
- <script setup>
39
- import { defineProps, defineEmits, ref, watch, computed } from 'vue';
40
- import { Form as TForm, Button as TButton, Space as TSpace, MessagePlugin } from 'tdesign-vue-next';
41
- import dataService from "../../../apiService/simpleDataService";
42
- import EbizSFormItem from './item.vue';
43
-
44
- const props = defineProps({
45
- /**
46
- * 表单数据对象
47
- */
48
- data: {
49
- type: Object,
50
- default: () => ({})
51
- },
52
- /**
53
- * 表单域标签的位置
54
- * @options left|right|top
55
- */
56
- labelAlign: {
57
- type: String,
58
- default: 'right',
59
- validator: (val) => ['left', 'right', 'top'].includes(val)
60
- },
61
- /**
62
- * 表单布局
63
- * @options vertical|inline
64
- */
65
- layout: {
66
- type: String,
67
- default: 'vertical',
68
- validator: (val) => ['vertical', 'inline'].includes(val)
69
- },
70
- /**
71
- * 是否显示必填标记
72
- */
73
- colon: {
74
- type: Boolean,
75
- default: false
76
- },
77
- /**
78
- * 是否禁用整个表单
79
- */
80
- disabled: {
81
- type: Boolean,
82
- default: false
83
- },
84
- /**
85
- * 表单域标签的宽度
86
- */
87
- labelWidth: {
88
- type: [String, Number],
89
- default: '100px'
90
- },
91
- /**
92
- * 表单校验规则
93
- */
94
- rules: {
95
- type: Object,
96
- default: () => ({})
97
- },
98
- /**
99
- * 是否显示校验错误信息
100
- */
101
- showErrorMessage: {
102
- type: Boolean,
103
- default: true
104
- },
105
- /**
106
- * 是否显示校验图标
107
- */
108
- statusIcon: {
109
- type: Boolean,
110
- default: false
111
- },
112
- /**
113
- * 表单重置时的方式
114
- * @options empty|initial
115
- */
116
- resetType: {
117
- type: String,
118
- default: 'empty',
119
- validator: (val) => ['empty', 'initial'].includes(val)
120
- },
121
- /**
122
- * 重置时是否清空所有非受控字段
123
- */
124
- resetOnSemiControlled: {
125
- type: Boolean,
126
- default: false
127
- },
128
- /**
129
- * 表单校验不通过时,是否自动定位到第一个错误字段
130
- */
131
- scrollToFirstError: {
132
- type: Boolean,
133
- default: true
134
- },
135
- /**
136
- * 自定义样式
137
- */
138
- customStyle: {
139
- type: [String, Object],
140
- default: ''
141
- },
142
- /**
143
- * 自定义类名
144
- */
145
- className: {
146
- type: String,
147
- default: ''
148
- },
149
- /**
150
- * 是否显示表单按钮(提交和取消)
151
- */
152
- showButtons: {
153
- type: Boolean,
154
- default: true
155
- },
156
- /**
157
- * 是否显示提交按钮
158
- */
159
- showSubmitButton: {
160
- type: Boolean,
161
- default: true
162
- },
163
- /**
164
- * 提交按钮文字
165
- */
166
- submitButtonText: {
167
- type: String,
168
- default: '提交'
169
- },
170
- /**
171
- * 是否显示取消按钮
172
- */
173
- showCancelButton: {
174
- type: Boolean,
175
- default: true
176
- },
177
- /**
178
- * 取消按钮文字
179
- */
180
- cancelButtonText: {
181
- type: String,
182
- default: '取消'
183
- },
184
- /**
185
- * 取消按钮主题
186
- */
187
- cancelButtonTheme: {
188
- type: String,
189
- default: 'default'
190
- },
191
- /**
192
- * API配置,用于表单提交
193
- */
194
- apiConfig: {
195
- type: Object,
196
- default: () => null
197
- },
198
- /**
199
- * 详情API配置,用于加载表单数据
200
- */
201
- detailApiConfig: {
202
- type: Object,
203
- default: () => null
204
- },
205
- /**
206
- * 是否在提交成功后重置表单
207
- */
208
- resetOnSuccess: {
209
- type: Boolean,
210
- default: false
211
- },
212
- /**
213
- * 提交成功后的消息提示
214
- */
215
- successMessage: {
216
- type: String,
217
- default: '提交成功'
218
- },
219
- /**
220
- * 提交失败后的消息提示
221
- */
222
- errorMessage: {
223
- type: String,
224
- default: '提交失败'
225
- },
226
- /**
227
- * 是否显示提交结果消息
228
- */
229
- showResultMessage: {
230
- type: Boolean,
231
- default: true
232
- }
233
- });
234
-
235
- const emit = defineEmits([
236
- 'reset',
237
- 'submit',
238
- 'validate',
239
- 'success',
240
- 'error',
241
- 'cancel',
242
- 'detail-loaded',
243
- 'detail-error'
244
- ]);
245
-
246
- const formRef = ref(null);
247
- const loading = ref(false);
248
- const currentId = ref(null);
249
- const currentParams = ref({});
250
- const localFormData = ref(props.data || {});
251
-
252
- // 合并rules并监听变化
253
- const formRules = computed(() => props.rules);
254
-
255
- // 监听props的data变化,同步到localFormData
256
- watch(() => props.data, (newData) => {
257
- // 如果外部传入的数据变化,同步更新本地数据
258
- if (newData && typeof newData === 'object') {
259
- // 清空现有数据
260
- Object.keys(localFormData.value).forEach(key => {
261
- delete localFormData.value[key];
262
- });
263
-
264
- // 写入新数据
265
- Object.keys(newData).forEach(key => {
266
- localFormData.value[key] = newData[key];
267
- });
268
- }
269
- }, { deep: true });
270
-
271
- /**
272
- * 获取错误消息
273
- * @param {Error} error 错误对象
274
- * @param {string} prefix 错误消息前缀
275
- * @returns {string} 格式化后的错误消息
276
- */
277
- const getErrorMessage = (error, prefix = '提交失败') => {
278
- if (!error) return `${prefix}: 未知错误`;
279
-
280
- // 处理不同类型的错误
281
- if (error.response && error.response.data) {
282
- // API返回的详细错误信息
283
- const { message, msg, error: errMsg } = error.response.data;
284
- return `${prefix}: ${message || msg || errMsg || error.message || '服务器返回错误'}`;
285
- } else if (error.message) {
286
- // 标准错误对象
287
- return `${prefix}: ${error.message}`;
288
- } else if (typeof error === 'string') {
289
- // 字符串错误
290
- return `${prefix}: ${error}`;
291
- } else {
292
- // 未知错误
293
- return `${prefix}: 未知错误`;
294
- }
295
- };
296
-
297
- /**
298
- * 调用API提交表单数据
299
- */
300
- const submitFormData = async () => {
301
- try {
302
- loading.value = true;
303
-
304
- // 准备请求参数
305
- const fetchParams = { ...localFormData.value };
306
-
307
- // 如果有ID,添加到请求参数中
308
- if (currentId.value) {
309
- fetchParams.id = currentId.value;
310
- }
311
-
312
- // 合并当前参数到请求参数
313
- if (currentParams.value && Object.keys(currentParams.value).length > 0) {
314
- Object.keys(currentParams.value).forEach(key => {
315
- fetchParams[key] = currentParams.value[key];
316
- });
317
- }
318
-
319
- // 直接使用 apiConfig,不做任何处理
320
- const response = await dataService.fetch({ saveData: { ...fetchParams } }, props.apiConfig);
321
-
322
- // 直接使用响应数据
323
- const transformedResponse = response;
324
- if (props.showResultMessage) {
325
- MessagePlugin.success(props.successMessage);
326
- }
327
-
328
- emit('success', transformedResponse);
329
-
330
- if (props.resetOnSuccess && formRef.value) {
331
- formRef.value.reset();
332
- }
333
-
334
- return transformedResponse;
335
- } catch (error) {
336
- if (props.showResultMessage) {
337
- const errorMsg = getErrorMessage(error, props.errorMessage);
338
- MessagePlugin.error(errorMsg);
339
- }
340
-
341
- emit('error', error);
342
- return null;
343
- } finally {
344
- loading.value = false;
345
- }
346
- };
347
-
348
- /**
349
- * 表单重置
350
- * @param {Object} context 表单上下文
351
- */
352
- const handleReset = (context) => {
353
- emit('reset', context);
354
- };
355
-
356
- /**
357
- * 表单验证
358
- * @param {Object} result 表单验证结果
359
- */
360
- const handleValidate = (result) => {
361
- emit('validate', result);
362
- };
363
-
364
- /**
365
- * 表单提交事件,由内置的HTML表单submit事件触发
366
- */
367
- const handleSubmit = async (_context) => {
368
- try {
369
- if (!formRef.value) return;
370
-
371
- const validateResult = await formRef.value.validate();
372
-
373
- if (validateResult !== true) {
374
- // 获取第一个错误信息
375
- const firstKey = Object.keys(validateResult)[0];
376
- const firstError = validateResult[firstKey]?.[0]?.message || '表单验证失败';
377
-
378
- if (props.showResultMessage) {
379
- MessagePlugin.error(firstError);
380
- }
381
-
382
- emit('error', { validateResult, firstError });
383
- return;
384
- }
385
-
386
- emit('submit', localFormData.value);
387
-
388
- if (props.apiConfig) {
389
- await submitFormData();
390
- }
391
- } catch (error) {
392
- if (props.showResultMessage) {
393
- MessagePlugin.error(getErrorMessage(error));
394
- }
395
-
396
- emit('error', error);
397
- }
398
- };
399
-
400
- /**
401
- * 加载详情数据
402
- * @param {string|number} id 记录ID
403
- */
404
- const loadDetailData = async (id) => {
405
- if (!props.detailApiConfig || !id) return null;
406
-
407
- try {
408
- loading.value = true;
409
-
410
- // 准备请求参数
411
- const fetchParams = { id };
412
-
413
- // 合并当前参数到请求参数
414
- if (currentParams.value && Object.keys(currentParams.value).length > 0) {
415
- Object.keys(currentParams.value).forEach(key => {
416
- fetchParams[key] = currentParams.value[key];
417
- });
418
- }
419
-
420
- // 调用dataService进行API请求,直接使用detailApiConfig
421
- const response = await dataService.fetch(fetchParams, props.detailApiConfig);
422
-
423
- // 获取详情数据
424
- const detailData = response.data || response;
425
-
426
- // 更新本地表单数据
427
- if (detailData) {
428
- // 清空现有数据
429
- Object.keys(localFormData.value).forEach(key => {
430
- delete localFormData.value[key];
431
- });
432
-
433
- // 写入新数据
434
- Object.keys(detailData).forEach(key => {
435
- localFormData.value[key] = detailData[key];
436
- });
437
- }
438
-
439
- // 触发加载成功事件
440
- emit('detail-loaded', detailData);
441
- return detailData;
442
- } catch (error) {
443
- // 显示错误消息
444
- if (props.showResultMessage) {
445
- MessagePlugin.error(`加载详情失败: ${error.message || '未知错误'}`);
446
- }
447
-
448
- // 触发错误事件
449
- emit('detail-error', error);
450
- return null;
451
- } finally {
452
- loading.value = false;
453
- }
454
- };
455
-
456
- /**
457
- * 打开表单并设置参数
458
- * @param {Object} params 表单参数
459
- */
460
- const openForm = (params = {}) => {
461
- // 处理传入的表单数据
462
- if (params.formData) {
463
- // 清空现有数据
464
- Object.keys(localFormData.value).forEach(key => {
465
- delete localFormData.value[key];
466
- });
467
-
468
- // 写入新数据
469
- Object.keys(params.formData).forEach(key => {
470
- localFormData.value[key] = params.formData[key];
471
- });
472
- } else if (params.clearData) {
473
- // 如果要求清空数据
474
- Object.keys(localFormData.value).forEach(key => {
475
- delete localFormData.value[key];
476
- });
477
- }
478
-
479
- // 存储ID
480
- if (params.id) {
481
- currentId.value = params.id;
482
-
483
- // 如果有detailApiConfig,加载详情数据
484
- if (props.detailApiConfig) {
485
- loadDetailData(params.id);
486
- }
487
- } else {
488
- currentId.value = null;
489
- }
490
-
491
- // 存储其他自定义参数
492
- currentParams.value = params;
493
-
494
- return { success: true, message: '表单已准备就绪' };
495
- };
496
-
497
- /**
498
- * 设置表单数据
499
- * @param {Object} data 要设置的数据
500
- */
501
- const setFormData = (data) => {
502
- if (!data || typeof data !== 'object') {
503
- return { success: false, message: '数据必须是一个对象' };
504
- }
505
-
506
- // 清空现有数据
507
- Object.keys(localFormData.value).forEach(key => {
508
- delete localFormData.value[key];
509
- });
510
-
511
- // 写入新数据
512
- Object.keys(data).forEach(key => {
513
- localFormData.value[key] = data[key];
514
- });
515
-
516
- return { success: true, message: '表单数据已设置' };
517
- };
518
-
519
- /**
520
- * 获取表单数据
521
- */
522
- const getFormData = () => {
523
- return { ...localFormData.value };
524
- };
525
-
526
- /**
527
- * 清空表单数据
528
- */
529
- const clearFormData = () => {
530
- // 清空表单数据
531
- Object.keys(localFormData.value).forEach(key => {
532
- delete localFormData.value[key];
533
- });
534
-
535
- emit('reset', { type: 'clear' });
536
- return { success: true, message: '表单数据已清空' };
537
- };
538
-
539
- /**
540
- * 提交表单
541
- */
542
- const submitForm = async () => {
543
- try {
544
- if (!formRef.value) {
545
- return { success: false, message: '表单引用不存在' };
546
- }
547
-
548
- const validateResult = await formRef.value.validate();
549
-
550
- if (validateResult === true) {
551
- emit('submit', localFormData.value);
552
-
553
- if (props.apiConfig) {
554
- const response = await submitFormData();
555
- return { success: true, message: '提交成功', data: response };
556
- }
557
-
558
- return { success: true, message: '表单验证通过', data: { ...localFormData.value } };
559
- } else {
560
- const firstKey = Object.keys(validateResult)[0];
561
- const firstError = validateResult[firstKey]?.[0]?.message || '表单验证失败';
562
-
563
- return { success: false, message: firstError, errors: validateResult };
564
- }
565
- } catch (error) {
566
- return { success: false, message: error.message || '提交过程中发生错误' };
567
- }
568
- };
569
-
570
- // 暴露方法给父组件
571
- defineExpose({
572
- /**
573
- * 提交表单方法
574
- */
575
- submit: submitForm,
576
- /**
577
- * 重置表单方法
578
- */
579
- reset: () => {
580
- if (formRef.value) {
581
- formRef.value.reset();
582
- }
583
- },
584
- /**
585
- * 校验表单方法
586
- * @returns {Promise} 校验结果Promise
587
- */
588
- validate: async () => {
589
- if (formRef.value) {
590
- return await formRef.value.validate();
591
- }
592
- return false;
593
- },
594
- /**
595
- * 校验特定字段
596
- * @param {Array|String} fields 字段名称或字段名称数组
597
- * @returns {Promise} 校验结果Promise
598
- */
599
- validateFields: async (fields) => {
600
- if (formRef.value) {
601
- return await formRef.value.validateFields(fields);
602
- }
603
- return false;
604
- },
605
- /**
606
- * 清除校验结果
607
- * @param {Array|String} fields 字段名称或字段名称数组,不传则清除所有
608
- */
609
- clearValidate: (fields) => {
610
- if (formRef.value) {
611
- formRef.value.clearValidate(fields);
612
- }
613
- },
614
- /**
615
- * 获取表单DOM元素
616
- */
617
- getFormElement: () => formRef.value,
618
- /**
619
- * 打开表单并设置参数
620
- */
621
- openForm,
622
- /**
623
- * 加载详情数据
624
- */
625
- loadDetailData,
626
- /**
627
- * 清空表单数据
628
- */
629
- clearFormData,
630
- /**
631
- * 设置表单数据
632
- */
633
- setFormData,
634
- /**
635
- * 获取表单数据
636
- */
637
- getFormData,
638
- /**
639
- * 表单引用
640
- */
641
- formRef,
642
- /**
643
- * 当前ID
644
- */
645
- currentId,
646
- /**
647
- * 当前参数
648
- */
649
- currentParams,
650
- /**
651
- * 本地表单数据
652
- */
653
- localFormData
654
- });
655
- </script>
656
-
657
- <style scoped>
658
- .ebiz-s-form {
659
- width: 100%;
660
- }
661
-
662
- .form-buttons {
663
- margin-top: 24px;
664
- padding: 8px 0;
665
- display: flex;
666
- justify-content: center;
667
- }
1
+ <template>
2
+ <t-form ref="formRef" :class="['ebiz-s-form', className]" :colon="colon" :data="localFormData" :disabled="disabled"
3
+ :label-align="labelAlign" :label-width="labelWidth" :layout="layout" :reset-type="resetType"
4
+ :reset-on-semi-controlled="resetOnSemiControlled" :rules="formRules" :scroll-to-first-error="scrollToFirstError"
5
+ :show-error-message="showErrorMessage" :status-icon="statusIcon" :style="customStyle" @reset="handleReset"
6
+ @submit="handleSubmit" @validate="handleValidate">
7
+
8
+ <slot :formData="localFormData"></slot>
9
+
10
+ <ebiz-s-form-item label=" ">
11
+ <slot name="buttons">
12
+ <t-space>
13
+ <t-button v-if="showCancelButton" :theme="cancelButtonTheme" type="reset" :loading="loading"
14
+ :disabled="loading || disabled">{{
15
+ cancelButtonText
16
+ }}</t-button>
17
+ <t-button v-if="showSubmitButton" theme="primary" :loading="loading" :disabled="loading || disabled"
18
+ type="submit">{{
19
+ submitButtonText }}</t-button>
20
+ </t-space>
21
+ </slot>
22
+ </ebiz-s-form-item>
23
+ </t-form>
24
+ </template>
25
+
26
+ <script>
27
+ /**
28
+ * @displayName PC端表单
29
+ * @description PC端表单组件,基于TDesign Form封装,支持表单验证、API提交等功能
30
+ * @category 表单组件
31
+ * @name EbizSForm
32
+ */
33
+ export default {
34
+ name: "EbizSForm"
35
+ }
36
+ </script>
37
+
38
+ <script setup>
39
+ import { defineProps, defineEmits, ref, watch, computed } from 'vue';
40
+ import { Form as TForm, Button as TButton, Space as TSpace, MessagePlugin } from 'tdesign-vue-next';
41
+ import dataService from "../../../apiService/simpleDataService";
42
+ import EbizSFormItem from './item.vue';
43
+
44
+ const props = defineProps({
45
+ /**
46
+ * 表单数据对象
47
+ */
48
+ data: {
49
+ type: Object,
50
+ default: () => ({})
51
+ },
52
+ /**
53
+ * 表单域标签的位置
54
+ * @options left|right|top
55
+ */
56
+ labelAlign: {
57
+ type: String,
58
+ default: 'right',
59
+ validator: (val) => ['left', 'right', 'top'].includes(val)
60
+ },
61
+ /**
62
+ * 表单布局
63
+ * @options vertical|inline
64
+ */
65
+ layout: {
66
+ type: String,
67
+ default: 'vertical',
68
+ validator: (val) => ['vertical', 'inline'].includes(val)
69
+ },
70
+ /**
71
+ * 是否显示必填标记
72
+ */
73
+ colon: {
74
+ type: Boolean,
75
+ default: false
76
+ },
77
+ /**
78
+ * 是否禁用整个表单
79
+ */
80
+ disabled: {
81
+ type: Boolean,
82
+ default: false
83
+ },
84
+ /**
85
+ * 表单域标签的宽度
86
+ */
87
+ labelWidth: {
88
+ type: [String, Number],
89
+ default: '100px'
90
+ },
91
+ /**
92
+ * 表单校验规则
93
+ */
94
+ rules: {
95
+ type: Object,
96
+ default: () => ({})
97
+ },
98
+ /**
99
+ * 是否显示校验错误信息
100
+ */
101
+ showErrorMessage: {
102
+ type: Boolean,
103
+ default: true
104
+ },
105
+ /**
106
+ * 是否显示校验图标
107
+ */
108
+ statusIcon: {
109
+ type: Boolean,
110
+ default: false
111
+ },
112
+ /**
113
+ * 表单重置时的方式
114
+ * @options empty|initial
115
+ */
116
+ resetType: {
117
+ type: String,
118
+ default: 'empty',
119
+ validator: (val) => ['empty', 'initial'].includes(val)
120
+ },
121
+ /**
122
+ * 重置时是否清空所有非受控字段
123
+ */
124
+ resetOnSemiControlled: {
125
+ type: Boolean,
126
+ default: false
127
+ },
128
+ /**
129
+ * 表单校验不通过时,是否自动定位到第一个错误字段
130
+ */
131
+ scrollToFirstError: {
132
+ type: Boolean,
133
+ default: true
134
+ },
135
+ /**
136
+ * 自定义样式
137
+ */
138
+ customStyle: {
139
+ type: [String, Object],
140
+ default: ''
141
+ },
142
+ /**
143
+ * 自定义类名
144
+ */
145
+ className: {
146
+ type: String,
147
+ default: ''
148
+ },
149
+ /**
150
+ * 是否显示表单按钮(提交和取消)
151
+ */
152
+ showButtons: {
153
+ type: Boolean,
154
+ default: true
155
+ },
156
+ /**
157
+ * 是否显示提交按钮
158
+ */
159
+ showSubmitButton: {
160
+ type: Boolean,
161
+ default: true
162
+ },
163
+ /**
164
+ * 提交按钮文字
165
+ */
166
+ submitButtonText: {
167
+ type: String,
168
+ default: '提交'
169
+ },
170
+ /**
171
+ * 是否显示取消按钮
172
+ */
173
+ showCancelButton: {
174
+ type: Boolean,
175
+ default: true
176
+ },
177
+ /**
178
+ * 取消按钮文字
179
+ */
180
+ cancelButtonText: {
181
+ type: String,
182
+ default: '取消'
183
+ },
184
+ /**
185
+ * 取消按钮主题
186
+ */
187
+ cancelButtonTheme: {
188
+ type: String,
189
+ default: 'default'
190
+ },
191
+ /**
192
+ * API配置,用于表单提交
193
+ */
194
+ apiConfig: {
195
+ type: Object,
196
+ default: () => null
197
+ },
198
+ /**
199
+ * 详情API配置,用于加载表单数据
200
+ */
201
+ detailApiConfig: {
202
+ type: Object,
203
+ default: () => null
204
+ },
205
+ /**
206
+ * 是否在提交成功后重置表单
207
+ */
208
+ resetOnSuccess: {
209
+ type: Boolean,
210
+ default: false
211
+ },
212
+ /**
213
+ * 提交成功后的消息提示
214
+ */
215
+ successMessage: {
216
+ type: String,
217
+ default: '提交成功'
218
+ },
219
+ /**
220
+ * 提交失败后的消息提示
221
+ */
222
+ errorMessage: {
223
+ type: String,
224
+ default: '提交失败'
225
+ },
226
+ /**
227
+ * 是否显示提交结果消息
228
+ */
229
+ showResultMessage: {
230
+ type: Boolean,
231
+ default: true
232
+ }
233
+ });
234
+
235
+ const emit = defineEmits([
236
+ 'reset',
237
+ 'submit',
238
+ 'validate',
239
+ 'success',
240
+ 'error',
241
+ 'cancel',
242
+ 'detail-loaded',
243
+ 'detail-error'
244
+ ]);
245
+
246
+ const formRef = ref(null);
247
+ const loading = ref(false);
248
+ const currentId = ref(null);
249
+ const currentParams = ref({});
250
+ const localFormData = ref(props.data || {});
251
+
252
+ // 合并rules并监听变化
253
+ const formRules = computed(() => props.rules);
254
+
255
+ // 监听props的data变化,同步到localFormData
256
+ watch(() => props.data, (newData) => {
257
+ // 如果外部传入的数据变化,同步更新本地数据
258
+ if (newData && typeof newData === 'object') {
259
+ // 清空现有数据
260
+ Object.keys(localFormData.value).forEach(key => {
261
+ delete localFormData.value[key];
262
+ });
263
+
264
+ // 写入新数据
265
+ Object.keys(newData).forEach(key => {
266
+ localFormData.value[key] = newData[key];
267
+ });
268
+ }
269
+ }, { deep: true });
270
+
271
+ /**
272
+ * 获取错误消息
273
+ * @param {Error} error 错误对象
274
+ * @param {string} prefix 错误消息前缀
275
+ * @returns {string} 格式化后的错误消息
276
+ */
277
+ const getErrorMessage = (error, prefix = '提交失败') => {
278
+ if (!error) return `${prefix}: 未知错误`;
279
+
280
+ // 处理不同类型的错误
281
+ if (error.response && error.response.data) {
282
+ // API返回的详细错误信息
283
+ const { message, msg, error: errMsg } = error.response.data;
284
+ return `${prefix}: ${message || msg || errMsg || error.message || '服务器返回错误'}`;
285
+ } else if (error.message) {
286
+ // 标准错误对象
287
+ return `${prefix}: ${error.message}`;
288
+ } else if (typeof error === 'string') {
289
+ // 字符串错误
290
+ return `${prefix}: ${error}`;
291
+ } else {
292
+ // 未知错误
293
+ return `${prefix}: 未知错误`;
294
+ }
295
+ };
296
+
297
+ /**
298
+ * 调用API提交表单数据
299
+ */
300
+ const submitFormData = async () => {
301
+ try {
302
+ loading.value = true;
303
+
304
+ // 准备请求参数
305
+ const fetchParams = { ...localFormData.value };
306
+
307
+ // 如果有ID,添加到请求参数中
308
+ if (currentId.value) {
309
+ fetchParams.id = currentId.value;
310
+ }
311
+
312
+ // 合并当前参数到请求参数
313
+ if (currentParams.value && Object.keys(currentParams.value).length > 0) {
314
+ Object.keys(currentParams.value).forEach(key => {
315
+ fetchParams[key] = currentParams.value[key];
316
+ });
317
+ }
318
+
319
+ // 直接使用 apiConfig,不做任何处理
320
+ const response = await dataService.fetch({ saveData: { ...fetchParams } }, props.apiConfig);
321
+
322
+ // 直接使用响应数据
323
+ const transformedResponse = response;
324
+ if (props.showResultMessage) {
325
+ MessagePlugin.success(props.successMessage);
326
+ }
327
+
328
+ emit('success', transformedResponse);
329
+
330
+ if (props.resetOnSuccess && formRef.value) {
331
+ formRef.value.reset();
332
+ }
333
+
334
+ return transformedResponse;
335
+ } catch (error) {
336
+ if (props.showResultMessage) {
337
+ const errorMsg = getErrorMessage(error, props.errorMessage);
338
+ MessagePlugin.error(errorMsg);
339
+ }
340
+
341
+ emit('error', error);
342
+ return null;
343
+ } finally {
344
+ loading.value = false;
345
+ }
346
+ };
347
+
348
+ /**
349
+ * 表单重置
350
+ * @param {Object} context 表单上下文
351
+ */
352
+ const handleReset = (context) => {
353
+ emit('reset', context);
354
+ };
355
+
356
+ /**
357
+ * 表单验证
358
+ * @param {Object} result 表单验证结果
359
+ */
360
+ const handleValidate = (result) => {
361
+ emit('validate', result);
362
+ };
363
+
364
+ /**
365
+ * 表单提交事件,由内置的HTML表单submit事件触发
366
+ */
367
+ const handleSubmit = async (_context) => {
368
+ try {
369
+ if (!formRef.value) return;
370
+
371
+ const validateResult = await formRef.value.validate();
372
+
373
+ if (validateResult !== true) {
374
+ // 获取第一个错误信息
375
+ const firstKey = Object.keys(validateResult)[0];
376
+ const firstError = validateResult[firstKey]?.[0]?.message || '表单验证失败';
377
+
378
+ if (props.showResultMessage) {
379
+ MessagePlugin.error(firstError);
380
+ }
381
+
382
+ emit('error', { validateResult, firstError });
383
+ return;
384
+ }
385
+
386
+ emit('submit', localFormData.value);
387
+
388
+ if (props.apiConfig) {
389
+ await submitFormData();
390
+ }
391
+ } catch (error) {
392
+ if (props.showResultMessage) {
393
+ MessagePlugin.error(getErrorMessage(error));
394
+ }
395
+
396
+ emit('error', error);
397
+ }
398
+ };
399
+
400
+ /**
401
+ * 加载详情数据
402
+ * @param {string|number} id 记录ID
403
+ */
404
+ const loadDetailData = async (id) => {
405
+ if (!props.detailApiConfig || !id) return null;
406
+
407
+ try {
408
+ loading.value = true;
409
+
410
+ // 准备请求参数
411
+ const fetchParams = { id };
412
+
413
+ // 合并当前参数到请求参数
414
+ if (currentParams.value && Object.keys(currentParams.value).length > 0) {
415
+ Object.keys(currentParams.value).forEach(key => {
416
+ fetchParams[key] = currentParams.value[key];
417
+ });
418
+ }
419
+
420
+ // 调用dataService进行API请求,直接使用detailApiConfig
421
+ const response = await dataService.fetch(fetchParams, props.detailApiConfig);
422
+
423
+ // 获取详情数据
424
+ const detailData = response.data || response;
425
+
426
+ // 更新本地表单数据
427
+ if (detailData) {
428
+ // 清空现有数据
429
+ Object.keys(localFormData.value).forEach(key => {
430
+ delete localFormData.value[key];
431
+ });
432
+
433
+ // 写入新数据
434
+ Object.keys(detailData).forEach(key => {
435
+ localFormData.value[key] = detailData[key];
436
+ });
437
+ }
438
+
439
+ // 触发加载成功事件
440
+ emit('detail-loaded', detailData);
441
+ return detailData;
442
+ } catch (error) {
443
+ // 显示错误消息
444
+ if (props.showResultMessage) {
445
+ MessagePlugin.error(`加载详情失败: ${error.message || '未知错误'}`);
446
+ }
447
+
448
+ // 触发错误事件
449
+ emit('detail-error', error);
450
+ return null;
451
+ } finally {
452
+ loading.value = false;
453
+ }
454
+ };
455
+
456
+ /**
457
+ * 打开表单并设置参数
458
+ * @param {Object} params 表单参数
459
+ */
460
+ const openForm = (params = {}) => {
461
+ // 处理传入的表单数据
462
+ if (params.formData) {
463
+ // 清空现有数据
464
+ Object.keys(localFormData.value).forEach(key => {
465
+ delete localFormData.value[key];
466
+ });
467
+
468
+ // 写入新数据
469
+ Object.keys(params.formData).forEach(key => {
470
+ localFormData.value[key] = params.formData[key];
471
+ });
472
+ } else if (params.clearData) {
473
+ // 如果要求清空数据
474
+ Object.keys(localFormData.value).forEach(key => {
475
+ delete localFormData.value[key];
476
+ });
477
+ }
478
+
479
+ // 存储ID
480
+ if (params.id) {
481
+ currentId.value = params.id;
482
+
483
+ // 如果有detailApiConfig,加载详情数据
484
+ if (props.detailApiConfig) {
485
+ loadDetailData(params.id);
486
+ }
487
+ } else {
488
+ currentId.value = null;
489
+ }
490
+
491
+ // 存储其他自定义参数
492
+ currentParams.value = params;
493
+
494
+ return { success: true, message: '表单已准备就绪' };
495
+ };
496
+
497
+ /**
498
+ * 设置表单数据
499
+ * @param {Object} data 要设置的数据
500
+ */
501
+ const setFormData = (data) => {
502
+ if (!data || typeof data !== 'object') {
503
+ return { success: false, message: '数据必须是一个对象' };
504
+ }
505
+
506
+ // 清空现有数据
507
+ Object.keys(localFormData.value).forEach(key => {
508
+ delete localFormData.value[key];
509
+ });
510
+
511
+ // 写入新数据
512
+ Object.keys(data).forEach(key => {
513
+ localFormData.value[key] = data[key];
514
+ });
515
+
516
+ return { success: true, message: '表单数据已设置' };
517
+ };
518
+
519
+ /**
520
+ * 获取表单数据
521
+ */
522
+ const getFormData = () => {
523
+ return { ...localFormData.value };
524
+ };
525
+
526
+ /**
527
+ * 清空表单数据
528
+ */
529
+ const clearFormData = () => {
530
+ // 清空表单数据
531
+ Object.keys(localFormData.value).forEach(key => {
532
+ delete localFormData.value[key];
533
+ });
534
+
535
+ emit('reset', { type: 'clear' });
536
+ return { success: true, message: '表单数据已清空' };
537
+ };
538
+
539
+ /**
540
+ * 提交表单
541
+ */
542
+ const submitForm = async () => {
543
+ try {
544
+ if (!formRef.value) {
545
+ return { success: false, message: '表单引用不存在' };
546
+ }
547
+
548
+ const validateResult = await formRef.value.validate();
549
+
550
+ if (validateResult === true) {
551
+ emit('submit', localFormData.value);
552
+
553
+ if (props.apiConfig) {
554
+ const response = await submitFormData();
555
+ return { success: true, message: '提交成功', data: response };
556
+ }
557
+
558
+ return { success: true, message: '表单验证通过', data: { ...localFormData.value } };
559
+ } else {
560
+ const firstKey = Object.keys(validateResult)[0];
561
+ const firstError = validateResult[firstKey]?.[0]?.message || '表单验证失败';
562
+
563
+ return { success: false, message: firstError, errors: validateResult };
564
+ }
565
+ } catch (error) {
566
+ return { success: false, message: error.message || '提交过程中发生错误' };
567
+ }
568
+ };
569
+
570
+ // 暴露方法给父组件
571
+ defineExpose({
572
+ /**
573
+ * 提交表单方法
574
+ */
575
+ submit: submitForm,
576
+ /**
577
+ * 重置表单方法
578
+ */
579
+ reset: () => {
580
+ if (formRef.value) {
581
+ formRef.value.reset();
582
+ }
583
+ },
584
+ /**
585
+ * 校验表单方法
586
+ * @returns {Promise} 校验结果Promise
587
+ */
588
+ validate: async () => {
589
+ if (formRef.value) {
590
+ return await formRef.value.validate();
591
+ }
592
+ return false;
593
+ },
594
+ /**
595
+ * 校验特定字段
596
+ * @param {Array|String} fields 字段名称或字段名称数组
597
+ * @returns {Promise} 校验结果Promise
598
+ */
599
+ validateFields: async (fields) => {
600
+ if (formRef.value) {
601
+ return await formRef.value.validateFields(fields);
602
+ }
603
+ return false;
604
+ },
605
+ /**
606
+ * 清除校验结果
607
+ * @param {Array|String} fields 字段名称或字段名称数组,不传则清除所有
608
+ */
609
+ clearValidate: (fields) => {
610
+ if (formRef.value) {
611
+ formRef.value.clearValidate(fields);
612
+ }
613
+ },
614
+ /**
615
+ * 获取表单DOM元素
616
+ */
617
+ getFormElement: () => formRef.value,
618
+ /**
619
+ * 打开表单并设置参数
620
+ */
621
+ openForm,
622
+ /**
623
+ * 加载详情数据
624
+ */
625
+ loadDetailData,
626
+ /**
627
+ * 清空表单数据
628
+ */
629
+ clearFormData,
630
+ /**
631
+ * 设置表单数据
632
+ */
633
+ setFormData,
634
+ /**
635
+ * 获取表单数据
636
+ */
637
+ getFormData,
638
+ /**
639
+ * 表单引用
640
+ */
641
+ formRef,
642
+ /**
643
+ * 当前ID
644
+ */
645
+ currentId,
646
+ /**
647
+ * 当前参数
648
+ */
649
+ currentParams,
650
+ /**
651
+ * 本地表单数据
652
+ */
653
+ localFormData
654
+ });
655
+ </script>
656
+
657
+ <style scoped>
658
+ .ebiz-s-form {
659
+ width: 100%;
660
+ }
661
+
662
+ .form-buttons {
663
+ margin-top: 24px;
664
+ padding: 8px 0;
665
+ display: flex;
666
+ justify-content: center;
667
+ }
668
668
  </style>