@ebiz/designer-components 0.0.62 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebiz/designer-components",
3
- "version": "0.0.62",
3
+ "version": "0.1.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -21,20 +21,20 @@
21
21
  <slot name="body"></slot>
22
22
  </div>
23
23
  <div v-else-if="dialogType === 'add'">
24
- <t-form ref="formRef" :colon="colon"
25
- :data="localFormData" :disabled="disabled" :label-align="labelAlign" :label-width="labelWidth" :layout="layout"
26
- :reset-type="resetType" :reset-on-semi-controlled="resetOnSemiControlled" :rules="rules"
27
- :show-error-message="showErrorMessage" :status-icon="statusIcon"
28
- :style="customStyle" @reset="handleReset" @submit="handleSubmit" @validate="handleValidate">
24
+ <t-form ref="formRef" :colon="colon" :data="localFormData" :disabled="disabled" :label-align="labelAlign"
25
+ :label-width="labelWidth" :layout="layout" :reset-type="resetType"
26
+ :reset-on-semi-controlled="resetOnSemiControlled" :rules="rules" :show-error-message="showErrorMessage"
27
+ :status-icon="statusIcon" :style="customStyle" @reset="handleReset" @submit="handleSubmit"
28
+ @validate="handleValidate">
29
29
  <slot name="body"></slot>
30
30
  </t-form>
31
31
  </div>
32
32
  <div v-else-if="dialogType === 'edit'">
33
- <t-form ref="formRef" :colon="colon"
34
- :data="localFormData" :disabled="disabled" :label-align="labelAlign" :label-width="labelWidth" :layout="layout"
35
- :reset-type="resetType" :reset-on-semi-controlled="resetOnSemiControlled" :rules="rules"
36
- :show-error-message="showErrorMessage" :status-icon="statusIcon"
37
- :style="customStyle" @reset="handleReset" @submit="handleSubmit" @validate="handleValidate">
33
+ <t-form ref="formRef" :colon="colon" :data="localFormData" :disabled="disabled" :label-align="labelAlign"
34
+ :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
38
  <slot name="body"></slot>
39
39
  </t-form>
40
40
  </div>
@@ -51,7 +51,7 @@
51
51
 
52
52
  <script setup>
53
53
  import { ref, computed, watch } from 'vue'
54
- import { Dialog as TDialog, MessagePlugin, Icon as TIcon,Form as TForm } from 'tdesign-vue-next'
54
+ import { Dialog as TDialog, MessagePlugin, Icon as TIcon, Form as TForm } from 'tdesign-vue-next'
55
55
  import dataService from '../../../apiService/simpleDataService'
56
56
 
57
57
  const props = defineProps({
@@ -61,13 +61,13 @@ const props = defineProps({
61
61
  default: 'normal', // 'normal', 'add', 'delete'
62
62
  validator: (value) => ['normal', 'add', 'edit', 'delete'].includes(value)
63
63
  },
64
-
64
+
65
65
  // 删除确认消息
66
66
  deleteConfirmMessage: {
67
67
  type: String,
68
68
  default: '确定要删除该数据吗?此操作不可逆,请谨慎操作。'
69
69
  },
70
-
70
+
71
71
  // 按钮基础属性
72
72
  buttonText: {
73
73
  type: String,
@@ -106,7 +106,7 @@ const props = defineProps({
106
106
  type: String,
107
107
  default: ''
108
108
  },
109
-
109
+
110
110
  // 弹窗基础属性
111
111
  title: {
112
112
  type: String,
@@ -124,7 +124,7 @@ const props = defineProps({
124
124
  type: String,
125
125
  default: undefined
126
126
  },
127
-
127
+
128
128
  // 弹窗样式和行为属性
129
129
  dialogWidth: {
130
130
  type: [String, Number],
@@ -166,7 +166,7 @@ const props = defineProps({
166
166
  type: Boolean,
167
167
  default: true
168
168
  },
169
-
169
+
170
170
  // API配置
171
171
  apiConfig: {
172
172
  type: Object,
@@ -180,13 +180,13 @@ const props = defineProps({
180
180
  },
181
181
 
182
182
  // 表单数据
183
- formData:{
183
+ formData: {
184
184
  type: Object,
185
185
  default: () => null
186
186
  },
187
187
 
188
188
  // 表单验证规则
189
- rules:{
189
+ rules: {
190
190
  type: Object,
191
191
  default: () => null
192
192
  },
@@ -201,7 +201,7 @@ const props = defineProps({
201
201
  type: Boolean,
202
202
  default: true
203
203
  },
204
-
204
+
205
205
  // 表单组件属性
206
206
  colon: {
207
207
  type: Boolean,
@@ -283,7 +283,9 @@ const formRef = ref(null)
283
283
  const currentId = ref(null)
284
284
  const currentParams = ref({})
285
285
  // 本地维护一份表单数据的副本
286
- const localFormData = ref(props.formData ? { ...props.formData } : {})
286
+ const localFormData = computed(() => {
287
+ return props.formData ? { ...props.formData } : {}
288
+ })
287
289
 
288
290
  // 监听props的visible变化
289
291
  watch(() => props.visible, (newVal) => {
@@ -304,16 +306,16 @@ const handleDialogClose = (e) => {
304
306
  // API调用方法
305
307
  // 获取错误消息
306
308
  const getErrorMessage = (error, dialogType) => {
307
- const errorPrefix = dialogType === 'delete'
308
- ? '删除失败'
309
- : dialogType === 'add'
310
- ? '添加失败'
309
+ const errorPrefix = dialogType === 'delete'
310
+ ? '删除失败'
311
+ : dialogType === 'add'
312
+ ? '添加失败'
311
313
  : dialogType === 'edit'
312
314
  ? '修改失败'
313
315
  : '操作失败'
314
-
316
+
315
317
  if (!error) return `${errorPrefix}: 未知错误`
316
-
318
+
317
319
  // 处理不同类型的错误
318
320
  if (error.response && error.response.data) {
319
321
  // API返回的详细错误信息
@@ -333,18 +335,18 @@ const getErrorMessage = (error, dialogType) => {
333
335
 
334
336
  const callApi = async (config = props.apiConfig) => {
335
337
  if (!config) return null
336
-
338
+
337
339
  try {
338
340
  apiLoading.value = true
339
-
341
+
340
342
  // 准备请求参数
341
343
  const fetchParams = { ...localFormData.value, ...props.formData }
342
-
344
+
343
345
  // 如果有ID,添加到请求参数中
344
346
  if (currentId.value) {
345
347
  fetchParams.id = currentId.value
346
348
  }
347
-
349
+
348
350
  // 合并当前参数到请求参数
349
351
  if (currentParams.value && Object.keys(currentParams.value).length > 0) {
350
352
  Object.keys(currentParams.value).forEach(key => {
@@ -353,44 +355,44 @@ const callApi = async (config = props.apiConfig) => {
353
355
  }
354
356
  })
355
357
  }
356
-
358
+
357
359
  // 调用dataService进行API请求,直接使用config
358
360
  config.apiType = 'PROCESS'
359
- const response = await dataService.fetch({ detailId: fetchParams.detailId || fetchParams.id, saveData: { ...fetchParams} }, config)
360
-
361
+ const response = await dataService.fetch({ detailId: fetchParams.detailId || fetchParams.id, saveData: { ...fetchParams } }, config)
362
+
361
363
  // 显示成功消息
362
364
  if (props.showResultMessage) {
363
- const successMessage = props.dialogType === 'delete'
364
- ? '删除成功'
365
- : props.dialogType === 'add'
366
- ? '添加成功'
365
+ const successMessage = props.dialogType === 'delete'
366
+ ? '删除成功'
367
+ : props.dialogType === 'add'
368
+ ? '添加成功'
367
369
  : props.dialogType === 'edit'
368
370
  ? '修改成功'
369
371
  : '操作成功'
370
372
  MessagePlugin.success(successMessage)
371
373
  }
372
-
374
+
373
375
  // 触发成功事件
374
376
  emit('api-success', response)
375
-
377
+
376
378
  // 如果设置了成功后关闭,则关闭弹窗
377
379
  if (props.closeOnSuccess) {
378
380
  dialogVisible.value = false
379
381
  }
380
-
382
+
381
383
  return response
382
384
  } catch (error) {
383
385
  // 错误处理和错误消息展示
384
386
  const errorMessage = getErrorMessage(error, props.dialogType)
385
-
387
+
386
388
  // 显示错误消息
387
389
  if (props.showResultMessage) {
388
390
  MessagePlugin.error(errorMessage)
389
391
  }
390
-
392
+
391
393
  // 触发错误事件
392
394
  emit('api-error', error)
393
-
395
+
394
396
  throw error // 继续抛出错误以便上层捕获
395
397
  } finally {
396
398
  apiLoading.value = false
@@ -400,7 +402,7 @@ const callApi = async (config = props.apiConfig) => {
400
402
  // 弹窗确认事件
401
403
  const handleDialogConfirm = async (e) => {
402
404
  emit('dialog-confirm', e)
403
-
405
+
404
406
  // 对于非普通类型的弹窗,总是尝试调用API
405
407
  if (props.dialogType !== 'normal') {
406
408
  if (props.apiConfig) {
@@ -411,10 +413,10 @@ const handleDialogConfirm = async (e) => {
411
413
  try {
412
414
  // 显示加载状态
413
415
  apiLoading.value = true
414
-
416
+
415
417
  // 使用表单的validate方法进行校验
416
418
  const validateResult = await formRef.value.validate()
417
-
419
+
418
420
  // 校验成功,执行提交操作
419
421
  if (validateResult === true) {
420
422
  // 直接调用callApi传入props.apiConfig
@@ -438,7 +440,7 @@ const handleDialogConfirm = async (e) => {
438
440
  try {
439
441
  // 显示加载状态
440
442
  apiLoading.value = true
441
-
443
+
442
444
  // 删除操作直接调用API
443
445
  await callApi(props.apiConfig)
444
446
  } catch (error) {
@@ -459,7 +461,7 @@ const handleDialogConfirm = async (e) => {
459
461
  try {
460
462
  // 显示加载状态
461
463
  apiLoading.value = true
462
-
464
+
463
465
  // 直接调用API,不修改apiConfig
464
466
  await callApi(props.apiConfig)
465
467
  } catch (error) {
@@ -505,14 +507,14 @@ const handleValidate = (params) => {
505
507
  // 加载详情数据
506
508
  const loadDetailData = async (id) => {
507
509
  if (!props.detailApiConfig) return null
508
-
510
+
509
511
  try {
510
512
  // 显示加载状态
511
513
  apiLoading.value = true
512
-
514
+
513
515
  // 准备请求参数
514
516
  const fetchParams = { id }
515
-
517
+
516
518
  // 合并当前参数到请求参数
517
519
  if (currentParams.value && Object.keys(currentParams.value).length > 0) {
518
520
  // 过滤掉id和formData,避免重复
@@ -521,26 +523,26 @@ const loadDetailData = async (id) => {
521
523
  fetchParams[key] = otherParams[key]
522
524
  })
523
525
  }
524
-
526
+
525
527
  // 调用dataService进行API请求,直接使用detailApiConfig
526
528
  const response = await dataService.fetch(fetchParams, props.detailApiConfig)
527
-
529
+
528
530
  // 获取详情数据
529
531
  const detailData = response.data || response
530
-
532
+
531
533
  // 更新本地表单数据
532
534
  if (detailData) {
533
535
  // 清空现有数据
534
536
  Object.keys(localFormData.value).forEach(key => {
535
537
  delete localFormData.value[key]
536
538
  })
537
-
539
+
538
540
  // 写入新数据
539
541
  Object.keys(detailData).forEach(key => {
540
542
  localFormData.value[key] = detailData[key]
541
543
  })
542
544
  }
543
-
545
+
544
546
  // 触发加载成功事件
545
547
  emit('detail-loaded', detailData)
546
548
  return detailData
@@ -549,7 +551,7 @@ const loadDetailData = async (id) => {
549
551
  if (props.showResultMessage) {
550
552
  MessagePlugin.error(`加载详情失败: ${error.message || '未知错误'}`)
551
553
  }
552
-
554
+
553
555
  // 触发错误事件
554
556
  emit('detail-error', error)
555
557
  return null
@@ -560,7 +562,7 @@ const loadDetailData = async (id) => {
560
562
 
561
563
  // 打开弹窗并传递参数
562
564
  const openDialog = (params = {}) => {
563
- params = { ...params , ...props.params}
565
+ params = { ...params, ...props.params }
564
566
  // 重置状态
565
567
  if (props.dialogType === 'add') {
566
568
  // 添加模式:清空表单数据
@@ -568,7 +570,7 @@ const openDialog = (params = {}) => {
568
570
  delete localFormData.value[key]
569
571
  })
570
572
  }
571
-
573
+
572
574
  // 处理传入的表单数据
573
575
  if (params.formData && (props.dialogType === 'add' || props.dialogType === 'edit')) {
574
576
  // 更新本地表单数据副本
@@ -576,11 +578,11 @@ const openDialog = (params = {}) => {
576
578
  localFormData.value[key] = params.formData[key]
577
579
  })
578
580
  }
579
-
581
+
580
582
  // 存储其他参数,如删除ID等
581
583
  if (params.id) {
582
584
  currentId.value = params.id
583
-
585
+
584
586
  // 如果是编辑模式且有detailApiConfig,加载详情数据
585
587
  if (props.dialogType === 'edit' && props.detailApiConfig) {
586
588
  loadDetailData(params.id)
@@ -588,13 +590,13 @@ const openDialog = (params = {}) => {
588
590
  } else {
589
591
  currentId.value = null
590
592
  }
591
-
593
+
592
594
  // 存储其他自定义参数
593
595
  currentParams.value = params
594
-
596
+
595
597
  // 打开弹窗
596
598
  dialogVisible.value = true
597
-
599
+
598
600
  return { success: true, message: '弹窗已打开' }
599
601
  }
600
602
 
@@ -610,7 +612,7 @@ const resetFormData = () => {
610
612
  formRef.value.reset()
611
613
  emit('reset', { type: 'manual' })
612
614
  }
613
-
615
+
614
616
  return { success: true, message: '表单已重置' }
615
617
  }
616
618
 
@@ -620,7 +622,7 @@ const clearFormData = () => {
620
622
  Object.keys(localFormData.value).forEach(key => {
621
623
  delete localFormData.value[key]
622
624
  })
623
-
625
+
624
626
  emit('reset', { type: 'clear' })
625
627
  return { success: true, message: '表单数据已清空' }
626
628
  }
@@ -630,17 +632,17 @@ const setFormData = (data) => {
630
632
  if (!data || typeof data !== 'object') {
631
633
  return { success: false, message: '数据必须是一个对象' }
632
634
  }
633
-
635
+
634
636
  // 清空现有数据
635
637
  Object.keys(localFormData.value).forEach(key => {
636
638
  delete localFormData.value[key]
637
639
  })
638
-
640
+
639
641
  // 写入新数据
640
642
  Object.keys(data).forEach(key => {
641
643
  localFormData.value[key] = data[key]
642
644
  })
643
-
645
+
644
646
  return { success: true, message: '表单数据已设置' }
645
647
  }
646
648
 
@@ -654,10 +656,10 @@ const validateForm = async () => {
654
656
  if (!formRef.value) {
655
657
  return { success: false, message: '表单引用不存在' }
656
658
  }
657
-
659
+
658
660
  try {
659
661
  const validateResult = await formRef.value.validate()
660
-
662
+
661
663
  if (validateResult === true) {
662
664
  return { success: true, message: '表单验证通过', data: getFormData() }
663
665
  } else {
@@ -711,4 +713,4 @@ defineExpose({
711
713
  font-size: 14px;
712
714
  line-height: 22px;
713
715
  }
714
- </style>
716
+ </style>
@@ -36,6 +36,13 @@
36
36
  </template>
37
37
  </template>
38
38
 
39
+ <!-- 日期选择器 -->
40
+ <template v-else-if="type === 'datetime'">
41
+ <t-date-picker v-model="computedModelValue" :placeholder="placeholder || '请选择日期时间'" :disabled="disabled"
42
+ :clearable="clearable" enable-time-picker format="YYYY-MM-DD HH:mm:ss" @change="handleChange" />
43
+ </template>
44
+
45
+
39
46
  <!-- 日期选择器 -->
40
47
  <template v-else-if="type === 'date'">
41
48
  <t-date-picker v-model="computedModelValue" :placeholder="placeholder || '请选择日期'" :disabled="disabled"