StdBatchEdit.vue 1.6 KB

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