133 lines
3.3 KiB
TypeScript
133 lines
3.3 KiB
TypeScript
import React, { FC, useEffect, useState } from 'react';
|
||
import {
|
||
ClassroomModelState,
|
||
ConnectProps,
|
||
connect,
|
||
Dispatch,
|
||
UserModelState,
|
||
useParams,
|
||
ShixunsDetailModelState
|
||
} from 'umi';
|
||
import {
|
||
Modal,
|
||
Upload,
|
||
message
|
||
} from 'antd';
|
||
import moment from 'moment';
|
||
import Fetch from '@/utils/fetch';
|
||
import { InboxOutlined } from '@ant-design/icons';
|
||
import { StatusClassroomsTags, timego } from '@/utils/util';
|
||
import { uploadFile } from '@/components/UploadFile';
|
||
interface PageProps extends ConnectProps {
|
||
classroomList: ClassroomModelState;
|
||
dispatch: Dispatch;
|
||
user: UserModelState;
|
||
onModalOk:any
|
||
shixunsDetail:ShixunsDetailModelState
|
||
getResults:any
|
||
}
|
||
const { Dragger } = Upload;
|
||
const ShixunsListPage: FC<PageProps> = ({
|
||
user,
|
||
dispatch,
|
||
classroomList,
|
||
shixunsDetail,
|
||
getResults,
|
||
}) => {
|
||
const params:any = useParams() ;
|
||
const[time,setTime]=useState<any>();
|
||
const[fileList,setFileList]=useState<any>([]);
|
||
const[confirmLoading,setConfirmLoading]=useState<any>(false)
|
||
const props = {
|
||
onRemove: () => {
|
||
setFileList([]);
|
||
},
|
||
beforeUpload: (file: any) => {
|
||
console.log(file);
|
||
if(file?.size>1024*1024*500){
|
||
message.info('文件超过500M,不符合上传要求')
|
||
return false
|
||
}
|
||
let filelist=[];
|
||
filelist.push(file)
|
||
setFileList([...filelist])
|
||
return false;
|
||
},
|
||
fileList:fileList,
|
||
};
|
||
|
||
return (
|
||
<Modal
|
||
title="提交文件"
|
||
open={shixunsDetail.actionTabs.key === 'md-tab'}
|
||
confirmLoading={confirmLoading}
|
||
onOk={async ()=>{
|
||
if(fileList?.length<=0){
|
||
message.info('请先选择文件')
|
||
return
|
||
}
|
||
setConfirmLoading(true);
|
||
const resulr=await uploadFile(fileList[0],{
|
||
login:user.userInfo?.login,
|
||
container_type:"Competition",
|
||
container_id: shixunsDetail.actionTabs.params.id,
|
||
stage_type:shixunsDetail.actionTabs.params.value,
|
||
file_name:fileList[0]?.name,
|
||
})
|
||
if(resulr?.status===0){
|
||
message.info('提交成功')
|
||
dispatch({
|
||
type: 'shixunsDetail/setActionTabs',
|
||
payload: {
|
||
key: '',
|
||
},
|
||
})
|
||
setConfirmLoading(false)
|
||
setFileList([]);
|
||
getResults(shixunsDetail.actionTabs.params.value)
|
||
}else{
|
||
setConfirmLoading(false)
|
||
message.info('提交失败')
|
||
}
|
||
|
||
}}
|
||
onCancel={() => {
|
||
setFileList([]);
|
||
dispatch({
|
||
type: 'shixunsDetail/setActionTabs',
|
||
payload: {
|
||
key: '',
|
||
},
|
||
})
|
||
}}
|
||
>
|
||
<Dragger {...props}>
|
||
<p className="ant-upload-drag-icon">
|
||
<InboxOutlined />
|
||
</p>
|
||
|
||
<p className="ant-upload-hint">
|
||
拖拽文件或者点击上传
|
||
</p>
|
||
</Dragger>
|
||
|
||
|
||
</Modal>
|
||
);
|
||
};
|
||
export default connect(
|
||
({
|
||
user,
|
||
classroomList,
|
||
shixunsDetail
|
||
}: {
|
||
user: UserModelState;
|
||
classroomList: ClassroomModelState;
|
||
shixunsDetail:ShixunsDetailModelState;
|
||
}) => ({
|
||
user,
|
||
classroomList,
|
||
shixunsDetail
|
||
}),
|
||
)(ShixunsListPage);
|