Files
oci-portal-dash/src/stores/console.ts
T
Wang Defa 5464d2dfea
CI / test (push) Successful in 27s
Release / release (push) Successful in 26s
发布 0.1.0:通知渠道、告警规则与多项体验修复
2026-07-10 17:31:19 +08:00

39 lines
1.1 KiB
TypeScript

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<string | undefined>(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 }
})