mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 04:29:20 +08:00
refactor: 全部改用vben模态框
This commit is contained in:
+28
-19
@@ -3,7 +3,9 @@ import type { AccountDTO, AccountVO } from '#/api/organization/account';
|
||||
|
||||
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 {
|
||||
admin_createAccountApi,
|
||||
@@ -18,10 +20,21 @@ defineOptions({ name: 'AccountFormModal' });
|
||||
|
||||
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<AccountVO.AccountInfoVO | null>(null);
|
||||
|
||||
@@ -67,7 +80,7 @@ function resetForm() {
|
||||
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
@@ -91,7 +104,7 @@ function open(accountData?: AccountVO.AccountInfoVO | null) {
|
||||
};
|
||||
}
|
||||
|
||||
visible.value = true;
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
@@ -109,8 +122,8 @@ async function handleSubmit() {
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
} catch (error: any) {
|
||||
console.error('保存账户失败:', error);
|
||||
const errorMessage =
|
||||
@@ -121,12 +134,15 @@ async function handleSubmit() {
|
||||
}
|
||||
}
|
||||
|
||||
// 监听弹窗关闭
|
||||
watch(visible, (val) => {
|
||||
if (!val) {
|
||||
resetForm();
|
||||
}
|
||||
});
|
||||
// 监听 modal 关闭状态
|
||||
watch(
|
||||
() => modalApi.useStore()?.value?.isOpen,
|
||||
(newVal) => {
|
||||
if (!newVal) {
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
@@ -135,14 +151,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"
|
||||
|
||||
Reference in New Issue
Block a user