diff --git a/spug_web/src/pages/exec/transfer/index.js b/spug_web/src/pages/exec/transfer/index.js index 06c1b43..b89b9da 100644 --- a/spug_web/src/pages/exec/transfer/index.js +++ b/spug_web/src/pages/exec/transfer/index.js @@ -28,10 +28,10 @@ function TransferIndex() { const [dir, setDir] = useState('') const [hosts, setHosts] = useState([]) const [sProps, setSProps] = useState({visible: false}) + const [percent, setPercent] = useState() const [token, setToken] = useState() const [histories, setHistories] = useState([]) - useEffect(() => { if (!loading) { http.get('/api/exec/transfer/') @@ -39,6 +39,12 @@ function TransferIndex() { } }, [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() { const formData = new FormData(); if (files.length === 0) return message.error('请添加数据源') @@ -55,7 +61,7 @@ function TransferIndex() { } formData.append('data', JSON.stringify(data)) setLoading(true) - http.post('/api/exec/transfer/', formData) + http.post('/api/exec/transfer/', formData, {timeout: 600000, onUploadProgress: _handleProgress}) .then(res => { const tmp = {} for (let host of hosts) { @@ -68,7 +74,10 @@ function TransferIndex() { store.outputs = tmp setToken(res) }) - .finally(() => setLoading(false)) + .finally(() => { + setLoading(false) + setPercent() + }) } function handleAddHostFile() { @@ -145,8 +154,9 @@ function TransferIndex() { - +