StdBatchEdit.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <script setup lang="ts">
  2. import { message } from 'ant-design-vue'
  3. import gettext from '@/gettext'
  4. import StdDataEntry from '@/components/StdDesign/StdDataEntry'
  5. const props = defineProps<{
  6. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  7. api: (ids: number[], data: any) => Promise<void>
  8. beforeSave?: () => Promise<void>
  9. }>()
  10. const emit = defineEmits(['onSave'])
  11. const { $gettext } = gettext
  12. const batchColumns = ref([])
  13. const visible = ref(false)
  14. const selectedRowKeys = ref([])
  15. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  16. function showModal(c: any, rowKeys: any) {
  17. visible.value = true
  18. selectedRowKeys.value = rowKeys
  19. batchColumns.value = c
  20. }
  21. defineExpose({
  22. showModal,
  23. })
  24. const data = reactive({})
  25. const error = reactive({})
  26. const loading = ref(false)
  27. async function ok() {
  28. loading.value = true
  29. await props.beforeSave?.()
  30. await props.api(selectedRowKeys.value, data).then(async () => {
  31. message.success($gettext('Save successfully'))
  32. emit('onSave')
  33. }).catch(e => {
  34. message.error($gettext(e?.message) ?? $gettext('Server error'))
  35. }).finally(() => {
  36. loading.value = false
  37. })
  38. }
  39. </script>
  40. <template>
  41. <AModal
  42. v-model:open="visible"
  43. class="std-curd-edit-modal"
  44. :mask="false"
  45. :title="$gettext('Batch Modify')"
  46. :cancel-text="$gettext('Cancel')"
  47. :ok-text="$gettext('OK')"
  48. :confirm-loading="loading"
  49. :width="600"
  50. destroy-on-close
  51. @ok="ok"
  52. >
  53. <StdDataEntry
  54. :data-list="batchColumns"
  55. :data-source="data"
  56. :error="error"
  57. />
  58. <slot name="extra" />
  59. </AModal>
  60. </template>
  61. <style scoped>
  62. </style>