CSAPP/src/EIAC_Desktop_Api.ts

279 lines
5.6 KiB
TypeScript
Raw Normal View History

// 从环境变量中获取 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<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[]>;
},
/**
* /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<TagResolutionConfig[]>;
}
};
/**
*
*/
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<FaultReportingResponse>;
}
};
}
/**
* API
*/
export interface ApiResponse<T = any> {
/**
* 00
*/
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();