优化命令片段处理逻辑.

This commit is contained in:
lijiahangmax
2024-08-02 01:52:29 +08:00
parent 18c605354a
commit 8ed42131d0
30 changed files with 327 additions and 415 deletions

View File

@@ -18,6 +18,8 @@ import { getCurrentAuthorizedHostIdentity, getCurrentAuthorizedHostKey } from '@
import { getCommandSnippetGroupList } from '@/api/asset/command-snippet-group';
import { getExecJobList } from '@/api/job/exec-job';
import { getPathBookmarkGroupList } from '@/api/asset/path-bookmark-group';
import { getCommandSnippetList } from '@/api/asset/command-snippet';
import { getPathBookmarkList } from '@/api/asset/path-bookmark';
export default defineStore('cache', {
state: (): CacheState => ({}),
@@ -121,6 +123,16 @@ export default defineStore('cache', {
return await this.load('pathBookmarkGroups', getPathBookmarkGroupList, force);
},
// 获取命令片段列表
async loadCommandSnippets(force = false) {
return await this.load('commandSnippets', getCommandSnippetList, force);
},
// 获取路径书签列表
async loadPathBookmarks(force = false) {
return await this.load('pathBookmarks', getPathBookmarkList, force);
},
// 获取执行计划列表
async loadExecJobs(force = false) {
return await this.load('execJob', getExecJobList, force);

View File

@@ -4,6 +4,7 @@ export type CacheType = 'users' | 'menus' | 'roles'
| 'dictKeys'
| 'authorizedHostKeys' | 'authorizedHostIdentities'
| 'commandSnippetGroups' | 'pathBookmarkGroups'
| 'commandSnippets' | 'pathBookmarks'
| 'execJob'
| string

View File

@@ -8,7 +8,7 @@ import type {
TerminalShortcutSetting,
TerminalState
} from './types';
import type { ITerminalSession, PanelSessionTabType, TerminalPanelTabItem } from '@/views/host/terminal/types/define';
import type { ISshSession, ITerminalSession, PanelSessionTabType, TerminalPanelTabItem } from '@/views/host/terminal/types/define';
import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data';
import { getCurrentAuthorizedHost } from '@/api/asset/asset-authorized-data';
import type { HostQueryResponse } from '@/api/asset/host';
@@ -18,7 +18,7 @@ import { defineStore } from 'pinia';
import { getPreference, updatePreference } from '@/api/user/preference';
import { nextId } from '@/utils';
import { Message } from '@arco-design/web-vue';
import { TerminalTabs } from '@/views/host/terminal/types/const';
import { PanelSessionType, TerminalTabs } from '@/views/host/terminal/types/const';
import TerminalTabManager from '@/views/host/terminal/handler/terminal-tab-manager';
import TerminalSessionManager from '@/views/host/terminal/handler/terminal-session-manager';
import TerminalPanelManager from '@/views/host/terminal/handler/terminal-panel-manager';
@@ -248,6 +248,22 @@ export default defineStore('terminal', {
return this.sessionManager.getSession<T>(sessionTab.sessionId);
},
// 拼接命令到当前会话
appendCommandToCurrentSession(command: string, newLine: boolean = false) {
this.appendCommandToSession(this.getCurrentSession<ISshSession>(PanelSessionType.SSH.type, true), command, newLine);
},
// 拼接命令到会话
appendCommandToSession(session: ISshSession | undefined, command: string, newLine: boolean = false) {
const handler = session?.handler;
if (handler && handler.enabledStatus('checkAppendMissing')) {
if (newLine) {
command = `${command}\r\n`;
}
handler.checkAppendMissing(command);
}
},
},
});