修改主页面的退出登录按钮为退出按钮,点击退出按钮立即退出应用程序。
This commit is contained in:
parent
dcdacf0694
commit
46285fb5a2
@ -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>
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
16
src/index.ts
16
src/index.ts
@ -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();
|
||||
|
@ -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和url。其中webContentId是请求打开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();
|
||||
}
|
||||
});
|
4
src/types/electron.d.ts
vendored
4
src/types/electron.d.ts
vendored
@ -1,6 +1,10 @@
|
||||
import { ApiResponse, MenuItem, TagResolutionConfig } from '../EIAC_Desktop_Api';
|
||||
|
||||
export interface ElectronAPI {
|
||||
/**
|
||||
* 关闭应用程序
|
||||
*/
|
||||
closeApp: () => Promise<void>;
|
||||
/**
|
||||
* 获取缓存
|
||||
* @param key 键
|
||||
|
Loading…
x
Reference in New Issue
Block a user