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

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 class="header-right">
<span id="userInfo"></span>
<button id="btnLogout" class="logout-btn">退出登录</button>
<button id="btnExit" class="exit-btn">退出</button>
</div>
</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 https from 'https';
import os from 'os';
@ -8,6 +8,11 @@ import { ApiResponse, MenuItem, TagResolutionConfig, EIACDesktopApi, SpecialPUrl
const memoryCache = new Map<string, any>();
export function initialize(): void {
// Close app
ipcMain.handle('app:close', (): void => {
app.exit(0); // 使用 exit 而不是 quit确保立即退出
});
// Set cache
ipcMain.handle('cache:set', (_event, key: string, value: any): void => {
memoryCache.set(key, value);

View File

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

View File

@ -274,14 +274,14 @@ function bindLogoClickEvent(tabGroup: TabGroup, menuItem: MenuItem): void {
}
/**
*
* 退
*/
function bindLogoutEvent(): void {
const logoutBtn: HTMLButtonElement = document.getElementById('btnLogout') as HTMLButtonElement;
if (logoutBtn) {
logoutBtn.addEventListener('click', () => {
function bindExitEvent(): void {
const exitBtn: HTMLButtonElement = document.getElementById('btnExit') as HTMLButtonElement;
if (exitBtn) {
exitBtn.addEventListener('click', async () => {
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];
bindLogoClickEvent(tabGroup, logoMenuItem);
// Bind logout event
bindLogoutEvent();
// Bind exit event
bindExitEvent();
// Bind error modal event
bindErrorModalEvent();

View File

@ -5,43 +5,48 @@ import { contextBridge, ipcRenderer } from 'electron';
import { ApiResponse, MenuItem, TagResolutionConfig } from './EIAC_Desktop_Api';
contextBridge.exposeInMainWorld('electronAPI', {
/**
*
*/
closeApp: (): Promise<void> => ipcRenderer.invoke('app:close'),
/**
*
* @param key
* @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 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
*/
getMenuCacheAsync: () => ipcRenderer.invoke('get-menu-cache') as Promise<ApiResponse<MenuItem[]>>,
getMenuCacheAsync: (): Promise<ApiResponse<MenuItem[]>> => ipcRenderer.invoke('get-menu-cache'),
/**
*
* @param code
* @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的缩放比例
* @param url URL
* @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
* @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));
},
@ -50,14 +55,14 @@ contextBridge.exposeInMainWorld('electronAPI', {
* @param url URL
* @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
* @param url cookie的URL
* @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 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
* @param key
* @param value
*/
setSessionStorage: (key: string, value: string) => {
setSessionStorage: (key: string, value: string): void => {
window.sessionStorage.setItem(key, value);
},
@ -81,7 +86,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
* @param key
* @returns
*/
getSessionStorage: (key: string) => {
getSessionStorage: (key: string): string | null => {
return window.sessionStorage.getItem(key);
},
@ -89,14 +94,14 @@ contextBridge.exposeInMainWorld('electronAPI', {
* sessionStorage中删除指定键的值
* @param key
*/
removeSessionStorage: (key: string) => {
removeSessionStorage: (key: string): void => {
window.sessionStorage.removeItem(key);
},
/**
* sessionStorage
*/
clearSessionStorage: () => {
clearSessionStorage: (): void => {
window.sessionStorage.clear();
}
});

View File

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