feat: 打开连接.

This commit is contained in:
lijiahangmax
2024-01-05 00:51:42 +08:00
parent c6b86f8346
commit c40a4fdf13
10 changed files with 251 additions and 79 deletions

View File

@@ -1,12 +1,10 @@
import type { TabItem, TerminalDisplaySetting, TerminalPreference, TerminalState, TerminalThemeSchema } from './types';
import type { HostQueryResponse } from '@/api/asset/host';
import type { TerminalDisplaySetting, TerminalPreference, TerminalState, TerminalThemeSchema } from './types';
import { defineStore } from 'pinia';
import { getPreference, updatePreference } from '@/api/user/preference';
import { Message } from '@arco-design/web-vue';
import { useDark } from '@vueuse/core';
import { DEFAULT_SCHEMA } from '@/views/host/terminal/types/terminal.theme';
import { InnerTabs } from '@/views/host/terminal/types/terminal.const';
import { getHostTerminalAccessToken } from '@/api/asset/host-terminal';
import TerminalDispatcher from '@/views/host/terminal/handler/TerminalDispatcher';
// 暗色主题
export const DarkTheme = {
@@ -31,11 +29,7 @@ export default defineStore('terminal', {
displaySetting: {} as TerminalDisplaySetting,
themeSchema: {} as TerminalThemeSchema
},
tabs: {
active: InnerTabs.NEW_CONNECTION.key,
items: [InnerTabs.NEW_CONNECTION, InnerTabs.VIEW_SETTING]
},
access: undefined
dispatcher: new TerminalDispatcher()
}),
actions: {
@@ -116,41 +110,6 @@ export default defineStore('terminal', {
}
},
// 点击 tab
clickTab(key: string) {
this.tabs.active = key;
},
// 删除 tab
deleteTab(key: string) {
const tabIndex = this.tabs.items.findIndex(s => s.key === key);
this.tabs.items.splice(tabIndex, 1);
if (key === this.tabs.active && this.tabs.items.length !== 0) {
// 切换为前一个 tab
this.tabs.active = this.tabs.items[Math.max(tabIndex - 1, 0)].key;
}
},
// 切换 tab
switchTab(tab: TabItem) {
// 不存在则创建tab
if (!this.tabs.items.find(s => s.key === tab.key)) {
this.tabs.items.push(tab);
}
this.tabs.active = tab.key;
},
// 打开终端
async openTerminal(record: HostQueryResponse) {
// 获取 access
if (!this.access) {
const { data } = await getHostTerminalAccessToken();
this.access = data;
}
console.log(this.access);
console.log(record);
}
},
});

View File

@@ -1,11 +1,9 @@
import type { Ref } from 'vue';
import type { HostTerminalAccessResponse } from '@/api/asset/host-terminal';
export interface TerminalState {
isDarkTheme: Ref<boolean>;
preference: TerminalPreference;
tabs: TerminalTabs;
access?: HostTerminalAccessResponse;
dispatcher: ITerminalDispatcher;
}
// 终端配置
@@ -58,17 +56,33 @@ export interface TerminalThemeSchema {
[key: string]: unknown;
}
// 终端 tab
export interface TerminalTabs {
active: string;
items: Array<TabItem>;
}
// tab 元素
export interface TabItem {
// 终端 tab 元素
export interface TerminalTabItem {
key: string;
title: string;
type: string;
[key: string]: unknown;
}
// 终端调度器
export interface ITerminalDispatcher {
// 当前活跃 tab
active: string;
// 所有 tab
items: Array<TerminalTabItem>;
// 点击 tab
clickTab: (key: string) => void;
// 删除 tab
deleteTab: (key: string) => void;
// 打开 tab
openTab: (tab: TerminalTabItem) => void;
// 打开终端
openTerminal: (record: any) => void;
// 注册终端钩子
registerTerminalHook: (tab: TerminalTabItem) => void;
// 重置
reset: () => void;
}