浏览代码

fix: update Vite configuration for Electron compatibility and enhance component type definitions

- Set base path in Vite config for Electron to use relative paths when loading from file://.
- Added missing Element Plus components to TypeScript definitions for better type support.
- Changed router history mode to hash for improved compatibility with Electron packaging.
Ethanfly 23 小时之前
父节点
当前提交
553213f5bb
共有 3 个文件被更改,包括 13 次插入2 次删除
  1. 8 0
      client/src/components.d.ts
  2. 3 2
      client/src/router/index.ts
  3. 2 0
      client/vite.config.ts

+ 8 - 0
client/src/components.d.ts

@@ -15,10 +15,15 @@ declare module 'vue' {
     ElBadge: typeof import('element-plus/es')['ElBadge']
     ElButton: typeof import('element-plus/es')['ElButton']
     ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup']
+    ElCascader: typeof import('element-plus/es')['ElCascader']
     ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
+    ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup']
+    ElCol: typeof import('element-plus/es')['ElCol']
     ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
     ElContainer: typeof import('element-plus/es')['ElContainer']
     ElDatePicker: typeof import('element-plus/es')['ElDatePicker']
+    ElDescriptions: typeof import('element-plus/es')['ElDescriptions']
+    ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem']
     ElDialog: typeof import('element-plus/es')['ElDialog']
     ElDivider: typeof import('element-plus/es')['ElDivider']
     ElDrawer: typeof import('element-plus/es')['ElDrawer']
@@ -38,6 +43,7 @@ declare module 'vue' {
     ElProgress: typeof import('element-plus/es')['ElProgress']
     ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
     ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
+    ElRow: typeof import('element-plus/es')['ElRow']
     ElSelect: typeof import('element-plus/es')['ElSelect']
     ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
     ElSwitch: typeof import('element-plus/es')['ElSwitch']
@@ -46,6 +52,8 @@ declare module 'vue' {
     ElTabPane: typeof import('element-plus/es')['ElTabPane']
     ElTabs: typeof import('element-plus/es')['ElTabs']
     ElTag: typeof import('element-plus/es')['ElTag']
+    ElText: typeof import('element-plus/es')['ElText']
+    ElUpload: typeof import('element-plus/es')['ElUpload']
     Icons: typeof import('./components/icons/index.vue')['default']
     RouterLink: typeof import('vue-router')['RouterLink']
     RouterView: typeof import('vue-router')['RouterView']

+ 3 - 2
client/src/router/index.ts

@@ -1,4 +1,4 @@
-import { createRouter, createWebHistory } from 'vue-router';
+import { createRouter, createWebHashHistory } from 'vue-router';
 import type { RouteRecordRaw } from 'vue-router';
 import { useAuthStore } from '@/stores/auth';
 import { useServerStore } from '@/stores/server';
@@ -103,8 +103,9 @@ const routes: RouteRecordRaw[] = [
   },
 ];
 
+// 使用 hash 模式,兼容 Electron 打包后从 file:// 加载
 const router = createRouter({
-  history: createWebHistory(),
+  history: createWebHashHistory(),
   routes,
 });
 

+ 2 - 0
client/vite.config.ts

@@ -12,6 +12,8 @@ export default defineConfig(({ command }) => {
   const isBuild = command === 'build';
 
   return {
+    // Electron 打包后从 file:// 加载,需使用相对路径
+    base: isBuild ? './' : '/',
     resolve: {
       alias: {
         '@': resolve(__dirname, 'src'),