Files
orion-visor/orion-ops-ui/src/views/host/terminal/index.vue

156 lines
4.1 KiB
Vue
Raw Normal View History

2023-12-05 19:23:03 +08:00
<template>
2024-02-01 16:15:51 +08:00
<div class="host-terminal-layout" v-if="render">
2023-12-05 19:23:03 +08:00
<!-- 头部区域 -->
2024-02-01 16:15:51 +08:00
<header class="host-terminal-layout-header">
<layout-header />
2023-12-05 19:23:03 +08:00
</header>
<!-- 主体区域 -->
2024-02-01 16:15:51 +08:00
<main class="host-terminal-layout-main">
2023-12-05 19:23:03 +08:00
<!-- 左侧操作栏 -->
2024-02-01 16:15:51 +08:00
<div class="host-terminal-layout-left">
<left-sidebar />
2023-12-05 19:23:03 +08:00
</div>
<!-- 内容区域 -->
2024-02-01 16:15:51 +08:00
<main class="host-terminal-layout-content">
2024-01-12 19:42:16 +08:00
<!-- 主机加载中骨架 -->
<loading-skeleton v-if="contentLoading" />
<!-- 终端内容区域 -->
2024-02-01 16:15:51 +08:00
<main-content v-else />
</main>
2023-12-05 19:23:03 +08:00
<!-- 右侧操作栏 -->
2024-02-01 16:15:51 +08:00
<div class="host-terminal-layout-right">
<right-sidebar />
2023-12-05 19:23:03 +08:00
</div>
</main>
</div>
</template>
<script lang="ts">
export default {
name: 'hostTerminal'
};
</script>
<script lang="ts" setup>
2024-01-05 16:13:34 +08:00
import { ref, onBeforeMount, onUnmounted, onMounted } from 'vue';
import { dictKeys, TerminalTabs } from './types/terminal.const';
2023-12-25 19:03:24 +08:00
import { useCacheStore, useDictStore, useTerminalStore } from '@/store';
2024-01-13 15:45:29 +08:00
import useLoading from '@/hooks/loading';
2024-02-24 15:40:57 +08:00
import debug from '@/utils/env';
2024-02-01 16:15:51 +08:00
import LayoutHeader from './components/layout/layout-header.vue';
import LeftSidebar from './components/layout/left-sidebar.vue';
import RightSidebar from './components/layout/right-sidebar.vue';
import MainContent from './components/layout/main-content.vue';
2024-01-12 19:42:16 +08:00
import LoadingSkeleton from './components/layout/loading-skeleton.vue';
2024-02-01 16:15:51 +08:00
import '@/assets/style/host-terminal-layout.less';
2023-12-13 23:59:31 +08:00
import 'xterm/css/xterm.css';
2023-12-05 19:23:03 +08:00
2023-12-08 19:05:00 +08:00
const terminalStore = useTerminalStore();
2023-12-08 16:40:14 +08:00
const dictStore = useDictStore();
2023-12-25 19:03:24 +08:00
const cacheStore = useCacheStore();
2024-01-12 19:42:16 +08:00
const { loading: contentLoading, setLoading: setContentLoading } = useLoading(true);
2023-12-05 19:23:03 +08:00
2024-01-10 19:30:25 +08:00
const originTitle = document.title;
2023-12-08 16:40:14 +08:00
const render = ref(false);
2023-12-08 14:33:24 +08:00
2024-01-05 16:13:34 +08:00
// 关闭视口处理
const handleBeforeUnload = (event: any) => {
event.preventDefault();
event.returnValue = confirm('系统可能不会保存您所做的更改');
};
2023-12-08 16:40:14 +08:00
// 加载用户终端偏好
onBeforeMount(async () => {
2023-12-08 19:05:00 +08:00
await terminalStore.fetchPreference();
2024-01-10 19:30:25 +08:00
// 设置系统主题配色
const dark = terminalStore.preference.theme.dark;
2024-02-01 16:15:51 +08:00
document.body.setAttribute('terminal-theme', dark ? 'dark' : 'light');
2023-12-08 19:05:00 +08:00
render.value = true;
2023-12-08 16:40:14 +08:00
});
// 加载字典值
onBeforeMount(async () => {
await dictStore.loadKeys([...dictKeys]);
2023-12-08 14:33:24 +08:00
});
2024-01-12 19:42:16 +08:00
// 加载主机信息
onMounted(async () => {
try {
await terminalStore.loadHosts();
} catch (e) {
} finally {
setContentLoading(false);
}
});
2024-02-24 15:40:57 +08:00
// 加载处理
2024-01-05 16:13:34 +08:00
onMounted(() => {
2024-01-13 02:49:25 +08:00
// 默认标题
document.title = TerminalTabs.NEW_CONNECTION.title;
2024-01-13 02:49:25 +08:00
// 注册关闭视口事件
if (!debug) {
2024-02-24 15:40:57 +08:00
window.addEventListener('beforeunload', handleBeforeUnload);
}
2024-01-05 16:13:34 +08:00
});
2024-02-24 15:40:57 +08:00
// 卸载处理
2023-12-25 19:03:24 +08:00
onUnmounted(() => {
2024-01-05 16:13:34 +08:00
// 卸载时清除 cache
2024-01-26 00:35:05 +08:00
cacheStore.reset('authorizedHostKeys', 'authorizedHostIdentities', 'commandSnippetGroups');
2024-01-05 16:13:34 +08:00
// 移除关闭视口事件
window.removeEventListener('beforeunload', handleBeforeUnload);
2024-01-10 19:30:25 +08:00
// 去除 body style
2024-02-01 16:15:51 +08:00
document.body.removeAttribute('terminal-theme');
2024-01-10 19:30:25 +08:00
// 重置 title
document.title = originTitle;
2023-12-25 19:03:24 +08:00
});
2023-12-05 19:23:03 +08:00
</script>
<style lang="less" scoped>
2024-02-01 16:15:51 +08:00
.host-terminal-layout {
2023-12-05 19:23:03 +08:00
width: 100%;
height: 100vh;
position: relative;
2023-12-08 19:05:00 +08:00
color: var(--color-content-text-2);
2023-12-05 19:23:03 +08:00
&-header {
width: 100%;
2024-01-11 16:55:37 +08:00
height: var(--header-height);
2023-12-05 19:23:03 +08:00
background: var(--color-bg-header);
2023-12-15 19:21:31 +08:00
position: relative;
2023-12-05 19:23:03 +08:00
}
&-main {
width: 100%;
height: calc(100% - var(--sidebar-width));
position: relative;
display: flex;
justify-content: space-between;
}
&-left, &-right {
width: var(--sidebar-width);
height: 100%;
background: var(--color-bg-sidebar);
2023-12-08 14:33:24 +08:00
overflow: hidden;
2023-12-05 19:23:03 +08:00
}
2024-01-08 19:27:44 +08:00
&-left {
border-right: 1px solid var(--color-bg-content);
}
&-right {
border-left: 1px solid var(--color-bg-content);
}
2023-12-05 19:23:03 +08:00
&-content {
2023-12-13 23:59:31 +08:00
width: calc(100% - var(--sidebar-width) * 2);
2023-12-05 19:23:03 +08:00
height: 100%;
background: var(--color-bg-content);
2023-12-08 14:33:24 +08:00
overflow: auto;
2023-12-05 19:23:03 +08:00
}
}
2023-12-08 14:33:24 +08:00
2023-12-05 19:23:03 +08:00
</style>