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