@ebiz/designer-components 0.1.89 → 0.1.90

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 (222) hide show
  1. package/README.md +29 -29
  2. package/dist/designer-components.css +1 -1
  3. package/dist/index.mjs +23394 -22646
  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 +338 -338
  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/EbizDictionarySelect.vue +229 -229
  28. package/src/components/EbizDiv.vue +40 -40
  29. package/src/components/EbizDivider.vue +96 -96
  30. package/src/components/EbizDropdown.vue +135 -135
  31. package/src/components/EbizDropdownItem.vue +85 -85
  32. package/src/components/EbizEmployeeInfo.vue +144 -144
  33. package/src/components/EbizEmployeeSelector.vue +1160 -1160
  34. package/src/components/EbizFileList.vue +466 -466
  35. package/src/components/EbizMap.vue +541 -541
  36. package/src/components/EbizMeetingRoomSelector.vue +664 -664
  37. package/src/components/EbizMobileMeetingRoomSelector.vue +727 -727
  38. package/src/components/EbizOkrTree.vue +99 -99
  39. package/src/components/EbizPageHeader.vue +98 -98
  40. package/src/components/EbizPagination.vue +162 -162
  41. package/src/components/EbizPdfViewer.vue +540 -540
  42. package/src/components/EbizPopconfirm.vue +47 -47
  43. package/src/components/EbizQrCode.vue +73 -73
  44. package/src/components/EbizRadio.vue +86 -86
  45. package/src/components/EbizRadioGroup.vue +83 -83
  46. package/src/components/EbizRemoteSelect.vue +232 -232
  47. package/src/components/EbizRichTextEditor.vue +275 -275
  48. package/src/components/EbizRouteBreadcrumb.vue +46 -46
  49. package/src/components/EbizSApprovalProcess.vue +1429 -1429
  50. package/src/components/EbizSelect.vue +85 -85
  51. package/src/components/EbizSpace.vue +100 -100
  52. package/src/components/EbizStatistic.vue +149 -149
  53. package/src/components/EbizStatsCard.vue +113 -113
  54. package/src/components/EbizSwiper.vue +113 -113
  55. package/src/components/EbizSwiperItem.vue +13 -13
  56. package/src/components/EbizSwitch.vue +85 -85
  57. package/src/components/EbizTabHeader.vue +132 -132
  58. package/src/components/EbizTabPanel.vue +22 -22
  59. package/src/components/EbizTable.vue +469 -469
  60. package/src/components/EbizTableColumn.vue +116 -116
  61. package/src/components/EbizTableSort.vue +179 -179
  62. package/src/components/EbizTabs.vue +142 -142
  63. package/src/components/EbizTdesignButtonDialog.vue +332 -332
  64. package/src/components/EbizTdesignLoading.vue +107 -107
  65. package/src/components/EbizTimePicker.vue +143 -143
  66. package/src/components/EbizTitle.vue +91 -91
  67. package/src/components/EbizTree.vue +141 -141
  68. package/src/components/EbizTreeMergeTable.vue +1494 -1494
  69. package/src/components/EbizTreeSelector.vue +451 -451
  70. package/src/components/EbizVideo.vue +553 -553
  71. package/src/components/EbizVxeTable.vue +290 -290
  72. package/src/components/Form.vue +28 -28
  73. package/src/components/Home.vue +7 -7
  74. package/src/components/LaunchInterview.vue +403 -0
  75. package/src/components/MyComponent.vue +39 -39
  76. package/src/components/Table.vue +45 -45
  77. package/src/components/TdesignAlert.vue +115 -115
  78. package/src/components/TdesignButton.vue +135 -135
  79. package/src/components/TdesignCalendar/index.vue +145 -145
  80. package/src/components/TdesignCard.vue +195 -195
  81. package/src/components/TdesignCol.vue +101 -101
  82. package/src/components/TdesignCollapse.vue +142 -142
  83. package/src/components/TdesignCollapsePanel.vue +79 -79
  84. package/src/components/TdesignDatePicker.vue +124 -124
  85. package/src/components/TdesignDescriptions.vue +74 -74
  86. package/src/components/TdesignDescriptionsItem.vue +50 -50
  87. package/src/components/TdesignDialog.vue +225 -225
  88. package/src/components/TdesignForm.vue +138 -138
  89. package/src/components/TdesignFormItem.vue +105 -105
  90. package/src/components/TdesignGrid.vue +55 -55
  91. package/src/components/TdesignIcon.vue +67 -67
  92. package/src/components/TdesignImage.vue +162 -162
  93. package/src/components/TdesignImageViewer.vue +200 -200
  94. package/src/components/TdesignInput.vue +242 -242
  95. package/src/components/TdesignSelect.vue +446 -446
  96. package/src/components/TdesignTag.vue +117 -117
  97. package/src/components/TdesignTextarea.vue +142 -142
  98. package/src/components/TdesignTimeline.vue +58 -58
  99. package/src/components/TdesignTimelineItem.vue +71 -71
  100. package/src/components/TdesignUpload.vue +414 -414
  101. package/src/components/TdesignWatermark.vue +107 -107
  102. package/src/components/ebiz-form/components/cascader.vue +61 -61
  103. package/src/components/ebiz-form/components/checkbox.vue +37 -37
  104. package/src/components/ebiz-form/components/city.vue +137 -137
  105. package/src/components/ebiz-form/components/date-panel.vue +52 -52
  106. package/src/components/ebiz-form/components/date-range-panel.vue +52 -52
  107. package/src/components/ebiz-form/components/date-range.vue +56 -56
  108. package/src/components/ebiz-form/components/date.vue +52 -52
  109. package/src/components/ebiz-form/components/editor-multi-language.vue +47 -47
  110. package/src/components/ebiz-form/components/editor.vue +78 -78
  111. package/src/components/ebiz-form/components/file-multi-language.vue +52 -52
  112. package/src/components/ebiz-form/components/file.vue +149 -149
  113. package/src/components/ebiz-form/components/images-multi-language.vue +52 -52
  114. package/src/components/ebiz-form/components/images.vue +129 -129
  115. package/src/components/ebiz-form/components/img-multi-language.vue +51 -51
  116. package/src/components/ebiz-form/components/img.vue +129 -129
  117. package/src/components/ebiz-form/components/number.vue +50 -50
  118. package/src/components/ebiz-form/components/radio.vue +28 -28
  119. package/src/components/ebiz-form/components/select.vue +119 -119
  120. package/src/components/ebiz-form/components/switch.vue +23 -23
  121. package/src/components/ebiz-form/components/text-multi-language.vue +47 -47
  122. package/src/components/ebiz-form/components/text.vue +52 -52
  123. package/src/components/ebiz-form/components/textarea-multi-language.vue +48 -48
  124. package/src/components/ebiz-form/components/textarea.vue +29 -29
  125. package/src/components/ebiz-form/components/video-multi-language.vue +51 -51
  126. package/src/components/ebiz-form/components/video.vue +97 -97
  127. package/src/components/ebiz-form/index.vue +157 -157
  128. package/src/components/examples/PopconfirmExample.vue +149 -149
  129. package/src/components/icons/IconCommunity.vue +7 -7
  130. package/src/components/icons/IconDocumentation.vue +7 -7
  131. package/src/components/icons/IconEcosystem.vue +7 -7
  132. package/src/components/icons/IconSupport.vue +7 -7
  133. package/src/components/icons/IconTooling.vue +19 -19
  134. package/src/components/mItems/UserInfo.vue +349 -349
  135. package/src/components/senior/EbizSData/index.vue +273 -273
  136. package/src/components/senior/EbizSDialog/index.vue +770 -770
  137. package/src/components/senior/EbizSForm/README.md +157 -157
  138. package/src/components/senior/EbizSForm/index.vue +667 -667
  139. package/src/components/senior/EbizSForm/item.vue +998 -998
  140. package/src/components/senior/EbizSForm/mItems/DateTimePicker.vue +51 -51
  141. package/src/components/senior/EbizSForm/mItems/Picker.vue +63 -63
  142. package/src/index.js +317 -313
  143. package/src/main.js +55 -55
  144. package/src/router/index.js +422 -415
  145. package/src/utils/formatCode.js +24 -24
  146. package/src/utils/generateImportStatement.js +52 -52
  147. package/src/utils/hasJsx.js +25 -25
  148. package/src/utils/index.js +166 -166
  149. package/src/utils/mergeOptions.js +29 -29
  150. package/src/utils/parseRequiredBlocks.js +18 -18
  151. package/src/utils/vue-sfc-validator.js +155 -155
  152. package/src/views/Button.vue +23 -23
  153. package/src/views/CheckboxDemo.vue +104 -104
  154. package/src/views/DataContainer.vue +19 -19
  155. package/src/views/DialogDemo.vue +125 -125
  156. package/src/views/EbizApprovalDemo.vue +87 -87
  157. package/src/views/EbizApprovalFormDemo.vue +207 -207
  158. package/src/views/EbizAutoFormDemo.vue +129 -129
  159. package/src/views/EbizAvatar.vue +223 -223
  160. package/src/views/EbizDepartmentSelectorDemo.vue +169 -169
  161. package/src/views/EbizDetailBlockDemo.vue +30 -30
  162. package/src/views/EbizDetailViewDemo.vue +412 -412
  163. package/src/views/EbizEmployeeInfo.vue +249 -249
  164. package/src/views/EbizEmployeeSelector.vue +85 -85
  165. package/src/views/EbizFileListDemo.vue +339 -339
  166. package/src/views/EbizMap.vue +201 -201
  167. package/src/views/EbizMeetingRoomSelectorDemo.vue +293 -293
  168. package/src/views/EbizMobileMeetingRoomSelectorDemo.vue +566 -566
  169. package/src/views/EbizRadioDemo.vue +151 -151
  170. package/src/views/EbizSDataDemo.vue +136 -136
  171. package/src/views/EbizSDialogDemo.vue +303 -303
  172. package/src/views/EbizSForm/index.vue +352 -352
  173. package/src/views/EbizSFormDemo.vue +420 -420
  174. package/src/views/EbizSpace.vue +185 -185
  175. package/src/views/EbizSwiper.vue +157 -157
  176. package/src/views/EbizTdesignButtonDialogExample.vue +437 -437
  177. package/src/views/Form.vue +19 -19
  178. package/src/views/GridDemo.vue +238 -238
  179. package/src/views/Home.vue +154 -153
  180. package/src/views/LaunchInterviewDemo.vue +112 -0
  181. package/src/views/Mindmap.vue +17 -17
  182. package/src/views/MyComponent.vue +19 -19
  183. package/src/views/OkrTree.vue +19 -19
  184. package/src/views/PageHeaderDemo.vue +104 -104
  185. package/src/views/PaginationDemo.vue +96 -96
  186. package/src/views/PdfViewerDemo.vue +433 -433
  187. package/src/views/PermissionBoxDemo.vue +85 -85
  188. package/src/views/PopconfirmDemo.vue +80 -80
  189. package/src/views/RemoteSelect.vue +350 -350
  190. package/src/views/StatisticDemo.vue +190 -190
  191. package/src/views/SwitchDemo.vue +79 -79
  192. package/src/views/Table.vue +19 -19
  193. package/src/views/TableDemo.vue +334 -334
  194. package/src/views/TableSortDemo.vue +143 -143
  195. package/src/views/TableView.vue +68 -68
  196. package/src/views/TabsDemo.vue +282 -282
  197. package/src/views/TagDemo.vue +101 -101
  198. package/src/views/TdesignAlert.vue +98 -98
  199. package/src/views/TdesignButton.vue +190 -190
  200. package/src/views/TdesignCalendar.vue +94 -94
  201. package/src/views/TdesignCard.vue +296 -296
  202. package/src/views/TdesignCollapse.vue +293 -293
  203. package/src/views/TdesignDatePicker.vue +187 -187
  204. package/src/views/TdesignDescriptions.vue +101 -101
  205. package/src/views/TdesignForm.vue +248 -248
  206. package/src/views/TdesignIcon.vue +203 -203
  207. package/src/views/TdesignImage.vue +215 -215
  208. package/src/views/TdesignImageViewer.vue +198 -198
  209. package/src/views/TdesignInput.vue +252 -252
  210. package/src/views/TdesignSelect.vue +473 -473
  211. package/src/views/TdesignSwiper.vue +157 -157
  212. package/src/views/TextareaDemo.vue +93 -93
  213. package/src/views/TimePickerDemo.vue +146 -146
  214. package/src/views/TimelineDemo.vue +160 -160
  215. package/src/views/Title.vue +19 -19
  216. package/src/views/TreeDemo.vue +254 -254
  217. package/src/views/TreeMergeTableDemo.vue +239 -239
  218. package/src/views/TreeSelectorDemo.vue +245 -245
  219. package/src/views/UploadDemo.vue +128 -128
  220. package/src/views/VideoDemo.vue +245 -245
  221. package/src/views/VxeTableDemo.vue +279 -279
  222. package/src/views/WatermarkDemo.vue +85 -85
@@ -1,771 +1,771 @@
1
- <template>
2
- <div class="ebiz-tdesign-button-dialog">
3
- <div v-if="$slots.trigger">
4
- <slot name="trigger" :event="{
5
- open: openDialog
6
- }"></slot>
7
- </div>
8
- <div v-else-if="showTriggerButton">
9
-
10
- <t-button :theme="buttonTheme" :size="buttonSize" @click="openDialog">
11
- {{ buttonText }}
12
- </t-button>
13
- </div>
14
- <t-dialog v-model:visible="dialogVisible" :header="title || computedTitle" :width="dialogWidth" :top="dialogTop"
15
- :attach="dialogAttach" :destroy-on-close="dialogDestroyOnClose" :mode="dialogMode" :placement="dialogPlacement"
16
- :show-overlay="dialogShowOverlay" :close-on-esc-keydown="dialogCloseOnEscKeydown"
17
- :close-on-overlay-click="dialogCloseOnOverlayClick" :show-footer="dialogShowFooter" @close="handleDialogClose"
18
- @confirm="handleDialogConfirm" @cancel="handleDialogCancel">
19
- <template #header>
20
- <slot name="header">
21
- <div :class="['dialog-header', dialogType === 'delete' ? 'dialog-header-delete' : '']">
22
- {{ title || computedTitle }}
23
- </div>
24
- </slot>
25
- </template>
26
-
27
- <template #body>
28
- <div v-if="dialogType === 'normal'">
29
- <slot name="body"></slot>
30
- <slot></slot>
31
- </div>
32
- <div v-else-if="dialogType === 'add'">
33
- <t-form ref="formRef" :loading="apiLoading" :colon="colon" :data="localFormData" :disabled="disabled"
34
- :label-align="labelAlign" :label-width="labelWidth" :layout="layout" :reset-type="resetType"
35
- :reset-on-semi-controlled="resetOnSemiControlled" :rules="rules" :show-error-message="showErrorMessage"
36
- :status-icon="statusIcon" :style="customStyle" @reset="handleReset" @submit="handleSubmit"
37
- @validate="handleValidate">
38
- <slot name="body" :formData="localFormData"></slot>
39
- </t-form>
40
- </div>
41
- <div v-else-if="dialogType === 'edit'">
42
- <t-form ref="formRef" :loading="apiLoading" :colon="colon" :data="localFormData" :disabled="disabled"
43
- :label-align="labelAlign" :label-width="labelWidth" :layout="layout" :reset-type="resetType"
44
- :reset-on-semi-controlled="resetOnSemiControlled" :rules="rules" :show-error-message="showErrorMessage"
45
- :status-icon="statusIcon" :style="customStyle" @reset="handleReset" @submit="handleSubmit"
46
- @validate="handleValidate">
47
- <slot name="body" :formData="localFormData"></slot>
48
- </t-form>
49
- </div>
50
- <slot v-else-if="dialogType === 'delete'" name="body">
51
- <div class="delete-confirm-content">
52
- <t-icon name="error-circle" size="large" class="delete-icon" />
53
- <p class="delete-message">{{ deleteConfirmMessage }}</p>
54
- </div>
55
- </slot>
56
- </template>
57
- </t-dialog>
58
- </div>
59
- </template>
60
-
61
- <script setup>
62
- import { ref, computed, watch } from 'vue'
63
- import { Dialog as TDialog, MessagePlugin, Icon as TIcon, Form as TForm, Button as TButton } from 'tdesign-vue-next'
64
- import dataService from '../../../apiService/simpleDataService'
65
-
66
- const props = defineProps({
67
- // 弹窗类型
68
- dialogType: {
69
- type: String,
70
- default: 'normal', // 'normal', 'add', 'delete'
71
- validator: (value) => ['normal', 'add', 'edit', 'delete'].includes(value)
72
- },
73
-
74
- // 删除确认消息
75
- deleteConfirmMessage: {
76
- type: String,
77
- default: '确定要删除该数据吗?此操作不可逆,请谨慎操作。'
78
- },
79
-
80
- // 按钮基础属性
81
- buttonText: {
82
- type: String,
83
- default: ''
84
- },
85
- // 按钮样式属性
86
- showTriggerButton: {
87
- type: Boolean,
88
- default: false
89
- },
90
- buttonTheme: {
91
- type: String,
92
- default: ''
93
- },
94
- buttonVariant: {
95
- type: String,
96
- default: 'base'
97
- },
98
- buttonSize: {
99
- type: String,
100
- default: 'medium'
101
- },
102
- buttonBlock: {
103
- type: Boolean,
104
- default: false
105
- },
106
- buttonShape: {
107
- type: String,
108
- default: 'rectangle'
109
- },
110
- buttonDisabled: {
111
- type: Boolean,
112
- default: false
113
- },
114
- buttonLoading: {
115
- type: Boolean,
116
- default: false
117
- },
118
- buttonIcon: {
119
- type: String,
120
- default: ''
121
- },
122
-
123
- // 弹窗基础属性
124
- title: {
125
- type: String,
126
- default: ''
127
- },
128
- visible: {
129
- type: Boolean,
130
- default: false
131
- },
132
- confirmText: {
133
- type: String,
134
- default: undefined
135
- },
136
- cancelText: {
137
- type: String,
138
- default: undefined
139
- },
140
-
141
- // 弹窗样式和行为属性
142
- dialogWidth: {
143
- type: [String, Number],
144
- default: '500px'
145
- },
146
- dialogTop: {
147
- type: [String, Number],
148
- default: '15vh'
149
- },
150
- dialogAttach: {
151
- type: [String, Function],
152
- default: 'body'
153
- },
154
- dialogDestroyOnClose: {
155
- type: Boolean,
156
- default: false
157
- },
158
- dialogMode: {
159
- type: String,
160
- default: 'modal'
161
- },
162
- dialogPlacement: {
163
- type: String,
164
- default: 'top'
165
- },
166
- dialogShowOverlay: {
167
- type: Boolean,
168
- default: true
169
- },
170
- dialogCloseOnEscKeydown: {
171
- type: Boolean,
172
- default: true
173
- },
174
- dialogCloseOnOverlayClick: {
175
- type: Boolean,
176
- default: true
177
- },
178
- dialogShowFooter: {
179
- type: Boolean,
180
- default: true
181
- },
182
-
183
- // API配置
184
- apiConfig: {
185
- type: Object,
186
- default: () => null
187
- },
188
-
189
- // 请求参数
190
- params: {
191
- type: Object,
192
- default: () => null
193
- },
194
-
195
- // 表单数据
196
- formData: {
197
- type: Object,
198
- default: () => null
199
- },
200
-
201
- // 表单验证规则
202
- rules: {
203
- type: Object,
204
- default: () => null
205
- },
206
-
207
- // 是否在API调用成功后自动关闭弹窗
208
- closeOnSuccess: {
209
- type: Boolean,
210
- default: true
211
- },
212
- // 是否显示API调用的结果消息
213
- showResultMessage: {
214
- type: Boolean,
215
- default: true
216
- },
217
-
218
- // 表单组件属性
219
- colon: {
220
- type: Boolean,
221
- default: false
222
- },
223
- disabled: {
224
- type: Boolean,
225
- default: false
226
- },
227
- labelAlign: {
228
- type: String,
229
- default: 'right'
230
- },
231
- labelWidth: {
232
- type: [String, Number],
233
- default: '100px'
234
- },
235
- layout: {
236
- type: String,
237
- default: 'vertical'
238
- },
239
- resetType: {
240
- type: String,
241
- default: 'empty'
242
- },
243
- resetOnSemiControlled: {
244
- type: Boolean,
245
- default: false
246
- },
247
- showErrorMessage: {
248
- type: Boolean,
249
- default: true
250
- },
251
- statusIcon: {
252
- type: Boolean,
253
- default: false
254
- },
255
- customStyle: {
256
- type: Object,
257
- default: () => ({})
258
- },
259
-
260
- // 详情API配置,用于编辑模式加载数据
261
- detailApiConfig: {
262
- type: Object,
263
- default: () => null
264
- },
265
- })
266
-
267
- const emit = defineEmits([
268
- 'update:visible',
269
- 'update:formData',
270
- 'button-click',
271
- 'dialog-close',
272
- 'dialog-confirm',
273
- 'dialog-cancel',
274
- 'api-success',
275
- 'api-error',
276
- 'reset',
277
- 'submit',
278
- 'submit-error',
279
- 'validate',
280
- 'detail-loaded',
281
- 'detail-error'
282
- ])
283
-
284
- const computedTitle = computed(() => {
285
- switch (props.dialogType) {
286
- case 'add': return '添加数据';
287
- case 'delete': return '删除确认';
288
- case 'edit': return '编辑数据';
289
- default: return '';
290
- }
291
- })
292
-
293
- // 初始化dialogVisible
294
- const dialogVisible = ref(props.visible)
295
- const apiLoading = ref(false)
296
- const formRef = ref(null)
297
- const currentId = ref(null)
298
- const currentParams = ref({})
299
- // 本地维护一份表单数据的副本
300
- const initFormData = ref(props.formData ? { ...props.formData } : {})
301
- const localFormData = ref({ ...initFormData.value })
302
-
303
- // 监听 props.formData 的变化,同步到本地数据
304
- watch(() => props.formData, (newFormData) => {
305
- if (newFormData) {
306
- // 合并新的表单数据到本地数据
307
- Object.keys(newFormData).forEach(key => {
308
- localFormData.value[key] = newFormData[key]
309
- })
310
- }
311
- }, { deep: true })
312
-
313
- // 监听本地数据变化,同步到父组件
314
- watch(localFormData, (newValue) => {
315
- emit('update:formData', { ...newValue })
316
- }, { deep: true })
317
-
318
- // 监听props的visible变化
319
- watch(() => props.visible, (newVal) => {
320
- dialogVisible.value = newVal
321
- })
322
-
323
- // 监听dialogVisible变化,同步更新modelValue
324
- watch(dialogVisible, (newVal) => {
325
- emit('update:visible', newVal)
326
- })
327
-
328
- // 弹窗关闭事件
329
- const handleDialogClose = (e) => {
330
- dialogVisible.value = false
331
- emit('dialog-close', e)
332
- }
333
-
334
- // API调用方法
335
- // 获取错误消息
336
- const getErrorMessage = (error, dialogType) => {
337
- console.error(error)
338
- const errorPrefix = dialogType === 'delete'
339
- ? '删除失败'
340
- : dialogType === 'add'
341
- ? '添加失败'
342
- : dialogType === 'edit'
343
- ? '修改失败'
344
- : '操作失败'
345
-
346
- if (!error) return `${errorPrefix}: 未知错误`
347
-
348
- // 处理不同类型的错误
349
- if (error.response && error.response.data) {
350
- // API返回的详细错误信息
351
- const { message, msg, error: errMsg } = error.response.data
352
- return `${errorPrefix}: ${message || msg || errMsg || error.message || '服务器返回错误'}`
353
- } else if (error.message) {
354
- // 标准错误对象
355
- return `${errorPrefix}: ${error.message}`
356
- } else if (typeof error === 'string') {
357
- // 字符串错误
358
- return `${errorPrefix}: ${error}`
359
- } else {
360
- // 未知错误
361
- return `${errorPrefix}: 未知错误`
362
- }
363
- }
364
-
365
- const callApi = async (config = props.apiConfig) => {
366
- if (!config) return null
367
-
368
- console.log("props.formData", props.formData)
369
- try {
370
-
371
- apiLoading.value = true
372
-
373
- console.log(123123123123)
374
- console.log(localFormData.value)
375
-
376
- // 准备请求参数
377
- const fetchParams = { ...localFormData.value }
378
-
379
- // 如果有ID,添加到请求参数中
380
- if (currentId.value) {
381
- fetchParams.id = currentId.value
382
- }
383
- console.log("123123")
384
-
385
- // 合并当前参数到请求参数
386
- if (currentParams.value && Object.keys(currentParams.value).length > 0) {
387
- Object.keys(currentParams.value).forEach(key => {
388
- if (key !== 'formData') { // 避免重复添加表单数据
389
- fetchParams[key] = currentParams.value[key]
390
- }
391
- })
392
- }
393
- console.log("123123")
394
-
395
- // 调用dataService进行API请求,直接使用config
396
- config.apiType = 'PROCESS'
397
- const response = await dataService.fetch({ detailId: fetchParams.detailId || fetchParams.id, saveData: { ...fetchParams } }, config)
398
-
399
- // 显示成功消息
400
- if (props.showResultMessage) {
401
- resetFormData()
402
- const successMessage = props.dialogType === 'delete'
403
- ? '删除成功'
404
- : props.dialogType === 'add'
405
- ? '添加成功'
406
- : props.dialogType === 'edit'
407
- ? '修改成功'
408
- : '操作成功'
409
- MessagePlugin.success(successMessage)
410
- }
411
-
412
- // 清空数据
413
- Object.keys(localFormData.value).forEach(key => {
414
- delete localFormData.value[key]
415
- })
416
-
417
- // 触发成功事件
418
- emit('api-success', response)
419
-
420
- // 如果设置了成功后关闭,则关闭弹窗
421
- if (props.closeOnSuccess) {
422
- dialogVisible.value = false
423
- }
424
-
425
- return response
426
- } catch (error) {
427
- console.log(error)
428
- // 错误处理和错误消息展示
429
- const errorMessage = getErrorMessage(error, props.dialogType)
430
-
431
- // 显示错误消息
432
- if (props.showResultMessage) {
433
- MessagePlugin.error(errorMessage)
434
- }
435
-
436
- // 触发错误事件
437
- emit('api-error', error)
438
-
439
- throw error // 继续抛出错误以便上层捕获
440
- } finally {
441
- apiLoading.value = false
442
- }
443
- }
444
-
445
- // 弹窗确认事件
446
- const handleDialogConfirm = async (e) => {
447
- emit('dialog-confirm', e)
448
- if(apiLoading.value) return
449
- // 对于非普通类型的弹窗,总是尝试调用API
450
- if (props.dialogType !== 'normal') {
451
- if (props.apiConfig) {
452
- // 如果是表单类型(添加或编辑),先进行表单校验
453
- if ((props.dialogType === 'add' || props.dialogType === 'edit') && formRef.value) {
454
-
455
- try {
456
- console.log(123123123)
457
- // 显示加载状态
458
- apiLoading.value = true
459
-
460
- // 使用表单的validate方法进行校验
461
- const validateResult = await formRef.value.validate()
462
- console.log("validateResult", validateResult)
463
-
464
- // 校验成功,执行提交操作
465
- if (validateResult === true) {
466
- // 直接调用callApi传入props.apiConfig
467
- await callApi(props.apiConfig)
468
- } else {
469
- // 校验失败,显示第一个错误信息
470
- const firstError = validateResult[Object.keys(validateResult)[0]]?.[0]?.message || '表单校验失败'
471
- MessagePlugin.error(firstError)
472
- emit('submit-error', { validateResult, firstError })
473
- return // 阻止关闭弹窗
474
- }
475
- } catch (error) {
476
- console.error(error)
477
- // 校验或API调用过程中的错误
478
- MessagePlugin.error(`操作失败: ${error.message || '未知错误'}`)
479
- emit('submit-error', { error })
480
- return // 阻止关闭弹窗
481
- } finally {
482
- apiLoading.value = false
483
- }
484
- } else if (props.dialogType === 'delete') {
485
- try {
486
- // 显示加载状态
487
- apiLoading.value = true
488
-
489
- // 删除操作直接调用API
490
- await callApi(props.apiConfig)
491
- } catch (error) {
492
- // API调用过程中的错误
493
- MessagePlugin.error(`删除失败: ${error.message || '未知错误'}`)
494
- emit('api-error', error)
495
- return // 阻止关闭弹窗
496
- } finally {
497
- apiLoading.value = false
498
- }
499
- }
500
- } else {
501
- dialogVisible.value = false
502
- }
503
- } else {
504
- // 普通弹窗的行为
505
- if (props.apiConfig) {
506
- try {
507
- // 显示加载状态
508
- apiLoading.value = true
509
-
510
- // 直接调用API,不修改apiConfig
511
- await callApi(props.apiConfig)
512
- } catch (error) {
513
- console.error(error)
514
- // API调用过程中的错误
515
- MessagePlugin.error(`操作失败: ${error.message || '未知错误'}`)
516
- emit('api-error', error)
517
- return // 阻止关闭弹窗
518
- } finally {
519
- apiLoading.value = false
520
- }
521
- } else {
522
- dialogVisible.value = false
523
- }
524
- }
525
- }
526
-
527
- // 弹窗取消事件
528
- const handleDialogCancel = (e) => {
529
- dialogVisible.value = false
530
- emit('dialog-cancel', e)
531
- }
532
-
533
- // 表单重置事件
534
- const handleReset = (e) => {
535
- emit('reset', e)
536
- }
537
-
538
- // 表单提交事件
539
- const handleSubmit = async ({ validateResult, firstError, e }) => {
540
- if (validateResult === true) {
541
- emit('submit', { e, formData: localFormData.value })
542
- } else {
543
- MessagePlugin.error(firstError)
544
- emit('submit-error', { validateResult, firstError })
545
- }
546
- }
547
-
548
- // 表单验证事件
549
- const handleValidate = (params) => {
550
- emit('validate', params)
551
- }
552
-
553
- // 加载详情数据
554
- const loadDetailData = async (id) => {
555
- if (!props.detailApiConfig) return null
556
-
557
- try {
558
- // 显示加载状态
559
- apiLoading.value = true
560
-
561
- // 准备请求参数
562
- const fetchParams = { detailId: id }
563
-
564
- // 合并当前参数到请求参数
565
- if (currentParams.value && Object.keys(currentParams.value).length > 0) {
566
- // 过滤掉id和formData,避免重复
567
- const { id: _id, formData: _formData, ...otherParams } = currentParams.value
568
- Object.keys(otherParams).forEach(key => {
569
- fetchParams[key] = otherParams[key]
570
- })
571
- }
572
-
573
- // 调用dataService进行API请求,直接使用detailApiConfig
574
- const response = await dataService.fetch(fetchParams, props.detailApiConfig)
575
-
576
- // 获取详情数据
577
- const detailData = response.data || response
578
-
579
- // 更新本地表单数据
580
- if (detailData) {
581
- // 清空现有数据
582
- Object.keys(localFormData.value).forEach(key => {
583
- delete localFormData.value[key]
584
- })
585
-
586
- // 写入新数据
587
- Object.keys(detailData).forEach(key => {
588
- localFormData.value[key] = detailData[key]
589
- })
590
- }
591
-
592
- // 触发加载成功事件
593
- emit('detail-loaded', detailData)
594
- return detailData
595
- } catch (error) {
596
- // 显示错误消息
597
- if (props.showResultMessage) {
598
- MessagePlugin.error(`加载详情失败: ${error.message || '未知错误'}`)
599
- }
600
-
601
- // 触发错误事件
602
- emit('detail-error', error)
603
- return null
604
- } finally {
605
- apiLoading.value = false
606
- }
607
- }
608
-
609
- // 打开弹窗并传递参数
610
- const openDialog = (params = {}) => {
611
- params = { ...params, ...props.params }
612
- // 重置状态
613
- if (props.dialogType === 'add') {
614
- // 添加模式:清空表单数据
615
- Object.keys(localFormData.value).forEach(key => {
616
- delete localFormData.value[key]
617
- })
618
- }
619
-
620
- resetFormData();
621
-
622
- // 处理传入的表单数据
623
- if (params.formData && (props.dialogType === 'add' || props.dialogType === 'edit')) {
624
- // 更新本地表单数据副本
625
- Object.keys(params.formData).forEach(key => {
626
- localFormData.value[key] = params.formData[key]
627
- })
628
- }
629
-
630
- // 存储其他参数,如删除ID等
631
- if (params.id) {
632
- currentId.value = params.id
633
-
634
- // 如果是编辑模式且有detailApiConfig,加载详情数据
635
- if (props.dialogType === 'edit' && props.detailApiConfig) {
636
- loadDetailData(params.id)
637
- }
638
- } else {
639
- currentId.value = null
640
- }
641
-
642
- // 存储其他自定义参数
643
- currentParams.value = params
644
-
645
- // 打开弹窗
646
- dialogVisible.value = true
647
-
648
- return { success: true, message: '弹窗已打开' }
649
- }
650
-
651
- // 关闭弹窗
652
- const closeDialog = () => {
653
- dialogVisible.value = false
654
- return { success: true, message: '弹窗已关闭' }
655
- }
656
-
657
- // 重置表单数据到初始状态
658
- const resetFormData = () => {
659
- if (formRef.value) {
660
- formRef.value.reset()
661
- emit('reset', { type: 'manual' })
662
- }
663
-
664
- // 重置本地表单数据
665
- Object.keys(localFormData.value).forEach(key => {
666
- delete localFormData.value[key]
667
- })
668
-
669
- emit('update:formData', { ...localFormData.value })
670
-
671
- return { success: true, message: '表单已重置' }
672
- }
673
-
674
- // 清空表单数据
675
- const clearFormData = () => {
676
- // 清空表单数据
677
- Object.keys(localFormData.value).forEach(key => {
678
- delete localFormData.value[key]
679
- })
680
-
681
- emit('reset', { type: 'clear' })
682
- return { success: true, message: '表单数据已清空' }
683
- }
684
-
685
- // 设置表单数据
686
- const setFormData = (data) => {
687
- if (!data || typeof data !== 'object') {
688
- return { success: false, message: '数据必须是一个对象' }
689
- }
690
-
691
- // 清空现有数据
692
- Object.keys(localFormData.value).forEach(key => {
693
- delete localFormData.value[key]
694
- })
695
-
696
- // 写入新数据
697
- Object.keys(data).forEach(key => {
698
- localFormData.value[key] = data[key]
699
- })
700
-
701
- return { success: true, message: '表单数据已设置' }
702
- }
703
-
704
- // 获取表单数据
705
- const getFormData = () => {
706
- return { ...localFormData.value }
707
- }
708
-
709
- // 获取表单的当前验证状态
710
- const validateForm = async () => {
711
- if (!formRef.value) {
712
- return { success: false, message: '表单引用不存在' }
713
- }
714
-
715
- try {
716
- const validateResult = await formRef.value.validate()
717
-
718
- if (validateResult === true) {
719
- return { success: true, message: '表单验证通过', data: getFormData() }
720
- } else {
721
- const firstError = validateResult[Object.keys(validateResult)[0]]?.[0]?.message || '表单校验失败'
722
- return { success: false, message: firstError, errors: validateResult }
723
- }
724
- } catch (error) {
725
- return { success: false, message: error.message || '表单验证过程中发生错误' }
726
- }
727
- }
728
-
729
- // 暴露给父组件的方法
730
- defineExpose({
731
- openDialog,
732
- closeDialog,
733
- resetFormData,
734
- clearFormData,
735
- setFormData,
736
- getFormData,
737
- validateForm,
738
- loadDetailData,
739
- currentId,
740
- currentParams,
741
- formRef
742
- })
743
- </script>
744
-
745
- <style scoped>
746
- .ebiz-tdesign-button-dialog {
747
- display: inline-block;
748
- }
749
-
750
- .dialog-header-delete {
751
- color: var(--td-error-color, #e34d59);
752
- }
753
-
754
- .delete-confirm-content {
755
- display: flex;
756
- align-items: center;
757
- padding: 16px;
758
- }
759
-
760
- .delete-icon {
761
- font-size: 24px;
762
- color: var(--td-error-color, #e34d59);
763
- margin-right: 12px;
764
- }
765
-
766
- .delete-message {
767
- margin: 0;
768
- font-size: 14px;
769
- line-height: 22px;
770
- }
1
+ <template>
2
+ <div class="ebiz-tdesign-button-dialog">
3
+ <div v-if="$slots.trigger">
4
+ <slot name="trigger" :event="{
5
+ open: openDialog
6
+ }"></slot>
7
+ </div>
8
+ <div v-else-if="showTriggerButton">
9
+
10
+ <t-button :theme="buttonTheme" :size="buttonSize" @click="openDialog">
11
+ {{ buttonText }}
12
+ </t-button>
13
+ </div>
14
+ <t-dialog v-model:visible="dialogVisible" :header="title || computedTitle" :width="dialogWidth" :top="dialogTop"
15
+ :attach="dialogAttach" :destroy-on-close="dialogDestroyOnClose" :mode="dialogMode" :placement="dialogPlacement"
16
+ :show-overlay="dialogShowOverlay" :close-on-esc-keydown="dialogCloseOnEscKeydown"
17
+ :close-on-overlay-click="dialogCloseOnOverlayClick" :show-footer="dialogShowFooter" @close="handleDialogClose"
18
+ @confirm="handleDialogConfirm" @cancel="handleDialogCancel">
19
+ <template #header>
20
+ <slot name="header">
21
+ <div :class="['dialog-header', dialogType === 'delete' ? 'dialog-header-delete' : '']">
22
+ {{ title || computedTitle }}
23
+ </div>
24
+ </slot>
25
+ </template>
26
+
27
+ <template #body>
28
+ <div v-if="dialogType === 'normal'">
29
+ <slot name="body"></slot>
30
+ <slot></slot>
31
+ </div>
32
+ <div v-else-if="dialogType === 'add'">
33
+ <t-form ref="formRef" :loading="apiLoading" :colon="colon" :data="localFormData" :disabled="disabled"
34
+ :label-align="labelAlign" :label-width="labelWidth" :layout="layout" :reset-type="resetType"
35
+ :reset-on-semi-controlled="resetOnSemiControlled" :rules="rules" :show-error-message="showErrorMessage"
36
+ :status-icon="statusIcon" :style="customStyle" @reset="handleReset" @submit="handleSubmit"
37
+ @validate="handleValidate">
38
+ <slot name="body" :formData="localFormData"></slot>
39
+ </t-form>
40
+ </div>
41
+ <div v-else-if="dialogType === 'edit'">
42
+ <t-form ref="formRef" :loading="apiLoading" :colon="colon" :data="localFormData" :disabled="disabled"
43
+ :label-align="labelAlign" :label-width="labelWidth" :layout="layout" :reset-type="resetType"
44
+ :reset-on-semi-controlled="resetOnSemiControlled" :rules="rules" :show-error-message="showErrorMessage"
45
+ :status-icon="statusIcon" :style="customStyle" @reset="handleReset" @submit="handleSubmit"
46
+ @validate="handleValidate">
47
+ <slot name="body" :formData="localFormData"></slot>
48
+ </t-form>
49
+ </div>
50
+ <slot v-else-if="dialogType === 'delete'" name="body">
51
+ <div class="delete-confirm-content">
52
+ <t-icon name="error-circle" size="large" class="delete-icon" />
53
+ <p class="delete-message">{{ deleteConfirmMessage }}</p>
54
+ </div>
55
+ </slot>
56
+ </template>
57
+ </t-dialog>
58
+ </div>
59
+ </template>
60
+
61
+ <script setup>
62
+ import { ref, computed, watch } from 'vue'
63
+ import { Dialog as TDialog, MessagePlugin, Icon as TIcon, Form as TForm, Button as TButton } from 'tdesign-vue-next'
64
+ import dataService from '../../../apiService/simpleDataService'
65
+
66
+ const props = defineProps({
67
+ // 弹窗类型
68
+ dialogType: {
69
+ type: String,
70
+ default: 'normal', // 'normal', 'add', 'delete'
71
+ validator: (value) => ['normal', 'add', 'edit', 'delete'].includes(value)
72
+ },
73
+
74
+ // 删除确认消息
75
+ deleteConfirmMessage: {
76
+ type: String,
77
+ default: '确定要删除该数据吗?此操作不可逆,请谨慎操作。'
78
+ },
79
+
80
+ // 按钮基础属性
81
+ buttonText: {
82
+ type: String,
83
+ default: ''
84
+ },
85
+ // 按钮样式属性
86
+ showTriggerButton: {
87
+ type: Boolean,
88
+ default: false
89
+ },
90
+ buttonTheme: {
91
+ type: String,
92
+ default: ''
93
+ },
94
+ buttonVariant: {
95
+ type: String,
96
+ default: 'base'
97
+ },
98
+ buttonSize: {
99
+ type: String,
100
+ default: 'medium'
101
+ },
102
+ buttonBlock: {
103
+ type: Boolean,
104
+ default: false
105
+ },
106
+ buttonShape: {
107
+ type: String,
108
+ default: 'rectangle'
109
+ },
110
+ buttonDisabled: {
111
+ type: Boolean,
112
+ default: false
113
+ },
114
+ buttonLoading: {
115
+ type: Boolean,
116
+ default: false
117
+ },
118
+ buttonIcon: {
119
+ type: String,
120
+ default: ''
121
+ },
122
+
123
+ // 弹窗基础属性
124
+ title: {
125
+ type: String,
126
+ default: ''
127
+ },
128
+ visible: {
129
+ type: Boolean,
130
+ default: false
131
+ },
132
+ confirmText: {
133
+ type: String,
134
+ default: undefined
135
+ },
136
+ cancelText: {
137
+ type: String,
138
+ default: undefined
139
+ },
140
+
141
+ // 弹窗样式和行为属性
142
+ dialogWidth: {
143
+ type: [String, Number],
144
+ default: '500px'
145
+ },
146
+ dialogTop: {
147
+ type: [String, Number],
148
+ default: '15vh'
149
+ },
150
+ dialogAttach: {
151
+ type: [String, Function],
152
+ default: 'body'
153
+ },
154
+ dialogDestroyOnClose: {
155
+ type: Boolean,
156
+ default: false
157
+ },
158
+ dialogMode: {
159
+ type: String,
160
+ default: 'modal'
161
+ },
162
+ dialogPlacement: {
163
+ type: String,
164
+ default: 'top'
165
+ },
166
+ dialogShowOverlay: {
167
+ type: Boolean,
168
+ default: true
169
+ },
170
+ dialogCloseOnEscKeydown: {
171
+ type: Boolean,
172
+ default: true
173
+ },
174
+ dialogCloseOnOverlayClick: {
175
+ type: Boolean,
176
+ default: true
177
+ },
178
+ dialogShowFooter: {
179
+ type: Boolean,
180
+ default: true
181
+ },
182
+
183
+ // API配置
184
+ apiConfig: {
185
+ type: Object,
186
+ default: () => null
187
+ },
188
+
189
+ // 请求参数
190
+ params: {
191
+ type: Object,
192
+ default: () => null
193
+ },
194
+
195
+ // 表单数据
196
+ formData: {
197
+ type: Object,
198
+ default: () => null
199
+ },
200
+
201
+ // 表单验证规则
202
+ rules: {
203
+ type: Object,
204
+ default: () => null
205
+ },
206
+
207
+ // 是否在API调用成功后自动关闭弹窗
208
+ closeOnSuccess: {
209
+ type: Boolean,
210
+ default: true
211
+ },
212
+ // 是否显示API调用的结果消息
213
+ showResultMessage: {
214
+ type: Boolean,
215
+ default: true
216
+ },
217
+
218
+ // 表单组件属性
219
+ colon: {
220
+ type: Boolean,
221
+ default: false
222
+ },
223
+ disabled: {
224
+ type: Boolean,
225
+ default: false
226
+ },
227
+ labelAlign: {
228
+ type: String,
229
+ default: 'right'
230
+ },
231
+ labelWidth: {
232
+ type: [String, Number],
233
+ default: '100px'
234
+ },
235
+ layout: {
236
+ type: String,
237
+ default: 'vertical'
238
+ },
239
+ resetType: {
240
+ type: String,
241
+ default: 'empty'
242
+ },
243
+ resetOnSemiControlled: {
244
+ type: Boolean,
245
+ default: false
246
+ },
247
+ showErrorMessage: {
248
+ type: Boolean,
249
+ default: true
250
+ },
251
+ statusIcon: {
252
+ type: Boolean,
253
+ default: false
254
+ },
255
+ customStyle: {
256
+ type: Object,
257
+ default: () => ({})
258
+ },
259
+
260
+ // 详情API配置,用于编辑模式加载数据
261
+ detailApiConfig: {
262
+ type: Object,
263
+ default: () => null
264
+ },
265
+ })
266
+
267
+ const emit = defineEmits([
268
+ 'update:visible',
269
+ 'update:formData',
270
+ 'button-click',
271
+ 'dialog-close',
272
+ 'dialog-confirm',
273
+ 'dialog-cancel',
274
+ 'api-success',
275
+ 'api-error',
276
+ 'reset',
277
+ 'submit',
278
+ 'submit-error',
279
+ 'validate',
280
+ 'detail-loaded',
281
+ 'detail-error'
282
+ ])
283
+
284
+ const computedTitle = computed(() => {
285
+ switch (props.dialogType) {
286
+ case 'add': return '添加数据';
287
+ case 'delete': return '删除确认';
288
+ case 'edit': return '编辑数据';
289
+ default: return '';
290
+ }
291
+ })
292
+
293
+ // 初始化dialogVisible
294
+ const dialogVisible = ref(props.visible)
295
+ const apiLoading = ref(false)
296
+ const formRef = ref(null)
297
+ const currentId = ref(null)
298
+ const currentParams = ref({})
299
+ // 本地维护一份表单数据的副本
300
+ const initFormData = ref(props.formData ? { ...props.formData } : {})
301
+ const localFormData = ref({ ...initFormData.value })
302
+
303
+ // 监听 props.formData 的变化,同步到本地数据
304
+ watch(() => props.formData, (newFormData) => {
305
+ if (newFormData) {
306
+ // 合并新的表单数据到本地数据
307
+ Object.keys(newFormData).forEach(key => {
308
+ localFormData.value[key] = newFormData[key]
309
+ })
310
+ }
311
+ }, { deep: true })
312
+
313
+ // 监听本地数据变化,同步到父组件
314
+ watch(localFormData, (newValue) => {
315
+ emit('update:formData', { ...newValue })
316
+ }, { deep: true })
317
+
318
+ // 监听props的visible变化
319
+ watch(() => props.visible, (newVal) => {
320
+ dialogVisible.value = newVal
321
+ })
322
+
323
+ // 监听dialogVisible变化,同步更新modelValue
324
+ watch(dialogVisible, (newVal) => {
325
+ emit('update:visible', newVal)
326
+ })
327
+
328
+ // 弹窗关闭事件
329
+ const handleDialogClose = (e) => {
330
+ dialogVisible.value = false
331
+ emit('dialog-close', e)
332
+ }
333
+
334
+ // API调用方法
335
+ // 获取错误消息
336
+ const getErrorMessage = (error, dialogType) => {
337
+ console.error(error)
338
+ const errorPrefix = dialogType === 'delete'
339
+ ? '删除失败'
340
+ : dialogType === 'add'
341
+ ? '添加失败'
342
+ : dialogType === 'edit'
343
+ ? '修改失败'
344
+ : '操作失败'
345
+
346
+ if (!error) return `${errorPrefix}: 未知错误`
347
+
348
+ // 处理不同类型的错误
349
+ if (error.response && error.response.data) {
350
+ // API返回的详细错误信息
351
+ const { message, msg, error: errMsg } = error.response.data
352
+ return `${errorPrefix}: ${message || msg || errMsg || error.message || '服务器返回错误'}`
353
+ } else if (error.message) {
354
+ // 标准错误对象
355
+ return `${errorPrefix}: ${error.message}`
356
+ } else if (typeof error === 'string') {
357
+ // 字符串错误
358
+ return `${errorPrefix}: ${error}`
359
+ } else {
360
+ // 未知错误
361
+ return `${errorPrefix}: 未知错误`
362
+ }
363
+ }
364
+
365
+ const callApi = async (config = props.apiConfig) => {
366
+ if (!config) return null
367
+
368
+ console.log("props.formData", props.formData)
369
+ try {
370
+
371
+ apiLoading.value = true
372
+
373
+ console.log(123123123123)
374
+ console.log(localFormData.value)
375
+
376
+ // 准备请求参数
377
+ const fetchParams = { ...localFormData.value }
378
+
379
+ // 如果有ID,添加到请求参数中
380
+ if (currentId.value) {
381
+ fetchParams.id = currentId.value
382
+ }
383
+ console.log("123123")
384
+
385
+ // 合并当前参数到请求参数
386
+ if (currentParams.value && Object.keys(currentParams.value).length > 0) {
387
+ Object.keys(currentParams.value).forEach(key => {
388
+ if (key !== 'formData') { // 避免重复添加表单数据
389
+ fetchParams[key] = currentParams.value[key]
390
+ }
391
+ })
392
+ }
393
+ console.log("123123")
394
+
395
+ // 调用dataService进行API请求,直接使用config
396
+ config.apiType = 'PROCESS'
397
+ const response = await dataService.fetch({ detailId: fetchParams.detailId || fetchParams.id, saveData: { ...fetchParams } }, config)
398
+
399
+ // 显示成功消息
400
+ if (props.showResultMessage) {
401
+ resetFormData()
402
+ const successMessage = props.dialogType === 'delete'
403
+ ? '删除成功'
404
+ : props.dialogType === 'add'
405
+ ? '添加成功'
406
+ : props.dialogType === 'edit'
407
+ ? '修改成功'
408
+ : '操作成功'
409
+ MessagePlugin.success(successMessage)
410
+ }
411
+
412
+ // 清空数据
413
+ Object.keys(localFormData.value).forEach(key => {
414
+ delete localFormData.value[key]
415
+ })
416
+
417
+ // 触发成功事件
418
+ emit('api-success', response)
419
+
420
+ // 如果设置了成功后关闭,则关闭弹窗
421
+ if (props.closeOnSuccess) {
422
+ dialogVisible.value = false
423
+ }
424
+
425
+ return response
426
+ } catch (error) {
427
+ console.log(error)
428
+ // 错误处理和错误消息展示
429
+ const errorMessage = getErrorMessage(error, props.dialogType)
430
+
431
+ // 显示错误消息
432
+ if (props.showResultMessage) {
433
+ MessagePlugin.error(errorMessage)
434
+ }
435
+
436
+ // 触发错误事件
437
+ emit('api-error', error)
438
+
439
+ throw error // 继续抛出错误以便上层捕获
440
+ } finally {
441
+ apiLoading.value = false
442
+ }
443
+ }
444
+
445
+ // 弹窗确认事件
446
+ const handleDialogConfirm = async (e) => {
447
+ emit('dialog-confirm', e)
448
+ if(apiLoading.value) return
449
+ // 对于非普通类型的弹窗,总是尝试调用API
450
+ if (props.dialogType !== 'normal') {
451
+ if (props.apiConfig) {
452
+ // 如果是表单类型(添加或编辑),先进行表单校验
453
+ if ((props.dialogType === 'add' || props.dialogType === 'edit') && formRef.value) {
454
+
455
+ try {
456
+ console.log(123123123)
457
+ // 显示加载状态
458
+ apiLoading.value = true
459
+
460
+ // 使用表单的validate方法进行校验
461
+ const validateResult = await formRef.value.validate()
462
+ console.log("validateResult", validateResult)
463
+
464
+ // 校验成功,执行提交操作
465
+ if (validateResult === true) {
466
+ // 直接调用callApi传入props.apiConfig
467
+ await callApi(props.apiConfig)
468
+ } else {
469
+ // 校验失败,显示第一个错误信息
470
+ const firstError = validateResult[Object.keys(validateResult)[0]]?.[0]?.message || '表单校验失败'
471
+ MessagePlugin.error(firstError)
472
+ emit('submit-error', { validateResult, firstError })
473
+ return // 阻止关闭弹窗
474
+ }
475
+ } catch (error) {
476
+ console.error(error)
477
+ // 校验或API调用过程中的错误
478
+ MessagePlugin.error(`操作失败: ${error.message || '未知错误'}`)
479
+ emit('submit-error', { error })
480
+ return // 阻止关闭弹窗
481
+ } finally {
482
+ apiLoading.value = false
483
+ }
484
+ } else if (props.dialogType === 'delete') {
485
+ try {
486
+ // 显示加载状态
487
+ apiLoading.value = true
488
+
489
+ // 删除操作直接调用API
490
+ await callApi(props.apiConfig)
491
+ } catch (error) {
492
+ // API调用过程中的错误
493
+ MessagePlugin.error(`删除失败: ${error.message || '未知错误'}`)
494
+ emit('api-error', error)
495
+ return // 阻止关闭弹窗
496
+ } finally {
497
+ apiLoading.value = false
498
+ }
499
+ }
500
+ } else {
501
+ dialogVisible.value = false
502
+ }
503
+ } else {
504
+ // 普通弹窗的行为
505
+ if (props.apiConfig) {
506
+ try {
507
+ // 显示加载状态
508
+ apiLoading.value = true
509
+
510
+ // 直接调用API,不修改apiConfig
511
+ await callApi(props.apiConfig)
512
+ } catch (error) {
513
+ console.error(error)
514
+ // API调用过程中的错误
515
+ MessagePlugin.error(`操作失败: ${error.message || '未知错误'}`)
516
+ emit('api-error', error)
517
+ return // 阻止关闭弹窗
518
+ } finally {
519
+ apiLoading.value = false
520
+ }
521
+ } else {
522
+ dialogVisible.value = false
523
+ }
524
+ }
525
+ }
526
+
527
+ // 弹窗取消事件
528
+ const handleDialogCancel = (e) => {
529
+ dialogVisible.value = false
530
+ emit('dialog-cancel', e)
531
+ }
532
+
533
+ // 表单重置事件
534
+ const handleReset = (e) => {
535
+ emit('reset', e)
536
+ }
537
+
538
+ // 表单提交事件
539
+ const handleSubmit = async ({ validateResult, firstError, e }) => {
540
+ if (validateResult === true) {
541
+ emit('submit', { e, formData: localFormData.value })
542
+ } else {
543
+ MessagePlugin.error(firstError)
544
+ emit('submit-error', { validateResult, firstError })
545
+ }
546
+ }
547
+
548
+ // 表单验证事件
549
+ const handleValidate = (params) => {
550
+ emit('validate', params)
551
+ }
552
+
553
+ // 加载详情数据
554
+ const loadDetailData = async (id) => {
555
+ if (!props.detailApiConfig) return null
556
+
557
+ try {
558
+ // 显示加载状态
559
+ apiLoading.value = true
560
+
561
+ // 准备请求参数
562
+ const fetchParams = { detailId: id }
563
+
564
+ // 合并当前参数到请求参数
565
+ if (currentParams.value && Object.keys(currentParams.value).length > 0) {
566
+ // 过滤掉id和formData,避免重复
567
+ const { id: _id, formData: _formData, ...otherParams } = currentParams.value
568
+ Object.keys(otherParams).forEach(key => {
569
+ fetchParams[key] = otherParams[key]
570
+ })
571
+ }
572
+
573
+ // 调用dataService进行API请求,直接使用detailApiConfig
574
+ const response = await dataService.fetch(fetchParams, props.detailApiConfig)
575
+
576
+ // 获取详情数据
577
+ const detailData = response.data || response
578
+
579
+ // 更新本地表单数据
580
+ if (detailData) {
581
+ // 清空现有数据
582
+ Object.keys(localFormData.value).forEach(key => {
583
+ delete localFormData.value[key]
584
+ })
585
+
586
+ // 写入新数据
587
+ Object.keys(detailData).forEach(key => {
588
+ localFormData.value[key] = detailData[key]
589
+ })
590
+ }
591
+
592
+ // 触发加载成功事件
593
+ emit('detail-loaded', detailData)
594
+ return detailData
595
+ } catch (error) {
596
+ // 显示错误消息
597
+ if (props.showResultMessage) {
598
+ MessagePlugin.error(`加载详情失败: ${error.message || '未知错误'}`)
599
+ }
600
+
601
+ // 触发错误事件
602
+ emit('detail-error', error)
603
+ return null
604
+ } finally {
605
+ apiLoading.value = false
606
+ }
607
+ }
608
+
609
+ // 打开弹窗并传递参数
610
+ const openDialog = (params = {}) => {
611
+ params = { ...params, ...props.params }
612
+ // 重置状态
613
+ if (props.dialogType === 'add') {
614
+ // 添加模式:清空表单数据
615
+ Object.keys(localFormData.value).forEach(key => {
616
+ delete localFormData.value[key]
617
+ })
618
+ }
619
+
620
+ resetFormData();
621
+
622
+ // 处理传入的表单数据
623
+ if (params.formData && (props.dialogType === 'add' || props.dialogType === 'edit')) {
624
+ // 更新本地表单数据副本
625
+ Object.keys(params.formData).forEach(key => {
626
+ localFormData.value[key] = params.formData[key]
627
+ })
628
+ }
629
+
630
+ // 存储其他参数,如删除ID等
631
+ if (params.id) {
632
+ currentId.value = params.id
633
+
634
+ // 如果是编辑模式且有detailApiConfig,加载详情数据
635
+ if (props.dialogType === 'edit' && props.detailApiConfig) {
636
+ loadDetailData(params.id)
637
+ }
638
+ } else {
639
+ currentId.value = null
640
+ }
641
+
642
+ // 存储其他自定义参数
643
+ currentParams.value = params
644
+
645
+ // 打开弹窗
646
+ dialogVisible.value = true
647
+
648
+ return { success: true, message: '弹窗已打开' }
649
+ }
650
+
651
+ // 关闭弹窗
652
+ const closeDialog = () => {
653
+ dialogVisible.value = false
654
+ return { success: true, message: '弹窗已关闭' }
655
+ }
656
+
657
+ // 重置表单数据到初始状态
658
+ const resetFormData = () => {
659
+ if (formRef.value) {
660
+ formRef.value.reset()
661
+ emit('reset', { type: 'manual' })
662
+ }
663
+
664
+ // 重置本地表单数据
665
+ Object.keys(localFormData.value).forEach(key => {
666
+ delete localFormData.value[key]
667
+ })
668
+
669
+ emit('update:formData', { ...localFormData.value })
670
+
671
+ return { success: true, message: '表单已重置' }
672
+ }
673
+
674
+ // 清空表单数据
675
+ const clearFormData = () => {
676
+ // 清空表单数据
677
+ Object.keys(localFormData.value).forEach(key => {
678
+ delete localFormData.value[key]
679
+ })
680
+
681
+ emit('reset', { type: 'clear' })
682
+ return { success: true, message: '表单数据已清空' }
683
+ }
684
+
685
+ // 设置表单数据
686
+ const setFormData = (data) => {
687
+ if (!data || typeof data !== 'object') {
688
+ return { success: false, message: '数据必须是一个对象' }
689
+ }
690
+
691
+ // 清空现有数据
692
+ Object.keys(localFormData.value).forEach(key => {
693
+ delete localFormData.value[key]
694
+ })
695
+
696
+ // 写入新数据
697
+ Object.keys(data).forEach(key => {
698
+ localFormData.value[key] = data[key]
699
+ })
700
+
701
+ return { success: true, message: '表单数据已设置' }
702
+ }
703
+
704
+ // 获取表单数据
705
+ const getFormData = () => {
706
+ return { ...localFormData.value }
707
+ }
708
+
709
+ // 获取表单的当前验证状态
710
+ const validateForm = async () => {
711
+ if (!formRef.value) {
712
+ return { success: false, message: '表单引用不存在' }
713
+ }
714
+
715
+ try {
716
+ const validateResult = await formRef.value.validate()
717
+
718
+ if (validateResult === true) {
719
+ return { success: true, message: '表单验证通过', data: getFormData() }
720
+ } else {
721
+ const firstError = validateResult[Object.keys(validateResult)[0]]?.[0]?.message || '表单校验失败'
722
+ return { success: false, message: firstError, errors: validateResult }
723
+ }
724
+ } catch (error) {
725
+ return { success: false, message: error.message || '表单验证过程中发生错误' }
726
+ }
727
+ }
728
+
729
+ // 暴露给父组件的方法
730
+ defineExpose({
731
+ openDialog,
732
+ closeDialog,
733
+ resetFormData,
734
+ clearFormData,
735
+ setFormData,
736
+ getFormData,
737
+ validateForm,
738
+ loadDetailData,
739
+ currentId,
740
+ currentParams,
741
+ formRef
742
+ })
743
+ </script>
744
+
745
+ <style scoped>
746
+ .ebiz-tdesign-button-dialog {
747
+ display: inline-block;
748
+ }
749
+
750
+ .dialog-header-delete {
751
+ color: var(--td-error-color, #e34d59);
752
+ }
753
+
754
+ .delete-confirm-content {
755
+ display: flex;
756
+ align-items: center;
757
+ padding: 16px;
758
+ }
759
+
760
+ .delete-icon {
761
+ font-size: 24px;
762
+ color: var(--td-error-color, #e34d59);
763
+ margin-right: 12px;
764
+ }
765
+
766
+ .delete-message {
767
+ margin: 0;
768
+ font-size: 14px;
769
+ line-height: 22px;
770
+ }
771
771
  </style>