From f1e414626ac74d79cf6318bbc36be5b4a5c236ea Mon Sep 17 00:00:00 2001 From: vapao Date: Fri, 17 Sep 2021 16:03:29 +0800 Subject: [PATCH] fix issue --- spug_web/src/pages/ssh/FileManager.js | 5 ++-- spug_web/src/pages/ssh/Terminal.js | 2 +- spug_web/src/pages/ssh/index.js | 34 +++++++++++++++--------- spug_web/src/pages/ssh/index.module.less | 4 +-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/spug_web/src/pages/ssh/FileManager.js b/spug_web/src/pages/ssh/FileManager.js index 55bdd55..d5c31c4 100644 --- a/spug_web/src/pages/ssh/FileManager.js +++ b/spug_web/src/pages/ssh/FileManager.js @@ -155,11 +155,10 @@ class FileManager extends React.Component { handleDownload = (name) => { const file = `/${this.state.pwd.join('/')}/${name}`; const link = document.createElement('a'); + link.download = name; link.href = `/api/file/object/?id=${this.props.id}&file=${file}&x-token=${X_TOKEN}`; document.body.appendChild(link); - const evt = document.createEvent("MouseEvents"); - evt.initEvent("click", false, false); - link.dispatchEvent(evt); + link.click(); document.body.removeChild(link); message.warning('即将开始下载,请勿重复点击。') }; diff --git a/spug_web/src/pages/ssh/Terminal.js b/spug_web/src/pages/ssh/Terminal.js index c8f6a8c..edaa3c7 100644 --- a/spug_web/src/pages/ssh/Terminal.js +++ b/spug_web/src/pages/ssh/Terminal.js @@ -42,7 +42,7 @@ function WebSSH(props) { }, []) useEffect(() => { - if (String(props.id) === props.activeId) { + if (props.vId === props.activeId) { setTimeout(() => term.focus()) } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/spug_web/src/pages/ssh/index.js b/spug_web/src/pages/ssh/index.js index 0c3be38..8b7e805 100644 --- a/spug_web/src/pages/ssh/index.js +++ b/spug_web/src/pages/ssh/index.js @@ -22,6 +22,7 @@ function WebSSH(props) { const [treeData, setTreeData] = useState([]); const [hosts, setHosts] = useState([]); const [activeId, setActiveId] = useState(); + const [hostId, setHostId] = useState(); useEffect(() => { window.document.title = 'Spug web terminal' @@ -38,29 +39,38 @@ function WebSSH(props) { function handleSelect(e) { if (e.nativeEvent.detail > 1 && e.node.isLeaf) { - if (!lds.find(hosts, x => x.id === e.node.id)) { - hosts.push(e.node); - setHosts(lds.cloneDeep(hosts)) - } - setActiveId(String(e.node.id)) + e.node.vId = String(new Date().getTime()) + hosts.push(e.node); + setHosts(lds.cloneDeep(hosts)) + setActiveId(e.node.vId) } } function handleRemove(key, action) { if (action === 'remove') { - const index = lds.findIndex(hosts, x => String(x.id) === key); + const index = lds.findIndex(hosts, x => x.vId === key); if (index !== -1) { hosts.splice(index, 1); setHosts(lds.cloneDeep(hosts)); if (hosts.length > index) { - setActiveId(String(hosts[index].id)) + setActiveId(hosts[index].vId) } else if (hosts.length) { - setActiveId(String(hosts[index - 1].id)) + setActiveId(hosts[index - 1].vId) + } else { + setActiveId(undefined) } } } } + function handleOpenFileManager() { + const index = lds.findIndex(hosts, x => x.vId === activeId); + if (index !== -1) { + setHostId(hosts[index].id) + setVisible(true) + } + } + function renderIcon(node) { if (node.isLeaf) { return @@ -108,11 +118,11 @@ function WebSSH(props) { type="primary" disabled={!activeId} style={{marginRight: 5}} - onClick={() => setVisible(true)} + onClick={handleOpenFileManager} icon={}>文件管理器}> {hosts.map(item => ( - - + + ))} @@ -120,7 +130,7 @@ function WebSSH(props) {
{spug_web_terminal}
)} - setVisible(false)}/> + setVisible(false)}/> ) : (
diff --git a/spug_web/src/pages/ssh/index.module.less b/spug_web/src/pages/ssh/index.module.less index 8f0ca67..d7ca9d9 100644 --- a/spug_web/src/pages/ssh/index.module.less +++ b/spug_web/src/pages/ssh/index.module.less @@ -5,7 +5,7 @@ .sider { display: flex; flex-direction: column; - width: 220px; + width: 280px; background-color: #fafafa; .logo { @@ -36,7 +36,7 @@ flex-direction: column; :global(.ant-tabs-nav) { - width: calc(100vw - 220px); + width: calc(100vw - 280px); height: 42px; margin: 0; }