From 23b0e5e80109f1f5043b9fd6a96f4408a0d2669b Mon Sep 17 00:00:00 2001 From: linxd <544554903@qq.com> Date: Tue, 5 Aug 2025 15:45:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=8A=E4=BC=A0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/FileUpload/FileUpload.tsx | 16 ++-- .../register/supplier/CommonFormSections.tsx | 86 +++++++++---------- src/utils/utils.ts | 18 ++-- 3 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/components/FileUpload/FileUpload.tsx b/src/components/FileUpload/FileUpload.tsx index fc2b973..33f84a1 100644 --- a/src/components/FileUpload/FileUpload.tsx +++ b/src/components/FileUpload/FileUpload.tsx @@ -50,7 +50,7 @@ const FileUpload: React.FC = ({ listType = 'text', buttonText, disabled = false, - accept = allowedTypes.map(type => `.${type}`).join(','), + accept = allowedTypes.map((type) => `.${type}`).join(','), showUploadList = true, isDragger = false, tip, @@ -62,7 +62,6 @@ const FileUpload: React.FC = ({ // 监听value变化 useEffect(() => { - // 处理字符串URL值(这是关键修复) if (typeof value === 'string' && value) { const file: Partial = { @@ -144,12 +143,12 @@ const FileUpload: React.FC = ({ const filteredList = newFileList.filter((file) => file.status !== 'error'); // 为每个文件添加正确的url - const processedList = filteredList.map(file => { + const processedList = filteredList.map((file) => { if (file.status === 'done' && file.response && !file.url) { return { ...file, url: getFileUrl(file), - filePath: file?.response?.filePath || "filePath not found", + filePath: file?.response?.filePath || 'filePath not found', }; } return file; @@ -163,7 +162,7 @@ const FileUpload: React.FC = ({ }; const beforeUpload = (file: File) => { - return validateFileSize(file, maxSize); + return validateFileSize(file, maxSize, allowedTypes); }; const UploadComponent = isDragger ? Upload.Dragger : Upload; @@ -204,7 +203,12 @@ const FileUpload: React.FC = ({ } return ( - ); diff --git a/src/pages/register/supplier/CommonFormSections.tsx b/src/pages/register/supplier/CommonFormSections.tsx index d84db6d..d285787 100644 --- a/src/pages/register/supplier/CommonFormSections.tsx +++ b/src/pages/register/supplier/CommonFormSections.tsx @@ -16,7 +16,7 @@ import { Radio, Cascader, Empty, - Descriptions + Descriptions, } from 'antd'; import { UploadOutlined, PlusOutlined, DeleteOutlined } from '@ant-design/icons'; import { message } from 'antd'; @@ -25,7 +25,7 @@ import { getRegionTree, getregionInternational } from '@/servers/api/register'; import { getDictList } from '@/servers/api/dicts'; import type { DictItem } from '@/servers/api/dicts'; import FileUpload from '@/components/FileUpload/FileUpload'; -import DictRegionSelect from '@/components/CommonSelect/DictRegionSelect' +import DictRegionSelect from '@/components/CommonSelect/DictRegionSelect'; const { Option } = Select; @@ -474,40 +474,40 @@ export const BankAccountSection: React.FC = ({ form, su const domesticColumns: ColumnType[] = supplierType === 'dvs' ? [ - { - title: '银联号', - dataIndex: 'interbankNumber', - render: (text, record) => ( - - - - ), - }, - ] + { + title: '银联号', + dataIndex: 'interbankNumber', + render: (text, record) => ( + + + + ), + }, + ] : []; // 境外企业特有列 const foreignColumns: ColumnType[] = supplierType === 'ovs' ? [ - { - title: 'SWIFT CODE', - dataIndex: 'swiftCode', - render: (text, record) => ( - - - - ), - }, - ] + { + title: 'SWIFT CODE', + dataIndex: 'swiftCode', + render: (text, record) => ( + + + + ), + }, + ] : []; // 通用列 @@ -589,11 +589,10 @@ export const BankAccountSection: React.FC = ({ form, su {/* 级联选择器用于用户选择 */} - - handleAddressChange(value as string[], record)} /> + + handleAddressChange(value as string[], record)} + /> {/* = ({ form }) = > 下载模版 - @@ -868,11 +866,10 @@ export const AttachmentSection: React.FC = ({ form }) = - { if (value && value.length > 0) { const file = value[0]; @@ -884,8 +881,8 @@ export const AttachmentSection: React.FC = ({ form }) = fileSize: file.size.toString(), fileUrl: file.url, filePath: file.filePath, - } - } + }, + }, }); return file.url; } @@ -902,6 +899,7 @@ export const AttachmentSection: React.FC = ({ form }) = maxCount={1} allowedTypes={['pdf', 'doc', 'docx', 'jpg', 'jpeg', 'png']} maxSize={10} + tip="pdf,doc,docx,jpg,jpeg,png类型的文件,大小不超过10MB" /> @@ -910,9 +908,7 @@ export const AttachmentSection: React.FC = ({ form }) = ); }} - -
其他附件
@@ -924,7 +920,7 @@ export const AttachmentSection: React.FC = ({ form }) = style={{ background: '#fff' }} > - + {(fields, { add, remove }) => ( <> {fields.map((field, index) => ( @@ -970,8 +966,8 @@ export const AttachmentSection: React.FC = ({ form }) = fileSize: file.size.toString(), fileUrl: file.url, filePath: file.filePath, - } - } + }, + }, }); return file.url; } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index ddcdaa4..7e152e9 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,17 +1,25 @@ -import { message,Upload } from 'antd'; +import { message, Upload } from 'antd'; // 验证上传文件大小是否符合要求 // 参数说明: // file: 上传的文件 // maxSize: 最大文件大小 -export const validateFileSize = (file: File, maxSize: number) => { +export const validateFileSize = (file: File, maxSize: number, type: string[]) => { + // 自己抓取文件的后缀名 + const dotIndex = file.name.lastIndexOf('.'); + const fileType = dotIndex !== -1 ? file.name.substring(dotIndex + 1) : ''; const { LIST_IGNORE } = Upload; const isLtMaxSize = file.size / 1024 / 1024 < maxSize; if (!isLtMaxSize) { message.error(`文件大小不能超过${maxSize}MB!`); return LIST_IGNORE; } - return isLtMaxSize; + const isValidFormat = type.includes('*') || (fileType ? type.includes(fileType) : type.includes('')); + if (!isValidFormat) { + message.error(`只能上传${type.join(',')}格式文件!`); + return LIST_IGNORE; + } + return isValidFormat && isLtMaxSize; }; @@ -33,11 +41,11 @@ export const generateUUID = (length: number) => { if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) { const array = new Uint8Array(length); window.crypto.getRandomValues(array); - for (let i = 0; i < length - result.length; i++) { + for (let i = 0;i < length - result.length;i++) { randomPart.push(characters.charAt(array[i] % charactersLength)); } } else { - for (let i = 0; i < length - result.length; i++) { + for (let i = 0;i < length - result.length;i++) { randomPart.push(characters.charAt(Math.floor(Math.random() * charactersLength))); } } From 08ca7af8a5defa4cd94048c609c10f84260c5892 Mon Sep 17 00:00:00 2001 From: linxd <544554903@qq.com> Date: Tue, 5 Aug 2025 16:07:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BE=9B=E5=BA=94=E5=95=86=E8=AF=84?= =?UTF-8?q?=E4=BB=B7=E6=A8=A1=E6=9D=BF=E7=AE=A1=E7=90=86=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supplierTemplateManageDetail.tsx | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManageDetail.tsx b/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManageDetail.tsx index 6bd14d7..871a9d4 100644 --- a/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManageDetail.tsx +++ b/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManageDetail.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { history, useIntl } from 'umi'; +import { useIntl, history, useLocation } from 'umi'; import { Button, Card, Descriptions, Divider, Spin, message, Typography, Empty } from 'antd'; import { ArrowLeftOutlined } from '@ant-design/icons'; import { getTemplateDetail } from '@/servers/api/supplierEvaluate'; @@ -12,12 +12,11 @@ const { Title } = Typography; const SupplierTemplateManageDetail: React.FC = () => { const intl = useIntl(); const [loading, setLoading] = useState(false); - const [templateDetail, setTemplateDetail] = useState(null); + const [templateDetail, setTemplateDetail] = useState< + SupplierTemplateManage.TemplateDetailResponse['data'] | null + >(null); const [templateData, setTemplateData] = useState([]); - - // 从路由获取ID - const { id } = history.location.state as { id: string }; - + const location = useLocation<{ id: string }>(); // 获取模板详情 const fetchTemplateDetail = async (templateId: string) => { try { @@ -43,16 +42,13 @@ const SupplierTemplateManageDetail: React.FC = () => { setLoading(false); } }; - // 首次加载获取数据 useEffect(() => { - if (id) { + if (location.state?.id) { + const id = location.state.id; fetchTemplateDetail(id); - } else { - message.error(intl.formatMessage({ id: 'supplierTemplateManage.detail.idNotExist' })); - history.goBack(); } - }, [id]); + }, [location]); // 返回列表页 const handleBack = () => { @@ -87,7 +83,7 @@ const SupplierTemplateManageDetail: React.FC = () => { bordered={false} className={styles.innerCard} > - +