mirror of https://github.com/openspug/spug
fix issue
parent
850cb08914
commit
f1e414626a
|
@ -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('即将开始下载,请勿重复点击。')
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <CloudServerOutlined/>
|
||||
|
@ -108,11 +118,11 @@ function WebSSH(props) {
|
|||
type="primary"
|
||||
disabled={!activeId}
|
||||
style={{marginRight: 5}}
|
||||
onClick={() => setVisible(true)}
|
||||
onClick={handleOpenFileManager}
|
||||
icon={<FolderOpenOutlined/>}>文件管理器</AuthButton>}>
|
||||
{hosts.map(item => (
|
||||
<Tabs.TabPane key={item.id} tab={item.title}>
|
||||
<Terminal id={item.id} activeId={activeId}/>
|
||||
<Tabs.TabPane key={item.vId} tab={item.title}>
|
||||
<Terminal id={item.id} vId={item.vId} activeId={activeId}/>
|
||||
</Tabs.TabPane>
|
||||
))}
|
||||
</Tabs>
|
||||
|
@ -120,7 +130,7 @@ function WebSSH(props) {
|
|||
<pre className={styles.fig}>{spug_web_terminal}</pre>
|
||||
)}
|
||||
</div>
|
||||
<FileManager id={activeId} visible={visible} onClose={() => setVisible(false)}/>
|
||||
<FileManager id={hostId} visible={visible} onClose={() => setVisible(false)}/>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{height: '100vh'}}>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue