// 从环境变量中获取 API Host const EIAC_DESKTOP_API_HOST = process.env.EIAC_DESKTOP_API_HOST || 'http://1.12.73.211:8848'; /** * EIAC 桌面 API */ export class EIAC_Desktop_Api { private host: string; /** * 构造函数,传入API Host */ constructor(host = EIAC_DESKTOP_API_HOST) { 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}/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; } }; /** * 菜单接口 */ 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; }, /** * 获取配置 /api/Menu/GetConfig * @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; } }; /** * 帮助接口 */ public Help = { /** * 故障报告 /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; } }; } /** * API 响应 */ export interface ApiResponse { /** * 状态。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: string | number; /** * 特殊页面 */ SpecialPUrl: SpecialPUrlItem[]; } /** * 特殊页面的缩放比例配置项 */ export interface SpecialPUrlItem { /** * 特殊页面URL */ SPUrl: string; /** * 特殊页面缩放比例 */ SPPer: string | 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();