diff --git a/src/api/product/device/index.ts b/src/api/product/device/index.ts index c7c9fb70..431d2590 100644 --- a/src/api/product/device/index.ts +++ b/src/api/product/device/index.ts @@ -45,4 +45,4 @@ export const DeviceApi = { exportDevice: async (params) => { return await request.download({ url: `/product/device/export-excel`, params }) }, -} \ No newline at end of file +} diff --git a/src/views/infra/file/index.vue b/src/views/infra/file/index.vue index 9b49851a..ac250081 100644 --- a/src/views/infra/file/index.vue +++ b/src/views/infra/file/index.vue @@ -126,6 +126,7 @@ import { fileSizeFormatter } from '@/utils' import { dateFormatter } from '@/utils/formatTime' import * as FileApi from '@/api/infra/file' import FileForm from './FileForm.vue' +import { ElMessage } from 'element-plus' defineOptions({ name: 'InfraFile' }) diff --git a/src/views/mall/product/device/DeviceForm.vue b/src/views/mall/product/device/DeviceForm.vue index 20faa1b1..9f8b3903 100644 --- a/src/views/mall/product/device/DeviceForm.vue +++ b/src/views/mall/product/device/DeviceForm.vue @@ -96,24 +96,50 @@ const open = async (type: string, id?: number) => { defineExpose({ open }) // 提供 open 方法,用于打开弹窗 /** 提交表单 */ -const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 +const emit = defineEmits<{ + success: [eventData: { type: string; data: DeviceVO }] +}>() +/** 提交表单 */ const submitForm = async () => { // 校验表单 await formRef.value.validate() // 提交请求 formLoading.value = true try { - const data = formData.value as unknown as DeviceVO + const data = { ...formData.value } as unknown as DeviceVO + + // 根据广告图类型设置 fileUrl + if (data.adType === 'upload' && data.adImage) { + data.fileUrl = data.adImage + } else if (data.adType === 'link' && data.adUrl) { + data.fileUrl = data.adUrl + } + // 如果没有设置广告,清空 fileUrl + else { + data.fileUrl = '' + } + + let result if (formType.value === 'create') { - await DeviceApi.createDevice(data) + result = await DeviceApi.createDevice(data) message.success(t('common.createSuccess')) } else { - await DeviceApi.updateDevice(data) + result = await DeviceApi.updateDevice(data) message.success(t('common.updateSuccess')) } + dialogVisible.value = false - // 发送操作成功的事件 - emit('success') + // 发送操作成功的事件,传递处理后的数据 + emit('success', { + type: formType.value, + data: { + ...data, + id: formType.value === 'create' ? result?.id || Date.now() : data.id, + createTime: formType.value === 'create' + ? new Date().toISOString() + : new Date().toISOString(), + } as DeviceVO, +}) } finally { formLoading.value = false } diff --git a/src/views/mall/product/device/index.vue b/src/views/mall/product/device/index.vue index ce1a2202..d40b05eb 100644 --- a/src/views/mall/product/device/index.vue +++ b/src/views/mall/product/device/index.vue @@ -86,7 +86,8 @@ type="success" plain @click="handleExport" :loading="exportLoading" - + +