🔨 重构主机模块.

This commit is contained in:
lijiahang
2024-07-22 19:36:02 +08:00
parent b7608fccb3
commit 4bd2de4ce2
64 changed files with 1062 additions and 603 deletions

View File

@@ -18,7 +18,7 @@
<host-table class="host-list"
v-model:selected-keys="selectedKeysValue"
:host-list="hostList"
empty-message="当前分组内无授权主机/主机未启用 SSH 配置!" />
empty-message="当前分组内无授权主机!" />
</div>
</template>

View File

@@ -79,6 +79,7 @@
import type { SelectOptionData } from '@arco-design/web-vue';
import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data';
import type { HostQueryResponse } from '@/api/asset/host';
import type { HostType } from '@/api/asset/host';
import { onMounted, ref, watch, computed } from 'vue';
import { dataColor } from '@/utils';
import { dictKeys, NewConnectionType, newConnectionTypeKey } from './types/const';
@@ -92,6 +93,12 @@
import HostTable from './components/host-table.vue';
import HostGroup from './components/host-group.vue';
const props = withDefaults(defineProps<Partial<{
type: HostType;
}>>(), {
type: undefined,
});
const emits = defineEmits(['selected']);
const { toRadioOptions, loadKeys } = useDictStore();
@@ -110,10 +117,10 @@
const emptyMessage = computed(() => {
if (newConnectionType.value === NewConnectionType.LIST) {
// 列表
return '无授权主机/主机未启用 SSH 配置!';
return '无授权主机!';
} else if (newConnectionType.value === NewConnectionType.FAVORITE) {
// 收藏
return '无收藏主机/主机未启用 SSH 配置!';
return '无收藏主机!';
} else if (newConnectionType.value === NewConnectionType.LATEST) {
// 最近连接
return '暂无连接记录!';
@@ -144,7 +151,7 @@
setLoading(true);
try {
// 加载主机列表
const { data } = await getCurrentAuthorizedHost('ssh');
const { data } = await getCurrentAuthorizedHost(props.type);
hosts.value = data;
// 禁用别名
data.hostList.forEach(s => s.alias = undefined as unknown as string);

View File

@@ -2,6 +2,7 @@
<a-select v-model:model-value="value"
:options="optionData"
:loading="loading"
:multiple="multiple"
placeholder="请选择主机"
allow-clear />
</template>
@@ -14,22 +15,30 @@
<script lang="ts" setup>
import type { SelectOptionData } from '@arco-design/web-vue';
import type { HostType } from '@/api/asset/host';
import { computed, onBeforeMount, ref } from 'vue';
import { useCacheStore } from '@/store';
import useLoading from '@/hooks/loading';
const props = defineProps<Partial<{
modelValue: number;
}>>();
const props = withDefaults(defineProps<Partial<{
type: HostType;
status: string | undefined;
modelValue: number | Array<number>;
multiple: boolean;
}>>(), {
type: undefined,
status: undefined,
multiple: false,
});
const emits = defineEmits(['update:modelValue']);
const { loading, setLoading } = useLoading();
const cacheStore = useCacheStore();
const value = computed<number>({
const value = computed({
get() {
return props.modelValue as number;
return props.modelValue;
},
set(e) {
if (e) {
@@ -45,13 +54,14 @@
onBeforeMount(async () => {
setLoading(true);
try {
const hosts = await cacheStore.loadHosts();
optionData.value = hosts.map(s => {
return {
label: `${s.name} - ${s.address}`,
value: s.id,
};
});
const hosts = await cacheStore.loadHosts(props.type);
optionData.value = hosts.filter(s => !props.status || s.status === props.status)
.map(s => {
return {
label: `${s.name} - ${s.address}`,
value: s.id,
};
});
} catch (e) {
} finally {
setLoading(false);

View File

@@ -1,9 +1,6 @@
import type { IDisposable, ITerminalInitOnlyOptions, ITerminalOptions, Terminal } from '@xterm/xterm';
import type { FitAddon } from '@xterm/addon-fit';
import type { SearchAddon } from '@xterm/addon-search';
import type { WebLinksAddon } from '@xterm/addon-web-links';
import type { WebglAddon } from '@xterm/addon-webgl';
import type { Unicode11Addon } from '@xterm/addon-unicode11';
import type { XtermAddons } from '@/types/xterm';
import { defaultFontFamily, defaultTheme } from '@/types/xterm';
import type { ITerminalInitOnlyOptions, ITerminalOptions, Terminal } from '@xterm/xterm';
// 执行类型
export type ExecType = 'BATCH' | 'JOB';
@@ -47,11 +44,7 @@ export const dictKeys = [execStatusKey, execHostStatusKey];
// appender 配置
export const LogAppenderOptions: ITerminalOptions & ITerminalInitOnlyOptions = {
theme: {
foreground: '#FFFFFF',
background: '#1C1C1C',
selectionBackground: '#444444',
},
theme: defaultTheme,
cols: 30,
rows: 8,
rightClickSelectsWord: true,
@@ -63,7 +56,7 @@ export const LogAppenderOptions: ITerminalOptions & ITerminalInitOnlyOptions = {
lineHeight: 1.12,
convertEol: true,
allowProposedApi: true,
fontFamily: 'Courier New, Monaco, courier, monospace',
fontFamily: defaultFontFamily,
};
// dom 引用
@@ -79,16 +72,7 @@ export interface LogAppenderConf {
el: HTMLElement;
openSearch: () => {};
terminal: Terminal;
addons: LogAddons;
}
// appender 插件
export interface LogAddons extends Record<string, IDisposable> {
fit: FitAddon;
webgl: WebglAddon;
search: SearchAddon;
weblink: WebLinksAddon;
unicode: Unicode11Addon;
addons: XtermAddons;
}
// 执行日志 appender 定义

View File

@@ -1,5 +1,6 @@
import type { ExecType, ILogAppender, LogAddons, LogAppenderConf, LogDomRef } from '../const';
import type { ExecType, ILogAppender, LogAppenderConf, LogDomRef } from '../const';
import { LogAppenderOptions } from '../const';
import type { XtermAddons } from '@/types/xterm';
import type { ExecLogTailRequest } from '@/api/exec/exec-log';
import { openExecLogChannel } from '@/api/exec/exec-log';
import { getExecCommandLogTailToken } from '@/api/exec/exec-command-log';
@@ -43,13 +44,13 @@ export default class LogAppender implements ILogAppender {
// 初始化
async init(logDomRefs: Array<LogDomRef>) {
// 初始化 appender
this.initAppender(logDomRefs);
await this.initAppender(logDomRefs);
// 初始化 client
await this.openClient();
}
// 初始化 appender
initAppender(logDomRefs: Array<LogDomRef>) {
async initAppender(logDomRefs: Array<LogDomRef>) {
// 打开 log-view
for (let logDomRef of logDomRefs) {
// 初始化 terminal
@@ -126,7 +127,7 @@ export default class LogAppender implements ILogAppender {
}
// 初始化插件
initAddons(terminal: Terminal): LogAddons {
initAddons(terminal: Terminal): XtermAddons {
const fit = new FitAddon();
const search = new SearchAddon();
const webgl = new WebglAddon();
@@ -144,7 +145,7 @@ export default class LogAppender implements ILogAppender {
webgl,
weblink,
unicode
};
} as XtermAddons;
}
// 初始化 client

View File

@@ -89,8 +89,8 @@
import useEmitter from '@/hooks/emitter';
const props = defineProps<CardProps & {
index: number,
item: CardRecord,
index: number;
item: CardRecord;
}>();
const emits = defineEmits(['emitter']);

View File

@@ -40,15 +40,15 @@ export const builtinParams: Array<TemplateParam> = [
}, {
name: 'hostAddress',
desc: '执行主机地址'
}, {
name: 'hostPort',
desc: '主机端口'
}, {
name: 'hostUsername',
desc: '执行主机用户名'
}, {
name: 'osType',
desc: '执行主机系统版本'
}, {
name: 'port',
desc: 'SSH 端口'
}, {
name: 'charset',
desc: 'SSH 编码集'