修改主页面的退出登录按钮为退出按钮,点击退出按钮立即退出应用程序。

This commit is contained in:
Allen 2025-05-18 23:00:51 +08:00
parent dcdacf0694
commit 46285fb5a2
6 changed files with 39 additions and 25 deletions

View File

@ -19,7 +19,7 @@
</div> </div>
<div class="header-right"> <div class="header-right">
<span id="userInfo"></span> <span id="userInfo"></span>
<button id="btnLogout" class="logout-btn">退出登录</button> <button id="btnExit" class="exit-btn">退出</button>
</div> </div>
</header> </header>

View File

@ -1,4 +1,4 @@
import { BrowserWindow, ipcMain, screen, session } from "electron"; import { BrowserWindow, ipcMain, screen, session, app } from "electron";
import http from 'http'; import http from 'http';
import https from 'https'; import https from 'https';
import os from 'os'; import os from 'os';
@ -8,6 +8,11 @@ import { ApiResponse, MenuItem, TagResolutionConfig, EIACDesktopApi, SpecialPUrl
const memoryCache = new Map<string, any>(); const memoryCache = new Map<string, any>();
export function initialize(): void { export function initialize(): void {
// Close app
ipcMain.handle('app:close', (): void => {
app.exit(0); // 使用 exit 而不是 quit确保立即退出
});
// Set cache // Set cache
ipcMain.handle('cache:set', (_event, key: string, value: any): void => { ipcMain.handle('cache:set', (_event, key: string, value: any): void => {
memoryCache.set(key, value); memoryCache.set(key, value);

View File

@ -44,7 +44,7 @@ body {
gap: 20px; gap: 20px;
} }
.logout-btn { .exit-btn {
padding: 8px 16px; padding: 8px 16px;
background-color: #f44336; background-color: #f44336;
color: white; color: white;
@ -53,7 +53,7 @@ body {
cursor: pointer; cursor: pointer;
} }
.logout-btn:hover { .exit-btn:hover {
background-color: #d32f2f; background-color: #d32f2f;
} }

View File

@ -274,14 +274,14 @@ function bindLogoClickEvent(tabGroup: TabGroup, menuItem: MenuItem): void {
} }
/** /**
* * 退
*/ */
function bindLogoutEvent(): void { function bindExitEvent(): void {
const logoutBtn: HTMLButtonElement = document.getElementById('btnLogout') as HTMLButtonElement; const exitBtn: HTMLButtonElement = document.getElementById('btnExit') as HTMLButtonElement;
if (logoutBtn) { if (exitBtn) {
logoutBtn.addEventListener('click', () => { exitBtn.addEventListener('click', async () => {
window.electronAPI.removeSessionStorage('cookies'); window.electronAPI.removeSessionStorage('cookies');
window.location.href = 'login.html'; await window.electronAPI.closeApp();
}); });
} }
} }
@ -412,8 +412,8 @@ async function initialize(): Promise<void> {
const logoMenuItem: MenuItem = menuList[menuList.length - 1]; const logoMenuItem: MenuItem = menuList[menuList.length - 1];
bindLogoClickEvent(tabGroup, logoMenuItem); bindLogoClickEvent(tabGroup, logoMenuItem);
// Bind logout event // Bind exit event
bindLogoutEvent(); bindExitEvent();
// Bind error modal event // Bind error modal event
bindErrorModalEvent(); bindErrorModalEvent();

View File

@ -5,43 +5,48 @@ import { contextBridge, ipcRenderer } from 'electron';
import { ApiResponse, MenuItem, TagResolutionConfig } from './EIAC_Desktop_Api'; import { ApiResponse, MenuItem, TagResolutionConfig } from './EIAC_Desktop_Api';
contextBridge.exposeInMainWorld('electronAPI', { contextBridge.exposeInMainWorld('electronAPI', {
/**
*
*/
closeApp: (): Promise<void> => ipcRenderer.invoke('app:close'),
/** /**
* *
* @param key * @param key
* @returns * @returns
*/ */
getCacheAsync: (key: string) => ipcRenderer.invoke('cache:get', key) as Promise<any>, getCacheAsync: (key: string): Promise<any> => ipcRenderer.invoke('cache:get', key),
/** /**
* *
* @param key * @param key
* @param value * @param value
*/ */
setCacheAsync: (key: string, value: any) => ipcRenderer.invoke('cache:set', key, value) as Promise<void>, setCacheAsync: (key: string, value: any): Promise<void> => ipcRenderer.invoke('cache:set', key, value),
/** /**
* *
* @returns * @returns
*/ */
getMenuCacheAsync: () => ipcRenderer.invoke('get-menu-cache') as Promise<ApiResponse<MenuItem[]>>, getMenuCacheAsync: (): Promise<ApiResponse<MenuItem[]>> => ipcRenderer.invoke('get-menu-cache'),
/** /**
* *
* @param code * @param code
* @returns * @returns
*/ */
getHelperDescripAsync: (code: string) => ipcRenderer.invoke('get-helper-descrip', code) as Promise<string | null>, getHelperDescripAsync: (code: string): Promise<string | null> => ipcRenderer.invoke('get-helper-descrip', code),
/** /**
* URL的缩放比例 * URL的缩放比例
* @param url URL * @param url URL
* @returns * @returns
*/ */
getZoomFactorByUrl: (url: string) => ipcRenderer.invoke('get-zoom-factor-by-url', url) as Promise<number>, getZoomFactorByUrl: (url: string): Promise<number> => ipcRenderer.invoke('get-zoom-factor-by-url', url),
/** /**
* URL * URL
* @param callback webContentId和urlwebContentId是请求打开URL的webview的id * @param callback webContentId和urlwebContentId是请求打开URL的webview的id
*/ */
onOpenTab: (callback: (webContentId: number, url: string) => void) => { onOpenTab: (callback: (webContentId: number, url: string) => void): void => {
ipcRenderer.on('webview-new-window', (_event, webContentId, url) => callback(webContentId, url)); ipcRenderer.on('webview-new-window', (_event, webContentId, url) => callback(webContentId, url));
}, },
@ -50,14 +55,14 @@ contextBridge.exposeInMainWorld('electronAPI', {
* @param url URL * @param url URL
* @returns * @returns
*/ */
checkUrlAvailable: (url: string) => ipcRenderer.invoke('check-url-available', url) as Promise<boolean>, checkUrlAvailable: (url: string): Promise<boolean> => ipcRenderer.invoke('check-url-available', url),
/** /**
* webview的cookie * webview的cookie
* @param url cookie的URL * @param url cookie的URL
* @param cookie cookie字符串 * @param cookie cookie字符串
*/ */
setWebviewCookie: (url: string, cookie: string) => ipcRenderer.invoke('set-webview-cookie', url, cookie) as Promise<boolean>, setWebviewCookie: (url: string, cookie: string): Promise<boolean> => ipcRenderer.invoke('set-webview-cookie', url, cookie),
/** /**
* *
@ -65,14 +70,14 @@ contextBridge.exposeInMainWorld('electronAPI', {
* @param message * @param message
* @param status * @param status
*/ */
faultReporting: (url: string, message: string, status: number) => ipcRenderer.invoke('fault-reporting', url, message, status) as Promise<{ ok: boolean; status: number; message?: string }>, faultReporting: (url: string, message: string, status: number): Promise<{ ok: boolean; status: number; message?: string }> => ipcRenderer.invoke('fault-reporting', url, message, status),
/** /**
* sessionStorage * sessionStorage
* @param key * @param key
* @param value * @param value
*/ */
setSessionStorage: (key: string, value: string) => { setSessionStorage: (key: string, value: string): void => {
window.sessionStorage.setItem(key, value); window.sessionStorage.setItem(key, value);
}, },
@ -81,7 +86,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
* @param key * @param key
* @returns * @returns
*/ */
getSessionStorage: (key: string) => { getSessionStorage: (key: string): string | null => {
return window.sessionStorage.getItem(key); return window.sessionStorage.getItem(key);
}, },
@ -89,14 +94,14 @@ contextBridge.exposeInMainWorld('electronAPI', {
* sessionStorage中删除指定键的值 * sessionStorage中删除指定键的值
* @param key * @param key
*/ */
removeSessionStorage: (key: string) => { removeSessionStorage: (key: string): void => {
window.sessionStorage.removeItem(key); window.sessionStorage.removeItem(key);
}, },
/** /**
* sessionStorage * sessionStorage
*/ */
clearSessionStorage: () => { clearSessionStorage: (): void => {
window.sessionStorage.clear(); window.sessionStorage.clear();
} }
}); });

View File

@ -1,6 +1,10 @@
import { ApiResponse, MenuItem, TagResolutionConfig } from '../EIAC_Desktop_Api'; import { ApiResponse, MenuItem, TagResolutionConfig } from '../EIAC_Desktop_Api';
export interface ElectronAPI { export interface ElectronAPI {
/**
*
*/
closeApp: () => Promise<void>;
/** /**
* *
* @param key * @param key