增加/api/Menu/GetConfig?configName=HelperDescrip接口,根据HTTP状态码匹配帮助描述文本
This commit is contained in:
parent
8d89be590b
commit
89ee08789d
@ -23,7 +23,7 @@ export class EIAC_Desktop_Api {
|
|||||||
* @param init 请求初始化,可选。
|
* @param init 请求初始化,可选。
|
||||||
* @returns 登录结果
|
* @returns 登录结果
|
||||||
*/
|
*/
|
||||||
LoginAsync: async (request: LoginRequest, init?: RequestInit) => {
|
LoginAsync: async (request: LoginRequest, init?: RequestInit): Promise<ApiResponse<LoginResponse>> => {
|
||||||
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Auth/Login`, {
|
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Auth/Login`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -46,7 +46,7 @@ export class EIAC_Desktop_Api {
|
|||||||
* @param init 请求初始化,可选。
|
* @param init 请求初始化,可选。
|
||||||
* @returns 菜单列表
|
* @returns 菜单列表
|
||||||
*/
|
*/
|
||||||
GetMenuAsync: async (init?: RequestInit) => {
|
GetMenuAsync: async (init?: RequestInit): Promise<ApiResponse<MenuItem[]>> => {
|
||||||
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Menu/GetMenu`, {
|
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Menu/GetMenu`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -62,7 +62,7 @@ export class EIAC_Desktop_Api {
|
|||||||
* @param init 请求初始化,可选。
|
* @param init 请求初始化,可选。
|
||||||
* @returns 配置列表
|
* @returns 配置列表
|
||||||
*/
|
*/
|
||||||
GetConfigAsync: async (configName = 'TagResolution', init?: RequestInit) => {
|
GetConfigAsync: async <T>(configName: string, init?: RequestInit): Promise<ApiResponse<T>> => {
|
||||||
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Menu/GetConfig?configName=${configName}`, {
|
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Menu/GetConfig?configName=${configName}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
@ -71,7 +71,25 @@ export class EIAC_Desktop_Api {
|
|||||||
...init
|
...init
|
||||||
});
|
});
|
||||||
|
|
||||||
return await response.json() as ApiResponse<TagResolutionConfig[]>;
|
return await response.json() as ApiResponse<T>;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分辨率配置 /api/Menu/GetConfig?configName=TagResolution
|
||||||
|
* @param init 请求初始化,可选。
|
||||||
|
* @returns 分辨率配置列表
|
||||||
|
*/
|
||||||
|
GetTagResolutionsAsync: (init?: RequestInit): Promise<ApiResponse<TagResolutionConfig[]>> => {
|
||||||
|
return this.Menu.GetConfigAsync<TagResolutionConfig[]>('TagResolution', init);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取帮助描述 /api/Menu/GetConfig?configName=HelperDescrip
|
||||||
|
* @param init 请求初始化,可选。
|
||||||
|
* @returns 帮助描述列表
|
||||||
|
*/
|
||||||
|
GetHelperDescripsAsync: (init?: RequestInit): Promise<ApiResponse<HelperDescription[]>> => {
|
||||||
|
return this.Menu.GetConfigAsync<HelperDescription[]>('HelperDescrip', init);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,7 +103,7 @@ export class EIAC_Desktop_Api {
|
|||||||
* @param init 请求初始化,可选。
|
* @param init 请求初始化,可选。
|
||||||
* @returns 故障报告结果
|
* @returns 故障报告结果
|
||||||
*/
|
*/
|
||||||
FaultReportingAsync: async (request: FaultReportingRequest, init?: RequestInit) => {
|
FaultReportingAsync: async (request: FaultReportingRequest, init?: RequestInit): Promise<ApiResponse<FaultReportingResponse>> => {
|
||||||
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Help/FaultReporting`, {
|
const response = await fetch(`${this.host}/EIAC_Desktop_Api/api/Help/FaultReporting`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -240,6 +258,20 @@ export interface SpecialPUrlItem {
|
|||||||
SPPer: string | number;
|
SPPer: string | number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 帮助描述
|
||||||
|
*/
|
||||||
|
export interface HelperDescription {
|
||||||
|
/**
|
||||||
|
* HTTP状态码,例如:403。*表示在匹配不到可用的状态码时使用。
|
||||||
|
*/
|
||||||
|
Code: string;
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
Descrip: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 故障报告请求
|
* 故障报告请求
|
||||||
*/
|
*/
|
||||||
|
@ -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