form-modal.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <script lang="ts" setup>
  2. import { onMounted, ref, unref } from 'vue';
  3. import { useVbenModal } from '@vben/common-ui';
  4. import { message } from 'ant-design-vue';
  5. import formDesign from './index.vue';
  6. const emit = defineEmits(['success']);
  7. const modelRef = ref<Record<string, any>>({});
  8. const isUpdate = ref(true);
  9. const [Modal, { close, setState, getData }] = useVbenModal({
  10. fullscreenButton: false,
  11. fullscreen: true,
  12. draggable: false,
  13. onCancel() {
  14. close();
  15. },
  16. onConfirm: async () => {
  17. try {
  18. close();
  19. emit('success');
  20. } catch {
  21. message.error('操作失败');
  22. } finally {
  23. setState({ confirmLoading: false });
  24. }
  25. },
  26. onOpenChange: async (isOpen: boolean) => {
  27. if (isOpen) {
  28. setState({ loading: true });
  29. const data = getData<Record<string, any>>();
  30. isUpdate.value = !!data.isUpdate;
  31. modelRef.value = { ...data.baseData };
  32. setState({ title: unref(isUpdate) ? '表单设计' : '表单设计' });
  33. setState({ loading: false });
  34. }
  35. },
  36. title: '表单设计',
  37. });
  38. onMounted(async () => {});
  39. </script>
  40. <template>
  41. <Modal>
  42. <formDesign />
  43. </Modal>
  44. </template>