refactor: 全部改用vben模态框

This commit is contained in:
ah--desktop
2025-11-10 00:10:08 +08:00
parent 5e0a085648
commit 8547e0714a
19 changed files with 401 additions and 292 deletions
@@ -6,7 +6,9 @@ import type {
import { computed, ref, watch } from 'vue';
import { Form, Input, message, Modal, Select } from 'ant-design-vue';
import { useVbenModal } from '@vben/common-ui';
import { Form, Input, message, Select } from 'ant-design-vue';
import {
super_createAccountApi,
@@ -21,10 +23,21 @@ defineOptions({ name: 'SuperAccountFormModal' });
const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[500px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据
const formRef = ref();
const loading = ref(false);
const visible = ref(false);
const isEdit = ref(false);
const currentAccountData = ref<null | SuperAccountVO.AccountInfoVO>(null);
@@ -76,7 +89,7 @@ function resetForm() {
// 处理模态框关闭
function handleCancel() {
visible.value = false;
modalApi.close();
}
// 暴露给父组件的方法
@@ -102,7 +115,7 @@ function open(accountData?: null | SuperAccountVO.AccountInfoVO) {
};
}
visible.value = true;
modalApi.open();
}
// 处理表单提交
@@ -120,8 +133,8 @@ async function handleSubmit() {
message.success('创建成功');
}
visible.value = false;
emit('success');
modalApi.close();
} catch (error: any) {
console.error('保存账户失败:', error);
const errorMessage =
@@ -132,12 +145,15 @@ async function handleSubmit() {
}
}
// 监听弹窗关闭
watch(visible, (val) => {
if (!val) {
resetForm();
}
});
// 监听 modal 关闭状态
watch(
() => modalApi.useStore()?.value?.isOpen,
(newVal) => {
if (!newVal) {
resetForm();
}
},
);
// 暴露方法给父组件
defineExpose({
@@ -146,14 +162,7 @@ defineExpose({
</script>
<template>
<Modal
:open="visible"
:title="modalTitle"
width="500px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<Modal :title="modalTitle" :confirm-loading="loading">
<Form
ref="formRef"
:model="formData"