import { defineStore } from 'pinia' import { nextTick, ref } from 'vue' interface SerialTarget { cfgId: number instanceId: string region?: string instanceName?: string } /** 全局串行控制台面板状态:面板挂在 AppLayout,切换路由不销毁会话 */ export const useConsoleStore = defineStore('console', () => { const show = ref(false) const cfgId = ref(0) const instanceId = ref('') const region = ref(undefined) const instanceName = ref('') /** 打开串行终端;已开着且换了实例时先关旧会话再开新 */ async function openSerial(target: SerialTarget) { if (show.value) { if (instanceId.value === target.instanceId && cfgId.value === target.cfgId) return show.value = false await nextTick() } cfgId.value = target.cfgId instanceId.value = target.instanceId region.value = target.region instanceName.value = target.instanceName ?? '' show.value = true } function close() { show.value = false } return { show, cfgId, instanceId, region, instanceName, openSerial, close } })