产品页面实现

This commit is contained in:
Qi 2025-08-10 08:14:42 +08:00
parent 6ac0146455
commit 5d2a017e8f
6 changed files with 1080 additions and 1 deletions

View File

@ -67,7 +67,7 @@
title: 'oroqen_heritage_project', title: 'oroqen_heritage_project',
api: list, api: list,
columns, columns,
canResize: true, canResize: false,
formConfig: { formConfig: {
//labelWidth: 120, //labelWidth: 120,
schemas: searchFormSchema, schemas: searchFormSchema,

View File

@ -0,0 +1,104 @@
import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
const { createConfirm } = useMessage();
enum Api {
list = '/oroqen/product/list',
save = '/oroqen/product/add',
edit = '/oroqen/product/edit',
deleteOne = '/oroqen/product/delete',
deleteBatch = '/oroqen/product/deleteBatch',
importExcel = '/oroqen/product/importExcel',
exportXls = '/oroqen/product/exportXls',
queryById = '/oroqen/product/queryById',
listByCategory = '/oroqen/product/listByCategory',
featured = '/oroqen/product/featured',
hot = '/oroqen/product/hot',
checkStock = '/oroqen/product/checkStock',
}
/**
* api
*/
export const getExportUrl = Api.exportXls;
/**
* api
*/
export const getImportUrl = Api.importExcel;
/**
*
*/
export const list = (params) => defHttp.get({ url: Api.list, params });
/**
*
*/
export const deleteOne = (params, handleSuccess) => {
return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
};
/**
*
*/
export const batchDelete = (params, handleSuccess) => {
createConfirm({
iconType: 'warning',
title: '确认删除',
content: '是否删除选中数据',
okText: '确认',
cancelText: '取消',
onOk: () => {
return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
}
});
};
/**
*
*/
export const saveOrUpdate = (params, isUpdate) => {
const url = isUpdate ? Api.edit : Api.save;
return defHttp.post({ url: url, params }, { isTransformResponse: false });
};
/**
* ID查询
*/
export const queryById = (params) => {
return defHttp.get({ url: Api.queryById, params });
};
/**
* ID查询产品列表
*/
export const listByCategory = (params) => {
return defHttp.get({ url: Api.listByCategory, params });
};
/**
*
*/
export const getFeaturedProducts = (params) => {
return defHttp.get({ url: Api.featured, params });
};
/**
*
*/
export const getHotProducts = (params) => {
return defHttp.get({ url: Api.hot, params });
};
/**
*
*/
export const checkStock = (params) => {
return defHttp.get({ url: Api.checkStock, params });
};

View File

@ -0,0 +1,494 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Image, Tag } from 'ant-design-vue';
import { render } from '/@/utils/common/renderUtils';
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
//列表数据
export const columns: BasicColumn[] = [
{
title: '主图',
align: 'center',
dataIndex: 'mainImage',
width: 80,
customRender: ({ text, record }) => {
if (!text) return '-';
const imageUrl = getFileAccessHttpUrl(text);
return h(Image, {
src: imageUrl,
alt: record?.productName || '产品主图',
width: 50,
height: 50,
style: { objectFit: 'cover', borderRadius: '4px' },
preview: true,
fallback: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAwqADAAQAAAABAAAAwwAAAAD9b/HnAAAHlklEQVR4Ae3dP3Ik1RnG4W+FgYxN'
});
}
},
{
title: '产品名称',
dataIndex: 'productName',
width: 150,
align: 'left',
ellipsis: true,
fixed: 'left',
},
{
title: '产品编码',
dataIndex: 'productCode',
width: 120,
align: 'center',
},
{
title: '产品分类',
dataIndex: 'categoryId',
width: 120,
align: 'center',
// TODO: 这里可以关联分类表显示分类名称
},
{
title: '价格',
dataIndex: 'price',
width: 100,
align: 'center',
customRender: ({ text }) => {
return text ? `¥${text}` : '-';
},
},
{
title: '库存数量',
dataIndex: 'stock',
width: 100,
align: 'center',
customRender: ({ text }) => {
const color = text > 10 ? 'green' : text > 0 ? 'orange' : 'red';
return h(Tag, { color }, text || 0);
},
},
{
title: '销量',
dataIndex: 'salesCount',
width: 80,
align: 'center',
},
{
title: '产品状态',
dataIndex: 'status',
width: 100,
align: 'center',
customRender: ({ text }) => {
const statusMap = {
1: { text: '上架', color: 'green' },
0: { text: '下架', color: 'red' },
};
const status = statusMap[text] || { text: '未知', color: 'default' };
return render.renderTag(status.text, status.color);
},
},
{
title: '是否推荐',
dataIndex: 'isFeatured',
width: 100,
align: 'center',
customRender: ({ text }) => {
return text === 1 ? render.renderTag('推荐', 'blue') : render.renderTag('普通', 'default');
},
},
{
title: '是否热销',
dataIndex: 'isHot',
width: 100,
align: 'center',
customRender: ({ text }) => {
return text === 1 ? render.renderTag('热销', 'orange') : render.renderTag('普通', 'default');
},
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 150,
align: 'center',
sorter: true,
},
];
//查询数据
export const searchFormSchema: FormSchema[] = [
{
label: '产品名称',
field: 'productName',
component: 'Input',
componentProps: {
placeholder: '请输入产品名称',
},
colProps: { span: 6 },
},
{
label: '产品编码',
field: 'productCode',
component: 'Input',
componentProps: {
placeholder: '请输入产品编码',
},
colProps: { span: 6 },
},
{
label: '产品状态',
field: 'status',
component: 'Select',
componentProps: {
placeholder: '请选择产品状态',
options: [
{ label: '上架', value: 1 },
{ label: '下架', value: 0 },
],
},
colProps: { span: 6 },
},
{
label: '是否推荐',
field: 'isFeatured',
component: 'Select',
componentProps: {
placeholder: '请选择是否推荐',
options: [
{ label: '推荐', value: 1 },
{ label: '普通', value: 0 },
],
},
colProps: { span: 6 },
},
{
label: '是否热销',
field: 'isHot',
component: 'Select',
componentProps: {
placeholder: '请选择是否热销',
options: [
{ label: '热销', value: 1 },
{ label: '普通', value: 0 },
],
},
colProps: { span: 6 },
},
];
//表单数据
export const formSchema: FormSchema[] = [
{
label: '',
field: 'id',
component: 'Input',
show: false,
},
{
label: '产品名称',
field: 'productName',
component: 'Input',
required: true,
componentProps: {
placeholder: '请输入产品名称',
},
colProps: { span: 12 },
},
{
label: '产品编码',
field: 'productCode',
component: 'Input',
required: true,
componentProps: {
placeholder: '请输入产品编码',
},
colProps: { span: 12 },
},
{
label: '分类ID',
field: 'categoryId',
component: 'Input',
required: true,
componentProps: {
placeholder: '请输入分类ID',
},
colProps: { span: 12 },
},
{
label: '价格',
field: 'price',
component: 'InputNumber',
componentProps: {
min: 0,
precision: 2,
addonBefore: '¥',
placeholder: '请输入价格',
},
required: true,
colProps: { span: 12 },
},
{
label: '库存数量',
field: 'stock',
component: 'InputNumber',
componentProps: {
min: 0,
placeholder: '请输入库存数量',
},
colProps: { span: 12 },
},
{
label: '销量',
field: 'salesCount',
component: 'InputNumber',
componentProps: {
min: 0,
placeholder: '请输入销量',
},
colProps: { span: 12 },
},
{
label: '排序',
field: 'sortOrder',
component: 'InputNumber',
componentProps: {
min: 0,
placeholder: '请输入排序值',
},
colProps: { span: 12 },
},
{
label: '产品状态',
field: 'status',
component: 'Select',
componentProps: {
placeholder: '请选择产品状态',
options: [
{ label: '上架', value: 1 },
{ label: '下架', value: 0 },
],
},
colProps: { span: 12 },
},
{
label: '是否推荐',
field: 'isFeatured',
component: 'Select',
componentProps: {
placeholder: '请选择是否推荐',
options: [
{ label: '推荐', value: 1 },
{ label: '普通', value: 0 },
],
},
colProps: { span: 12 },
},
{
label: '是否热销',
field: 'isHot',
component: 'Select',
componentProps: {
placeholder: '请选择是否热销',
options: [
{ label: '热销', value: 1 },
{ label: '普通', value: 0 },
],
},
colProps: { span: 12 },
},
{
label: '材质',
field: 'material',
component: 'Input',
componentProps: {
placeholder: '请输入材质',
},
colProps: { span: 12 },
},
{
label: '规格参数',
field: 'specifications',
component: 'Input',
componentProps: {
placeholder: '请输入规格参数',
},
colProps: { span: 12 },
},
{
label: '重量(克)',
field: 'weight',
component: 'InputNumber',
componentProps: {
min: 0,
placeholder: '请输入重量',
},
colProps: { span: 12 },
},
{
label: '尺寸',
field: 'dimensions',
component: 'Input',
componentProps: {
placeholder: '请输入尺寸',
},
colProps: { span: 12 },
},
{
label: '标签',
field: 'tags',
component: 'Input',
componentProps: {
placeholder: '请输入标签,多个标签用逗号分隔',
},
colProps: { span: 24 },
},
{
label: '产品描述',
field: 'description',
component: 'InputTextArea',
componentProps: {
rows: 4,
placeholder: '请输入产品描述',
},
colProps: { span: 24 },
},
{
label: '文化故事',
field: 'culturalStory',
component: 'InputTextArea',
componentProps: {
rows: 3,
placeholder: '请输入文化故事',
},
colProps: { span: 24 },
},
{
label: '工匠信息',
field: 'craftsmanInfo',
component: 'InputTextArea',
componentProps: {
rows: 3,
placeholder: '请输入工匠信息',
},
colProps: { span: 24 },
},
{
label: '主图',
field: 'mainImage',
component: 'JUpload',
componentProps: {
fileType: 'image',
maxCount: 1,
maxSize: 5,
bizPath: 'product/main',
customRequest: (options) => {
// 验证文件类型和大小
const { file } = options;
const isImage = file.type.startsWith('image/');
if (!isImage) {
console.error('只能上传图片文件!');
return;
}
const isLt5M = file.size / 1024 / 1024 < 5;
if (!isLt5M) {
console.error('图片大小不能超过5MB!');
return;
}
// 创建本地预览URL
const localUrl = URL.createObjectURL(file);
// 直接设置文件的url为本地预览URL
file.url = localUrl;
// 模拟上传成功响应但不返回local:前缀,避免被解析
setTimeout(() => {
options.onSuccess({
success: true,
message: file.name, // 仅使用文件名不使用local:前缀
}, file);
}, 100);
},
},
colProps: { span: 12 },
},
{
label: '产品图片',
field: 'images',
component: 'JUpload',
componentProps: {
fileType: 'image',
maxCount: 8,
maxSize: 5,
bizPath: 'product/images',
customRequest: (options) => {
// 验证文件类型和大小
const { file } = options;
const isImage = file.type.startsWith('image/');
if (!isImage) {
console.error('只能上传图片文件!');
return;
}
const isLt5M = file.size / 1024 / 1024 < 5;
if (!isLt5M) {
console.error('图片大小不能超过5MB!');
return;
}
// 创建本地预览URL
const localUrl = URL.createObjectURL(file);
// 直接设置文件的url为本地预览URL
file.url = localUrl;
// 模拟上传成功响应但不返回local:前缀,避免被解析
setTimeout(() => {
options.onSuccess({
success: true,
message: file.name, // 仅使用文件名不使用local:前缀
}, file);
}, 100);
},
},
colProps: { span: 12 },
},
{
label: '产品视频',
field: 'productVideo',
component: 'JUpload',
componentProps: {
fileType: 'video',
maxCount: 1,
maxSize: 50,
bizPath: 'product/video',
customRequest: (options) => {
// 验证文件类型和大小
const { file } = options;
const isVideo = file.type.startsWith('video/');
if (!isVideo) {
console.error('只能上传视频文件!');
return;
}
const isLt50M = file.size / 1024 / 1024 < 50;
if (!isLt50M) {
console.error('视频大小不能超过50MB!');
return;
}
// 创建本地预览URL
const localUrl = URL.createObjectURL(file);
// 直接设置文件的url为本地预览URL
file.url = localUrl;
// 模拟上传成功响应但不返回local:前缀,避免被解析
setTimeout(() => {
options.onSuccess({
success: true,
message: file.name, // 仅使用文件名不使用local:前缀
}, file);
}, 100);
},
},
colProps: { span: 24 },
},
];

View File

@ -0,0 +1,168 @@
<template>
<div>
<!--引用表格-->
<BasicTable @register="registerTable" :rowSelection="rowSelection">
<!--插槽:table标题-->
<template #tableTitle>
<a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
<a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
<j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
<a-dropdown v-if="selectedRowKeys.length > 0">
<template #overlay>
<a-menu>
<a-menu-item key="1" @click="batchHandleDelete">
<Icon icon="ant-design:delete-outlined"></Icon>
删除
</a-menu-item>
</a-menu>
</template>
<a-button>批量操作
<Icon icon="mdi:chevron-down"></Icon>
</a-button>
</a-dropdown>
</template>
<!--操作栏-->
<template #action="{ record }">
<TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
</template>
<!--字段回显插槽-->
<template #htmlSlot="{text}">
<div v-html="text"></div>
</template>
</BasicTable>
<!-- 表单区域 -->
<OroqenProductModal @register="registerModal" @success="handleSuccess"></OroqenProductModal>
</div>
</template>
<script lang="ts" name="oroqen-product" setup>
import { ref, computed, unref } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
import OroqenProductModal from './components/OroqenProductModal.vue';
import { columns, searchFormSchema } from './OroqenProduct.data';
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './OroqenProduct.api';
import { downloadByOnlineUrl } from '/@/utils/file/download';
import { useMessage } from '/@/hooks/web/useMessage';
const checkedKeys = ref<Array<string | number>>([]);
const { createMessage } = useMessage();
//model
const [registerModal, { openModal }] = useModal();
//table
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
tableProps: {
title: '产品',
api: list,
columns,
canResize: false,
formConfig: {
//labelWidth: 120,
schemas: searchFormSchema,
autoSubmitOnEnter: true,
showAdvancedButton: true,
fieldMapToNumber: [],
fieldMapToTime: [],
},
actionColumn: {
width: 120,
fixed: 'right'
},
},
exportConfig: {
name: "产品",
url: getExportUrl,
},
importConfig: {
url: getImportUrl,
success: handleSuccess
},
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
/**
* 新增事件
*/
function handleAdd() {
openModal(true, {
isUpdate: false,
showFooter: true,
});
}
/**
* 编辑事件
*/
function handleEdit(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: true,
});
}
/**
* 详情
*/
function handleDetail(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: false,
});
}
/**
* 删除事件
*/
async function handleDelete(record) {
await deleteOne({ id: record.id }, handleSuccess);
}
/**
* 批量删除事件
*/
async function batchHandleDelete() {
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
}
/**
* 成功回调
*/
function handleSuccess() {
(selectedRowKeys.value = []) && reload();
}
/**
* 操作栏
*/
function getTableAction(record) {
return [
{
label: '编辑',
onClick: handleEdit.bind(null, record),
},
]
}
/**
* 下拉操作栏
*/
function getDropDownAction(record) {
return [
{
label: '详情',
onClick: handleDetail.bind(null, record),
},
{
label: '删除',
color: 'error',
popConfirm: {
title: '是否确认删除',
placement: 'topLeft',
confirm: handleDelete.bind(null, record),
}
}
]
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,47 @@
<template>
<div class="oroqen-product-form">
<BasicForm @register="registerForm" />
</div>
</template>
<script lang="ts" setup>
import { watch } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from '../OroqenProduct.data';
const props = defineProps({
formData: {
type: Object,
default: () => ({})
}
});
const emit = defineEmits(['submit']);
//
const [registerForm, { setFieldsValue, validate, resetFields }] = useForm({
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 }
});
//
watch(() => props.formData, (newData) => {
if (newData && Object.keys(newData).length > 0) {
setFieldsValue(newData);
}
}, { immediate: true, deep: true });
//
defineExpose({
validate,
resetFields,
setFieldsValue
});
</script>
<style scoped>
.oroqen-product-form {
padding: 16px;
}
</style>

View File

@ -0,0 +1,266 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
<BasicForm @register="registerForm" />
</BasicModal>
</template>
<script lang="ts" setup>
import { ref, computed, unref, reactive } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from '../OroqenProduct.data';
import { saveOrUpdate } from '../OroqenProduct.api';
import { useMessage } from '/@/hooks/web/useMessage';
import { getDateByPicker } from '/@/utils';
import { uploadFile } from '/@/api/common/api';
import { defHttp } from '/@/utils/http/axios';
const { createMessage } = useMessage();
// Emits
const emit = defineEmits(['register', 'success']);
const isUpdate = ref(true);
const isDetail = ref(false);
//
const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({
//labelWidth: 150,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 }
});
//
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
//
await resetFields();
setModalProps({ confirmLoading: false, width: "800px", showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
isUpdate.value = !!data?.isUpdate;
isDetail.value = !!data?.showFooter;
if (unref(isUpdate)) {
//
await setFieldsValue({
...data.record,
});
}
//
setProps({ disabled: !data?.showFooter });
});
//
const fieldPickers = reactive({});
const getTitle = computed(() => (!unref(isUpdate) ? '新增' : !unref(isDetail) ? '详情' : '编辑'));
//
async function handleSubmit(v) {
try {
let values = await validate();
//
changeDateValue(values);
setModalProps({ confirmLoading: true });
//
await handleFileUploads(values);
//
await saveOrUpdate(values, isUpdate.value);
//
closeModal();
//
emit('success');
} catch (error) {
console.error('表单提交失败:', error);
//
if (error && error.errorFields) {
const firstField = error.errorFields[0];
if (firstField) {
scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
}
}
//
if (error && error.message) {
createMessage.error(error.message);
} else if (typeof error === 'string') {
createMessage.error(error);
} else {
createMessage.error('操作失败,请重试');
}
// Promise
throw error;
} finally {
setModalProps({ confirmLoading: false });
}
}
/**
* 处理文件上传
* @param formData 表单数据
*/
async function handleFileUploads(formData) {
console.log('开始处理文件上传,表单数据:', formData);
try {
//
const fileFields = ['mainImage', 'images', 'productVideo'];
for (const field of fileFields) {
// blob URL
if (formData[field] && typeof formData[field] === 'string') {
const fieldValue = formData[field];
const filePaths = fieldValue.split(',').filter(path => path.trim());
for (const path of filePaths) {
if (path.startsWith('blob:')) {
// blob
console.log(`发现需要处理的blob文件: ${field} -> ${path}`);
try {
const uploadedPath = await uploadBlobFile(path, field);
// blob URL
formData[field] = formData[field].replace(path, uploadedPath);
console.log(`文件上传成功,更新路径: ${path} -> ${uploadedPath}`);
} catch (error) {
console.error(`上传文件失败 (${field}):`, error);
createMessage.error(`上传文件失败: ${error.message}`);
throw error;
}
}
}
}
}
console.log('所有文件处理完成,最终表单数据:', formData);
} catch (error) {
console.error('文件上传处理失败:', error);
throw error;
}
}
/**
* 上传blob文件
* @param filePath 文件路径或blob URL
* @param fieldName 字段名
* @returns 上传后的文件路径
*/
async function uploadBlobFile(filePath, fieldName) {
try {
console.log('处理文件:', filePath, '字段:', fieldName);
let file;
let fileName;
if (filePath.startsWith('blob:')) {
// blob URL
console.log('从blob URL获取文件');
const response = await fetch(filePath);
const blob = await response.blob();
fileName = `${fieldName}_${Date.now()}.${blob.type.split('/')[1] || 'jpg'}`;
file = new File([blob], fileName, { type: blob.type });
console.log('从blob URL创建的文件:', file);
} else {
console.log('非blob URL可能是已存在的文件路径');
return filePath; //
}
if (!file) {
throw new Error('无法获取文件对象');
}
//
let bizPath = 'product/temp';
if (fieldName === 'mainImage') {
bizPath = 'product/main';
} else if (fieldName === 'images') {
bizPath = 'product/images';
} else if (fieldName === 'productVideo') {
bizPath = 'product/video';
}
//
const uploadParams = {
file: file,
name: 'file',
filename: fileName,
data: {
biz: bizPath
}
};
console.log('上传参数:', uploadParams);
console.log('上传参数详细信息:');
console.log('- file对象:', file);
console.log('- file.name:', file.name);
console.log('- file.size:', file.size);
console.log('- file.type:', file.type);
console.log('- bizPath:', bizPath);
//
const uploadResult = await defHttp.uploadFile(
{
url: '/sys/common/upload',
timeout: 30000
},
uploadParams,
{
isReturnResponse: true
}
);
console.log('上传结果完整信息:', uploadResult);
console.log('上传结果类型:', typeof uploadResult);
// undefined
if (!uploadResult) {
console.error('上传结果为空或undefined');
throw new Error('上传失败:服务器未返回结果');
}
console.log('上传结果success字段:', uploadResult?.success);
console.log('上传结果message字段:', uploadResult?.message);
console.log('上传结果code字段:', uploadResult?.code);
// -
const isSuccess = uploadResult && (
uploadResult.success === true ||
uploadResult.code === 0 ||
uploadResult.code === 200
);
if (isSuccess) {
const filePath = uploadResult.message || uploadResult.result || uploadResult.data;
console.log('上传成功,文件路径:', filePath);
return filePath;
} else {
console.error('上传失败详细信息:', {
result: uploadResult,
success: uploadResult?.success,
message: uploadResult?.message,
code: uploadResult?.code,
error: uploadResult?.error
});
throw new Error(uploadResult?.message || uploadResult?.error || '上传失败,请检查网络连接或联系管理员');
}
} catch (error) {
console.error('上传文件失败:', error);
throw error;
}
}
/**
* 处理日期值
* @param formData 表单数据
*/
const changeDateValue = (formData) => {
if (formData && fieldPickers) {
for (let key in fieldPickers) {
if (formData[key]) {
formData[key] = getDateByPicker(formData[key], fieldPickers[key]);
}
}
}
};
</script>