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
@@ -1,7 +1,9 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue'; import { ref, watch } from 'vue';
import { Button, message, Modal } from 'ant-design-vue'; import { useVbenModal } from '@vben/common-ui';
import { Button, message } from 'ant-design-vue';
import ProductFormModal from '#/views/shop/product/components/ProductFormModal.vue'; import ProductFormModal from '#/views/shop/product/components/ProductFormModal.vue';
import ProductSpecModal from '#/views/shop/product/components/ProductSpecModal.vue'; import ProductSpecModal from '#/views/shop/product/components/ProductSpecModal.vue';
@@ -25,6 +27,31 @@ interface Emits {
const props = defineProps<Props>(); const props = defineProps<Props>();
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[800px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleSubmit();
},
});
// 监听 visible 变化
watch(
() => props.visible,
(newVal) => {
if (newVal) {
modalApi.open();
} else {
modalApi.close();
}
},
{ immediate: true },
);
// 响应式数据 // 响应式数据
const loading = ref(false); const loading = ref(false);
const shopFormModalRef = ref(); const shopFormModalRef = ref();
@@ -42,23 +69,23 @@ const currentCreatingSpec = ref<null | {
// 处理提交 // 处理提交
function handleSubmit() { function handleSubmit() {
// 检查是否还有未创建的实体 // 检查是否还有未创建的实体
const { entitiesToCreate } = defineProps<Props>();
if ( if (
entitiesToCreate.shops.length > 0 || props.entitiesToCreate.shops.length > 0 ||
entitiesToCreate.products.length > 0 || props.entitiesToCreate.products.length > 0 ||
entitiesToCreate.specs.length > 0 props.entitiesToCreate.specs.length > 0
) { ) {
message.warning('请先创建所有缺失的实体'); message.warning('请先创建所有缺失的实体');
return; return;
} }
emit('success'); emit('success');
modalApi.close();
} }
// 处理取消 // 处理取消
function handleCancel() { function handleCancel() {
emit('cancel'); emit('cancel');
modalApi.close();
} }
// 打开店铺创建模态框 // 打开店铺创建模态框
@@ -149,14 +176,7 @@ function handleProductSpecCreated() {
</script> </script>
<template> <template>
<Modal <Modal title="创建缺失的实体" :confirm-loading="loading">
:open="visible"
title="创建缺失的实体"
width="800px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<div class="space-y-6"> <div class="space-y-6">
<!-- 店铺创建 --> <!-- 店铺创建 -->
<div <div
@@ -1,12 +1,23 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons'; import { createIconifyIcon } from '@vben/icons';
import { Button, Modal, Select } from 'ant-design-vue'; import { Button, Select } from 'ant-design-vue';
const props = defineProps<Props>(); const props = defineProps<Props>();
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[1200px]',
onCancel() {
handleCancel();
},
});
// 创建图标组件 // 创建图标组件
const InfoIcon = createIconifyIcon('lucide:info'); const InfoIcon = createIconifyIcon('lucide:info');
const CheckIcon = createIconifyIcon('lucide:check'); const CheckIcon = createIconifyIcon('lucide:check');
@@ -32,8 +43,6 @@ interface Emits {
(e: 'cancel'): void; (e: 'cancel'): void;
} }
const visible = ref(false);
// 系统字段定义 // 系统字段定义
const systemFields: SystemField[] = [ const systemFields: SystemField[] = [
{ {
@@ -147,18 +156,17 @@ const unmappedFieldsCount = computed(() => {
watch( watch(
() => props.visible, () => props.visible,
(newVal) => { (newVal) => {
visible.value = newVal;
if (newVal) { if (newVal) {
modalApi.open();
// 初始化字段映射 // 初始化字段映射
initializeFieldMappings(); initializeFieldMappings();
} else {
modalApi.close();
} }
}, },
{ immediate: true },
); );
watch(visible, (newVal) => {
emit('update:visible', newVal);
});
// 初始化字段映射 // 初始化字段映射
const initializeFieldMappings = () => { const initializeFieldMappings = () => {
const mappings: Record<string, string> = {}; const mappings: Record<string, string> = {};
@@ -258,12 +266,14 @@ const handleConfirm = () => {
} }
emit('confirm', { ...fieldMappings.value }); emit('confirm', { ...fieldMappings.value });
visible.value = false; modalApi.close();
emit('update:visible', false);
}; };
// 处理取消 // 处理取消
const handleCancel = () => { const handleCancel = () => {
visible.value = false; modalApi.close();
emit('update:visible', false);
emit('cancel'); emit('cancel');
}; };
@@ -274,13 +284,7 @@ const handleReset = () => {
</script> </script>
<template> <template>
<Modal <Modal title="字段匹配配置" :footer="false">
v-model:open="visible"
title="字段匹配配置"
width="1200px"
:footer="null"
@cancel="handleCancel"
>
<div class="field-mapping-container"> <div class="field-mapping-container">
<!-- 说明信息 --> <!-- 说明信息 -->
<div class="mb-4 rounded-lg border border-blue-200 bg-blue-50 p-3"> <div class="mb-4 rounded-lg border border-blue-200 bg-blue-50 p-3">
@@ -1,14 +1,25 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons'; import { createIconifyIcon } from '@vben/icons';
import { Button, message, Modal } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
defineOptions({ name: 'FileUploadModal' }); defineOptions({ name: 'FileUploadModal' });
const props = defineProps<Props>(); const props = defineProps<Props>();
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[800px]',
onCancel() {
handleCancel();
},
});
// 创建图标组件 // 创建图标组件
const UploadIcon = createIconifyIcon('lucide:upload'); const UploadIcon = createIconifyIcon('lucide:upload');
const CheckCircleIcon = createIconifyIcon('lucide:check-circle'); const CheckCircleIcon = createIconifyIcon('lucide:check-circle');
@@ -26,7 +37,6 @@ interface Emits {
} }
// 响应式数据 // 响应式数据
const visible = ref(false);
const uploadedFile = ref<File | null>(null); const uploadedFile = ref<File | null>(null);
const isDragOver = ref(false); const isDragOver = ref(false);
const fileInputRef = ref<HTMLInputElement>(); const fileInputRef = ref<HTMLInputElement>();
@@ -35,20 +45,18 @@ const fileInputRef = ref<HTMLInputElement>();
watch( watch(
() => props.open, () => props.open,
(newVal) => { (newVal) => {
visible.value = newVal; if (newVal) {
if (!newVal) { modalApi.open();
} else {
modalApi.close();
// 关闭时重置状态 // 关闭时重置状态
uploadedFile.value = null; uploadedFile.value = null;
isDragOver.value = false; isDragOver.value = false;
} }
}, },
{ immediate: true },
); );
// 监听visible变化,同步到父组件
watch(visible, (newVal) => {
emit('update:open', newVal);
});
// 文件验证 // 文件验证
const validateFile = (file: File): boolean => { const validateFile = (file: File): boolean => {
const isCSV = file.type === 'text/csv' || file.name.endsWith('.csv'); const isCSV = file.type === 'text/csv' || file.name.endsWith('.csv');
@@ -125,14 +133,16 @@ const clearFile = () => {
const handleConfirm = () => { const handleConfirm = () => {
if (uploadedFile.value) { if (uploadedFile.value) {
emit('confirm', uploadedFile.value); emit('confirm', uploadedFile.value);
visible.value = false; modalApi.close();
emit('update:open', false);
} }
}; };
// 取消 // 取消
const handleCancel = () => { const handleCancel = () => {
emit('cancel'); emit('cancel');
visible.value = false; modalApi.close();
emit('update:open', false);
}; };
// 格式化文件大小 // 格式化文件大小
@@ -146,13 +156,7 @@ const formatFileSize = (bytes: number) => {
</script> </script>
<template> <template>
<Modal <Modal title="继续导入CSV文件" :footer="false">
v-model:open="visible"
title="继续导入CSV文件"
width="800px"
:footer="null"
@cancel="handleCancel"
>
<div class="space-y-6"> <div class="space-y-6">
<!-- 文件拖拽上传区域 --> <!-- 文件拖拽上传区域 -->
<div <div
@@ -1,14 +1,25 @@
<script setup lang="ts"> <script setup lang="ts">
import type { MatchDetail } from '../services/EntityMatchingService'; import type { MatchDetail } from '../services/EntityMatchingService';
import { computed, ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons'; import { createIconifyIcon } from '@vben/icons';
import { Button, Modal, Select } from 'ant-design-vue'; import { Button, Select } from 'ant-design-vue';
const props = defineProps<Props>(); const props = defineProps<Props>();
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[600px]',
onCancel() {
handleCancel();
},
});
// 创建图标组件 // 创建图标组件
const CheckIcon = createIconifyIcon('lucide:check'); const CheckIcon = createIconifyIcon('lucide:check');
const XIcon = createIconifyIcon('lucide:x'); const XIcon = createIconifyIcon('lucide:x');
@@ -30,22 +41,20 @@ interface Emits {
const selectedMatchId = ref<string>(''); const selectedMatchId = ref<string>('');
// 计算属性用于双向绑定
const visible = computed({
get: () => props.visible,
set: (value) => {
emit('update:visible', value);
},
});
watch( watch(
() => props.visible, () => props.visible,
(newVal) => { (newVal) => {
if (newVal && props.matchDetail) { if (newVal) {
// 初始化选中的匹配项 modalApi.open();
selectedMatchId.value = getCurrentMatchId() || ''; if (props.matchDetail) {
// 初始化选中的匹配项
selectedMatchId.value = getCurrentMatchId() || '';
}
} else {
modalApi.close();
} }
}, },
{ immediate: true },
); );
const getStatusText = (status: string) => { const getStatusText = (status: string) => {
@@ -228,7 +237,8 @@ const handleApplyMatch = () => {
selectedMatchId.value, selectedMatchId.value,
); );
} }
visible.value = false; modalApi.close();
emit('update:visible', false);
}; };
// 处理应用到所有相同数据 // 处理应用到所有相同数据
@@ -241,22 +251,18 @@ const handleApplyToAll = () => {
selectedMatchId.value, selectedMatchId.value,
); );
} }
visible.value = false; modalApi.close();
emit('update:visible', false);
}; };
const handleCancel = () => { const handleCancel = () => {
visible.value = false; modalApi.close();
emit('update:visible', false);
}; };
</script> </script>
<template> <template>
<Modal <Modal :title="getModalTitle()">
v-model:open="visible"
:title="getModalTitle()"
width="600px"
:footer="null"
@cancel="handleCancel"
>
<div v-if="matchDetail" class="space-y-4"> <div v-if="matchDetail" class="space-y-4">
<!-- 当前匹配状态 --> <!-- 当前匹配状态 -->
<div class="mb-4 flex items-center space-x-2"> <div class="mb-4 flex items-center space-x-2">
@@ -14,7 +14,7 @@ import { createIconifyIcon } from '@vben/icons';
import { Button, message, Progress, Space } from 'ant-design-vue'; import { Button, message, Progress, Space } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { batchImportOrdersApi } from '#/api/ecommerce'; import { batchImportOrdersApi } from '#/api/ecommerce/order';
import FieldMappingModal from '#/views/ecommerce/data-import/components/FieldMappingModal.vue'; import FieldMappingModal from '#/views/ecommerce/data-import/components/FieldMappingModal.vue';
import EntityCreationModal from './components/EntityCreationModal.vue'; import EntityCreationModal from './components/EntityCreationModal.vue';
@@ -3,7 +3,9 @@ import type { FileDTO, FileVO } from '#/api/media/file/types';
import { ref, watch } from 'vue'; 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'; import { updateFileApi } from '#/api/media/file';
@@ -26,8 +28,18 @@ interface Emits {
(e: 'cancel'): void; (e: 'cancel'): void;
} }
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
onCancel() {
handleCancel();
},
onConfirm() {
handleOk();
},
});
// 响应式数据 // 响应式数据
const visible = ref(false);
const formRef = ref(); const formRef = ref();
const formData = ref<FileDTO.Update>({ const formData = ref<FileDTO.Update>({
tags: '', tags: '',
@@ -38,22 +50,22 @@ const formData = ref<FileDTO.Update>({
watch( watch(
() => props.open, () => props.open,
(newVal) => { (newVal) => {
visible.value = newVal; if (newVal) {
if (newVal && props.fileData) { modalApi.open();
// 填充表单数据 if (props.fileData) {
formData.value = { // 填充表单数据
tags: props.fileData.tags, formData.value = {
remark: props.fileData.remark, tags: props.fileData.tags,
}; remark: props.fileData.remark,
};
}
} else {
modalApi.close();
} }
}, },
{ immediate: true },
); );
// 监听visible变化,同步到父组件
watch(visible, (newVal) => {
emit('update:open', newVal);
});
// 确认操作 // 确认操作
const handleOk = async () => { const handleOk = async () => {
try { try {
@@ -62,7 +74,8 @@ const handleOk = async () => {
await updateFileApi(props.fileData.id, formData.value); await updateFileApi(props.fileData.id, formData.value);
message.success('更新成功'); message.success('更新成功');
emit('success'); emit('success');
visible.value = false; modalApi.close();
emit('update:open', false);
} }
} catch { } catch {
message.error('更新失败'); message.error('更新失败');
@@ -72,7 +85,8 @@ const handleOk = async () => {
// 取消操作 // 取消操作
const handleCancel = () => { const handleCancel = () => {
emit('cancel'); emit('cancel');
visible.value = false; modalApi.close();
emit('update:open', false);
// 重置表单数据 // 重置表单数据
formData.value = { formData.value = {
tags: '', tags: '',
@@ -82,12 +96,7 @@ const handleCancel = () => {
</script> </script>
<template> <template>
<Modal <Modal title="编辑文件信息">
v-model:open="visible"
title="编辑文件信息"
@ok="handleOk"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -3,7 +3,9 @@ import type { ImageDTO, ImageVO } from '#/api/media/image/types';
import { ref, watch } from 'vue'; 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'; import { updateImageApi } from '#/api/media/image';
@@ -26,8 +28,18 @@ interface Emits {
(e: 'cancel'): void; (e: 'cancel'): void;
} }
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
onCancel() {
handleCancel();
},
onConfirm() {
handleOk();
},
});
// 响应式数据 // 响应式数据
const visible = ref(false);
const formRef = ref(); const formRef = ref();
const formData = ref<ImageDTO.Update>({ const formData = ref<ImageDTO.Update>({
tags: '', tags: '',
@@ -38,22 +50,22 @@ const formData = ref<ImageDTO.Update>({
watch( watch(
() => props.open, () => props.open,
(newVal) => { (newVal) => {
visible.value = newVal; if (newVal) {
if (newVal && props.imageData) { modalApi.open();
// 填充表单数据 if (props.imageData) {
formData.value = { // 填充表单数据
tags: props.imageData.tags, formData.value = {
remark: props.imageData.remark, tags: props.imageData.tags,
}; remark: props.imageData.remark,
};
}
} else {
modalApi.close();
} }
}, },
{ immediate: true },
); );
// 监听visible变化,同步到父组件
watch(visible, (newVal) => {
emit('update:open', newVal);
});
// 确认操作 // 确认操作
const handleOk = async () => { const handleOk = async () => {
try { try {
@@ -62,7 +74,8 @@ const handleOk = async () => {
await updateImageApi(props.imageData.id, formData.value); await updateImageApi(props.imageData.id, formData.value);
message.success('更新成功'); message.success('更新成功');
emit('success'); emit('success');
visible.value = false; modalApi.close();
emit('update:open', false);
} }
} catch { } catch {
message.error('更新失败'); message.error('更新失败');
@@ -72,7 +85,8 @@ const handleOk = async () => {
// 取消操作 // 取消操作
const handleCancel = () => { const handleCancel = () => {
emit('cancel'); emit('cancel');
visible.value = false; modalApi.close();
emit('update:open', false);
// 重置表单数据 // 重置表单数据
formData.value = { formData.value = {
tags: '', tags: '',
@@ -82,12 +96,7 @@ const handleCancel = () => {
</script> </script>
<template> <template>
<Modal <Modal title="编辑图片信息">
v-model:open="visible"
title="编辑图片信息"
@ok="handleOk"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -6,7 +6,9 @@ import type {
import { computed, ref, watch } from 'vue'; 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 { import {
super_createAccountApi, super_createAccountApi,
@@ -21,10 +23,21 @@ defineOptions({ name: 'SuperAccountFormModal' });
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[500px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据 // 响应式数据
const formRef = ref(); const formRef = ref();
const loading = ref(false); const loading = ref(false);
const visible = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentAccountData = ref<null | SuperAccountVO.AccountInfoVO>(null); const currentAccountData = ref<null | SuperAccountVO.AccountInfoVO>(null);
@@ -76,7 +89,7 @@ function resetForm() {
// 处理模态框关闭 // 处理模态框关闭
function handleCancel() { 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('创建成功'); message.success('创建成功');
} }
visible.value = false;
emit('success'); emit('success');
modalApi.close();
} catch (error: any) { } catch (error: any) {
console.error('保存账户失败:', error); console.error('保存账户失败:', error);
const errorMessage = const errorMessage =
@@ -132,12 +145,15 @@ async function handleSubmit() {
} }
} }
// 监听弹窗关闭 // 监听 modal 关闭状态
watch(visible, (val) => { watch(
if (!val) { () => modalApi.useStore()?.value?.isOpen,
resetForm(); (newVal) => {
} if (!newVal) {
}); resetForm();
}
},
);
// 暴露方法给父组件 // 暴露方法给父组件
defineExpose({ defineExpose({
@@ -146,14 +162,7 @@ defineExpose({
</script> </script>
<template> <template>
<Modal <Modal :title="modalTitle" :confirm-loading="loading">
:open="visible"
:title="modalTitle"
width="500px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -3,7 +3,9 @@ import type { AccountDTO, AccountVO } from '#/api/organization/account';
import { computed, ref, watch } from 'vue'; 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 { import {
admin_createAccountApi, admin_createAccountApi,
@@ -18,10 +20,21 @@ defineOptions({ name: 'AccountFormModal' });
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[500px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据 // 响应式数据
const formRef = ref(); const formRef = ref();
const loading = ref(false); const loading = ref(false);
const visible = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentAccountData = ref<AccountVO.AccountInfoVO | null>(null); const currentAccountData = ref<AccountVO.AccountInfoVO | null>(null);
@@ -67,7 +80,7 @@ function resetForm() {
// 处理模态框关闭 // 处理模态框关闭
function handleCancel() { 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('创建成功'); message.success('创建成功');
} }
visible.value = false;
emit('success'); emit('success');
modalApi.close();
} catch (error: any) { } catch (error: any) {
console.error('保存账户失败:', error); console.error('保存账户失败:', error);
const errorMessage = const errorMessage =
@@ -121,12 +134,15 @@ async function handleSubmit() {
} }
} }
// 监听弹窗关闭 // 监听 modal 关闭状态
watch(visible, (val) => { watch(
if (!val) { () => modalApi.useStore()?.value?.isOpen,
resetForm(); (newVal) => {
} if (!newVal) {
}); resetForm();
}
},
);
// 暴露方法给父组件 // 暴露方法给父组件
defineExpose({ defineExpose({
@@ -135,14 +151,7 @@ defineExpose({
</script> </script>
<template> <template>
<Modal <Modal :title="modalTitle" :confirm-loading="loading">
:open="visible"
:title="modalTitle"
width="500px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -3,6 +3,7 @@ import type { CompanyDTO, CompanyVO } from '#/api/organization/company';
import { computed, onUnmounted, ref } from 'vue'; import { computed, onUnmounted, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons'; import { createIconifyIcon } from '@vben/icons';
import { import {
@@ -11,7 +12,6 @@ import {
Form, Form,
Input, Input,
message, message,
Modal,
Switch, Switch,
} from 'ant-design-vue'; } from 'ant-design-vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@@ -28,11 +28,22 @@ interface Emits {
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[600px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleSubmit();
},
});
// 创建相机图标组件 // 创建相机图标组件
const CameraIcon = createIconifyIcon('mdi:camera'); const CameraIcon = createIconifyIcon('mdi:camera');
// 内部状态管理 // 内部状态管理
const visible = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentCompanyData = ref<CompanyVO.CompanyInfoVO | null>(null); const currentCompanyData = ref<CompanyVO.CompanyInfoVO | null>(null);
@@ -169,8 +180,8 @@ async function handleSubmit() {
message.success('创建成功'); message.success('创建成功');
} }
visible.value = false;
emit('success'); emit('success');
modalApi.close();
} catch (error) { } catch (error) {
console.error('保存公司失败:', error); console.error('保存公司失败:', error);
message.error('保存公司失败'); message.error('保存公司失败');
@@ -181,7 +192,7 @@ async function handleSubmit() {
// 处理取消 // 处理取消
function handleCancel() { function handleCancel() {
visible.value = false; modalApi.close();
} }
// 暴露给父组件的方法 // 暴露给父组件的方法
@@ -195,7 +206,7 @@ function open(
resetForm(); // 先重置表单 resetForm(); // 先重置表单
initFormData(); // 再初始化数据 initFormData(); // 再初始化数据
visible.value = true; modalApi.open();
} }
// 暴露方法给父组件 // 暴露方法给父组件
@@ -281,14 +292,7 @@ onUnmounted(() => {
</script> </script>
<template> <template>
<Modal <Modal :title="modalTitle" :confirm-loading="loading">
:open="visible"
:title="modalTitle"
width="600px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -3,7 +3,9 @@ import type { DepartmentVO } from '#/api/organization/department';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { Form, Input, message, Modal, Select, Switch } from 'ant-design-vue'; import { useVbenModal } from '@vben/common-ui';
import { Form, Input, message, Select, Switch } from 'ant-design-vue';
import { import {
createDepartmentApi, createDepartmentApi,
@@ -22,10 +24,21 @@ const props = defineProps<Props>();
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[500px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据 // 响应式数据
const formRef = ref(); const formRef = ref();
const loading = ref(false); const loading = ref(false);
const visible = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentDepartmentData = ref<DepartmentVO.DepartmentInfoVO | null>(null); const currentDepartmentData = ref<DepartmentVO.DepartmentInfoVO | null>(null);
@@ -114,7 +127,7 @@ function resetForm() {
// 处理模态框关闭 // 处理模态框关闭
function handleCancel() { function handleCancel() {
visible.value = false; modalApi.close();
} }
// 处理表单提交 // 处理表单提交
@@ -137,8 +150,8 @@ async function handleSubmit() {
message.success('创建成功'); message.success('创建成功');
} }
visible.value = false;
emit('success'); emit('success');
modalApi.close();
} catch (error) { } catch (error) {
console.error('保存部门失败:', error); console.error('保存部门失败:', error);
message.error('保存部门失败'); message.error('保存部门失败');
@@ -166,7 +179,7 @@ function open(
}; };
} }
visible.value = true; modalApi.open();
} }
// 暴露方法给父组件 // 暴露方法给父组件
@@ -176,14 +189,7 @@ defineExpose({
</script> </script>
<template> <template>
<Modal <Modal :title="modalTitle" :confirm-loading="loading">
:open="visible"
:title="modalTitle"
width="500px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -3,7 +3,9 @@ import type { PositionVO } from '#/api/organization/position';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { Form, Input, message, Modal, Select, Switch } from 'ant-design-vue'; import { useVbenModal } from '@vben/common-ui';
import { Form, Input, message, Select, Switch } from 'ant-design-vue';
import { import {
createPositionApi, createPositionApi,
@@ -22,10 +24,21 @@ defineProps<Props>();
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[500px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据 // 响应式数据
const formRef = ref(); const formRef = ref();
const loading = ref(false); const loading = ref(false);
const visible = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentPositionData = ref<null | PositionVO.PositionInfoVO>(null); const currentPositionData = ref<null | PositionVO.PositionInfoVO>(null);
@@ -66,7 +79,7 @@ function resetForm() {
// 处理模态框关闭 // 处理模态框关闭
function handleCancel() { function handleCancel() {
visible.value = false; modalApi.close();
} }
// 处理表单提交 // 处理表单提交
@@ -89,8 +102,8 @@ async function handleSubmit() {
message.success('创建成功'); message.success('创建成功');
} }
visible.value = false;
emit('success'); emit('success');
modalApi.close();
} catch (error) { } catch (error) {
console.error('保存岗位失败:', error); console.error('保存岗位失败:', error);
message.error('保存岗位失败'); message.error('保存岗位失败');
@@ -119,7 +132,7 @@ function open(
}; };
} }
visible.value = true; modalApi.open();
} }
// 暴露方法给父组件 // 暴露方法给父组件
@@ -129,14 +142,7 @@ defineExpose({
</script> </script>
<template> <template>
<Modal <Modal :title="modalTitle" :confirm-loading="loading">
:open="visible"
:title="modalTitle"
width="500px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -6,14 +6,9 @@ import type {
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { import { useVbenModal } from '@vben/common-ui';
Form,
Input, import { Form, Input, InputNumber, message, Switch } from 'ant-design-vue';
InputNumber,
message,
Modal,
Switch,
} from 'ant-design-vue';
import { import {
createOrderStatusApi, createOrderStatusApi,
@@ -25,8 +20,19 @@ const emit = defineEmits<{
success: []; success: [];
}>(); }>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[500px]',
onCancel() {
close();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据 // 响应式数据
const visible = ref(false);
const loading = ref(false); const loading = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentRecord = ref<null | OrderStatusVO.Info>(null); const currentRecord = ref<null | OrderStatusVO.Info>(null);
@@ -52,7 +58,7 @@ const formRef = ref();
function open(edit: boolean, record?: OrderStatusVO.Info) { function open(edit: boolean, record?: OrderStatusVO.Info) {
isEdit.value = edit; isEdit.value = edit;
currentRecord.value = record || null; currentRecord.value = record || null;
visible.value = true; modalApi.open();
// 根据模式填充表单数据 // 根据模式填充表单数据
formData.value = formData.value =
@@ -73,7 +79,7 @@ function open(edit: boolean, record?: OrderStatusVO.Info) {
// 关闭模态框 // 关闭模态框
function close() { function close() {
visible.value = false; modalApi.close();
formRef.value?.resetFields(); formRef.value?.resetFields();
emit('cancel'); emit('cancel');
} }
@@ -107,8 +113,8 @@ async function handleSubmit() {
message.success('创建订单状态成功'); message.success('创建订单状态成功');
} }
close();
emit('success'); emit('success');
close();
} catch (error) { } catch (error) {
console.error('提交订单状态失败:', (error as any).message); console.error('提交订单状态失败:', (error as any).message);
} finally { } finally {
@@ -116,12 +122,15 @@ async function handleSubmit() {
} }
} }
// 监听visible变化 // 监听 modal 关闭状态
watch(visible, (newVal) => { watch(
if (!newVal) { () => modalApi.useStore()?.value?.isOpen,
formRef.value?.resetFields(); (newVal) => {
} if (!newVal) {
}); formRef.value?.resetFields();
}
},
);
// 暴露方法 // 暴露方法
defineExpose({ defineExpose({
@@ -132,12 +141,8 @@ defineExpose({
<template> <template>
<Modal <Modal
v-model:open="visible"
:title="isEdit ? '编辑订单状态' : '添加订单状态'" :title="isEdit ? '编辑订单状态' : '添加订单状态'"
:confirm-loading="loading" :confirm-loading="loading"
width="500px"
@ok="handleSubmit"
@cancel="close"
> >
<Form <Form
ref="formRef" ref="formRef"
@@ -6,12 +6,13 @@ import type {
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { import {
Form, Form,
Input, Input,
InputNumber, InputNumber,
message, message,
Modal,
Select, Select,
Switch, Switch,
} from 'ant-design-vue'; } from 'ant-design-vue';
@@ -26,8 +27,19 @@ const emit = defineEmits<{
success: []; success: [];
}>(); }>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[600px]',
onCancel() {
close();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据 // 响应式数据
const visible = ref(false);
const loading = ref(false); const loading = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentRecord = ref<null | PromotionFeeTypeVO.Info>(null); const currentRecord = ref<null | PromotionFeeTypeVO.Info>(null);
@@ -63,7 +75,7 @@ const formRef = ref();
function open(edit: boolean, record?: PromotionFeeTypeVO.Info) { function open(edit: boolean, record?: PromotionFeeTypeVO.Info) {
isEdit.value = edit; isEdit.value = edit;
currentRecord.value = record || null; currentRecord.value = record || null;
visible.value = true; modalApi.open();
// 根据模式填充表单数据 // 根据模式填充表单数据
formData.value = formData.value =
@@ -86,7 +98,7 @@ function open(edit: boolean, record?: PromotionFeeTypeVO.Info) {
// 关闭模态框 // 关闭模态框
function close() { function close() {
visible.value = false; modalApi.close();
formRef.value?.resetFields(); formRef.value?.resetFields();
emit('cancel'); emit('cancel');
} }
@@ -122,8 +134,8 @@ async function handleSubmit() {
message.success('创建推广费类型成功'); message.success('创建推广费类型成功');
} }
close();
emit('success'); emit('success');
close();
} catch (error) { } catch (error) {
console.error('提交推广费类型失败:', (error as any).message); console.error('提交推广费类型失败:', (error as any).message);
} finally { } finally {
@@ -131,12 +143,15 @@ async function handleSubmit() {
} }
} }
// 监听visible变化 // 监听 modal 关闭状态
watch(visible, (newVal) => { watch(
if (!newVal) { () => modalApi.useStore()?.value?.isOpen,
formRef.value?.resetFields(); (newVal) => {
} if (!newVal) {
}); formRef.value?.resetFields();
}
},
);
// 暴露方法 // 暴露方法
defineExpose({ defineExpose({
@@ -147,12 +162,8 @@ defineExpose({
<template> <template>
<Modal <Modal
v-model:open="visible"
:title="isEdit ? '编辑推广费类型' : '添加推广费类型'" :title="isEdit ? '编辑推广费类型' : '添加推广费类型'"
:confirm-loading="loading" :confirm-loading="loading"
width="600px"
@ok="handleSubmit"
@cancel="close"
> >
<Form <Form
ref="formRef" ref="formRef"
@@ -3,7 +3,9 @@ import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
import type { OrderStatusVO } from '#/api/ecommerce/order-status'; import type { OrderStatusVO } from '#/api/ecommerce/order-status';
import type { ShopVO } from '#/api/shop/shop/types'; import type { ShopVO } from '#/api/shop/shop/types';
import { ref, watch } from 'vue'; import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { import {
DatePicker, DatePicker,
@@ -11,7 +13,6 @@ import {
Input, Input,
InputNumber, InputNumber,
message, message,
Modal,
Select, Select,
} from 'ant-design-vue'; } from 'ant-design-vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@@ -25,8 +26,19 @@ const emit = defineEmits<{
success: []; success: [];
}>(); }>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[600px]',
onCancel() {
close();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据 // 响应式数据
const visible = ref(false);
const loading = ref(false); const loading = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentRecord = ref<null | OrderVO.Info>(null); const currentRecord = ref<null | OrderVO.Info>(null);
@@ -107,7 +119,12 @@ async function fetchOrderStatusOptions() {
function open(edit: boolean, record?: OrderVO.Info) { function open(edit: boolean, record?: OrderVO.Info) {
isEdit.value = edit; isEdit.value = edit;
currentRecord.value = record || null; currentRecord.value = record || null;
visible.value = true;
// 加载下拉选项数据
fetchShopOptions();
fetchOrderStatusOptions();
modalApi.open();
// 根据模式填充表单数据 // 根据模式填充表单数据
formData.value = formData.value =
@@ -150,7 +167,7 @@ function open(edit: boolean, record?: OrderVO.Info) {
// 关闭模态框 // 关闭模态框
function close() { function close() {
visible.value = false; modalApi.close();
formRef.value?.resetFields(); formRef.value?.resetFields();
emit('cancel'); emit('cancel');
} }
@@ -203,8 +220,8 @@ async function handleSubmit() {
message.success('创建订单成功'); message.success('创建订单成功');
} }
close();
emit('success'); emit('success');
close();
} catch (error) { } catch (error) {
console.error('提交订单失败:', error); console.error('提交订单失败:', error);
message.error('提交订单失败'); message.error('提交订单失败');
@@ -213,14 +230,6 @@ async function handleSubmit() {
} }
} }
// 监听visible变化
watch(visible, (newVal) => {
if (newVal) {
fetchShopOptions();
fetchOrderStatusOptions();
}
});
// 暴露方法 // 暴露方法
defineExpose({ defineExpose({
open, open,
@@ -229,14 +238,7 @@ defineExpose({
</script> </script>
<template> <template>
<Modal <Modal :title="isEdit ? '编辑订单' : '添加订单'" :confirm-loading="loading">
v-model:open="visible"
:title="isEdit ? '编辑订单' : '添加订单'"
:confirm-loading="loading"
width="600px"
@ok="handleSubmit"
@cancel="close"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -2,7 +2,7 @@
import type { ProductDTO, ProductVO } from '#/api/shop/product/types'; import type { ProductDTO, ProductVO } from '#/api/shop/product/types';
import type { PageQueryDTO } from '#/types/common'; import type { PageQueryDTO } from '#/types/common';
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'; import { onMounted, onUnmounted, ref, watch } from 'vue';
import { Waterfall } from 'vue-waterfall-plugin-next'; import { Waterfall } from 'vue-waterfall-plugin-next';
import 'vue-waterfall-plugin-next/dist/style.css'; import 'vue-waterfall-plugin-next/dist/style.css';
@@ -51,11 +51,6 @@ const pageSize = ref(24); // 无限滚动默认每页24个
const hasMore = ref(true); // 是否还有更多数据 const hasMore = ref(true); // 是否还有更多数据
const scrollContainerRef = ref<HTMLElement | null>(null); const scrollContainerRef = ref<HTMLElement | null>(null);
// 显示列表(只包含商品数据,不包含占位项)
const displayList = computed(() => {
return productList.value;
});
// 本地搜索表单副本(用于 v-model) // 本地搜索表单副本(用于 v-model)
const localSearchForm = ref({ const localSearchForm = ref({
name: props.searchForm.name, name: props.searchForm.name,
@@ -310,7 +305,7 @@ onUnmounted(() => {
<!-- 瀑布流 --> <!-- 瀑布流 -->
<Waterfall <Waterfall
v-else-if="productList.length > 0" v-else-if="productList.length > 0"
:list="displayList" :list="productList"
row-key="id" row-key="id"
:width="300" :width="300"
:breakpoints="{ :breakpoints="{
@@ -8,13 +8,14 @@ import type { ShopVO } from '#/api/shop/shop/types';
import { onMounted, ref, watch } from 'vue'; import { onMounted, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { import {
DatePicker, DatePicker,
Form, Form,
Input, Input,
InputNumber, InputNumber,
message, message,
Modal,
Select, Select,
} from 'ant-design-vue'; } from 'ant-design-vue';
@@ -44,8 +45,19 @@ interface Emits {
(e: 'cancel'): void; (e: 'cancel'): void;
} }
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[800px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleOk();
},
});
// 响应式数据 // 响应式数据
const visible = ref(false);
const formRef = ref(); const formRef = ref();
const isEdit = ref(false); const isEdit = ref(false);
@@ -100,8 +112,8 @@ const feeTypeListLoading = ref(false);
watch( watch(
() => props.open, () => props.open,
(newVal) => { (newVal) => {
visible.value = newVal;
if (newVal) { if (newVal) {
modalApi.open();
isEdit.value = !!props.promotionFeeData; isEdit.value = !!props.promotionFeeData;
if (props.promotionFeeData) { if (props.promotionFeeData) {
// 编辑模式,填充表单数据 // 编辑模式,填充表单数据
@@ -124,15 +136,13 @@ watch(
// 新增模式,重置表单数据 // 新增模式,重置表单数据
resetFormData(); resetFormData();
} }
} else {
modalApi.close();
} }
}, },
{ immediate: true },
); );
// 监听visible变化,同步到父组件
watch(visible, (newVal) => {
emit('update:open', newVal);
});
// 加载店铺列表 // 加载店铺列表
const loadShopList = async () => { const loadShopList = async () => {
shopListLoading.value = true; shopListLoading.value = true;
@@ -202,7 +212,8 @@ const handleOk = async () => {
} }
emit('success'); emit('success');
visible.value = false; modalApi.close();
emit('update:open', false);
} catch (error) { } catch (error) {
console.error('操作失败:', error); console.error('操作失败:', error);
message.error(isEdit.value ? '更新失败' : '创建失败'); message.error(isEdit.value ? '更新失败' : '创建失败');
@@ -212,7 +223,8 @@ const handleOk = async () => {
// 取消操作 // 取消操作
const handleCancel = () => { const handleCancel = () => {
emit('cancel'); emit('cancel');
visible.value = false; modalApi.close();
emit('update:open', false);
resetFormData(); resetFormData();
}; };
@@ -224,13 +236,7 @@ onMounted(() => {
</script> </script>
<template> <template>
<Modal <Modal :title="isEdit ? '编辑推广费记录' : '新增推广费记录'">
v-model:open="visible"
:title="isEdit ? '编辑推广费记录' : '新增推广费记录'"
width="800px"
@ok="handleOk"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -3,9 +3,10 @@ import type { ShopDTO, ShopVO } from '#/api/shop/shop/types';
import { computed, onUnmounted, ref } from 'vue'; import { computed, onUnmounted, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons'; import { createIconifyIcon } from '@vben/icons';
import { Button, Form, Input, message, Modal, Select } from 'ant-design-vue'; import { Button, Form, Input, message, Select } from 'ant-design-vue';
import { import {
createShopApi, createShopApi,
@@ -19,11 +20,22 @@ interface Emits {
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[600px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleSubmit();
},
});
// 创建相机图标组件 // 创建相机图标组件
const CameraIcon = createIconifyIcon('mdi:camera'); const CameraIcon = createIconifyIcon('mdi:camera');
// 内部状态管理 // 内部状态管理
const visible = ref(false);
const isEdit = ref(false); const isEdit = ref(false);
const currentShopData = ref<null | Partial<ShopVO.Info> | ShopVO.Info>(null); const currentShopData = ref<null | Partial<ShopVO.Info> | ShopVO.Info>(null);
@@ -132,8 +144,8 @@ async function handleSubmit() {
message.success('创建成功'); message.success('创建成功');
} }
visible.value = false;
emit('success'); emit('success');
modalApi.close();
} catch (error) { } catch (error) {
console.error('保存店铺失败:', error); console.error('保存店铺失败:', error);
message.error('保存店铺失败'); message.error('保存店铺失败');
@@ -144,7 +156,7 @@ async function handleSubmit() {
// 处理取消 // 处理取消
function handleCancel() { function handleCancel() {
visible.value = false; modalApi.close();
} }
// 暴露给父组件的方法 // 暴露给父组件的方法
@@ -158,7 +170,7 @@ function open(
resetForm(); // 先重置表单 resetForm(); // 先重置表单
initFormData(); // 再初始化数据 initFormData(); // 再初始化数据
visible.value = true; modalApi.open();
} }
// 暴露方法给父组件 // 暴露方法给父组件
@@ -244,14 +256,7 @@ onUnmounted(() => {
</script> </script>
<template> <template>
<Modal <Modal :title="modalTitle" :confirm-loading="loading">
:open="visible"
:title="modalTitle"
width="600px"
:confirm-loading="loading"
@ok="handleSubmit"
@cancel="handleCancel"
>
<Form <Form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@@ -20,7 +20,6 @@ import {
getImportFieldDefPageApi, getImportFieldDefPageApi,
} from '#/api/ecommerce/import-field-def'; } from '#/api/ecommerce/import-field-def';
// @ts-expect-error - Vue SFC 类型声明
import FieldFormModal from './components/FieldFormModal.vue'; import FieldFormModal from './components/FieldFormModal.vue';
defineOptions({ name: 'FieldManagement' }); defineOptions({ name: 'FieldManagement' });