商品列表、分类管理、客户等级

This commit is contained in:
liu
2026-08-05 19:28:53 +08:00
parent dfa471bf22
commit 258df92e6c
36 changed files with 472 additions and 516 deletions
@@ -6,6 +6,7 @@ import type { UploadFile, UploadProps } from 'antd';
import type { RcFile } from 'antd/es/upload';
import type { ImageUploaderProps } from './typings';
import type { ISysFileInfo } from '@/domain/iSysFile';
import { getFileInfo } from '@/api/system/sysFile';
import { useTranslation } from 'react-i18next';
/**
@@ -51,8 +52,29 @@ const ImageUploader: React.FC<ImageUploaderProps> = ({
return;
}
const valueArray = Array.isArray(value) ? value : [value];
const newFileList: UploadFile[] = valueArray.map(fileToList);
setFileList(newFileList);
// changeType='id' 时表单值为文件 id:拉取文件信息回显;
if (changeType === 'id') {
const ids = valueArray as number[];
const idSet = new Set(fileList.map(obj => Number(obj.uid)));
// 过滤出不在 Set 中的数字
const missing = ids.filter(num => !idSet.has(Number(num)));
if (missing.length > 0) {
const fetchers = missing.map((id) => getFileInfo(id));
Promise.all(fetchers).then((resList) => {
const files = resList
.map((res) => res.data.data)
.filter(i => !!i)
.map(fileToList);
setFileList([...files, ...fileList]);
})
}
} else {
const newFileList: UploadFile[] = (valueArray as ISysFileInfo[]).map(fileToList);
setFileList(newFileList);
}
}, [value]);
// 上传前校验
@@ -106,8 +128,16 @@ const ImageUploader: React.FC<ImageUploaderProps> = ({
// 处理文件列表变化
const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) => {
// 如果所有文件都被删除
if (newFileList.length === 0) return;
// 所有文件都被删除时,同步清空表单值,避免残留旧 id 被提交
if (newFileList.length === 0) {
setFileList([]);
if (mode === 'single') {
onChange?.(null);
} else {
onChange?.([]);
}
return;
}
setFileList(newFileList);
// 全部上传完成格式化图片列表
if (newFileList.every((file) => file.status === 'done' || file.status === 'error')) {
@@ -130,6 +160,7 @@ const ImageUploader: React.FC<ImageUploaderProps> = ({
}
// 上传失败的文件
const errorFiles = newFileList.filter((file) => file.status === 'error');
setFileList([...uploadedFiles.map(fileToList), ...errorFiles]);
}
};