276 lines
5.4 KiB
TypeScript
276 lines
5.4 KiB
TypeScript
![]() |
/**
|
|||
|
* EIAC 桌面 API
|
|||
|
*/
|
|||
|
export class EIAC_Desktop_Api {
|
|||
|
private host: string;
|
|||
|
/**
|
|||
|
* 构造函数,传入API Host
|
|||
|
*/
|
|||
|
constructor(host = 'http://1.12.73.211:8848/EIAC_Desktop_Api') {
|
|||
|
this.host = host;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 认证接口
|
|||
|
*/
|
|||
|
public Auth = {
|
|||
|
/**
|
|||
|
* 登录 /api/Auth/Login
|
|||
|
* @param request 登录请求
|
|||
|
* @param init 请求初始化,可选。
|
|||
|
* @returns 登录结果
|
|||
|
*/
|
|||
|
LoginAsync: async (request: LoginRequest, init?: RequestInit) => {
|
|||
|
const response = await fetch(`${this.host}/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}/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 (configName = 'TagResolution', init?: RequestInit) => {
|
|||
|
const response = await fetch(`${this.host}/api/Menu/GetConfig?configName=${configName}`, {
|
|||
|
method: 'GET',
|
|||
|
headers: {
|
|||
|
'Content-Type': 'application/json; charset=utf-8'
|
|||
|
},
|
|||
|
...init
|
|||
|
});
|
|||
|
|
|||
|
return await response.json() as ApiResponse<TagResolutionConfig[]>;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* 帮助接口
|
|||
|
*/
|
|||
|
public Help = {
|
|||
|
/**
|
|||
|
* 故障报告 /api/Help/FaultReporting
|
|||
|
* @param request 故障报告请求
|
|||
|
* @param init 请求初始化,可选。
|
|||
|
* @returns 故障报告结果
|
|||
|
*/
|
|||
|
FaultReportingAsync: async (request: FaultReportingRequest, init?: RequestInit) => {
|
|||
|
const response = await fetch(`${this.host}/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 响应
|
|||
|
*/
|
|||
|
export interface ApiResponse<T = any> {
|
|||
|
/**
|
|||
|
* 状态。0:成功,非0:失败
|
|||
|
*/
|
|||
|
status: number;
|
|||
|
/**
|
|||
|
* HTTP状态码
|
|||
|
*/
|
|||
|
code: number;
|
|||
|
/**
|
|||
|
* 状态消息
|
|||
|
*/
|
|||
|
msg: string;
|
|||
|
/**
|
|||
|
* 数据
|
|||
|
*/
|
|||
|
data: T;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 登录请求
|
|||
|
*/
|
|||
|
export interface LoginRequest {
|
|||
|
/**
|
|||
|
* 账号
|
|||
|
*/
|
|||
|
Account: string;
|
|||
|
/**
|
|||
|
* 密码
|
|||
|
*/
|
|||
|
Password: string;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 登录响应
|
|||
|
*/
|
|||
|
export interface LoginResponse {
|
|||
|
/**
|
|||
|
* 是否需要发送短信
|
|||
|
*/
|
|||
|
IsNeedSendSMS: boolean;
|
|||
|
/**
|
|||
|
* 令牌
|
|||
|
*/
|
|||
|
Token: string;
|
|||
|
/**
|
|||
|
* Cookies
|
|||
|
*/
|
|||
|
Cookies: Array<{ Key: string, Value: string }>;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 菜单项
|
|||
|
*/
|
|||
|
export interface MenuItem {
|
|||
|
/**
|
|||
|
* 显示名称
|
|||
|
*/
|
|||
|
ShowName: string;
|
|||
|
/**
|
|||
|
* 菜单链接
|
|||
|
*/
|
|||
|
Url: string;
|
|||
|
/**
|
|||
|
* 图标配置
|
|||
|
*/
|
|||
|
IconConfig: IconConfig;
|
|||
|
/**
|
|||
|
* 子菜单
|
|||
|
*/
|
|||
|
Children: MenuItem[] | null;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 图标配置
|
|||
|
*/
|
|||
|
export interface IconConfig {
|
|||
|
/**
|
|||
|
* 1x 图标
|
|||
|
*/
|
|||
|
_1x: {
|
|||
|
/**
|
|||
|
* 默认图标
|
|||
|
*/
|
|||
|
Default: string;
|
|||
|
/**
|
|||
|
* 选中图标
|
|||
|
*/
|
|||
|
Selected: string;
|
|||
|
};
|
|||
|
/**
|
|||
|
* 2x 图标
|
|||
|
*/
|
|||
|
_2x: {
|
|||
|
/**
|
|||
|
* 默认图标
|
|||
|
*/
|
|||
|
Default: string;
|
|||
|
/**
|
|||
|
* 选中图标
|
|||
|
*/
|
|||
|
Selected: string;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* TagResolution 配置项
|
|||
|
*/
|
|||
|
export interface TagResolutionConfig {
|
|||
|
/**
|
|||
|
* 分辨率列表,以','分隔
|
|||
|
*/
|
|||
|
Resolutions: string;
|
|||
|
/**
|
|||
|
* 缩放比例
|
|||
|
*/
|
|||
|
Percentage: number;
|
|||
|
/**
|
|||
|
* 特殊页面
|
|||
|
*/
|
|||
|
SpecialPUrl: SpecialPUrlItem[];
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 特殊页面的缩放比例配置项
|
|||
|
*/
|
|||
|
export interface SpecialPUrlItem {
|
|||
|
/**
|
|||
|
* 特殊页面URL
|
|||
|
*/
|
|||
|
SPUrl: string;
|
|||
|
/**
|
|||
|
* 特殊页面缩放比例
|
|||
|
*/
|
|||
|
SPPer: number;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 故障报告请求
|
|||
|
*/
|
|||
|
export interface FaultReportingRequest {
|
|||
|
/**
|
|||
|
* IP
|
|||
|
*/
|
|||
|
IP: string;
|
|||
|
/**
|
|||
|
* 页面URL
|
|||
|
*/
|
|||
|
Url: string;
|
|||
|
/**
|
|||
|
* 账号
|
|||
|
*/
|
|||
|
Account: string;
|
|||
|
/**
|
|||
|
* 图片Base64
|
|||
|
*/
|
|||
|
ImgBase64: string;
|
|||
|
/**
|
|||
|
* 说明
|
|||
|
*/
|
|||
|
Explain: string;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 故障报告响应
|
|||
|
*/
|
|||
|
export interface FaultReportingResponse {
|
|||
|
/**
|
|||
|
* 故障报告ID
|
|||
|
*/
|
|||
|
FaultReportingId: string;
|
|||
|
}
|
|||
|
|
|||
|
export const EIACDesktopApi = new EIAC_Desktop_Api();
|