Procházet zdrojové kódy

增加清除缓存功能

快乐的梦鱼 před 2 týdny
rodič
revize
b7e7390e0e
5 změnil soubory, kde provedl 54 přidání a 6 odebrání
  1. 1 0
      electron/electron-env.d.ts
  2. 31 5
      electron/main.ts
  3. 1 0
      electron/preload.ts
  4. 12 0
      public/apps.json
  5. 9 1
      src/views/Main.vue

+ 1 - 0
electron/electron-env.d.ts

@@ -36,5 +36,6 @@ interface Window {
     toggleChildSide: (isSideOen: boolean) => void
     showConfig: () => void
     showAbout: () => void
+    clearCache: () => Promise<void>
   }
 }

+ 31 - 5
electron/main.ts

@@ -1,4 +1,4 @@
-import { app, BrowserWindow, Event, Input, ipcMain, Menu, WebContentsView } from 'electron'
+import { app, BrowserWindow, dialog, Event, Input, ipcMain, Menu, WebContentsView } from 'electron'
 import { fileURLToPath } from 'node:url'
 import path from 'node:path'
 import fs from 'node:fs'
@@ -31,7 +31,7 @@ let childViewAspectRatio = 0;
 const SIDE_WIDTH = 250
 const EXPAND_VIEW_SIZE = 40
 const LOADING_VIEW_WIDTH = 150
-const LOADING_VIEW_HEIGHT = 100
+const LOADING_VIEW_HEIGHT = 60
 
 function loadWindowPage(window: BrowserWindow, subPath: string) {
   if (VITE_DEV_SERVER_URL) {
@@ -118,7 +118,7 @@ function createWindow() {
     })
     loadingView.setBounds({ 
       x: bounds.x + (bounds.width - LOADING_VIEW_WIDTH) / 2, 
-      y: bounds.y + (bounds.height - LOADING_VIEW_HEIGHT) / 2, 
+      y: bounds.y + 30, 
       width: LOADING_VIEW_WIDTH, 
       height: LOADING_VIEW_HEIGHT 
     })
@@ -193,9 +193,15 @@ function createWindow() {
     } else if (input.key === 'F5' && input.type === 'keyDown') {
       event.preventDefault();
       if (window === mainWindow) {
-        mainWindow?.webContents.reload()
+        if (input.control)
+          mainWindow?.webContents.reloadIgnoringCache()
+        else 
+          mainWindow?.webContents.reload()
       } else if (window === childView) {
-        childView?.webContents.reload()
+        if (input.control)
+          childView?.webContents.reloadIgnoringCache()
+        else 
+          childView?.webContents.reload()
       }
     }
   }
@@ -380,6 +386,26 @@ function createWindow() {
     }
   })
   // 处理显示关于窗口事件
+  ipcMain.handle('clear-cache', async () => {
+    if (mainWindow) {
+      const res = await dialog.showMessageBox(mainWindow, {
+        title: '提示',
+        message: '是否要清除缓存?',
+        type: 'question',
+        buttons: ['取消', '确定'],
+        defaultId: 0,
+        noLink: true,
+      });
+      if (res.response === 0) 
+        return
+      await mainWindow.webContents.session.clearCache()
+      if (childView) {
+        await childView.webContents.session.clearCache()
+        childView.webContents.reloadIgnoringCache();
+      }
+    }
+  })
+
   ipcMain.on('show-about', () => {
     const aboutWindow = new BrowserWindow({
       icon: path.join(process.env.VITE_PUBLIC, 'icon.ico'),

+ 1 - 0
electron/preload.ts

@@ -36,4 +36,5 @@ contextBridge.exposeInMainWorld('electronAPI', {
   toggleChildSide: (isSideOen: boolean) => ipcRenderer.send('toggle-child-side', isSideOen),
   showConfig: () => ipcRenderer.send('show-config'),
   showAbout: () => ipcRenderer.send('show-about'),
+  clearCache: () => ipcRenderer.invoke('clear-cache'),
 })

+ 12 - 0
public/apps.json

@@ -17,6 +17,18 @@
       "title": "闽南文化官网",
       "openType": "iframe",
       "url": "https://minnan.wenlvti.net/"
+    },
+    {
+      "id": 3,
+      "title": "护理驾驶舱",
+      "keepScreenSize": true,
+      "aspectRatio": "16/9",
+      "openType": "iframe",
+      "url": "https://hulicdn.wenlvti.net/test_one/#/",
+      "inputPassword": {
+        "username": "admin",
+        "password": "bh2643"
+      }
     }
   ],
   "文物管家": [

+ 9 - 1
src/views/Main.vue

@@ -1,11 +1,11 @@
 <script setup lang="ts">
-import { ScrollRect } from '@imengyu/vue-scroll-rect'
 import { ref, onMounted } from 'vue'
 import ContextMenu from '@imengyu/vue3-context-menu'
 import { HtmlUtils } from '@imengyu/imengyu-utils'
 import { AppItem } from '../model/App'
 import AppList from '../components/AppList.vue'
 import AppListItem from '../components/AppListItem.vue'
+import { Modal, message } from 'ant-design-vue'
 
 // 状态管理
 const apps = ref<Record<string, AppItem[]>>({})
@@ -90,6 +90,10 @@ function showConfig() {
 function showAbout() {
   window.electronAPI.showAbout()
 }
+// 清除缓存
+async function clearCache() {
+  await window.electronAPI.clearCache()
+}
 // 显示菜单
 function showMenu() {
   if (ContextMenu.isAnyContextMenuOpen())
@@ -100,6 +104,10 @@ function showMenu() {
     direction: 'bl',
     items: [
       {
+        label: '清除缓存',
+        onClick: clearCache,
+      },
+      {
         label: '列表配置',
         onClick: showConfig,
       },