From ca5c6f4a4d42d9f2a555dba547c426e7e358b29e Mon Sep 17 00:00:00 2001 From: lyp Date: Tue, 27 May 2025 11:35:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/route/AppElectron/AppEdit.tsx | 10 +- .../components/AppCompany/AppCompany.tsx | 168 +++++++++++------- 2 files changed, 107 insertions(+), 71 deletions(-) diff --git a/src/route/AppElectron/AppEdit.tsx b/src/route/AppElectron/AppEdit.tsx index 03acd77..12267bb 100644 --- a/src/route/AppElectron/AppEdit.tsx +++ b/src/route/AppElectron/AppEdit.tsx @@ -93,7 +93,7 @@ export default function AppEdit() { return { label: item.dataId, value: item.dataName, - } + } })) } catch (error: any) { @@ -196,8 +196,8 @@ export default function AppEdit() { getRunSystemList() getBigClassList() - if(appInfo.bigClassify) { - getSmallClassList(appInfo.bigClassify) + if (appInfo.bigClassify) { + getSmallClassList(appInfo.bigClassify) } }, []); const height = window.innerHeight - 180; @@ -302,6 +302,7 @@ export default function AppEdit() { display: editProcess == 1 ? 'block' : 'none' }}> { @@ -318,6 +319,7 @@ export default function AppEdit() { display: editProcess == 2 ? 'block' : 'none' }}> { @@ -353,6 +356,7 @@ export default function AppEdit() { } }> */} { const isJpgOrPng = ['image/jpeg', 'image/png', 'image/bmp'].includes(file.type); @@ -34,13 +35,13 @@ export default function AppCompany(props: any) { } return isJpgOrPng && isLt4M; }; - type FileType = Parameters>[0]; + // type FileType = Parameters>[0]; const [loading, setLoading] = useState(false); - const getBase64 = (img: FileType, callback: (url: string) => void) => { - const reader = new FileReader(); - reader.addEventListener('load', () => callback(reader.result as string)); - reader.readAsDataURL(img); - }; + // const getBase64 = (img: FileType, callback: (url: string) => void) => { + // const reader = new FileReader(); + // reader.addEventListener('load', () => callback(reader.result as string)); + // reader.readAsDataURL(img); + // }; const [imageUrl, setImageUrl] = useState(''); const handleChange: UploadProps['onChange'] = (info) => { if (info.file.status === 'uploading') { @@ -49,12 +50,18 @@ export default function AppCompany(props: any) { } if (info.file.status === 'done') { // Get this url from response in real world. - getBase64(info.file.originFileObj as FileType, (url) => { - setLoading(false); - setImageUrl(url); - }); - console.log(info); - + // getBase64(info.file.originFileObj as FileType, (url) => { + // setLoading(false); + // setImageUrl(url); + // }); + // console.log(info.file.response.data.fileId); + setLoading(false); + const fileId = info.file.response.data.fileId; + const url = showImage(fileId, false); + setImageUrl(url); + form.setFieldsValue({ + img: fileId, + }) } if (info.file.status === 'error') { setLoading(false); @@ -66,21 +73,52 @@ export default function AppCompany(props: any) { }) } }; - + const[textloading, setTextLoading] = useState(false); + const [textImageUrl, setTextImageUrl] = useState(''); + const textHandleChange: UploadProps['onChange'] = (info) => { + if (info.file.status === 'uploading') { + setTextLoading(true); + return; + } + if (info.file.status === 'done') { + // Get this url from response in real world. + // getBase64(info.file.originFileObj as FileType, (url) => { + // setLoading(false); + // setImageUrl(url); + // }); + // console.log(info.file.response.data.fileId); + setTextLoading(false); + const fileId = info.file.response.data.fileId; + const url = showImage(fileId, false); + setTextImageUrl(url); + form.setFieldsValue({ + textImg: fileId, + }) + } + if (info.file.status === 'error') { + setTextLoading(false); + // 显示错误提示 + message.error(`上传失败`); + //伤处表单name为ing的值 + form.setFieldsValue({ + textImg: '', // 将值设置为 undefined 以清除错误状态 + }) + } + }; // 自定义验证规则 - const validateUpload = () => { + // const validateUpload = () => { - if (loading) { - return Promise.reject(new Error('文件上传中,请等待上传完成')); - } - if (!imageUrl) { - return Promise.reject(new Error('请上传有效的文件')); - } - return Promise.resolve(); + // if (loading) { + // return Promise.reject(new Error('文件上传中,请等待上传完成')); + // } + // if (!imageUrl) { + // return Promise.reject(new Error('请上传有效的文件')); + // } + // return Promise.resolve(); - }; + // }; const token = sessionStorage.getItem('token') const submitInfo = (values: any) => { message.success('提交成功'); @@ -95,7 +133,7 @@ export default function AppCompany(props: any) { const handleSubmit = () => { // console.log(form); - props.setEditProcess(2); + // props.setEditProcess(2); // 调用表单实例的 submit 方法 form.submit(); @@ -108,12 +146,12 @@ export default function AppCompany(props: any) { }; useEffect(() => { - // console.log('认证数据',props.companyInfo); - if(props.companyInfo.companyName){ + // console.log('认证数据',props.companyInfo); + if (props.companyInfo.companyName) { console.log('嘻嘻'); - + } - },[props.companyInfo]) + }, [props.companyInfo]) return (
{/* {contextHolder} */} @@ -134,7 +172,7 @@ export default function AppCompany(props: any) { // background: 'pink' }}>
-
企业/机构名称*
+
企业/机构名称*
@@ -146,10 +184,10 @@ export default function AppCompany(props: any) { }} placeholder="请输入企业/机构名称" />
- +
统一社会信用代码*
+ }}>统一社会信用代码*
@@ -163,7 +201,7 @@ export default function AppCompany(props: any) {
- +
上传证件*
+ }}>上传证件*
{ - // setUpArray([]) - // setDisabled(false) - }} + headers={{ 'Auth': `Bearer ${token}` }} - disabled={!!imageUrl} + // disabled={!!imageUrl} // beforeUpload={beforeUpload} > {imageUrl ? @@ -239,20 +274,20 @@ export default function AppCompany(props: any) { }} onClick={() => { setImageUrl('') + form.setFieldsValue({ + img: '', // 将值设置为 undefined 以清除错误状态 + }) }} >删除
- { - // setUpArray([]) - // setDisabled(false) }} headers={{ 'Auth': `Bearer ${token}` }} - disabled={!!imageUrl} - // beforeUpload={beforeUpload} + // disabled={!!imageUrl} > - {imageUrl ? + {textImageUrl ?
- @@ -302,9 +331,9 @@ export default function AppCompany(props: any) { borderRadius: '5px', color: '#929292', }} - disabled={loading} + disabled={textloading} > - {loading ? 正在上传 : + {textloading ? 正在上传 : '点击上传文件' @@ -321,10 +350,13 @@ export default function AppCompany(props: any) { padding: '5px 10px', cursor: 'pointer', color: 'red', - display: imageUrl ? 'block' : 'none', + display: textImageUrl ? 'block' : 'none', }} onClick={() => { - setImageUrl('') + setTextImageUrl('') + form.setFieldsValue({ + textImg: '', // 将值设置为 undefined 以清除错误状态 + }) }} >删除