feat: 切换标签异常问题修复
This commit is contained in:
@@ -11,6 +11,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module" src="../src/renderer/views/home/index.ts"></script>
|
<script type="module" src="../src/renderer/views/home/tab.ts"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -11,6 +11,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module" src="../src/renderer/views/home/index.ts"></script>
|
<script type="module" src="../src/renderer/main.ts"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ export class TabManager {
|
|||||||
|
|
||||||
const HEADER_HEIGHT = 88
|
const HEADER_HEIGHT = 88
|
||||||
const PADDING = 8
|
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 x = PADDING
|
||||||
const y = HEADER_HEIGHT + PADDING
|
const y = HEADER_HEIGHT + PADDING
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ interface SizeOptions {
|
|||||||
|
|
||||||
const SHARED_WINDOW_OPTIONS = {
|
const SHARED_WINDOW_OPTIONS = {
|
||||||
frame: false,
|
frame: false,
|
||||||
|
titleBarStyle: 'hidden',
|
||||||
|
trafficLightPosition: { x: -100, y: -100 },
|
||||||
show: false,
|
show: false,
|
||||||
title: 'NIANXX',
|
title: 'NIANXX',
|
||||||
darkTheme: themeManager.isDark,
|
darkTheme: themeManager.isDark,
|
||||||
|
|||||||
@@ -136,7 +136,8 @@ export function setupMainWindow() {
|
|||||||
|
|
||||||
mainWindow.webContents.on('did-finish-load', () => {
|
mainWindow.webContents.on('did-finish-load', () => {
|
||||||
const url = mainWindow.webContents.getURL()
|
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()
|
initTabs()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -26,22 +26,37 @@ import { menus, type MenuItem } from '@constant/menus'
|
|||||||
|
|
||||||
const currentId = ref(1)
|
const currentId = ref(1)
|
||||||
const tabMap = new Map<number, string>()
|
const tabMap = new Map<number, string>()
|
||||||
let cleanupListener: (() => void) | undefined
|
const cleanupListeners: (() => void)[] = []
|
||||||
|
|
||||||
const getHtmlPath = (menuUrl: string) => {
|
const getHtmlPath = (menuUrl: string) => {
|
||||||
const cleanUrl = menuUrl.startsWith('/') ? menuUrl.slice(1) : menuUrl
|
const cleanUrl = menuUrl.startsWith('/') ? menuUrl.slice(1) : menuUrl
|
||||||
|
let filename = ''
|
||||||
switch (cleanUrl) {
|
switch (cleanUrl) {
|
||||||
case 'home': return 'home.html'
|
case 'home':
|
||||||
case 'knowledge': return 'knowledge.html'
|
filename = 'home.html'
|
||||||
case 'task': return 'task.html'
|
break
|
||||||
case 'setting': return 'setting.html'
|
case 'knowledge':
|
||||||
default: return 'home.html'
|
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 () => {
|
onMounted(async () => {
|
||||||
if (window.api && window.api.tabs) {
|
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
|
const { tabId } = payload
|
||||||
for (const [menuId, id] of tabMap.entries()) {
|
for (const [menuId, id] of tabMap.entries()) {
|
||||||
if (id === tabId) {
|
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 {
|
try {
|
||||||
const tabs = await window.api.tabs.list()
|
const tabs = await window.api.tabs.list()
|
||||||
@@ -71,7 +98,7 @@ onMounted(async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (cleanupListener) cleanupListener()
|
cleanupListeners.forEach(fn => fn())
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleClick = async (item: MenuItem) => {
|
const handleClick = async (item: MenuItem) => {
|
||||||
|
|||||||
@@ -19,10 +19,12 @@ import 'element-plus/dist/index.css'
|
|||||||
// 引入全局组件
|
// 引入全局组件
|
||||||
import HeaderBar from '@components/HeaderBar/index.vue'
|
import HeaderBar from '@components/HeaderBar/index.vue'
|
||||||
import DragRegion from '@components/DragRegion/index.vue'
|
import DragRegion from '@components/DragRegion/index.vue'
|
||||||
|
import Layout from '@components/Layout/index.vue'
|
||||||
|
|
||||||
const components: Plugin = (app) => {
|
const components: Plugin = (app) => {
|
||||||
app.component('HeaderBar', HeaderBar);
|
app.component('HeaderBar', HeaderBar);
|
||||||
app.component('DragRegion', DragRegion);
|
app.component('DragRegion', DragRegion);
|
||||||
|
app.component('Layout', Layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建 Vue 应用实例
|
// 创建 Vue 应用实例
|
||||||
|
|||||||
40
src/renderer/views/home/tab.ts
Normal file
40
src/renderer/views/home/tab.ts
Normal 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");
|
||||||
@@ -17,12 +17,10 @@ import 'element-plus/dist/index.css'
|
|||||||
// 引入全局组件
|
// 引入全局组件
|
||||||
import HeaderBar from '@components/HeaderBar/index.vue'
|
import HeaderBar from '@components/HeaderBar/index.vue'
|
||||||
import DragRegion from '@components/DragRegion/index.vue'
|
import DragRegion from '@components/DragRegion/index.vue'
|
||||||
import Layout from '@components/Layout/index.vue'
|
|
||||||
|
|
||||||
const components: Plugin = (app) => {
|
const components: Plugin = (app) => {
|
||||||
app.component('HeaderBar', HeaderBar);
|
app.component('HeaderBar', HeaderBar);
|
||||||
app.component('DragRegion', DragRegion);
|
app.component('DragRegion', DragRegion);
|
||||||
app.component('Layout', Layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建 Vue 应用实例
|
// 创建 Vue 应用实例
|
||||||
|
|||||||
@@ -17,12 +17,10 @@ import 'element-plus/dist/index.css'
|
|||||||
// 引入全局组件
|
// 引入全局组件
|
||||||
import HeaderBar from '@components/HeaderBar/index.vue'
|
import HeaderBar from '@components/HeaderBar/index.vue'
|
||||||
import DragRegion from '@components/DragRegion/index.vue'
|
import DragRegion from '@components/DragRegion/index.vue'
|
||||||
import Layout from '@components/Layout/index.vue'
|
|
||||||
|
|
||||||
const components: Plugin = (app) => {
|
const components: Plugin = (app) => {
|
||||||
app.component('HeaderBar', HeaderBar);
|
app.component('HeaderBar', HeaderBar);
|
||||||
app.component('DragRegion', DragRegion);
|
app.component('DragRegion', DragRegion);
|
||||||
app.component('Layout', Layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建 Vue 应用实例
|
// 创建 Vue 应用实例
|
||||||
|
|||||||
Reference in New Issue
Block a user