forked from Gitlink/forgeplus-react
作品提交代码更新
This commit is contained in:
parent
3a6ab13df8
commit
9bf6c1fd67
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import React,{ useEffect, useRef, useState } from 'react';
|
||||
import type { FC } from 'react';
|
||||
import {
|
||||
connect, ConnectProps, Dispatch, useParams
|
||||
|
|
@ -52,7 +52,6 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
StaffDetail,
|
||||
getTabResults = () => { }
|
||||
}) => {
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const [formButLoading, setFormButLoading] = useState<boolean>(false);
|
||||
// 开启/关闭 编辑
|
||||
|
|
@ -88,18 +87,18 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
// 分页,搜索
|
||||
const [urlData, setUrlData] = useState<any>({
|
||||
page: 1,
|
||||
per_page: 20,
|
||||
limit: 20,
|
||||
keyword: "",
|
||||
});
|
||||
// MD内容
|
||||
const [mdContent, setMdContent] = useState<any>("");
|
||||
// 下载所有文件时打包成zip文件
|
||||
const [zipAll, setZipAll] = useState(new JSZip());
|
||||
let zipAll = useRef<JSZip>(new JSZip());
|
||||
|
||||
useEffect(() => {
|
||||
setIdentity(userinfo?.admin || userinfo?.business || Editable)
|
||||
}, [userinfo?.admin, userinfo?.business, Editable])
|
||||
useEffect(() => {
|
||||
ItemData?.only_file ? setModelType(2) : setModelType(1);
|
||||
if (ItemData?.only_file) setModelType(2);
|
||||
}, [ItemData])
|
||||
useEffect(() => {
|
||||
if (TabResults.stages && TabResults.stages?.length > 0) {
|
||||
|
|
@ -112,7 +111,7 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
getResults();
|
||||
// getTeamList()
|
||||
getTeam()
|
||||
}, [gameItem?.id, urlData.page])
|
||||
}, [gameItem?.id, urlData.page, urlData.limit])
|
||||
async function getTeamList() {
|
||||
setisloading(true)
|
||||
let res = await Fetch(`${ENV.API_SERVER}/api/competitions/${identifier}/my_teams`, {
|
||||
|
|
@ -121,6 +120,8 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
setisloading(false)
|
||||
setIsSubmitModel(true)
|
||||
if (res?.status === 0) {
|
||||
|
||||
|
||||
setTeamlist(res?.data)
|
||||
form.setFieldsValue({
|
||||
name: '',
|
||||
|
|
@ -274,13 +275,12 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
}
|
||||
// 作品提交或者编辑
|
||||
const handleFormFinish = async (values: any) => {
|
||||
|
||||
setFormButLoading(true);
|
||||
let res: any;
|
||||
if (modelType == 2 && fileList.length == 0) {
|
||||
message.error("请选择文件");
|
||||
return;
|
||||
}
|
||||
setFormButLoading(true);
|
||||
let res: any;
|
||||
const Data: any = {
|
||||
login: userinfo?.login,
|
||||
container_type: "Competition",
|
||||
|
|
@ -303,9 +303,7 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
}
|
||||
}
|
||||
)
|
||||
setFormButLoading(false);
|
||||
|
||||
if (res?.status != 0) return
|
||||
if (res?.status != 0) { setFormButLoading(false); return }
|
||||
Data["name"] = values.name;
|
||||
Data["url"] = values.url;
|
||||
}
|
||||
|
|
@ -344,10 +342,9 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
identifier: identifier,
|
||||
stage_id: gameItem?.id,
|
||||
page: 1,
|
||||
per_page: 9999999, // TODO :查询所有列表数据
|
||||
limit: 9999999, // TODO :查询所有列表数据
|
||||
keyword: "",
|
||||
module_type: 'worksubmit',
|
||||
|
||||
}
|
||||
})
|
||||
const DownloadList = res?.results?.filter((item: any) => item?.result_url && item.file_name)
|
||||
|
|
@ -361,23 +358,37 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
}
|
||||
});
|
||||
const nameLsit: string[] = [];
|
||||
// 下载所有文件时打包成zip文件
|
||||
// let zipAll = new JSZip();
|
||||
let maxSize = 800 * 1024 * 1024; // 900MB的最大限制
|
||||
let currentSize = 0; // 当前压缩包的大小
|
||||
let currentBatch = 0;
|
||||
const addzip = async (data: any, progress: number) => {
|
||||
try {
|
||||
const zip = new JSZip();
|
||||
const response = await fetch(data.result_url, { method: "get" });
|
||||
const blob = await response.blob();
|
||||
zip.file(data.file_name, blob);
|
||||
await zip.generateAsync({ type: "blob" }).then((blob) => {
|
||||
const getNameFile = (name: string, index: number = 0) => {
|
||||
if ((index == 0 && nameLsit.includes(name)) || nameLsit.includes(`${name}(${index})`)) {
|
||||
getNameFile(name, index + 1);
|
||||
} else {
|
||||
nameLsit.push(index == 0 ? name : `${name}(${index})`)
|
||||
zipAll.file(index == 0 ? name + ".zip" : `${name}(${index})` + ".zip", blob);
|
||||
}
|
||||
const fileBlob = await zip.generateAsync({ type: "blob" })
|
||||
const fileSize = blob.size;
|
||||
if (currentSize + fileSize > maxSize) {
|
||||
await zipAll.current.generateAsync({ type: "blob" }).then((blob) => {
|
||||
downLoadLink(`${HeaderDetail.name}-batch${currentBatch + 1}`, window.URL.createObjectURL(blob));
|
||||
});
|
||||
zipAll.current = new JSZip();
|
||||
currentSize = 0;
|
||||
currentBatch++;
|
||||
}
|
||||
const getNameFile = (name: string, index: number = 0) => {
|
||||
if ((index == 0 && nameLsit.includes(name)) || nameLsit.includes(`${name}(${index})`)) {
|
||||
getNameFile(name, index + 1);
|
||||
} else {
|
||||
nameLsit.push(index == 0 ? name : `${name}(${index})`)
|
||||
zipAll.current.file(index == 0 ? name + ".zip" : `${name}(${index})` + ".zip", fileBlob);
|
||||
currentSize += fileSize; // 更新当前批次的大小
|
||||
}
|
||||
getNameFile(`${data?.team_name}-${data?.user_name}`);
|
||||
})
|
||||
}
|
||||
getNameFile(`${data?.team_name}-${data?.user_name}`);
|
||||
modal.update({
|
||||
content: <div>当前进度: <span className="c-blue">{progress}</span>/{DownloadList.length}</div>,
|
||||
})
|
||||
|
|
@ -385,16 +396,24 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
message.error(`${data.file_name}下载失败`);
|
||||
}
|
||||
}
|
||||
if (DownloadList.length > 0) {
|
||||
const processBatch = async () => {
|
||||
let i = 0;
|
||||
for (let item of DownloadList) {
|
||||
for (const item of DownloadList) {
|
||||
await addzip(item, ++i);
|
||||
}
|
||||
zipAll.generateAsync({ type: "blob" }).then((blob) => {
|
||||
downLoadLink(HeaderDetail.name, window.URL.createObjectURL(blob));
|
||||
})
|
||||
if (currentSize > 0) {
|
||||
await zipAll.current.generateAsync({ type: "blob" }).then((blob) => {
|
||||
downLoadLink(`${HeaderDetail.name}-batch${currentBatch + 1}`, window.URL.createObjectURL(blob));
|
||||
});
|
||||
}
|
||||
|
||||
modal.destroy(); // 关闭弹窗
|
||||
};
|
||||
console.log("DownloadList===", DownloadList);
|
||||
|
||||
if (DownloadList.length > 0) {
|
||||
processBatch();
|
||||
}
|
||||
modal.destroy()
|
||||
}
|
||||
const uploadProps = {
|
||||
maxCount: 1,
|
||||
|
|
@ -419,8 +438,7 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
|
||||
|
||||
return (<div className={styles.WorkSubmit}>
|
||||
{gameItem ?
|
||||
<Tabs defaultActiveKey={TabResults.stages?.[0]?.id || 1}
|
||||
{gameItem ? <Tabs defaultActiveKey={TabResults.stages?.[0]?.id || 1}
|
||||
destroyInactiveTabPane
|
||||
tabBarExtraContent={<Row style={{ marginBottom: "10px" }}>
|
||||
{!identity && StaffDetail.enrolled && <Button type="primary" onClick={() => setIsSubmitModel(true)}>作品提交</Button>}
|
||||
|
|
@ -445,8 +463,7 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
{item.children?.map((ChildItem: any) => <Tabs.TabPane tab={ChildItem.name} key={ChildItem.id} ></Tabs.TabPane>)}
|
||||
</Tabs>}
|
||||
</Tabs.TabPane>)}
|
||||
</Tabs> :
|
||||
<div>
|
||||
</Tabs> : <div>
|
||||
{(StaffDetail.enrolled || identity) && <Row style={{ marginBottom: "10px", paddingBottom: "10px", borderBottom: "1px solid #eee" }}>
|
||||
{!identity && StaffDetail.enrolled && <Button style={{ marginLeft: "auto" }} loading={isloading} type="primary" onClick={() => {
|
||||
getTeamList()
|
||||
|
|
@ -477,8 +494,7 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
bordered={false}
|
||||
onPressEnter={getResults} />
|
||||
<div style={{ color: "#9B9B9B", fontSize: "14px", marginLeft: "20px" }}>
|
||||
当前共计作品
|
||||
<span style={{ color: "#165DFF" }}>{tableList.total_count}</span>个
|
||||
当前共计作品<span style={{ color: "#165DFF" }}>{tableList.total_count}</span>个
|
||||
(<span style={{ color: "#ff9000" }}>页面仅展示本队作品</span>)
|
||||
</div>
|
||||
</Row>
|
||||
|
|
@ -496,13 +512,14 @@ const WorkSubmit: FC<PageProps> = ({
|
|||
(gameItem?.end_time && gameItem?.start_time || HeaderDetail.start_time && HeaderDetail.end_time) &&
|
||||
<span className={styles.span}>提交时间:<span>{moment(gameItem?.start_time || HeaderDetail.start_time).format("YYYY-MM-DD HH:mm:ss")}</span> 至 <span>{moment(gameItem?.end_time || HeaderDetail.end_time).format("YYYY-MM-DD HH:mm:ss")}</span></span>
|
||||
}
|
||||
<Pagination showQuickJumper hideOnSinglePage
|
||||
<Pagination showQuickJumper hideOnSinglePage showSizeChanger
|
||||
current={urlData.page}
|
||||
pageSize={urlData.per_page}
|
||||
onChange={(page) => setUrlData({ ...urlData, page })}
|
||||
onShowSizeChange={(page, per_page) => setUrlData({ ...urlData, page: 1, per_page })}
|
||||
pageSize={urlData.limit}
|
||||
onChange={(page, limit) => setUrlData({ ...urlData, page, limit })}
|
||||
onShowSizeChange={(page, limit) => setUrlData({ ...urlData, page: 1, limit })}
|
||||
total={tableList.total_count || 0} />
|
||||
</Row>
|
||||
|
||||
<Modal centered destroyOnClose
|
||||
title={<div style={{
|
||||
fontWeight: "500",
|
||||
|
|
|
|||
|
|
@ -126,8 +126,8 @@ export default function request(url: string, option: any, flag?: boolean) {
|
|||
|
||||
let newOptions = { ...defaultOptions, ...options }
|
||||
let eduHeader = {
|
||||
'X-Edu-Signature':'2145e1fc2be2e1312293ba786ba64534',
|
||||
'X-Edu-Timestamp':'1728893347020',
|
||||
'X-Edu-Signature':'1619eba6f182db728a190d444965c47c',
|
||||
'X-Edu-Timestamp':'1728974333737',
|
||||
'X-Edu-Type':'pc',
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue