StdBatchEdit.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script setup lang="ts">
  2. import type Curd from '@/api/curd'
  3. import type { Column } from '@/components/StdDesign/types'
  4. import { getPithyColumns } from '@/components/StdDesign/StdDataDisplay/methods/columns'
  5. import StdDataEntry from '@/components/StdDesign/StdDataEntry'
  6. import { message } from 'ant-design-vue'
  7. const props = defineProps<{
  8. // eslint-disable-next-line ts/no-explicit-any
  9. api: Curd<any>
  10. beforeSave?: () => Promise<void>
  11. columns: Column[]
  12. }>()
  13. const emit = defineEmits(['save'])
  14. const batchColumns = ref<Column[]>([])
  15. const selectedRowKeys = ref<(number | string)[]>([])
  16. // eslint-disable-next-line ts/no-explicit-any
  17. const selectedRows = ref<any[]>([])
  18. const visible = ref(false)
  19. const data = ref({})
  20. const error = ref({})
  21. const loading = ref(false)
  22. // eslint-disable-next-line ts/no-explicit-any
  23. function showModal(c: Column[], rowKeys: (number | string)[], rows: any[]) {
  24. data.value = {}
  25. visible.value = true
  26. selectedRowKeys.value = rowKeys
  27. batchColumns.value = c
  28. selectedRows.value = rows
  29. }
  30. defineExpose({
  31. showModal,
  32. })
  33. async function ok() {
  34. loading.value = true
  35. await props.beforeSave?.()
  36. await props.api.batch_save(selectedRowKeys.value, data.value)
  37. .then(async () => {
  38. message.success($gettext('Save successfully'))
  39. emit('save')
  40. visible.value = false
  41. })
  42. .finally(() => {
  43. loading.value = false
  44. })
  45. }
  46. </script>
  47. <template>
  48. <AModal
  49. v-model:open="visible"
  50. class="std-curd-edit-modal"
  51. :mask="false"
  52. :title="$gettext('Batch Modify')"
  53. :cancel-text="$gettext('No')"
  54. :ok-text="$gettext('Save')"
  55. :confirm-loading="loading"
  56. :width="600"
  57. destroy-on-close
  58. @ok="ok"
  59. >
  60. <p>{{ $gettext('Belows are selected items that you want to batch modify') }}</p>
  61. <ATable
  62. class="mb-4"
  63. size="small"
  64. :columns="getPithyColumns(columns)"
  65. :data-source="selectedRows"
  66. :pagination="{ showSizeChanger: false, pageSize: 5, size: 'small' }"
  67. />
  68. <p>{{ $gettext('Leave blank if do not want to modify') }}</p>
  69. <StdDataEntry
  70. :data-list="batchColumns"
  71. :data-source="data"
  72. :errors="error"
  73. />
  74. <slot name="extra" />
  75. </AModal>
  76. </template>
  77. <style scoped></style>