mirror of
https://github.com/chaos-zhu/easynode.git
synced 2026-10-07 15:57:53 +08:00
feat: 增加cd菜单&修复重复bus
This commit is contained in:
@@ -17,6 +17,15 @@ EventBus.$on = (event, callback) => {
|
||||
EventBus[event].push(callback)
|
||||
}
|
||||
|
||||
EventBus.$off = (event, callback) => {
|
||||
if (!EventBus[event]) return
|
||||
if (!callback) {
|
||||
delete EventBus[event]
|
||||
} else {
|
||||
EventBus[event] = EventBus[event].filter(cb => cb !== callback)
|
||||
}
|
||||
}
|
||||
|
||||
export const randomStr = (e) =>{
|
||||
e = e || 16
|
||||
let str = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678',
|
||||
|
||||
@@ -541,6 +541,7 @@ import unknowIcon from '@/assets/image/system/unknow.png'
|
||||
import { useContextMenu } from '@/composables/useContextMenu'
|
||||
import TextEditor from '@/components/text-editor/index.vue'
|
||||
import ImagePreview from '@/components/image-preview/index.vue'
|
||||
import { EventBus } from '@/utils'
|
||||
|
||||
const props = defineProps({
|
||||
hostId: {
|
||||
@@ -1586,6 +1587,17 @@ const onRowContextMenu = (row, _column, event) => {
|
||||
}
|
||||
})
|
||||
|
||||
// 发送cd指令到终端
|
||||
if (row.type === 'd') {
|
||||
const cdCommand = `cd ${ currentPath.value }/${ row.name }`.replace(/\/+/g, '/')
|
||||
items.push({
|
||||
label: '发送cd指令到终端',
|
||||
onClick: () => {
|
||||
EventBus.$emit('exec_external_command', cdCommand)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
showMenu(event, items)
|
||||
}
|
||||
|
||||
|
||||
@@ -671,14 +671,14 @@ const inputCommand = (command, isSyncAllSession = false) => {
|
||||
socket.value.emit('input', command)
|
||||
}
|
||||
|
||||
EventBus.$on('exec_external_command', (command) => {
|
||||
const execExternalCommand = (command) => {
|
||||
if (!socket.value || !socket.value.connected || curStatus.value !== CONNECT_SUCCESS) {
|
||||
$message.error('终端连接已断开,无法执行指令')
|
||||
return
|
||||
}
|
||||
socket.value.emit('input', command + '\n')
|
||||
term.value?.focus()
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
createLocalTerminal()
|
||||
@@ -686,9 +686,11 @@ onMounted(async () => {
|
||||
connectIO()
|
||||
await nextTick()
|
||||
onData()
|
||||
EventBus.$on('exec_external_command', execExternalCommand)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
EventBus.$off('exec_external_command', execExternalCommand)
|
||||
socket.value?.close()
|
||||
window.removeEventListener('resize', handleResize)
|
||||
clearInterval(pingTimer.value)
|
||||
|
||||
Reference in New Issue
Block a user