mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:09:20 +08:00
refactor: 全部改用vben模态框
This commit is contained in:
@@ -3,7 +3,9 @@ import type { FileDTO, FileVO } from '#/api/media/file/types';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { Form, Input, message, Modal } from 'ant-design-vue';
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message } from 'ant-design-vue';
|
||||
|
||||
import { updateFileApi } from '#/api/media/file';
|
||||
|
||||
@@ -26,8 +28,18 @@ interface Emits {
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleOk();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false);
|
||||
const formRef = ref();
|
||||
const formData = ref<FileDTO.Update>({
|
||||
tags: '',
|
||||
@@ -38,22 +50,22 @@ const formData = ref<FileDTO.Update>({
|
||||
watch(
|
||||
() => props.open,
|
||||
(newVal) => {
|
||||
visible.value = newVal;
|
||||
if (newVal && props.fileData) {
|
||||
// 填充表单数据
|
||||
formData.value = {
|
||||
tags: props.fileData.tags,
|
||||
remark: props.fileData.remark,
|
||||
};
|
||||
if (newVal) {
|
||||
modalApi.open();
|
||||
if (props.fileData) {
|
||||
// 填充表单数据
|
||||
formData.value = {
|
||||
tags: props.fileData.tags,
|
||||
remark: props.fileData.remark,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
modalApi.close();
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 监听visible变化,同步到父组件
|
||||
watch(visible, (newVal) => {
|
||||
emit('update:open', newVal);
|
||||
});
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
@@ -62,7 +74,8 @@ const handleOk = async () => {
|
||||
await updateFileApi(props.fileData.id, formData.value);
|
||||
message.success('更新成功');
|
||||
emit('success');
|
||||
visible.value = false;
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
}
|
||||
} catch {
|
||||
message.error('更新失败');
|
||||
@@ -72,7 +85,8 @@ const handleOk = async () => {
|
||||
// 取消操作
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
visible.value = false;
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
// 重置表单数据
|
||||
formData.value = {
|
||||
tags: '',
|
||||
@@ -82,12 +96,7 @@ const handleCancel = () => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
title="编辑文件信息"
|
||||
@ok="handleOk"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Modal title="编辑文件信息">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
|
||||
+31
-22
@@ -3,7 +3,9 @@ import type { ImageDTO, ImageVO } from '#/api/media/image/types';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { Form, Input, message, Modal } from 'ant-design-vue';
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message } from 'ant-design-vue';
|
||||
|
||||
import { updateImageApi } from '#/api/media/image';
|
||||
|
||||
@@ -26,8 +28,18 @@ interface Emits {
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleOk();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false);
|
||||
const formRef = ref();
|
||||
const formData = ref<ImageDTO.Update>({
|
||||
tags: '',
|
||||
@@ -38,22 +50,22 @@ const formData = ref<ImageDTO.Update>({
|
||||
watch(
|
||||
() => props.open,
|
||||
(newVal) => {
|
||||
visible.value = newVal;
|
||||
if (newVal && props.imageData) {
|
||||
// 填充表单数据
|
||||
formData.value = {
|
||||
tags: props.imageData.tags,
|
||||
remark: props.imageData.remark,
|
||||
};
|
||||
if (newVal) {
|
||||
modalApi.open();
|
||||
if (props.imageData) {
|
||||
// 填充表单数据
|
||||
formData.value = {
|
||||
tags: props.imageData.tags,
|
||||
remark: props.imageData.remark,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
modalApi.close();
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 监听visible变化,同步到父组件
|
||||
watch(visible, (newVal) => {
|
||||
emit('update:open', newVal);
|
||||
});
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
@@ -62,7 +74,8 @@ const handleOk = async () => {
|
||||
await updateImageApi(props.imageData.id, formData.value);
|
||||
message.success('更新成功');
|
||||
emit('success');
|
||||
visible.value = false;
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
}
|
||||
} catch {
|
||||
message.error('更新失败');
|
||||
@@ -72,7 +85,8 @@ const handleOk = async () => {
|
||||
// 取消操作
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
visible.value = false;
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
// 重置表单数据
|
||||
formData.value = {
|
||||
tags: '',
|
||||
@@ -82,12 +96,7 @@ const handleCancel = () => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
title="编辑图片信息"
|
||||
@ok="handleOk"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Modal title="编辑图片信息">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
|
||||
Reference in New Issue
Block a user