merge 修改文件服务地址

This commit is contained in:
何童崇 2022-05-18 16:44:20 +08:00 committed by caishi
parent 5689bf439c
commit 576fd8b2c3
1 changed files with 291 additions and 186 deletions

View File

@ -1,14 +1,14 @@
import React, { useCallback, useEffect, useState, Fragment } from 'react';
import { Breadcrumb, Button, Form, Input, Select, Upload, Modal, Cascader, Tooltip } from 'antd';
import { getUploadActionUrl, appendFileSizeToUploadFileAll } from 'educoder';
import { Breadcrumb, Button, Form, Input, Select, Upload, Cascader, Spin } from 'antd';
import { getUploadActionUrl, getUrl, appendFileSizeToUploadFileAll } from 'educoder';
import { locData } from '../../forge/Utils/locData';
import { getStudentApplyInfo, applyGlcc } from '../api';
import axios from 'axios';
import { getStudentApplyInfo, taskList, studentApply, studentApplyEdit } from '../api';
import TextArea from 'antd/lib/input/TextArea';
import { main_site_url } from '../fetch';
import { httpUrl } from '../fetch';
import banner from "../img/banner.png";
import studentSvg from "../img/student.png";
import './index.scss';
import { Link } from 'react-router-dom';
const Option = Select.Option;
const gradeList = [
@ -22,23 +22,25 @@ const gradeList = [
{ id: '研三', name: '研三' }];
function Apply(props) {
const { form, current_user, showNotification, isGlccApplyDate, match } = props;
const { taskId } = match.params;
const taskId = Number(match.params.taskId);
//
// current_user && (current_user.user_id = 6)
// current_user && (current_user.userName = "使")
const { getFieldDecorator, validateFields, setFieldsValue, validateFieldsAndScroll } = form;
const [imageUrl, setImageUrl] = useState(undefined);
const [loading, setLoading] = useState(false);
const [reload, setReload] = useState();
const [userApplyInfo, setUserApplyInfo] = useState(undefined);
const [editable, setEditable] = useState(true);
const [files, setFiles] = useState([]);
const [files1, setFiles1] = useState([]);
const initTask = {
memo: '',
taskId,
taskName: '',
memo: '',
memoAttachmentId: ''
};
const [taskList, setTaskList] = useState([]);
const [myTaskList, setMyTaskList] = useState([]);
const [allTaskList, setAllTaskList] = useState([]);
useEffect(() => {
//
@ -53,6 +55,19 @@ function Apply(props) {
}
}, [])
useEffect(() => {
const params = {
curPage: 1,
pageSize: 10000
}
taskList(params).then(response => {
if (response && response.message === "success") {
setAllTaskList(response.data.rows);
}
})
}, [])
useEffect(() => {
//
current_user && getStudentApplyInfo({ userId: current_user.user_id }).then(response => {
@ -60,32 +75,65 @@ function Apply(props) {
let data = response.data;
let applyInfo = {
grade: data.grade,
location: data.location && data.location.split(),
location: data.location && data.location.split(','),
mail: data.mail,
phone: data.phone,
proveAttachmentId: data.proveAttachmentId,
school: data.school,
studentName: data.studentName,
userId: current_user.user_id,
profession:data.profession,
profession: data.profession,
};
console.log(applyInfo);
if (Array.isArray(data.registrationStudentTaskList) && data.registrationStudentTaskList.length) {
setTaskList(data.registrationStudentTaskList);
let initTaskList = [];
for (const [i, item] of data.registrationStudentTaskList.entries()) {
applyInfo['memo' + i] = item.memo;
applyInfo['taskId' + i] = item.taskId;
applyInfo['taskName' + i] = item.taskName;
applyInfo['memoAttachmentId'+i] =item.memoAttachmentId;
applyInfo['memoAttachmentId' + i] = item.memoAttachmentId;
if (i == 0) {
setFiles([{
name: item.memoAttachment && item.memoAttachment.fileName || '已上传文件',
id: item.memoAttachmentId,
uid: item.memoAttachmentId
}]);
} else {
setFiles1([{
name: item.memoAttachment && item.memoAttachment.fileName || '已上传文件',
id: item.memoAttachmentId,
uid: item.memoAttachmentId,
}]);
}
initTaskList.push({
id: item.id,
memo: item.memo,
memoAttachmentId: item.memoAttachmentId,
taskId: item.taskId,
});
}
setMyTaskList(initTaskList);
// idid
if (data.registrationStudentTaskList.length === 1 && data.registrationStudentTaskList[0].taskId != taskId) {
addTask(data.registrationStudentTaskList);
}
}
setFieldsValue(applyInfo);
setUserApplyInfo(response.data);
} else {
setTaskList([initTask]);
//
new Promise((resove) => {
setMyTaskList(() => {
resove();
return [initTask]
});
}).then(res => setFieldsValue({ 'taskId0': taskId }))
}
})
}, [current_user])
}, [current_user, reload])
//
function verify(dataIndex) {
@ -101,10 +149,7 @@ function Apply(props) {
e.preventDefault();
validateFieldsAndScroll((err, values) => {
if (!err) {
// Modal.confirm({
// title: "",
// content: "",
// onOk: () => {
setLoading(true);
const params = {
grade: values.grade,
location: values.location.join(),
@ -112,23 +157,30 @@ function Apply(props) {
phone: values.phone,
proveAttachmentId: values.proveAttachmentId.file ? values.proveAttachmentId.file.response.id : userApplyInfo.proveAttachmentId,
school: values.school,
profession:data.profession,
profession: values.profession,
studentName: values.studentName,
userId: current_user.user_id,
registrationStudentTaskList: taskList
registrationStudentTaskList: myTaskList
}
// applyGlcc(params).then(response => {
// if (response && response.message === "success") {
// showNotification("");
// setReload(Math.random());
// }
// })
// }
// })
console.log(params);
if (userApplyInfo) {
params.id = userApplyInfo.id;
studentApplyEdit(params).then(response => {
if (response && response.message === "success") {
showNotification("修改信息成功");
setReload(Math.random());
setLoading(false);
}
});
} else {
studentApply(params).then(response => {
if (response && response.message === "success") {
showNotification("报名成功");
setReload(Math.random());
setLoading(false);
}
});
}
}
});
};
@ -145,10 +197,6 @@ function Apply(props) {
//
function beforeUpload(file) {
// const isSmall = file.size / 1024 / 1024 < 2;
// if (!isSmall) {
// showNotification(`${2}MB!`);
// }
const isType = file.type === "image/png" || file.type === "image/jpg" || file.type === "image/jpeg";
if (!isType) {
showNotification("只能上传png、jpg、jpeg格式文件");
@ -165,7 +213,7 @@ function Apply(props) {
}
}
//
//
function handleChange(info) {
if (info && info.file && info.file.status === "done") {
getBase64(info.file.originFileObj, imageUrl =>
@ -175,12 +223,24 @@ function Apply(props) {
}
//
function bookChange(info) {
function bookChange(info, i) {
if (info.file.status === 'uploading' || info.file.status === "done" || info.file.status === 'removed') {
setLoading(true);
if (info.file.status === "done") {
changeTaskItem('memoAttachmentId', info.fileList[0].response && info.fileList[0].response.data.id, i)
}
if (info.file.status === 'removed') {
console.log(1111)
changeTaskItem('memoAttachmentId', '', i);
}
console.log(info.fileList);
setFiles(appendFileSizeToUploadFileAll(info.fileList).slice(-1));
if (i) {
setFiles1(appendFileSizeToUploadFileAll(info.fileList).slice(-1));
} else {
setFiles(appendFileSizeToUploadFileAll(info.fileList).slice(-1));
}
}
if (info.file.status === "done" || info.file.status === 'removed') {
setLoading(false);
}
@ -188,174 +248,219 @@ function Apply(props) {
//
function download(file) {
const fileId = file.id || file.response.id;
window.open(`${current_main_site_url}/api/attachments/${fileId}`);
const fileId = file.id || file.response.data.id;
window.open(`${httpUrl}/busiAttachments/download/${fileId}`);
}
function addTask() {
let taskListNew = [...taskList];
taskListNew.push(initTask);
setTaskList(taskListNew);
function addTask(List) {
let taskListNew = List ? [...List] : [...myTaskList];
if (taskId != taskListNew[0].taskId) {
taskListNew.push(initTask);
//
new Promise((resove) => {
setMyTaskList(() => {
resove();
return taskListNew
});
}).then(res => setFieldsValue({ 'taskId0': taskId }))
} else {
taskListNew.push({ ...initTask, taskId: '' });
setMyTaskList(taskListNew);
}
}
function deleteTask(i) {
let taskListNew = [...taskList];
let taskListNew = myTaskList.slice();
let reWriteInfo;
if (i) {
reWriteInfo = {
taskId1: '',
memo1: '',
memoAttachmentId1: ''
}
setFiles1([]);
} else {
reWriteInfo = {
taskId0: taskListNew[1].taskId,
memo0: taskListNew[1].memo,
memoAttachmentId0: taskListNew[1].memoAttachmentId,
taskId1: '',
memo1: '',
memoAttachmentId1: ''
}
setFiles(files1);
setFiles1([]);
}
taskListNew.splice(i, 1);
setTaskList(taskListNew);
setMyTaskList(taskListNew);
setFieldsValue(reWriteInfo);
}
function changeTaskItem(field, val, i) {
let taskListNew = [...taskList];
let taskListNew = [...myTaskList];
taskListNew[i][field] = val;
setTaskList(taskListNew);
setMyTaskList(taskListNew);
}
return (
<div className="glcc_student_apply">
<img className="glcc-banner" src={banner} alt=''></img>
<div className='apply'>
<Breadcrumb className='glcc_breadcrumb font-16'>
<Breadcrumb.Item><a href="/glcc">开源夏令营</a></Breadcrumb.Item>
<Breadcrumb.Item><a href="/glcc">查看项目</a></Breadcrumb.Item>
<Breadcrumb.Item>学生报名</Breadcrumb.Item>
</Breadcrumb>
<Spin spinning={loading}>
<div className='apply'>
<Breadcrumb className='glcc_breadcrumb font-16'>
<Breadcrumb.Item><Link to="/glcc">开源夏令营</Link></Breadcrumb.Item>
<Breadcrumb.Item><Link to="/glcc/student/2">查看项目</Link></Breadcrumb.Item>
<Breadcrumb.Item>学生报名</Breadcrumb.Item>
</Breadcrumb>
<div className="head_introduce">
<h4 className="head_tit">申请说明</h4>
<div className="head_content">1学生报名时间为<span className="head_bold">2022年5月21日-6月19日</span>请在报名截止时间北京时间<span className="head_bold">2022年6月19日18点</span>前提交报名信息</div>
<div className="head_content">2本次GLCC夏令营基于GitLink代码托管平台完成编程任务若您没有平台账户请先注册后完成课题申请</div>
<div className="head_content">3每位学员最多可申请2个课题至多有且仅有1个课题可以入选</div>
<div className="head_content">4建议在提交课题申请与课题导师邮件沟通详细了解课题描述编码任务技能要求&编程语言预期产出结果等信息以便您能够选择最适合的课题</div>
<div className="head_content">5提交申请后请耐心等待我们会在2022年7月1日公布入围结果如有任何问题请添加开源夏令营微信群进行咨询</div>
</div>
<div className="main-tit">
<img src={studentSvg} /><span className="tit-text">学生报名</span>
</div>
<div className="form-tit">申请课题</div>
<Form className="glcc_info_form" onSubmit={handleSubmit}>
<h4 className="item-tit">基本信息</h4>
{helper('学生姓名',
'',
'studentName',
[{ required: true, message: "请正确输入学生姓名" },
{ max: 32, message: '超出限制长度32位字符请重新编辑' }],
<Input placeholder="请输入学生姓名" onBlur={() => { verify("studentName") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
{helper('所在高校',
'',
'school',
[{ required: true, message: "请正确输入所在高校" },
{ max: 32, message: '超出限制长度32位字符请重新编辑' }],
<Input placeholder="请输入所在高校" onBlur={() => { verify("school") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
{helper('所学专业',
'',
'profession',
[{ max: 32, message: '超出限制长度32位字符请重新编辑' }],
<Input placeholder="请输入所学专业" onBlur={() => { verify("profession") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
<Form.Item label="地区">
{getFieldDecorator("location", {
rules: []
})(
<Cascader placeholder="请选择省份城市" options={locData} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
<div className="head_introduce">
<h4 className="head_tit">申请说明</h4>
<div className="head_content">1学生报名时间为<span className="head_bold">2022年5月21日-6月19日</span>请在报名截止时间北京时间<span className="head_bold">2022年6月19日18点</span>前提交报名信息</div>
<div className="head_content">2本次GLCC夏令营基于GitLink代码托管平台完成编程任务若您没有平台账户请先注册后完成课题申请</div>
<div className="head_content">3每位学员最多可申请2个课题至多有且仅有1个课题可以入选</div>
<div className="head_content">4建议在提交课题申请与课题导师邮件沟通详细了解课题描述编码任务技能要求&编程语言预期产出结果等信息以便您能够选择最适合的课题</div>
<div className="head_content">5提交申请后请耐心等待我们会在2022年7月1日公布入围结果如有任何问题请添加开源夏令营微信群进行咨询</div>
</div>
<div className="main-tit">
<img src={studentSvg} /><span className="tit-text">学生报名</span>
</div>
<div className="form-tit">申请课题</div>
<Form className="glcc_info_form" onSubmit={handleSubmit}>
<h4 className="item-tit">基本信息</h4>
{helper('学生姓名',
'',
'studentName',
[{ required: true, message: "请正确输入学生姓名" },
{ max: 32, message: '超出限制长度32位字符请重新编辑' }],
<Input placeholder="请输入学生姓名" onBlur={() => { verify("studentName") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
{helper('所在高校',
'',
'school',
[{ required: true, message: "请正确输入所在高校" },
{ max: 32, message: '超出限制长度32位字符请重新编辑' }],
<Input placeholder="请输入所在高校" onBlur={() => { verify("school") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
{helper('所学专业',
'',
'profession',
[{ max: 32, message: '超出限制长度32位字符请重新编辑' }],
<Input placeholder="请输入所学专业" onBlur={() => { verify("profession") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
<Form.Item label="地区">
{getFieldDecorator("location", {
rules: []
})(
<Cascader placeholder="请选择省份城市" options={locData} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
</Form.Item>
{helper('所在年级',
'',
'grade',
[],
<Select placeholder="请选择所在年级" disabled={editable ? false : true} className={editable ? "" : "disabledInput"}>
{gradeList.map(item => { return <Option value={item.name} key={item.id}>{item.name}</Option> })}
</Select>
)}
{helper('联系电话',
'',
'phone',
[{ required: true, message: "请正确输入联系电话" }],
<Input placeholder="请输入联系电话" onBlur={() => { verify("phone") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
{helper('邮箱地址',
'',
'mail',
[{ required: true, message: "请正确输入邮箱地址" }],
<Input placeholder="请输入邮箱地址" onBlur={() => { verify("mail") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
</Form.Item>
{helper('所在年级',
'',
'grade',
[],
<Select placeholder="请选择所在年级" disabled={editable ? false : true} className={editable ? "" : "disabledInput"}>
{gradeList.map(item => { return <Option value={item.name} key={item.id}>{item.name}</Option> })}
</Select>
)}
{helper('联系电话',
'',
'phone',
[{ required: true, message: "请正确输入联系电话" }],
<Input placeholder="请输入联系电话" onBlur={() => { verify("phone") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
{helper('邮箱地址',
'',
'mail',
[{ required: true, message: "请正确输入邮箱地址" }],
<Input placeholder="请输入邮箱地址" onBlur={() => { verify("mail") }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
<div className='introArea update_item'>{helper('学生证明',
'请以图片的形式上传学生证明格式为png、jpg、jpeg',
'proveAttachmentId',
[{ required: true, message: "请正确上传学生证明" }],
userApplyInfo && userApplyInfo.proveAttachmentId ? <div className='projectLogo'><img src={`${main_site_url}/api/attachments/${userApplyInfo.proveAttachmentId}`} alt='' /></div>
: <Upload
listType="picture-card"
className="avatar-uploader"
showUploadList={false}
action={getUploadActionUrl()}
accept=".png,.jpg,.jpeg"
beforeUpload={beforeUpload}
onChange={handleChange}
>
{imageUrl ? <img src={imageUrl} alt="avatar" style={{ maxWidth: '100px', maxHeight: '100px' }} /> : <div>
<i className='iconfont icon-tianjiadaohang font-30'></i>
<div className="ant-upload-text font-13">请上传学生证明</div>
</div>}
</Upload>
)}</div>
<div className='introArea update_item'>{helper('学生证明',
'请以图片的形式上传学生证明格式为png、jpg、jpeg',
'proveAttachmentId',
[{ required: true, message: "请正确上传学生证明" }],
userApplyInfo && userApplyInfo.proveAttachmentId ? <div className='projectLogo'><img src={`${getUrl()}/api/attachments/${userApplyInfo.proveAttachmentId}`} alt='' /></div>
: <Upload
listType="picture-card"
className="avatar-uploader"
showUploadList={false}
action={getUploadActionUrl()}
accept=".png,.jpg,.jpeg"
beforeUpload={beforeUpload}
onChange={handleChange}
>
{imageUrl ? <img src={imageUrl} alt="avatar" style={{ maxWidth: '100px', maxHeight: '100px' }} /> : <div>
<i className='iconfont icon-tianjiadaohang font-30'></i>
<div className="ant-upload-text font-13">请上传学生证明</div>
</div>}
</Upload>
)}</div>
{
taskList.map((item, i) => {
return (
<Fragment>
<h4 className="item-tit">课题信息{i + 1}/2) {taskList.length > 1 && <i className="iconfont icon-shanchu" onClick={() => { deleteTask(i) }}></i>}</h4>
{helper('课题名称',
'',
'taskName' + i,
[{ required: true, message: "请正确输入课题名称" }],
<Input placeholder="请输入课题名称" onBlur={(e) => { verify("taskName" + i); changeTaskItem("taskName", e.currentTarget.value, i) }} className={editable ? "" : "disabledInput"} disabled={editable ? false : true} />
)}
<div className='introArea'>{helper('自荐书',
'',
'memo' + i,
[{ required: true, message: "请正确输入自荐书" },
{ max: 500, message: '超出限制长度500位字符请重新编辑' }],
<TextArea placeholder="请填写你的优势和能力不超过500字" onBlur={(e) => { verify("memo" + i); changeTaskItem("memo", e.currentTarget.value, i) }} rows={4} className={editable ? "" : "disabledInput"} />
)}</div>
{
myTaskList.map((item, i) => {
return (
<Fragment key={item.taskId + '' + i}>
<h4 className="item-tit">课题信息<span className="item-tit-num">{i + 1}</span>/2) {myTaskList.length > 1 && <i className="iconfont icon-shanchu" onClick={() => { deleteTask(i) }}></i>}</h4>
{helper('课题名称',
'',
'taskId' + i,
[{ required: true, message: "请选择课题名称" }],
<Select
placeholder="请选择课题名称"
showSearch
disabled={editable ? false : true}
className={editable ? "" : "disabledInput"}
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) > -1}
onBlur={() => { verify("taskId" + i) }}
onChange={(val) => { changeTaskItem("taskId", val, i) }}
>
{allTaskList.map(item => { return <Option value={item.id} key={item.id + ''}>{item.taskName}</Option> })}
</Select>
)}
<div className='introArea'>{helper('自荐书',
'',
'memo' + i,
[{ required: true, message: "请正确输入自荐书" },
{ max: 500, message: '超出限制长度500位字符请重新编辑' }],
<TextArea placeholder="请填写你的优势和能力不超过500字" onBlur={(e) => { verify("memo" + i); changeTaskItem("memo", e.currentTarget.value, i) }} rows={4} className={editable ? "" : "disabledInput"} />
)}</div>
<div className='introArea'>{helper('附件',
'',
'memoAttachmentId' + i,
[],
<Upload
accept=".zip,.rar"
action={getUploadActionUrl()}
fileList={files}
onChange={bookChange}
onDownload={download}
showUploadList={{
showDownloadIcon: true,
downloadIcon: <i className="iconfont icon-xiazai-icon"></i>,
showRemoveIcon: true
}}
>
<div className="glcc_btn">上传自荐书</div>
</Upload>
)}</div>
</Fragment>
)
})
}
<div className='introArea'>{helper('附件',
'',
'memoAttachmentId' + i,
[],
<Upload
// action={getUploadActionUrl()}
action={httpUrl + `/busiAttachments/upload`}
fileList={i ? files1 : files}
onChange={(info) => { bookChange(info, i) }}
onDownload={download}
showUploadList={{
showDownloadIcon: true,
downloadIcon: <i className="iconfont icon-xiazai-icon"></i>,
showRemoveIcon: true
}}
>
<div className="glcc_btn">上传自荐书</div>
</Upload>
)}</div>
</Fragment>
)
})
}
{
taskList.length < 2 && <Button className="add_task" type="primary" onClick={addTask}>添加课题</Button>
}
{
myTaskList.length < 2 && <Button className="add_task" type="primary" onClick={addTask}>添加课题</Button>
}
{!userApplyInfo && <Form.Item className='subInfo introArea'>
<Button type="primary" htmlType="submit" className='sub' >提交</Button>
</Form.Item>}
</Form>
<Form.Item className='subInfo introArea'>
<Button type="primary" htmlType="submit" className='sub' disabled={!editable}>提交</Button>
</Form.Item>
</Form>
</div>
</div>
</Spin>
</div>
)
}