From 70e867410f5e522c3d3615cba73656f00e25ff4f Mon Sep 17 00:00:00 2001 From: chaos-zhu Date: Thu, 17 Oct 2024 23:06:16 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20=E9=87=8D=E6=9E=84=E7=BB=88?= =?UTF-8?q?=E7=AB=AF=E8=AE=BE=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/store/index.js | 37 ++++++++++----- .../terminal/components/terminal-setting.vue | 47 +++++-------------- .../terminal/components/terminal-tab.vue | 20 ++------ .../views/terminal/components/terminal.vue | 31 +----------- 4 files changed, 43 insertions(+), 92 deletions(-) diff --git a/web/src/store/index.js b/web/src/store/index.js index 8bc0426..536a1f4 100644 --- a/web/src/store/index.js +++ b/web/src/store/index.js @@ -20,7 +20,26 @@ const useStore = defineStore({ token: sessionStorage.getItem('token') || localStorage.getItem('token') || null, title: '', isDark: false, - menuCollapse: localStorage.getItem('menuCollapse') === 'true' + menuCollapse: localStorage.getItem('menuCollapse') === 'true', + defaultBackgroundImages: [ + 'https://wmimg.com/i/1099/2024/08/66c42ff3cd6ab.png', + 'https://wmimg.com/i/1099/2024/08/66c42ff3e3f45.png', + 'https://wmimg.com/i/1099/2024/08/66c42ff411ffb.png', + 'https://wmimg.com/i/1099/2024/08/66c42ff4c5753.png', + 'https://wmimg.com/i/1099/2024/08/66c42ff4e8b4d.jpg', + 'https://wmimg.com/i/1099/2024/08/66c42ff51ee3a.jpg', + 'https://wmimg.com/i/1099/2024/08/66c42ff5db377.png', + 'https://wmimg.com/i/1099/2024/08/66c42ff536a64.png', + 'https://wmimg.com/i/1099/2024/08/66c42ff51d8dd.png', + ], + terminalConfig: { + ...{ + fontSize: 14, + themeName: localStorage.getItem('themeName') || 'Afterglow', + background: localStorage.getItem('terminalBackground') || '' + }, + ...(localStorage.getItem('terminalConfig') ? JSON.parse(localStorage.getItem('terminalConfig')) : {}) + } }), actions: { async setJwtToken(token, isSession = true) { @@ -72,17 +91,11 @@ const useStore = defineStore({ const { data: localScriptList } = await $api.getLocalScriptList() this.$patch({ localScriptList }) }, - // getHostPing() { - // setInterval(() => { - // this.hostList.forEach((item) => { - // const { host } = item - // ping(`http://${ host }:${ 22022 }`) - // .then((res) => { - // item.ping = res - // }) - // }) - // }, 2000) - // }, + setTerminalSetting(setTarget = {}) { + let newConfig = { ...this.terminalConfig, ...setTarget } + localStorage.setItem('terminalConfig', JSON.stringify(newConfig)) + this.$patch({ terminalConfig: newConfig }) + }, async wsClientsStatus() { // if (this.HostStatusSocket) this.HostStatusSocket.close() let socketInstance = io(this.serviceURI, { diff --git a/web/src/views/terminal/components/terminal-setting.vue b/web/src/views/terminal/components/terminal-setting.vue index 88644f5..91e8b62 100644 --- a/web/src/views/terminal/components/terminal-setting.vue +++ b/web/src/views/terminal/components/terminal-setting.vue @@ -35,7 +35,7 @@
  • diff --git a/web/src/views/terminal/components/terminal-tab.vue b/web/src/views/terminal/components/terminal-tab.vue index cd2915a..26dc24b 100644 --- a/web/src/views/terminal/components/terminal-tab.vue +++ b/web/src/views/terminal/components/terminal-tab.vue @@ -21,6 +21,7 @@ import { SearchAddon } from '@xterm/addon-search' // import { SearchBarAddon } from 'xterm-addon-search-bar' import { WebLinksAddon } from '@xterm/addon-web-links' import socketIo from 'socket.io-client' +import themeList from 'xterm-theme' import { terminalStatus } from '@/utils/enum' const { CONNECTING, RECONNECTING, CONNECT_SUCCESS, CONNECT_FAIL } = terminalStatus @@ -32,19 +33,6 @@ const props = defineProps({ hostObj: { required: true, type: Object - }, - fontSize: { - required: false, - default: 16, - type: Number - }, - theme: { - required: true, - type: Object - }, - background: { - required: true, - type: [String, null,] } }) @@ -66,9 +54,9 @@ const terminal = ref(null) const terminalRef = ref(null) const token = computed(() => $store.token) -const theme = computed(() => props.theme) -const fontSize = computed(() => props.fontSize) -const background = computed(() => props.background) +const theme = computed(() => themeList[$store.terminalConfig.theme]) +const fontSize = computed(() => $store.terminalConfig.fontSize) +const background = computed(() => $store.terminalConfig.background) const hostObj = computed(() => props.hostObj) const hostId = computed(() => hostObj.value.id) const host = computed(() => hostObj.value.host) diff --git a/web/src/views/terminal/components/terminal.vue b/web/src/views/terminal/components/terminal.vue index ba416cb..3613b94 100644 --- a/web/src/views/terminal/components/terminal.vue +++ b/web/src/views/terminal/components/terminal.vue @@ -134,9 +134,6 @@ - + @@ -177,7 +168,6 @@ import Sftp from './sftp.vue' import InputCommand from '@/components/input-command/index.vue' import HostForm from '../../server/components/host-form.vue' import TerminalSetting from './terminal-setting.vue' -import themeList from 'xterm-theme' import { terminalStatusList } from '@/utils/enum' const { proxy: { $nextTick, $store, $message } } = getCurrentInstance() @@ -204,31 +194,12 @@ const isSyncAllSession = ref(false) const hostFormVisible = ref(false) const updateHostData = ref(null) const showSetting = ref(false) -const themeName = ref(localStorage.getItem('themeName') || 'Afterglow') -let localTerminalBackground = localStorage.getItem('terminalBackground') -const terminalBackground = ref(localTerminalBackground || '') -let localTerminalFontSize = localStorage.getItem('terminalFontSize') -const terminalFontSize = ref(Number(localTerminalFontSize) || 16) const terminalTabs = computed(() => props.terminalTabs) const terminalTabsLen = computed(() => props.terminalTabs.length) const hostList = computed(() => $store.hostList) const curHost = computed(() => hostList.value.find(item => item.host === terminalTabs.value[activeTabIndex.value]?.host)) const scriptList = computed(() => $store.scriptList) -const themeObj = computed(() => themeList[themeName.value]) - -watch(themeName, (newVal) => { - console.log('update theme:', newVal) - localStorage.setItem('themeName', newVal) -}) -watch(terminalBackground, (newVal) => { - console.log('update terminalBackground:', newVal) - localStorage.setItem('terminalBackground', newVal) -}) -watch(terminalFontSize, (newVal) => { - console.log('update terminalFontSize:', newVal) - localStorage.setItem('terminalFontSize', newVal) -}) onMounted(() => { handleResizeTerminalSftp()