支持多开实例隔离并默认打开小店

This commit is contained in:
yml2213
2026-08-09 17:25:18 +08:00
parent 6c881e9182
commit a9ad969b64
16 changed files with 385 additions and 27 deletions
+6 -3
View File
@@ -8,7 +8,7 @@ import { useLogs } from '@/composables/useLogs'
import { useActivity } from '@/composables/useActivity'
import AppShell from '@/components/layout/AppShell.vue'
import ToastContainer from '@/components/ToastContainer.vue'
import { GetTime, GetVersion } from '@wails/go/app/App'
import { GetInstanceName, GetTime, GetVersion } from '@wails/go/app/App'
import { WindowGetSize, WindowSetSize } from '@wails/runtime/runtime'
const { initTheme } = useTheme()
@@ -20,6 +20,7 @@ const { clearResults } = useLogs()
const { loadActivities } = useActivity()
const version = ref('')
const instanceName = ref('默认实例')
const serverTime = ref('--')
// 轮询定时器
@@ -91,7 +92,9 @@ onMounted(async () => {
// 获取版本号
try {
version.value = await GetVersion()
const [appVersion, currentInstanceName] = await Promise.all([GetVersion(), GetInstanceName()])
version.value = appVersion.split(' ')[0] || appVersion
instanceName.value = currentInstanceName || '默认实例'
} catch {}
// 清空后端旧结果
@@ -112,7 +115,7 @@ onUnmounted(() => {
</script>
<template>
<AppShell :version="version" :server-time="serverTime" />
<AppShell :version="version" :instance-name="instanceName" :server-time="serverTime" />
<ToastContainer />
</template>
+2 -1
View File
@@ -4,13 +4,14 @@ import RightConsole from './RightConsole.vue'
defineProps<{
version: string
instanceName: string
serverTime: string
}>()
</script>
<template>
<div class="app-shell">
<LeftSidebar :version="version" />
<LeftSidebar :version="version" :instance-name="instanceName" />
<RightConsole :server-time="serverTime" />
</div>
</template>
+45 -3
View File
@@ -9,6 +9,7 @@ import XiaodianTabs from '@/components/product/XiaodianTabs.vue'
defineProps<{
version: string
instanceName: string
}>()
const { loadProducts, productInfo, filteredProducts, loading } = useProducts()
@@ -28,11 +29,14 @@ const onSwitchActivity = async (e: Event) => {
<aside class="left">
<!-- 品牌区 -->
<div class="brand">
<div>
<div class="brand-content">
<h1>斗鱼抢购</h1>
<div class="brand-sub">实时库存 · 多账号 · 定时触发</div>
</div>
<span class="stat-pill">v{{ version }}</span>
<div class="brand-meta">
<span class="instance-pill">{{ instanceName }}</span>
<span class="stat-pill">v{{ version }}</span>
</div>
</div>
<!-- 活动选择 -->
@@ -98,18 +102,46 @@ const onSwitchActivity = async (e: Event) => {
.brand {
display: flex;
align-items: center;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
padding: 16px 18px;
border-bottom: 1px solid var(--line);
}
.brand-content {
flex: 1;
min-width: 0;
}
.brand h1 {
font-size: 15px;
font-weight: 600;
color: var(--text-strong);
letter-spacing: -.01em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.brand-meta {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 4px;
flex-shrink: 0;
}
.instance-pill {
padding: 3px 6px;
border: 1px solid var(--line-strong);
border-radius: var(--radius-sm);
color: var(--muted);
font-size: 11px;
white-space: nowrap;
max-width: 120px;
overflow: hidden;
text-overflow: ellipsis;
}
.brand-sub {
@@ -117,6 +149,16 @@ const onSwitchActivity = async (e: Event) => {
color: var(--muted);
margin-top: 3px;
letter-spacing: .02em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.brand-meta .stat-pill {
max-width: 120px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.brand + .activity-box {
+15 -5
View File
@@ -1,9 +1,19 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import { GetInstanceName } from '@wails/go/app/App'
import { installInstanceStorage } from './utils/instanceStorage'
const app = createApp(App)
const pinia = createPinia()
const bootstrap = async () => {
let instanceName = '默认实例'
try {
instanceName = await GetInstanceName() || instanceName
} catch {}
app.use(pinia)
app.mount('#app')
installInstanceStorage(instanceName)
const { default: App } = await import('./App.vue')
const app = createApp(App)
app.use(createPinia())
app.mount('#app')
}
void bootstrap()
+26
View File
@@ -0,0 +1,26 @@
let installed = false
// WebView 的 localStorage 会在同一个应用标识下跨窗口共享;在加载界面前
// 为每个后端实例加前缀,避免选择、监控参数和窗口状态互相覆盖。
export const installInstanceStorage = (instanceName: string) => {
if (installed || typeof Storage === 'undefined') return
installed = true
const suffix = encodeURIComponent(instanceName || '默认实例')
const prefix = `douyu-go:${suffix}:`
const storage = Storage.prototype
const getItem = storage.getItem
const setItem = storage.setItem
const removeItem = storage.removeItem
const key = (value: string) => prefix + value
storage.getItem = function (name: string) {
return getItem.call(this, key(name))
}
storage.setItem = function (name: string, value: string) {
return setItem.call(this, key(name), value)
}
storage.removeItem = function (name: string) {
return removeItem.call(this, key(name))
}
}