feat: 添加管理员实验板管理界面

This commit is contained in:
2025-07-11 21:09:10 +08:00
parent 546b9250fa
commit 8789d6f9ee
12 changed files with 1060 additions and 240 deletions

View File

@@ -482,11 +482,57 @@ export class DataClient {
return Promise.resolve<string>(null as any);
}
/**
* 测试管理员用户认证,需携带有效 JWT
* @return 认证成功信息
*/
testAdminAuth(): Promise<string> {
let url_ = this.baseUrl + "/api/Data/TestAdminAuth";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processTestAdminAuth(_response);
});
}
protected processTestAdminAuth(response: Response): Promise<string> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 401) {
return response.text().then((_responseText) => {
let result401: any = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<string>(null as any);
}
/**
* 获取当前用户信息
* @return 用户信息包括ID、用户名、邮箱和板卡ID
*/
getUserInfo(): Promise<GetUserInfoResponse> {
getUserInfo(): Promise<UserInfo> {
let url_ = this.baseUrl + "/api/Data/GetUserInfo";
url_ = url_.replace(/[?&]$/, "");
@@ -502,14 +548,14 @@ export class DataClient {
});
}
protected processGetUserInfo(response: Response): Promise<GetUserInfoResponse> {
protected processGetUserInfo(response: Response): Promise<UserInfo> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = GetUserInfoResponse.fromJS(resultData200);
result200 = UserInfo.fromJS(resultData200);
return result200;
});
} else if (status === 400) {
@@ -535,7 +581,7 @@ export class DataClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<GetUserInfoResponse>(null as any);
return Promise.resolve<UserInfo>(null as any);
}
/**
@@ -602,6 +648,172 @@ export class DataClient {
}
return Promise.resolve<boolean>(null as any);
}
/**
* 新增板子(管理员权限)
* @param name (optional)
* @param ipAddr (optional)
* @param port (optional)
*/
addBoard(name: string | undefined, ipAddr: string | undefined, port: number | undefined): Promise<number> {
let url_ = this.baseUrl + "/api/Data/AddBoard?";
if (name === null)
throw new Error("The parameter 'name' cannot be null.");
else if (name !== undefined)
url_ += "name=" + encodeURIComponent("" + name) + "&";
if (ipAddr === null)
throw new Error("The parameter 'ipAddr' cannot be null.");
else if (ipAddr !== undefined)
url_ += "ipAddr=" + encodeURIComponent("" + ipAddr) + "&";
if (port === null)
throw new Error("The parameter 'port' cannot be null.");
else if (port !== undefined)
url_ += "port=" + encodeURIComponent("" + port) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processAddBoard(_response);
});
}
protected processAddBoard(response: Response): Promise<number> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<number>(null as any);
}
/**
* 删除板子(管理员权限)
* @param id (optional)
*/
deleteBoard(id: string | undefined): Promise<number> {
let url_ = this.baseUrl + "/api/Data/DeleteBoard?";
if (id === null)
throw new Error("The parameter 'id' cannot be null.");
else if (id !== undefined)
url_ += "id=" + encodeURIComponent("" + id) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "DELETE",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processDeleteBoard(_response);
});
}
protected processDeleteBoard(response: Response): Promise<number> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<number>(null as any);
}
/**
* 获取全部板子(管理员权限)
*/
getAllBoards(): Promise<Board[]> {
let url_ = this.baseUrl + "/api/Data/GetAllBoards";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetAllBoards(_response);
});
}
protected processGetAllBoards(response: Response): Promise<Board[]> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
if (Array.isArray(resultData200)) {
result200 = [] as any;
for (let item of resultData200)
result200!.push(Board.fromJS(item));
}
else {
result200 = <any>null;
}
return result200;
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<Board[]>(null as any);
}
}
export class DDSClient {
@@ -2445,7 +2657,8 @@ export interface IProblemDetails {
[key: string]: any;
}
export class GetUserInfoResponse implements IGetUserInfoResponse {
/** [TODO:description] */
export class UserInfo implements IUserInfo {
/** 用户的唯一标识符 */
id!: string;
/** 用户的名称 */
@@ -2455,7 +2668,7 @@ export class GetUserInfoResponse implements IGetUserInfoResponse {
/** 用户关联的板卡ID */
boardID!: string;
constructor(data?: IGetUserInfoResponse) {
constructor(data?: IUserInfo) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
@@ -2473,9 +2686,9 @@ export class GetUserInfoResponse implements IGetUserInfoResponse {
}
}
static fromJS(data: any): GetUserInfoResponse {
static fromJS(data: any): UserInfo {
data = typeof data === 'object' ? data : {};
let result = new GetUserInfoResponse();
let result = new UserInfo();
result.init(data);
return result;
}
@@ -2490,7 +2703,8 @@ export class GetUserInfoResponse implements IGetUserInfoResponse {
}
}
export interface IGetUserInfoResponse {
/** [TODO:description] */
export interface IUserInfo {
/** 用户的唯一标识符 */
id: string;
/** 用户的名称 */
@@ -2501,6 +2715,82 @@ export interface IGetUserInfoResponse {
boardID: string;
}
/** FPGA 板子类,表示板子信息 */
export class Board implements IBoard {
/** FPGA 板子的唯一标识符 */
id!: string;
/** FPGA 板子的名称 */
boardName!: string;
/** [TODO:description] */
ipAddr!: string;
/** [TODO:description] */
port!: number;
/** [TODO:description] */
status!: BoardStatus;
/** [TODO:description] */
firmVersion!: string;
constructor(data?: IBoard) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(_data?: any) {
if (_data) {
this.id = _data["id"];
this.boardName = _data["boardName"];
this.ipAddr = _data["ipAddr"];
this.port = _data["port"];
this.status = _data["status"];
this.firmVersion = _data["firmVersion"];
}
}
static fromJS(data: any): Board {
data = typeof data === 'object' ? data : {};
let result = new Board();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["id"] = this.id;
data["boardName"] = this.boardName;
data["ipAddr"] = this.ipAddr;
data["port"] = this.port;
data["status"] = this.status;
data["firmVersion"] = this.firmVersion;
return data;
}
}
/** FPGA 板子类,表示板子信息 */
export interface IBoard {
/** FPGA 板子的唯一标识符 */
id: string;
/** FPGA 板子的名称 */
boardName: string;
/** [TODO:description] */
ipAddr: string;
/** [TODO:description] */
port: number;
/** [TODO:description] */
status: BoardStatus;
/** [TODO:description] */
firmVersion: string;
}
/** [TODO:description] */
export enum BoardStatus {
Busy = 0,
Available = 1,
}
export class SystemException extends Exception implements ISystemException {
constructor(data?: ISystemException) {