system-copyright-react/src/route/AppElectron/components/EditAppFiles/EditAppFiles.tsx

267 lines
12 KiB
TypeScript
Raw Normal View History

2025-05-19 17:29:11 +08:00
import { useState } from 'react'
2025-05-16 17:48:03 +08:00
import { Button, Form, Upload, message, } from "antd"
import { uploadFileUrl } from '../../../../request/request'
import { UploadOutlined } from '@ant-design/icons';
import './edit-app-files.css'
export default function EditAppFiles(props: any) {
2025-05-19 17:29:11 +08:00
// 定义允许上传的文件格式
const ALLOWED_FILE_TYPES = ['.pdf', '.doc', '.docx', '.jpg', '.jpeg', '.png'];
const beforeUpload = (file: File) => {
const fileExt = file.name.slice(file.name.lastIndexOf('.')).toLowerCase();
if (!ALLOWED_FILE_TYPES.includes(fileExt)) {
message.error(`仅支持 ${ALLOWED_FILE_TYPES.join(', ')} 格式的文件`);
return Upload.LIST_IGNORE;
}
return true;
};
// 上传文件源码文档列表
const [upCodeArray, setUpCodeArray] = useState<any>([])
const [codeDis, setCodeDis] = useState(false)
const validateCodeFileUpload = (_rule: any, value: any) => {
if (!value || value.fileList.length === 0) {
return Promise.reject('请选择上传文件');
}
const file = value.fileList[0];
if (file.status === 'uploading') {
setCodeDis(true)
return Promise.reject('文件上传中,请稍候');
} else if (file.status === 'error') {
setCodeDis(true)
setUpCodeArray([])
return Promise.reject('文件上传失败,请删除后重新上传');
} else if (file.status !== 'done') {
setCodeDis(true)
setUpCodeArray([])
return Promise.reject('文件上传失败,请删除后重新上传');
} else if (file.status === 'done') {
setCodeDis(true)
return Promise.resolve();
}
return Promise.resolve();
};
// 上传文件软件文档列表
const [upSoftArray, setUpSoftArray] = useState<any>([])
const [softDis, setSoftDis] = useState(false)
const validateSoftFileUpload = (_rule: any, value: any) => {
if (!value || value.fileList.length === 0) {
return Promise.reject('请选择上传文件');
}
const file = value.fileList[0];
if (file.status === 'uploading') {
setSoftDis(true)
return Promise.reject('文件上传中,请稍候');
} else if (file.status === 'error') {
setSoftDis(true)
setUpSoftArray([])
return Promise.reject('文件上传失败,请删除后重新上传');
} else if (file.status !== 'done') {
setSoftDis(true)
setUpSoftArray([])
return Promise.reject('文件上传失败,请删除后重新上传');
} else if (file.status === 'done') {
setSoftDis(true)
return Promise.resolve();
}
return Promise.resolve();
};
2025-05-16 17:48:03 +08:00
const token = sessionStorage.getItem('token')
const height = window.innerHeight - 460;
const [form] = Form.useForm();
const handleSubmit = () => {
// console.log(form);
props.setEditProcess(4);
// 调用表单实例的 submit 方法
form.submit();
};
const submitInfo = (values: any) => {
message.success('提交成功');
console.log(values);
props.setEditProcess(3);
}
const onFinish = (values: any) => {
// 处理表单提交逻辑
console.log('表单提交成功', values);
submitInfo(values)
2025-05-20 15:07:26 +08:00
console.log(upCodeArray);
2025-05-16 17:48:03 +08:00
};
return (
<div>
<div className='bigLine'></div>
<div className='appInfoFormBox' style={{
height: height,
justifyContent: 'flex-start',
flexDirection: 'column',
marginLeft: '100px',
paddingBottom: '0'
}}>
<div style={{
height: '80px',
}}>
<Form form={form} onFinish={onFinish}
2025-05-19 17:29:11 +08:00
onFinishFailed={(errorInfo: any) => {
const errorMessages = errorInfo.errorFields.map((field: any) => field.errors[0]);
if (errorMessages.some((msg: any) => msg.includes('文件上传失败'))) {
message.error('文件上传失败,请重新上传');
} else if (errorMessages.some((msg: any) => msg.includes('文件上传中'))) {
message.error('文件上传中,请稍候');
} else if (errorMessages.some((msg: any) => msg.includes('文件状态异常'))) {
message.error('文件状态异常,请重新上传');
} else {
message.error('请完善信息');
}
2025-05-16 17:48:03 +08:00
}}
>
<div style={{
display: 'flex',
justifyContent: 'space-between',
width: '600px',
// background: 'pink'
}}>
<div className='appInfoFormInput' style={{
position: 'relative',
}}>
<div className='FormInputTitle' style={{
}}></div>
<div style={{
2025-05-19 17:29:11 +08:00
width: '220px',
2025-05-16 17:48:03 +08:00
}}>
2025-05-19 17:29:11 +08:00
<Form.Item name="ym" label="" rules={[
// { required: true, message: '请选上传文件' },
{ validator: validateCodeFileUpload }
2025-05-16 17:48:03 +08:00
]}>
<Upload
name="file"
action={uploadFileUrl()}
2025-05-19 17:29:11 +08:00
defaultFileList={upCodeArray}
onChange={({ fileList }) => {
console.log(fileList);
2025-05-20 15:07:26 +08:00
// console.log(upCodeArray);
2025-05-19 17:29:11 +08:00
}}
onRemove={() => {
setUpCodeArray([])
setCodeDis(false)
}}
beforeUpload={beforeUpload}
2025-05-16 17:48:03 +08:00
// onChange={handleUploadChange}
headers={{ 'Auth': `Bearer ${token}` }}
>
<Button icon={<UploadOutlined />} style={{
marginTop: '4px'
2025-05-19 17:29:11 +08:00
}}
disabled={codeDis}
></Button>
2025-05-16 17:48:03 +08:00
</Upload>
</Form.Item>
</div>
<a style={{
position: 'absolute',
top: '10px',
left: '240px',
textWrap: 'nowrap'
}}>[ ]</a>
</div>
<div className='appInfoFormInput' style={{
position: 'relative',
}}>
<div className='FormInputTitle' style={{
}}></div>
<div style={{
2025-05-19 17:29:11 +08:00
width: '220px',
2025-05-16 17:48:03 +08:00
}}>
2025-05-19 17:29:11 +08:00
<Form.Item name="file" label="" rules={[
// { required: true, message: '请上传文件' },
{ validator: validateSoftFileUpload }
2025-05-16 17:48:03 +08:00
]}>
<Upload
name="file"
action={uploadFileUrl()}
2025-05-19 17:29:11 +08:00
defaultFileList={upSoftArray}
onChange={({ fileList }) => {
console.log(fileList);
}}
onRemove={() => {
setUpSoftArray([])
setSoftDis(false)
}}
beforeUpload={beforeUpload}
2025-05-16 17:48:03 +08:00
// onChange={handleUploadChange}
headers={{ 'Auth': `Bearer ${token}` }}
>
<Button icon={<UploadOutlined />} style={{
marginTop: '4px'
2025-05-19 17:29:11 +08:00
}}
disabled={softDis}
></Button>
2025-05-16 17:48:03 +08:00
</Upload>
</Form.Item>
</div>
<a style={{
position: 'absolute',
top: '10px',
left: '240px',
textWrap: 'nowrap'
}}>[ ]</a>
</div>
</div>
</Form>
</div>
<div className="fileTextBox">
{/* 循环100次 */}
{Array.from({ length: 100 }).map((_, index) => (
<span style={{
lineHeight: '30px',
fontSize: '14px',
}}
key={index}>
说明:1嘻嘻嘻啊司机大佬觉得拉家带口垃圾狄拉克
</span>
))}
</div>
</div>
<div className='bigLine'></div>
<div className='nextBtnBxo'>
<Button
style={{
width: '235px',
height: '46px',
borderRadius: '5px',
}}
onClick={() => {
props.setEditProcess(2)
}}></Button>
<Button
style={{
width: '235px',
height: '46px',
borderRadius: '5px',
marginLeft: '10px',
}}
type='primary'
onClick={() => {
handleSubmit()
}}></Button>
</div>
</div>
)
}