fix issue

pull/410/head
vapao 2021-09-17 16:03:29 +08:00
parent 850cb08914
commit f1e414626a
4 changed files with 27 additions and 18 deletions

View File

@ -155,11 +155,10 @@ class FileManager extends React.Component {
handleDownload = (name) => { handleDownload = (name) => {
const file = `/${this.state.pwd.join('/')}/${name}`; const file = `/${this.state.pwd.join('/')}/${name}`;
const link = document.createElement('a'); const link = document.createElement('a');
link.download = name;
link.href = `/api/file/object/?id=${this.props.id}&file=${file}&x-token=${X_TOKEN}`; link.href = `/api/file/object/?id=${this.props.id}&file=${file}&x-token=${X_TOKEN}`;
document.body.appendChild(link); document.body.appendChild(link);
const evt = document.createEvent("MouseEvents"); link.click();
evt.initEvent("click", false, false);
link.dispatchEvent(evt);
document.body.removeChild(link); document.body.removeChild(link);
message.warning('即将开始下载,请勿重复点击。') message.warning('即将开始下载,请勿重复点击。')
}; };

View File

@ -42,7 +42,7 @@ function WebSSH(props) {
}, []) }, [])
useEffect(() => { useEffect(() => {
if (String(props.id) === props.activeId) { if (props.vId === props.activeId) {
setTimeout(() => term.focus()) setTimeout(() => term.focus())
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps

View File

@ -22,6 +22,7 @@ function WebSSH(props) {
const [treeData, setTreeData] = useState([]); const [treeData, setTreeData] = useState([]);
const [hosts, setHosts] = useState([]); const [hosts, setHosts] = useState([]);
const [activeId, setActiveId] = useState(); const [activeId, setActiveId] = useState();
const [hostId, setHostId] = useState();
useEffect(() => { useEffect(() => {
window.document.title = 'Spug web terminal' window.document.title = 'Spug web terminal'
@ -38,29 +39,38 @@ function WebSSH(props) {
function handleSelect(e) { function handleSelect(e) {
if (e.nativeEvent.detail > 1 && e.node.isLeaf) { if (e.nativeEvent.detail > 1 && e.node.isLeaf) {
if (!lds.find(hosts, x => x.id === e.node.id)) { e.node.vId = String(new Date().getTime())
hosts.push(e.node); hosts.push(e.node);
setHosts(lds.cloneDeep(hosts)) setHosts(lds.cloneDeep(hosts))
} setActiveId(e.node.vId)
setActiveId(String(e.node.id))
} }
} }
function handleRemove(key, action) { function handleRemove(key, action) {
if (action === 'remove') { 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) { if (index !== -1) {
hosts.splice(index, 1); hosts.splice(index, 1);
setHosts(lds.cloneDeep(hosts)); setHosts(lds.cloneDeep(hosts));
if (hosts.length > index) { if (hosts.length > index) {
setActiveId(String(hosts[index].id)) setActiveId(hosts[index].vId)
} else if (hosts.length) { } 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) { function renderIcon(node) {
if (node.isLeaf) { if (node.isLeaf) {
return <CloudServerOutlined/> return <CloudServerOutlined/>
@ -108,11 +118,11 @@ function WebSSH(props) {
type="primary" type="primary"
disabled={!activeId} disabled={!activeId}
style={{marginRight: 5}} style={{marginRight: 5}}
onClick={() => setVisible(true)} onClick={handleOpenFileManager}
icon={<FolderOpenOutlined/>}>文件管理器</AuthButton>}> icon={<FolderOpenOutlined/>}>文件管理器</AuthButton>}>
{hosts.map(item => ( {hosts.map(item => (
<Tabs.TabPane key={item.id} tab={item.title}> <Tabs.TabPane key={item.vId} tab={item.title}>
<Terminal id={item.id} activeId={activeId}/> <Terminal id={item.id} vId={item.vId} activeId={activeId}/>
</Tabs.TabPane> </Tabs.TabPane>
))} ))}
</Tabs> </Tabs>
@ -120,7 +130,7 @@ function WebSSH(props) {
<pre className={styles.fig}>{spug_web_terminal}</pre> <pre className={styles.fig}>{spug_web_terminal}</pre>
)} )}
</div> </div>
<FileManager id={activeId} visible={visible} onClose={() => setVisible(false)}/> <FileManager id={hostId} visible={visible} onClose={() => setVisible(false)}/>
</div> </div>
) : ( ) : (
<div style={{height: '100vh'}}> <div style={{height: '100vh'}}>

View File

@ -5,7 +5,7 @@
.sider { .sider {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
width: 220px; width: 280px;
background-color: #fafafa; background-color: #fafafa;
.logo { .logo {
@ -36,7 +36,7 @@
flex-direction: column; flex-direction: column;
:global(.ant-tabs-nav) { :global(.ant-tabs-nav) {
width: calc(100vw - 220px); width: calc(100vw - 280px);
height: 42px; height: 42px;
margin: 0; margin: 0;
} }