edit.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <basicModal @register="modalRegister" style="width: 45%">
  3. <BasicForm @register="register" @submit="handleSubmit" class="mt-5" />
  4. </basicModal>
  5. </template>
  6. <script lang="ts" setup>
  7. import { nextTick } from 'vue';
  8. import { update, getById } from '@/api/aigc/flow';
  9. import { useMessage } from 'naive-ui';
  10. import { formSchemas } from './columns';
  11. import { BasicForm, useForm } from '@/components/Form';
  12. import { basicModal, useModal } from '@/components/Modal';
  13. const emit = defineEmits(['reload']);
  14. const message = useMessage();
  15. const [
  16. modalRegister,
  17. { openModal: openModal, closeModal: closeModal, setSubLoading: setSubLoading },
  18. ] = useModal({
  19. title: '新增/编辑',
  20. closable: true,
  21. maskClosable: false,
  22. showCloseBtn: false,
  23. showSubBtn: false,
  24. });
  25. const [register, { setFieldsValue }] = useForm({
  26. gridProps: { cols: 1 },
  27. labelWidth: 120,
  28. layout: 'horizontal',
  29. submitButtonText: '提交',
  30. schemas: formSchemas,
  31. });
  32. async function show(id: string) {
  33. openModal();
  34. await nextTick();
  35. if (id) {
  36. setFieldsValue(await getById(id));
  37. }
  38. }
  39. async function handleSubmit(values: any) {
  40. if (values !== false) {
  41. closeModal();
  42. await update(values);
  43. emit('reload');
  44. message.success('修改成功');
  45. } else {
  46. message.error('请完善表单');
  47. }
  48. }
  49. defineExpose({ show });
  50. </script>
  51. <style scoped lang="less"></style>