From d1fb64a0507e8b2b33ee2291655f603a33c5e0b2 Mon Sep 17 00:00:00 2001 From: lijiahang Date: Mon, 8 Jan 2024 19:27:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=88=E7=AB=AF=E5=A4=B4=E9=83=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orion-ops-ui/src/assets/style/global.less | 10 +- orion-ops-ui/src/hooks/copy.ts | 11 +- orion-ops-ui/src/utils/index.ts | 31 +++- .../components/new-connection/hosts-view.vue | 3 + .../components/xterm/terminal-view.vue | 154 ++++++++++++------ .../handler/terminal-session-manager.ts | 12 +- .../host/terminal/handler/terminal-session.ts | 50 +++++- .../src/views/host/terminal/index.vue | 8 + .../host/terminal/types/terminal.type.ts | 20 ++- 9 files changed, 228 insertions(+), 71 deletions(-) diff --git a/orion-ops-ui/src/assets/style/global.less b/orion-ops-ui/src/assets/style/global.less index 8d058609..1843d421 100644 --- a/orion-ops-ui/src/assets/style/global.less +++ b/orion-ops-ui/src/assets/style/global.less @@ -217,12 +217,20 @@ body { margin-bottom: 16px; } -.copy-left { +.copy-left, .copy-right { color: rgb(var(--arcoblue-6)); cursor: pointer; margin-right: 4px; } +.copy-left { + margin-right: 4px; +} + +.copy-right { + margin-left: 4px; +} + .span-blue { color: rgb(var(--arcoblue-6)); } diff --git a/orion-ops-ui/src/hooks/copy.ts b/orion-ops-ui/src/hooks/copy.ts index f33c9b4a..d3ed2d9d 100644 --- a/orion-ops-ui/src/hooks/copy.ts +++ b/orion-ops-ui/src/hooks/copy.ts @@ -2,7 +2,8 @@ import { useClipboard } from '@vueuse/core'; import { Message } from '@arco-design/web-vue'; export default function useCopy() { - const { isSupported, copy: c, text, copied } = useClipboard(); + const { copy: c } = useClipboard(); + // 复制 const copy = async (value: string | undefined, tips = `${value} 已复制`) => { try { if (!value) { @@ -16,10 +17,12 @@ export default function useCopy() { Message.error('复制失败'); } }; + // 获取剪切板内容 + const readText = () => { + return navigator.clipboard.readText(); + }; return { - isSupported, copy, - text, - copied + readText, }; } diff --git a/orion-ops-ui/src/utils/index.ts b/orion-ops-ui/src/utils/index.ts index b9299639..4657989e 100644 --- a/orion-ops-ui/src/utils/index.ts +++ b/orion-ops-ui/src/utils/index.ts @@ -163,7 +163,7 @@ export const resetObject = (obj: any, ignore: string[] = []) => { export const objectTruthKeyCount = (obj: any, ignore: string[] = []) => { return Object.keys(obj) .filter(s => !ignore.includes(s)) - .reduce(function (acc, curr) { + .reduce(function(acc, curr) { const currVal = obj[curr]; return acc + ~~(currVal !== undefined && currVal !== null && currVal?.length !== 0 && currVal !== ''); }, 0); @@ -192,24 +192,37 @@ export function detectZoom() { return ratio; } -/** - * 获取页面路由 - */ -export function getRoute(url = location.href) { - return url.substring(url.lastIndexOf('#') + 1).split('?')[0]; -} - /** * 获取唯一的 UUID */ export function getUUID() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } +/** + * 调整颜色 + * @param color color + * @param range 正数越浅 负数越深 + */ +export function adjustColor(color: string, range: number) { + let newColor = '#'; + for (let i = 0; i < 3; i++) { + let c = parseInt(color.substring(i * 2 + 1, i * 2 + 3), 16); + c += range; + if (c < 0) { + c = 0; + } else if (c > 255) { + c = 255; + } + newColor += c.toString(16).padStart(2, '0'); + } + return newColor; +} + /** * 清除 xss */ diff --git a/orion-ops-ui/src/views/host/terminal/components/new-connection/hosts-view.vue b/orion-ops-ui/src/views/host/terminal/components/new-connection/hosts-view.vue index 53d0e1ef..e8d00df9 100644 --- a/orion-ops-ui/src/views/host/terminal/components/new-connection/hosts-view.vue +++ b/orion-ops-ui/src/views/host/terminal/components/new-connection/hosts-view.vue @@ -91,6 +91,9 @@ } else if (NewConnectionType.FAVORITE === props.newConnectionType) { // 过滤-个人收藏 list = list.filter(item => item.favorite); + } else if (NewConnectionType.LATEST === props.newConnectionType) { + // 过滤-最近连接 + // todo } // 排序 hostList.value = list?.sort((o1, o2) => { diff --git a/orion-ops-ui/src/views/host/terminal/components/xterm/terminal-view.vue b/orion-ops-ui/src/views/host/terminal/components/xterm/terminal-view.vue index 16cbdb27..343e9b2a 100644 --- a/orion-ops-ui/src/views/host/terminal/components/xterm/terminal-view.vue +++ b/orion-ops-ui/src/views/host/terminal/components/xterm/terminal-view.vue @@ -10,19 +10,17 @@ {{ tab.address }} - +
- - - 粘贴 - + +
@@ -42,61 +40,97 @@