mirror of https://github.com/openspug/spug
U 优化文件分发上传进度展示
parent
4729a48d39
commit
93a5beb43d
|
@ -28,10 +28,10 @@ function TransferIndex() {
|
||||||
const [dir, setDir] = useState('')
|
const [dir, setDir] = useState('')
|
||||||
const [hosts, setHosts] = useState([])
|
const [hosts, setHosts] = useState([])
|
||||||
const [sProps, setSProps] = useState({visible: false})
|
const [sProps, setSProps] = useState({visible: false})
|
||||||
|
const [percent, setPercent] = useState()
|
||||||
const [token, setToken] = useState()
|
const [token, setToken] = useState()
|
||||||
const [histories, setHistories] = useState([])
|
const [histories, setHistories] = useState([])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!loading) {
|
if (!loading) {
|
||||||
http.get('/api/exec/transfer/')
|
http.get('/api/exec/transfer/')
|
||||||
|
@ -39,6 +39,12 @@ function TransferIndex() {
|
||||||
}
|
}
|
||||||
}, [loading])
|
}, [loading])
|
||||||
|
|
||||||
|
function _handleProgress(e) {
|
||||||
|
const data = e.loaded / e.total * 100
|
||||||
|
if (!percent && data === 100) return
|
||||||
|
setPercent(String(data).replace(/(\d+\.\d).*/, '$1'))
|
||||||
|
}
|
||||||
|
|
||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
if (files.length === 0) return message.error('请添加数据源')
|
if (files.length === 0) return message.error('请添加数据源')
|
||||||
|
@ -55,7 +61,7 @@ function TransferIndex() {
|
||||||
}
|
}
|
||||||
formData.append('data', JSON.stringify(data))
|
formData.append('data', JSON.stringify(data))
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
http.post('/api/exec/transfer/', formData)
|
http.post('/api/exec/transfer/', formData, {timeout: 600000, onUploadProgress: _handleProgress})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const tmp = {}
|
const tmp = {}
|
||||||
for (let host of hosts) {
|
for (let host of hosts) {
|
||||||
|
@ -68,7 +74,10 @@ function TransferIndex() {
|
||||||
store.outputs = tmp
|
store.outputs = tmp
|
||||||
setToken(res)
|
setToken(res)
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false))
|
.finally(() => {
|
||||||
|
setLoading(false)
|
||||||
|
setPercent()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAddHostFile() {
|
function handleAddHostFile() {
|
||||||
|
@ -145,8 +154,9 @@ function TransferIndex() {
|
||||||
</Form>
|
</Form>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Button loading={loading} icon={<ThunderboltOutlined/>} type="primary"
|
<Button loading={loading} icon={<ThunderboltOutlined/>} type="primary" onClick={() => handleSubmit()}>
|
||||||
onClick={() => handleSubmit()}>开始执行</Button>
|
{percent ? `上传中 ${percent}%` : '开始执行'}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={style.right}>
|
<div className={style.right}>
|
||||||
|
|
|
@ -123,12 +123,6 @@ class FileManager extends React.Component {
|
||||||
this.fetchFiles(pwd)
|
this.fetchFiles(pwd)
|
||||||
};
|
};
|
||||||
|
|
||||||
handlePathInput = (e) => {
|
|
||||||
const value = e.target.value;
|
|
||||||
const pwd = value.substring(1).split('/')
|
|
||||||
this.setState({pwd})
|
|
||||||
};
|
|
||||||
|
|
||||||
handleInputEnter = () => {
|
handleInputEnter = () => {
|
||||||
if (this.state.inputPath === null) {
|
if (this.state.inputPath === null) {
|
||||||
if (this.state.pwd.length > 0) {
|
if (this.state.pwd.length > 0) {
|
||||||
|
|
Loading…
Reference in New Issue