feat: 完善用户界面,添加绑定与解除绑定的功能

This commit is contained in:
2025-07-12 17:46:23 +08:00
parent 0fb0c4e395
commit f253a33c83
11 changed files with 1654 additions and 185 deletions

View File

@@ -651,9 +651,14 @@ export class DataClient {
/**
* 获取一个空闲的实验板(普通用户权限)
* @param durationHours (optional) 绑定持续时间小时默认为1小时
*/
getAvailableBoard(): Promise<Board> {
let url_ = this.baseUrl + "/api/Data/GetAvailableBoard";
getAvailableBoard(durationHours: number | undefined): Promise<Board> {
let url_ = this.baseUrl + "/api/Data/GetAvailableBoard?";
if (durationHours === null)
throw new Error("The parameter 'durationHours' cannot be null.");
else if (durationHours !== undefined)
url_ += "durationHours=" + encodeURIComponent("" + durationHours) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
@@ -697,6 +702,108 @@ export class DataClient {
return Promise.resolve<Board>(null as any);
}
/**
* 解除当前用户绑定的实验板(普通用户权限)
*/
unbindBoard(): Promise<boolean> {
let url_ = this.baseUrl + "/api/Data/UnbindBoard";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processUnbindBoard(_response);
});
}
protected processUnbindBoard(response: Response): Promise<boolean> {
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<boolean>(null as any);
}
/**
* 用户根据实验板ID获取实验板信息普通用户权限
* @param id (optional)
*/
getBoardByID(id: string | undefined): Promise<Board> {
let url_ = this.baseUrl + "/api/Data/GetBoardByID?";
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: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetBoardByID(_response);
});
}
protected processGetBoardByID(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);
result200 = Board.fromJS(resultData200);
return result200;
});
} else if (status === 404) {
return response.text().then((_responseText) => {
let result404: any = null;
let resultData404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result404 = ProblemDetails.fromJS(resultData404);
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
});
} 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);
}
/**
* 新增板子(管理员权限)
* @param name (optional)
@@ -1115,7 +1222,8 @@ export class JtagClient {
}
/**
* 页面
* 控制器首页信息
* @return 控制器描述信息
*/
index(): Promise<string> {
let url_ = this.baseUrl + "/api/Jtag";
@@ -1153,9 +1261,10 @@ export class JtagClient {
}
/**
* 获取Jtag ID Code
* @param address (optional) 设备地址
* @param port (optional) 设备端口
* 获取 JTAG 设备的 ID Code
* @param address (optional) JTAG 设备地址
* @param port (optional) JTAG 设备端口
* @return 设备的 ID Code
*/
getDeviceIDCode(address: string | undefined, port: number | undefined): Promise<number> {
let url_ = this.baseUrl + "/api/Jtag/GetDeviceIDCode?";
@@ -1199,6 +1308,13 @@ export class JtagClient {
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} 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);
@@ -1208,9 +1324,10 @@ export class JtagClient {
}
/**
* 获取状态寄存器
* @param address (optional) 设备地址
* @param port (optional) 设备端口
* 读取 JTAG 设备的状态寄存器
* @param address (optional) JTAG 设备地址
* @param port (optional) JTAG 设备端口
* @return 状态寄存器的原始值、二进制表示和解码值
*/
readStatusReg(address: string | undefined, port: number | undefined): Promise<void> {
let url_ = this.baseUrl + "/api/Jtag/ReadStatusReg?";
@@ -1246,6 +1363,13 @@ export class JtagClient {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} 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);
@@ -1255,9 +1379,10 @@ export class JtagClient {
}
/**
* 上传比特流文件
* @param address (optional) 设备地址
* 上传比特流文件到服务器
* @param address (optional) 目标设备地址
* @param file (optional) 比特流文件
* @return 上传结果
*/
uploadBitstream(address: string | undefined, file: FileParameter | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/Jtag/UploadBitstream?";
@@ -1305,6 +1430,17 @@ export class JtagClient {
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} 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 === 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);
@@ -1314,9 +1450,10 @@ export class JtagClient {
}
/**
* 通过Jtag下载比特流文件
* @param address (optional) 设备地址
* @param port (optional) 设备端口
* 通过 JTAG 下载比特流文件到 FPGA 设备
* @param address (optional) JTAG 设备地址
* @param port (optional) JTAG 设备端口
* @return 下载结果
*/
downloadBitstream(address: string | undefined, port: number | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/Jtag/DownloadBitstream?";
@@ -1368,6 +1505,13 @@ export class JtagClient {
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} 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);
@@ -1377,10 +1521,10 @@ export class JtagClient {
}
/**
* [TODO:description]
* @param address (optional) [TODO:parameter]
* @param port (optional) [TODO:parameter]
* @return [TODO:return]
* 执行边界扫描,获取所有端口状态
* @param address (optional) JTAG 设备地址
* @param port (optional) JTAG 设备端口
* @return 边界扫描结果
*/
boundaryScanAllPorts(address: string | undefined, port: number | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/Jtag/BoundaryScanAllPorts?";
@@ -1432,6 +1576,13 @@ export class JtagClient {
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} 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);
@@ -1441,10 +1592,10 @@ export class JtagClient {
}
/**
* [TODO:description]
* @param address (optional) [TODO:parameter]
* @param port (optional) [TODO:parameter]
* @return [TODO:return]
* 执行逻辑端口边界扫描
* @param address (optional) JTAG 设备地址
* @param port (optional) JTAG 设备端口
* @return 逻辑端口状态字典
*/
boundaryScanLogicalPorts(address: string | undefined, port: number | undefined): Promise<{ [key: string]: boolean; }> {
let url_ = this.baseUrl + "/api/Jtag/BoundaryScanLogicalPorts?";
@@ -1496,6 +1647,13 @@ export class JtagClient {
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} 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);
@@ -1505,11 +1663,11 @@ export class JtagClient {
}
/**
* [TODO:description]
* @param address (optional) [TODO:parameter]
* @param port (optional) [TODO:parameter]
* @param speed (optional) [TODO:parameter]
* @return [TODO:return]
* 设置 JTAG 时钟速度
* @param address (optional) JTAG 设备地址
* @param port (optional) JTAG 设备端口
* @param speed (optional) 时钟速度 (Hz)
* @return 设置结果
*/
setSpeed(address: string | undefined, port: number | undefined, speed: number | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/Jtag/SetSpeed?";
@@ -1557,6 +1715,13 @@ export class JtagClient {
result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
});
} 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);
@@ -2715,6 +2880,8 @@ export class UserInfo implements IUserInfo {
eMail!: string;
/** 用户关联的板卡ID */
boardID!: string;
/** 用户绑定板子的过期时间 */
boardExpireTime?: Date | undefined;
constructor(data?: IUserInfo) {
if (data) {
@@ -2731,6 +2898,7 @@ export class UserInfo implements IUserInfo {
this.name = _data["name"];
this.eMail = _data["eMail"];
this.boardID = _data["boardID"];
this.boardExpireTime = _data["boardExpireTime"] ? new Date(_data["boardExpireTime"].toString()) : <any>undefined;
}
}
@@ -2747,6 +2915,7 @@ export class UserInfo implements IUserInfo {
data["name"] = this.name;
data["eMail"] = this.eMail;
data["boardID"] = this.boardID;
data["boardExpireTime"] = this.boardExpireTime ? this.boardExpireTime.toISOString() : <any>undefined;
return data;
}
}
@@ -2761,6 +2930,8 @@ export interface IUserInfo {
eMail: string;
/** 用户关联的板卡ID */
boardID: string;
/** 用户绑定板子的过期时间 */
boardExpireTime?: Date | undefined;
}
/** FPGA 板子类,表示板子信息 */
@@ -2775,6 +2946,10 @@ export class Board implements IBoard {
port!: number;
/** FPGA 板子的当前状态 */
status!: BoardStatus;
/** 占用该板子的用户的唯一标识符 */
occupiedUserID!: string;
/** 占用该板子的用户的用户名 */
occupiedUserName?: string | undefined;
/** FPGA 板子的固件版本号 */
firmVersion!: string;
@@ -2794,6 +2969,8 @@ export class Board implements IBoard {
this.ipAddr = _data["ipAddr"];
this.port = _data["port"];
this.status = _data["status"];
this.occupiedUserID = _data["occupiedUserID"];
this.occupiedUserName = _data["occupiedUserName"];
this.firmVersion = _data["firmVersion"];
}
}
@@ -2812,6 +2989,8 @@ export class Board implements IBoard {
data["ipAddr"] = this.ipAddr;
data["port"] = this.port;
data["status"] = this.status;
data["occupiedUserID"] = this.occupiedUserID;
data["occupiedUserName"] = this.occupiedUserName;
data["firmVersion"] = this.firmVersion;
return data;
}
@@ -2829,6 +3008,10 @@ export interface IBoard {
port: number;
/** FPGA 板子的当前状态 */
status: BoardStatus;
/** 占用该板子的用户的唯一标识符 */
occupiedUserID: string;
/** 占用该板子的用户的用户名 */
occupiedUserName?: string | undefined;
/** FPGA 板子的固件版本号 */
firmVersion: string;
}