feat: 切换标签异常问题修复

This commit is contained in:
duanshuwen
2025-12-25 23:03:53 +08:00
parent 7ff7232fc6
commit 63b72cbd8e
10 changed files with 84 additions and 16 deletions

View File

@@ -177,7 +177,7 @@ export class TabManager {
const HEADER_HEIGHT = 88
const PADDING = 8
const RIGHT_PANEL_WIDTH = 392 + 80 + 8 // TaskList + SideMenu + Gap
const RIGHT_PANEL_WIDTH = 392 + 80 + 8 + 8 // TaskList + SideMenu + Gap + RightPadding
const x = PADDING
const y = HEADER_HEIGHT + PADDING

View File

@@ -28,6 +28,8 @@ interface SizeOptions {
const SHARED_WINDOW_OPTIONS = {
frame: false,
titleBarStyle: 'hidden',
trafficLightPosition: { x: -100, y: -100 },
show: false,
title: 'NIANXX',
darkTheme: themeManager.isDark,

View File

@@ -136,7 +136,8 @@ export function setupMainWindow() {
mainWindow.webContents.on('did-finish-load', () => {
const url = mainWindow.webContents.getURL()
if (url.includes('/html/index.html') || url.endsWith('index.html')) {
const isDevRoot = MAIN_WINDOW_VITE_DEV_SERVER_URL && (url === MAIN_WINDOW_VITE_DEV_SERVER_URL || url === `${MAIN_WINDOW_VITE_DEV_SERVER_URL}/`)
if (url.includes('/html/index.html') || url.endsWith('index.html') || isDevRoot) {
initTabs()
}
})

View File

@@ -26,22 +26,37 @@ import { menus, type MenuItem } from '@constant/menus'
const currentId = ref(1)
const tabMap = new Map<number, string>()
let cleanupListener: (() => void) | undefined
const cleanupListeners: (() => void)[] = []
const getHtmlPath = (menuUrl: string) => {
const cleanUrl = menuUrl.startsWith('/') ? menuUrl.slice(1) : menuUrl
let filename = ''
switch (cleanUrl) {
case 'home': return 'home.html'
case 'knowledge': return 'knowledge.html'
case 'task': return 'task.html'
case 'setting': return 'setting.html'
default: return 'home.html'
case 'home':
filename = 'home.html'
break
case 'knowledge':
filename = 'knowledge.html'
break
case 'task':
filename = 'task.html'
break
case 'setting':
filename = 'setting.html'
break
default:
filename = 'home.html'
}
if (import.meta.env.DEV) {
return `/html/${filename}`
}
return filename
}
onMounted(async () => {
if (window.api && window.api.tabs) {
cleanupListener = window.api.tabs.on('tab-closed', (payload: any) => {
const cleanupClosed = window.api.tabs.on('tab-closed', (payload: any) => {
const { tabId } = payload
for (const [menuId, id] of tabMap.entries()) {
if (id === tabId) {
@@ -50,6 +65,18 @@ onMounted(async () => {
}
}
})
if (cleanupClosed) cleanupListeners.push(cleanupClosed)
const cleanupCreated = window.api.tabs.on('tab-created', (tab: any) => {
for (const menu of menus) {
const targetHtml = getHtmlPath(menu.url)
if (tab.url.includes(targetHtml)) {
tabMap.set(menu.id, tab.id)
break
}
}
})
if (cleanupCreated) cleanupListeners.push(cleanupCreated)
try {
const tabs = await window.api.tabs.list()
@@ -71,7 +98,7 @@ onMounted(async () => {
})
onUnmounted(() => {
if (cleanupListener) cleanupListener()
cleanupListeners.forEach(fn => fn())
})
const handleClick = async (item: MenuItem) => {

View File

@@ -19,10 +19,12 @@ import 'element-plus/dist/index.css'
// 引入全局组件
import HeaderBar from '@components/HeaderBar/index.vue'
import DragRegion from '@components/DragRegion/index.vue'
import Layout from '@components/Layout/index.vue'
const components: Plugin = (app) => {
app.component('HeaderBar', HeaderBar);
app.component('DragRegion', DragRegion);
app.component('Layout', Layout);
}
// 创建 Vue 应用实例

View File

@@ -0,0 +1,40 @@
import { createApp, type Plugin } from "vue"
import errorHandler from '@utils/errorHandler'
// 引入 Element Plus 组件库
import ElementPlus from 'element-plus'
import locale from 'element-plus/es/locale/lang/zh-cn'
// 引入 i18n 插件
import i18n from '@renderer/i18n'
import Home from './HomeTab.vue'
// 样式文件隔离
import '@renderer/styles/index.css'
import 'element-plus/dist/index.css'
// 引入全局组件
import HeaderBar from '@components/HeaderBar/index.vue'
import DragRegion from '@components/DragRegion/index.vue'
import Layout from '@components/Layout/index.vue'
const components: Plugin = (app) => {
app.component('HeaderBar', HeaderBar);
app.component('DragRegion', DragRegion);
app.component('Layout', Layout);
}
// 创建 Vue 应用实例
const app = createApp(Home);
const pinia = createPinia();
// 使用 Pinia 状态管理
app.use(pinia);
app.use(ElementPlus, { locale })
app.use(components)
app.use(i18n)
app.use(errorHandler)
// 挂载应用到 DOM
app.mount("#app");

View File

@@ -17,12 +17,10 @@ import 'element-plus/dist/index.css'
// 引入全局组件
import HeaderBar from '@components/HeaderBar/index.vue'
import DragRegion from '@components/DragRegion/index.vue'
import Layout from '@components/Layout/index.vue'
const components: Plugin = (app) => {
app.component('HeaderBar', HeaderBar);
app.component('DragRegion', DragRegion);
app.component('Layout', Layout);
}
// 创建 Vue 应用实例

View File

@@ -17,12 +17,10 @@ import 'element-plus/dist/index.css'
// 引入全局组件
import HeaderBar from '@components/HeaderBar/index.vue'
import DragRegion from '@components/DragRegion/index.vue'
import Layout from '@components/Layout/index.vue'
const components: Plugin = (app) => {
app.component('HeaderBar', HeaderBar);
app.component('DragRegion', DragRegion);
app.component('Layout', Layout);
}
// 创建 Vue 应用实例