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