Skip to content

Commit

Permalink
Merge pull request #108 from NJUPT-SAST/bqx-dev
Browse files Browse the repository at this point in the history
Bqx dev
  • Loading branch information
MaxtuneLee authored Apr 4, 2024
2 parents 1ffa700 + b434ca5 commit 61f9164
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 66 deletions.
15 changes: 14 additions & 1 deletion src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const signUp = (
competitionId: number,
teamName: string | null,
teamMember: { name: string; code: string }[],
teacherMember: { name: string; code: string}[]
teacherMember: { name: string; code: string }[],
) => {
return apis({
method: 'POST',
Expand Down Expand Up @@ -191,3 +191,16 @@ export const getUserProfile = () => {
url: '/user/profile',
})
}

export const getLicense = (name: string, input: string, id: number) => {
return apis({
method: 'get',
url: `/user/com/uploadCertificate?id=${id}&input=${input}&filename=${name}`,
})
}

export const uploadFile = () => {
return apis({
method: 'post',
})
}
26 changes: 13 additions & 13 deletions src/pages/workDetail/component/Uploader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ function Uploader(props: any) {
onChange(info: any) {
console.log('onChange', info)
},
customRequest(options: any) {
console.log('options', options)
const { onSuccess, onError, file, onProgress } = options
uploadWork(Number(props.competitionId), props.inputName, file, onProgress).then((res) => {
console.log(res)
if (res.data.errCode === null) {
onSuccess(res, file)
message.success({
content: file.name + ' 上传成功',
})
}
})
},
// customRequest(options: any) {
// console.log('options', options)
// const { onSuccess, onError, file, onProgress } = options
// uploadWork(Number(props.competitionId), props.inputName, file, onProgress).then((res) => {
// console.log(res)
// if (res.data.errCode === null) {
// onSuccess(res, file)
// message.success({
// content: file.name + ' 上传成功',
// })
// }
// })
// },
headers: { Token: localStorage.getItem('approval-system-token') },
}
return (
Expand Down
98 changes: 55 additions & 43 deletions src/pages/workDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { LoadingOutlined, UploadOutlined } from '@ant-design/icons'
import { Button, Input, message, notification, Result, Spin, Upload, UploadProps } from 'antd'
import { UploadFile } from 'antd/lib/upload/interface'
import FormRender, { useForm } from 'form-render'
import React, { Fragment, ReactElement, useLayoutEffect, useState } from 'react'
import React, { Fragment, ReactElement, useEffect, useLayoutEffect, useState } from 'react'
import { useNavigate, useParams } from 'react-router-dom'
import { fileDownload } from '../../api/public'
import {
getCompetitionInfo,
getLicense,
getTeamInfo,
getWorkInfo,
getWorkSchema,
Expand Down Expand Up @@ -241,19 +242,6 @@ function WorkDetail() {
}
})
}
const onRemove = (inputName: string) => {
form.setValueByPath(inputName, null)
setFileList((prev) => {
return {
...prev,
[inputName]: [],
}
})
}
const handleDownload = (file: string) => {
console.log(file)
// downloadFile()
}
const localProps: any = {
accept: props.accept,
maxCount: '1',
Expand Down Expand Up @@ -288,26 +276,26 @@ function WorkDetail() {
form.setValueByPath(props.inputName, null)
}
},
customRequest(options: any) {
console.log('options', options)
const { onSuccess, onError, file, onProgress } = options
uploadWork(Number(id), props.inputName, file, onProgress).then((res) => {
console.log('upload res: ', res)
if (res.data.errCode === null) {
onSuccess(res, file)
message.success({
content: file.name + ' 上传成功',
})
setFileList((prev) => {
return {
...prev,
[props.inputName]: [{ ...prev[props.inputName][0], url: res.data.data.url, status: 'done' }],
}
})
form.setValueByPath(props.inputName, res.data.data.url)
}
})
},
// customRequest(options: any) {
// console.log('options', options)
// const { onSuccess, onError, file, onProgress } = options
// uploadWork(Number(id), props.inputName, file, onProgress).then((res) => {
// console.log('upload res: ', res)
// if (res.data.errCode === null) {
// onSuccess(res, file)
// message.success({
// content: file.name + ' 上传成功',
// })
// setFileList((prev) => {
// return {
// ...prev,
// [props.inputName]: [{ ...prev[props.inputName][0], url: res.data.data.url, status: 'done' }],
// }
// })
// form.setValueByPath(props.inputName, res.data.data.url)
// }
// })
// },
headers: { Token: localStorage.getItem('approval-system-token') },
fileList: localFileList,
showUploadList: { showDownloadIcon: true },
Expand All @@ -323,25 +311,49 @@ function WorkDetail() {
<Upload
{...localProps}
customRequest={(options) => {
console.log('options', options)
const { onSuccess, onError, file, onProgress } = options
uploadWork(Number(id), props.inputName, file as File, onProgress).then((res) => {
console.log('upload res: ', res)
if (res.data.errCode === null) {
if (onSuccess)
onSuccess(res)
const temp = options.file as File
getLicense(temp.name, props.inputName, id as unknown as number).then(res => {
console.log(res);
const { onSuccess, file } = options
console.log(res.data.data.url);
fetch(res.data.data.url, {
method: "put",
body: temp
}).then(_ => {
onSuccess && onSuccess(res)
message.success({
content: (file as File).name + ' 上传成功',
})
form.setValueByPath(props.inputName, res)
setFileList((prev) => {
return {
...prev,
[props.inputName]: [{ ...prev[props.inputName][0], url: res.data.data.url, status: 'done' }],
}
})
form.setValueByPath(props.inputName, res.data.data.url)
}
})
}).catch(err => {
console.log(err);
})
// console.log('options', options)
// const { onSuccess, onError, file, onProgress } = options
// uploadWork(Number(id), props.inputName, file as File, onProgress).then((res) => {
// console.log('upload res: ', res)
// if (res.data.errCode === null) {
// if (onSuccess)
// onSuccess(res)
// message.success({
// content: (file as File).name + ' 上传成功',
// })
// setFileList((prev) => {
// return {
// ...prev,
// [props.inputName]: [{ ...prev[props.inputName][0], url: res.data.data.url, status: 'done' }],
// }
// })
// form.setValueByPath(props.inputName, res.data.data.url)
// }
// })
}}
onDownload={(file) => {
console.log(file)
Expand Down
12 changes: 3 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"target": "es2015",
"lib": ["dom", "dom.iterable", "esnext"],
"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
Expand All @@ -23,7 +19,5 @@
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
"include": ["src"]
}

0 comments on commit 61f9164

Please sign in to comment.