增加/api/Menu/GetConfig?configName=HelperDescrip接口,根据HTTP状态码匹配帮助描述文本
This commit is contained in:
parent
8d89be590b
commit
89ee08789d
@ -5,275 +5,307 @@ const EIAC_DESKTOP_API_HOST = process.env.EIAC_DESKTOP_API_HOST || 'http://1.12.
|
|||||||
* EIAC 桌面 API
|
* EIAC 桌面 API
|
||||||
*/
|
*/
|
||||||
export class EIAC_Desktop_Api {
|
export class EIAC_Desktop_Api {
|
||||||
private host: string;
|
private host: string;
|
||||||
/**
|
/**
|
||||||
* 构造函数,传入API Host
|
* 构造函数,传入API Host
|
||||||
*/
|
*/
|
||||||
constructor(host = EIAC_DESKTOP_API_HOST) {
|
constructor(host = EIAC_DESKTOP_API_HOST) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证接口
|
||||||
|
*/
|
||||||
|
public Auth = {
|
||||||
/**
|
/**
|
||||||
* 认证接口
|
* 登录 /api/Auth/Login
|
||||||
|
* @param request 登录请求
|
||||||
|
* @param init 请求初始化,可选。
|
||||||
|
* @returns 登录结果
|
||||||
*/
|
*/
|
||||||
public Auth = {
|
LoginAsync: async (request: LoginRequest, init?: RequestInit): Promise<ApiResponse<LoginResponse>> => {
|
||||||
/**
|
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Auth/Login`, {
|
||||||
* 登录 /api/Auth/Login
|
method: 'POST',
|
||||||
* @param request 登录请求
|
headers: {
|
||||||
* @param init 请求初始化,可选。
|
'Content-Type': 'application/json; charset=utf-8'
|
||||||
* @returns 登录结果
|
|
||||||
*/
|
|
||||||
LoginAsync: async (request: LoginRequest, init?: RequestInit) => {
|
|
||||||
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Auth/Login`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json; charset=utf-8'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(request),
|
|
||||||
...init
|
|
||||||
});
|
|
||||||
|
|
||||||
return await response.json() as ApiResponse<LoginResponse>;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 菜单接口
|
|
||||||
*/
|
|
||||||
public Menu = {
|
|
||||||
/**
|
|
||||||
* 获取菜单 /api/Menu/GetMenu
|
|
||||||
* @param init 请求初始化,可选。
|
|
||||||
* @returns 菜单列表
|
|
||||||
*/
|
|
||||||
GetMenuAsync: async (init?: RequestInit) => {
|
|
||||||
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Menu/GetMenu`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json; charset=utf-8'
|
|
||||||
},
|
|
||||||
...init
|
|
||||||
});
|
|
||||||
return await response.json() as ApiResponse<MenuItem[]>;
|
|
||||||
},
|
},
|
||||||
/**
|
body: JSON.stringify(request),
|
||||||
* 获取配置 /api/Menu/GetConfig
|
...init
|
||||||
* @param configName 配置名称,可选。
|
});
|
||||||
* @param init 请求初始化,可选。
|
|
||||||
* @returns 配置列表
|
|
||||||
*/
|
|
||||||
GetConfigAsync: async (configName = 'TagResolution', init?: RequestInit) => {
|
|
||||||
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Menu/GetConfig?configName=${configName}`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json; charset=utf-8'
|
|
||||||
},
|
|
||||||
...init
|
|
||||||
});
|
|
||||||
|
|
||||||
return await response.json() as ApiResponse<TagResolutionConfig[]>;
|
return await response.json() as ApiResponse<LoginResponse>;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单接口
|
||||||
|
*/
|
||||||
|
public Menu = {
|
||||||
|
/**
|
||||||
|
* 获取菜单 /api/Menu/GetMenu
|
||||||
|
* @param init 请求初始化,可选。
|
||||||
|
* @returns 菜单列表
|
||||||
|
*/
|
||||||
|
GetMenuAsync: async (init?: RequestInit): Promise<ApiResponse<MenuItem[]>> => {
|
||||||
|
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Menu/GetMenu`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json; charset=utf-8'
|
||||||
|
},
|
||||||
|
...init
|
||||||
|
});
|
||||||
|
return await response.json() as ApiResponse<MenuItem[]>;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 获取配置 /api/Menu/GetConfig
|
||||||
|
* @param configName 配置名称,可选。
|
||||||
|
* @param init 请求初始化,可选。
|
||||||
|
* @returns 配置列表
|
||||||
|
*/
|
||||||
|
GetConfigAsync: async <T>(configName: string, init?: RequestInit): Promise<ApiResponse<T>> => {
|
||||||
|
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Menu/GetConfig?configName=${configName}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json; charset=utf-8'
|
||||||
|
},
|
||||||
|
...init
|
||||||
|
});
|
||||||
|
|
||||||
|
return await response.json() as ApiResponse<T>;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 帮助接口
|
* 获取分辨率配置 /api/Menu/GetConfig?configName=TagResolution
|
||||||
|
* @param init 请求初始化,可选。
|
||||||
|
* @returns 分辨率配置列表
|
||||||
*/
|
*/
|
||||||
public Help = {
|
GetTagResolutionsAsync: (init?: RequestInit): Promise<ApiResponse<TagResolutionConfig[]>> => {
|
||||||
/**
|
return this.Menu.GetConfigAsync<TagResolutionConfig[]>('TagResolution', init);
|
||||||
* 故障报告 /api/Help/FaultReporting
|
},
|
||||||
* @param request 故障报告请求
|
|
||||||
* @param init 请求初始化,可选。
|
|
||||||
* @returns 故障报告结果
|
|
||||||
*/
|
|
||||||
FaultReportingAsync: async (request: FaultReportingRequest, init?: RequestInit) => {
|
|
||||||
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Help/FaultReporting`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json; charset=utf-8'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(request),
|
|
||||||
...init
|
|
||||||
});
|
|
||||||
|
|
||||||
return await response.json() as ApiResponse<FaultReportingResponse>;
|
/**
|
||||||
}
|
* 获取帮助描述 /api/Menu/GetConfig?configName=HelperDescrip
|
||||||
};
|
* @param init 请求初始化,可选。
|
||||||
|
* @returns 帮助描述列表
|
||||||
|
*/
|
||||||
|
GetHelperDescripsAsync: (init?: RequestInit): Promise<ApiResponse<HelperDescription[]>> => {
|
||||||
|
return this.Menu.GetConfigAsync<HelperDescription[]>('HelperDescrip', init);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 帮助接口
|
||||||
|
*/
|
||||||
|
public Help = {
|
||||||
|
/**
|
||||||
|
* 故障报告 /api/Help/FaultReporting
|
||||||
|
* @param request 故障报告请求
|
||||||
|
* @param init 请求初始化,可选。
|
||||||
|
* @returns 故障报告结果
|
||||||
|
*/
|
||||||
|
FaultReportingAsync: async (request: FaultReportingRequest, init?: RequestInit): Promise<ApiResponse<FaultReportingResponse>> => {
|
||||||
|
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Help/FaultReporting`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json; charset=utf-8'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(request),
|
||||||
|
...init
|
||||||
|
});
|
||||||
|
|
||||||
|
return await response.json() as ApiResponse<FaultReportingResponse>;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API 响应
|
* API 响应
|
||||||
*/
|
*/
|
||||||
export interface ApiResponse<T = any> {
|
export interface ApiResponse<T = any> {
|
||||||
/**
|
/**
|
||||||
* 状态。0:成功,非0:失败
|
* 状态。0:成功,非0:失败
|
||||||
*/
|
*/
|
||||||
status: number;
|
status: number;
|
||||||
/**
|
/**
|
||||||
* HTTP状态码
|
* HTTP状态码
|
||||||
*/
|
*/
|
||||||
code: number;
|
code: number;
|
||||||
/**
|
/**
|
||||||
* 状态消息
|
* 状态消息
|
||||||
*/
|
*/
|
||||||
msg: string;
|
msg: string;
|
||||||
/**
|
/**
|
||||||
* 数据
|
* 数据
|
||||||
*/
|
*/
|
||||||
data: T;
|
data: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录请求
|
* 登录请求
|
||||||
*/
|
*/
|
||||||
export interface LoginRequest {
|
export interface LoginRequest {
|
||||||
/**
|
/**
|
||||||
* 账号
|
* 账号
|
||||||
*/
|
*/
|
||||||
Account: string;
|
Account: string;
|
||||||
/**
|
/**
|
||||||
* 密码
|
* 密码
|
||||||
*/
|
*/
|
||||||
Password: string;
|
Password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录响应
|
* 登录响应
|
||||||
*/
|
*/
|
||||||
export interface LoginResponse {
|
export interface LoginResponse {
|
||||||
/**
|
/**
|
||||||
* 是否需要发送短信
|
* 是否需要发送短信
|
||||||
*/
|
*/
|
||||||
IsNeedSendSMS: boolean;
|
IsNeedSendSMS: boolean;
|
||||||
/**
|
/**
|
||||||
* 令牌
|
* 令牌
|
||||||
*/
|
*/
|
||||||
Token: string;
|
Token: string;
|
||||||
/**
|
/**
|
||||||
* Cookies
|
* Cookies
|
||||||
*/
|
*/
|
||||||
Cookies: Array<{ Key: string, Value: string }>;
|
Cookies: Array<{ Key: string, Value: string }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单项
|
* 菜单项
|
||||||
*/
|
*/
|
||||||
export interface MenuItem {
|
export interface MenuItem {
|
||||||
/**
|
/**
|
||||||
* 显示名称
|
* 显示名称
|
||||||
*/
|
*/
|
||||||
ShowName: string;
|
ShowName: string;
|
||||||
/**
|
/**
|
||||||
* 菜单链接
|
* 菜单链接
|
||||||
*/
|
*/
|
||||||
Url: string;
|
Url: string;
|
||||||
/**
|
/**
|
||||||
* 图标配置
|
* 图标配置
|
||||||
*/
|
*/
|
||||||
IconConfig: IconConfig;
|
IconConfig: IconConfig;
|
||||||
/**
|
/**
|
||||||
* 子菜单
|
* 子菜单
|
||||||
*/
|
*/
|
||||||
Children: MenuItem[] | null;
|
Children: MenuItem[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图标配置
|
* 图标配置
|
||||||
*/
|
*/
|
||||||
export interface IconConfig {
|
export interface IconConfig {
|
||||||
|
/**
|
||||||
|
* 1x 图标
|
||||||
|
*/
|
||||||
|
_1x: {
|
||||||
/**
|
/**
|
||||||
* 1x 图标
|
* 默认图标
|
||||||
*/
|
*/
|
||||||
_1x: {
|
Default: string;
|
||||||
/**
|
|
||||||
* 默认图标
|
|
||||||
*/
|
|
||||||
Default: string;
|
|
||||||
/**
|
|
||||||
* 选中图标
|
|
||||||
*/
|
|
||||||
Selected: string;
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* 2x 图标
|
* 选中图标
|
||||||
*/
|
*/
|
||||||
_2x: {
|
Selected: string;
|
||||||
/**
|
};
|
||||||
* 默认图标
|
/**
|
||||||
*/
|
* 2x 图标
|
||||||
Default: string;
|
*/
|
||||||
/**
|
_2x: {
|
||||||
* 选中图标
|
/**
|
||||||
*/
|
* 默认图标
|
||||||
Selected: string;
|
*/
|
||||||
};
|
Default: string;
|
||||||
|
/**
|
||||||
|
* 选中图标
|
||||||
|
*/
|
||||||
|
Selected: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TagResolution 配置项
|
* TagResolution 配置项
|
||||||
*/
|
*/
|
||||||
export interface TagResolutionConfig {
|
export interface TagResolutionConfig {
|
||||||
/**
|
/**
|
||||||
* 分辨率列表,以','分隔
|
* 分辨率列表,以','分隔
|
||||||
*/
|
*/
|
||||||
Resolutions: string;
|
Resolutions: string;
|
||||||
/**
|
/**
|
||||||
* 缩放比例
|
* 缩放比例
|
||||||
*/
|
*/
|
||||||
Percentage: string | number;
|
Percentage: string | number;
|
||||||
/**
|
/**
|
||||||
* 特殊页面
|
* 特殊页面
|
||||||
*/
|
*/
|
||||||
SpecialPUrl: SpecialPUrlItem[];
|
SpecialPUrl: SpecialPUrlItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 特殊页面的缩放比例配置项
|
* 特殊页面的缩放比例配置项
|
||||||
*/
|
*/
|
||||||
export interface SpecialPUrlItem {
|
export interface SpecialPUrlItem {
|
||||||
/**
|
/**
|
||||||
* 特殊页面URL
|
* 特殊页面URL
|
||||||
*/
|
*/
|
||||||
SPUrl: string;
|
SPUrl: string;
|
||||||
/**
|
/**
|
||||||
* 特殊页面缩放比例
|
* 特殊页面缩放比例
|
||||||
*/
|
*/
|
||||||
SPPer: string | number;
|
SPPer: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 帮助描述
|
||||||
|
*/
|
||||||
|
export interface HelperDescription {
|
||||||
|
/**
|
||||||
|
* HTTP状态码,例如:403。*表示在匹配不到可用的状态码时使用。
|
||||||
|
*/
|
||||||
|
Code: string;
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
Descrip: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 故障报告请求
|
* 故障报告请求
|
||||||
*/
|
*/
|
||||||
export interface FaultReportingRequest {
|
export interface FaultReportingRequest {
|
||||||
/**
|
/**
|
||||||
* IP
|
* IP
|
||||||
*/
|
*/
|
||||||
IP: string;
|
IP: string;
|
||||||
/**
|
/**
|
||||||
* 页面URL
|
* 页面URL
|
||||||
*/
|
*/
|
||||||
Url: string;
|
Url: string;
|
||||||
/**
|
/**
|
||||||
* 账号
|
* 账号
|
||||||
*/
|
*/
|
||||||
Account: string;
|
Account: string;
|
||||||
/**
|
/**
|
||||||
* 图片Base64
|
* 图片Base64
|
||||||
*/
|
*/
|
||||||
ImgBase64: string;
|
ImgBase64: string;
|
||||||
/**
|
/**
|
||||||
* 说明
|
* 说明
|
||||||
*/
|
*/
|
||||||
Explain: string;
|
Explain: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 故障报告响应
|
* 故障报告响应
|
||||||
*/
|
*/
|
||||||
export interface FaultReportingResponse {
|
export interface FaultReportingResponse {
|
||||||
/**
|
/**
|
||||||
* 故障报告ID
|
* 故障报告ID
|
||||||
*/
|
*/
|
||||||
FaultReportingId: string;
|
FaultReportingId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EIACDesktopApi = new EIAC_Desktop_Api();
|
export const EIACDesktopApi = new EIAC_Desktop_Api();
|
@ -3,29 +3,45 @@ import http from 'http';
|
|||||||
import https from 'https';
|
import https from 'https';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import { ApiResponse, MenuItem, TagResolutionConfig, EIACDesktopApi, SpecialPUrlItem, FaultReportingResponse } from './EIAC_Desktop_Api';
|
import { ApiResponse, MenuItem, TagResolutionConfig, EIACDesktopApi, SpecialPUrlItem, FaultReportingResponse, HelperDescription } from './EIAC_Desktop_Api';
|
||||||
|
|
||||||
const memoryCache = new Map<string, any>();
|
const memoryCache = new Map<string, any>();
|
||||||
|
|
||||||
export function initialize(): void {
|
export function initialize(): void {
|
||||||
// Set cache
|
// Set cache
|
||||||
ipcMain.handle('cache:set', (_event, key: string, value: any) => {
|
ipcMain.handle('cache:set', (_event, key: string, value: any): void => {
|
||||||
memoryCache.set(key, value);
|
memoryCache.set(key, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get cache
|
// Get cache
|
||||||
ipcMain.handle('cache:get', (_event, key: string) => {
|
ipcMain.handle('cache:get', (_event, key: string): any | null => {
|
||||||
return memoryCache.get(key) ?? null;
|
return memoryCache.get(key) ?? null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get menu cache
|
// Get menu cache
|
||||||
ipcMain.handle('get-menu-cache', async () => menuData ?? await menuDataReadyPromise);
|
ipcMain.handle('get-menu-cache', async () => menuData ?? await menuDataReadyPromise);
|
||||||
|
|
||||||
// Get config cache
|
// Get helper descrip by code
|
||||||
ipcMain.handle('get-config-cache', async () => configData ?? await configDataReadyPromise);
|
ipcMain.handle('get-helper-descrip', async (event, code: string): Promise<string | null> => {
|
||||||
|
if (!helperDescriptionData) {
|
||||||
|
await helperDescriptionDataReadyPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (helperDescriptionData.code != 200 || helperDescriptionData.status != 0) {
|
||||||
|
console.error('Get config failed:', helperDescriptionData.msg + ', status: ' + helperDescriptionData.status + ', code: ' + helperDescriptionData.code);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let helperDescrip: HelperDescription | null = helperDescriptionData.data.find(h => h.Code === code);
|
||||||
|
if (!helperDescrip) {
|
||||||
|
helperDescrip = helperDescriptionData.data.find(h => h.Code === '*');
|
||||||
|
}
|
||||||
|
|
||||||
|
return helperDescrip ? helperDescrip.Descrip : null;
|
||||||
|
});
|
||||||
|
|
||||||
// Get zoom factor
|
// Get zoom factor
|
||||||
ipcMain.handle('get-zoom-factor-by-url', async (event, url: string) => {
|
ipcMain.handle('get-zoom-factor-by-url', async (event, url: string): Promise<number> => {
|
||||||
const display: Electron.Display = screen.getPrimaryDisplay();
|
const display: Electron.Display = screen.getPrimaryDisplay();
|
||||||
const physicalSize: Electron.Size = {
|
const physicalSize: Electron.Size = {
|
||||||
width: display.size.width * display.scaleFactor,
|
width: display.size.width * display.scaleFactor,
|
||||||
@ -36,16 +52,16 @@ export function initialize(): void {
|
|||||||
console.log(`Resolution: ${display.size.width}*${display.size.height}`);
|
console.log(`Resolution: ${display.size.width}*${display.size.height}`);
|
||||||
console.log(`ScaleFactor: ${display.scaleFactor}`);
|
console.log(`ScaleFactor: ${display.scaleFactor}`);
|
||||||
|
|
||||||
if (!configData) {
|
if (!tagResolutionData) {
|
||||||
await configDataReadyPromise;
|
await tagResolutionDataReadyPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configData.code != 200 || configData.status != 0) {
|
if (tagResolutionData.code != 200 || tagResolutionData.status != 0) {
|
||||||
console.error('Get config failed:', configData.msg + ', status: ' + configData.status + ', code: ' + configData.code);
|
console.error('Get config failed:', tagResolutionData.msg + ', status: ' + tagResolutionData.status + ', code: ' + tagResolutionData.code);
|
||||||
return display.scaleFactor;
|
return display.scaleFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
const configList: TagResolutionConfig[] = configData.data;
|
const configList: TagResolutionConfig[] = tagResolutionData.data;
|
||||||
let config: TagResolutionConfig = configList.find(c => c.Resolutions.includes(resolution));
|
let config: TagResolutionConfig = configList.find(c => c.Resolutions.includes(resolution));
|
||||||
if (!config) {
|
if (!config) {
|
||||||
config = configList.find(c => c.Resolutions === '*');
|
config = configList.find(c => c.Resolutions === '*');
|
||||||
@ -71,7 +87,7 @@ export function initialize(): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Check if the URL is available
|
// Check if the URL is available
|
||||||
ipcMain.handle('check-url-available', async (event, rawUrl: string) => {
|
ipcMain.handle('check-url-available', async (event, rawUrl: string): Promise<{ ok: boolean, status: number, message: string }> => {
|
||||||
try {
|
try {
|
||||||
const url: URL = new URL(rawUrl);
|
const url: URL = new URL(rawUrl);
|
||||||
const lib = url.protocol === 'https:' ? https : http;
|
const lib = url.protocol === 'https:' ? https : http;
|
||||||
@ -138,7 +154,7 @@ export function initialize(): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Set webview‘s cookie
|
// Set webview‘s cookie
|
||||||
ipcMain.handle('set-webview-cookie', async (event, url: string, cookie: string) => {
|
ipcMain.handle('set-webview-cookie', async (event, url: string, cookie: string): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
const parsedUrl = new URL(url);
|
const parsedUrl = new URL(url);
|
||||||
const cookies: Array<{ Key: string, Value: string }> = JSON.parse(cookie);
|
const cookies: Array<{ Key: string, Value: string }> = JSON.parse(cookie);
|
||||||
@ -162,7 +178,7 @@ export function initialize(): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Fault reporting
|
// Fault reporting
|
||||||
ipcMain.handle('fault-reporting', async (event, url: string, message: string, status: number) => {
|
ipcMain.handle('fault-reporting', async (event, url: string, message: string, status: number): Promise<{ ok: boolean, status: number, message: string }> => {
|
||||||
console.log('Fault reporting:', url, message, status);
|
console.log('Fault reporting:', url, message, status);
|
||||||
const webContents = event.sender;
|
const webContents = event.sender;
|
||||||
|
|
||||||
@ -197,6 +213,10 @@ export function initialize(): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取本机IP地址
|
||||||
|
* @returns 本机IP地址
|
||||||
|
*/
|
||||||
function getLocalIPAddress(): string | null {
|
function getLocalIPAddress(): string | null {
|
||||||
const interfaces = os.networkInterfaces();
|
const interfaces = os.networkInterfaces();
|
||||||
|
|
||||||
@ -212,6 +232,11 @@ function getLocalIPAddress(): string | null {
|
|||||||
return null; // 没有找到
|
return null; // 没有找到
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 捕获当前窗口并且转换为Base64格式的图像
|
||||||
|
* @param win 窗口
|
||||||
|
* @returns 返回Base64格式的图像
|
||||||
|
*/
|
||||||
async function captureWindowAsBase64(win: BrowserWindow): Promise<string> {
|
async function captureWindowAsBase64(win: BrowserWindow): Promise<string> {
|
||||||
const image = await win.capturePage(); // 截图
|
const image = await win.capturePage(); // 截图
|
||||||
const pngBuffer = image.toPNG(); // 转为 PNG Buffer
|
const pngBuffer = image.toPNG(); // 转为 PNG Buffer
|
||||||
@ -221,9 +246,14 @@ async function captureWindowAsBase64(win: BrowserWindow): Promise<string> {
|
|||||||
|
|
||||||
let menuData: ApiResponse<MenuItem[]> = null;
|
let menuData: ApiResponse<MenuItem[]> = null;
|
||||||
let menuDataReadyPromise: Promise<ApiResponse<MenuItem[]>>;
|
let menuDataReadyPromise: Promise<ApiResponse<MenuItem[]>>;
|
||||||
let configData: ApiResponse<TagResolutionConfig[]> = null;
|
let tagResolutionData: ApiResponse<TagResolutionConfig[]> = null;
|
||||||
let configDataReadyPromise: Promise<ApiResponse<TagResolutionConfig[]>>;
|
let tagResolutionDataReadyPromise: Promise<ApiResponse<TagResolutionConfig[]>>;
|
||||||
|
let helperDescriptionData: ApiResponse<HelperDescription[]> = null;
|
||||||
|
let helperDescriptionDataReadyPromise: Promise<ApiResponse<HelperDescription[]>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取菜单数据
|
||||||
|
*/
|
||||||
function getMenuAsync(): void {
|
function getMenuAsync(): void {
|
||||||
if (!menuDataReadyPromise) {
|
if (!menuDataReadyPromise) {
|
||||||
menuDataReadyPromise = new Promise((resolve, reject) => {
|
menuDataReadyPromise = new Promise((resolve, reject) => {
|
||||||
@ -239,12 +269,15 @@ function getMenuAsync(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConfigAsync(): void {
|
/**
|
||||||
if (!configDataReadyPromise) {
|
* 获取分辨率配置
|
||||||
configDataReadyPromise = new Promise((resolve, reject) => {
|
*/
|
||||||
EIACDesktopApi.Menu.GetConfigAsync()
|
function getTagResolutionsAsync(): void {
|
||||||
|
if (!tagResolutionDataReadyPromise) {
|
||||||
|
tagResolutionDataReadyPromise = new Promise((resolve, reject) => {
|
||||||
|
EIACDesktopApi.Menu.GetTagResolutionsAsync()
|
||||||
.then(data => {
|
.then(data => {
|
||||||
configData = data;
|
tagResolutionData = data;
|
||||||
resolve(data);
|
resolve(data);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
@ -254,7 +287,29 @@ function getConfigAsync(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取帮助描述
|
||||||
|
*/
|
||||||
|
function getHelperDescriptionsAsync(): void {
|
||||||
|
if (!helperDescriptionDataReadyPromise) {
|
||||||
|
helperDescriptionDataReadyPromise = new Promise((resolve, reject) => {
|
||||||
|
EIACDesktopApi.Menu.GetHelperDescripsAsync()
|
||||||
|
.then(data => {
|
||||||
|
helperDescriptionData = data;
|
||||||
|
resolve(data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预加载数据
|
||||||
|
*/
|
||||||
export function preloadData(): void {
|
export function preloadData(): void {
|
||||||
getMenuAsync();
|
getMenuAsync();
|
||||||
getConfigAsync();
|
getTagResolutionsAsync();
|
||||||
|
getHelperDescriptionsAsync();
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,9 @@ async function addTabAsync(tabGroup: TabGroup, menuItem: MenuItem): Promise<Tab
|
|||||||
} else {
|
} else {
|
||||||
console.warn(`❌ URL ${url} 不可访问:`, result.message ?? `status ${result.status}`);
|
console.warn(`❌ URL ${url} 不可访问:`, result.message ?? `status ${result.status}`);
|
||||||
lastInvalidUrlResult = { url, message: result.message, status: result.status };
|
lastInvalidUrlResult = { url, message: result.message, status: result.status };
|
||||||
showErrorModal(`无法访问 ${url}\r\n异常原因:${result.message ?? `status ${result.status}`}\r\n请联系10000技术支持。`);
|
|
||||||
|
const helpDescrip: string = await window.electronAPI.getHelperDescripAsync(result.status.toString()) ?? `无法访问 {URL}\r\n异常原因:${result.message ?? `status ${result.status}`}\r\n${helpDescrip ?? ''}`;
|
||||||
|
showErrorModal(helpDescrip.replace('{URL}', url));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,8 +364,7 @@ async function initialize(): Promise<void> {
|
|||||||
await addTabAsync(tabGroup, firstMenuItem);
|
await addTabAsync(tabGroup, firstMenuItem);
|
||||||
|
|
||||||
// Bind logo click event
|
// Bind logo click event
|
||||||
const lastMenuItem: MenuItem = menuList[menuList.length - 1];
|
const logoMenuItem: MenuItem = menuList[menuList.length - 1];
|
||||||
const logoMenuItem: MenuItem = lastMenuItem.Children[lastMenuItem.Children.length - 1];
|
|
||||||
bindLogoClickEvent(tabGroup, logoMenuItem);
|
bindLogoClickEvent(tabGroup, logoMenuItem);
|
||||||
|
|
||||||
// Bind logout event
|
// Bind logout event
|
||||||
|
@ -24,10 +24,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||||||
getMenuCacheAsync: () => ipcRenderer.invoke('get-menu-cache') as Promise<ApiResponse<MenuItem[]>>,
|
getMenuCacheAsync: () => ipcRenderer.invoke('get-menu-cache') as Promise<ApiResponse<MenuItem[]>>,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取配置缓存
|
* 获取帮助描述
|
||||||
* @returns 配置缓存
|
* @param code 帮助描述代码
|
||||||
|
* @returns 帮助描述
|
||||||
*/
|
*/
|
||||||
getConfigCacheAsync: () => ipcRenderer.invoke('get-config-cache') as Promise<ApiResponse<TagResolutionConfig[]>>,
|
getHelperDescripAsync: (code: string) => ipcRenderer.invoke('get-helper-descrip', code) as Promise<string | null>,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定URL的缩放比例
|
* 获取指定URL的缩放比例
|
||||||
|
7
src/types/electron.d.ts
vendored
7
src/types/electron.d.ts
vendored
@ -19,10 +19,11 @@ export interface ElectronAPI {
|
|||||||
*/
|
*/
|
||||||
getMenuCacheAsync: () => Promise<ApiResponse<MenuItem[]>>;
|
getMenuCacheAsync: () => Promise<ApiResponse<MenuItem[]>>;
|
||||||
/**
|
/**
|
||||||
* 获取配置缓存
|
* 获取帮助描述
|
||||||
* @returns 配置缓存
|
* @param code 帮助描述代码
|
||||||
|
* @returns 帮助描述
|
||||||
*/
|
*/
|
||||||
getConfigCacheAsync: () => Promise<ApiResponse<TagResolutionConfig[]>>;
|
getHelperDescripAsync: (code: string) => Promise<string | null>;
|
||||||
/**
|
/**
|
||||||
* 获取指定URL的缩放比例
|
* 获取指定URL的缩放比例
|
||||||
* @param url 要获取缩放比例的URL
|
* @param url 要获取缩放比例的URL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user