feat: 完成数码管websocket通信

This commit is contained in:
2025-08-14 20:25:32 +08:00
parent 7bfc362b1f
commit 56eeb5dce3
12 changed files with 444 additions and 243 deletions

View File

@@ -1675,6 +1675,54 @@ export class DataClient {
}
return Promise.resolve<number>(null as any);
}
addEmptyBoard( cancelToken?: CancelToken): Promise<void> {
let url_ = this.baseUrl + "/api/Data/AddEmptyBoard";
url_ = url_.replace(/[?&]$/, "");
let options_: AxiosRequestConfig = {
method: "POST",
url: url_,
headers: {
},
cancelToken
};
return this.instance.request(options_).catch((_error: any) => {
if (isAxiosError(_error) && _error.response) {
return _error.response;
} else {
throw _error;
}
}).then((_response: AxiosResponse) => {
return this.processAddEmptyBoard(_response);
});
}
protected processAddEmptyBoard(response: AxiosResponse): Promise<void> {
const status = response.status;
let _headers: any = {};
if (response.headers && typeof response.headers === "object") {
for (const k in response.headers) {
if (response.headers.hasOwnProperty(k)) {
_headers[k] = response.headers[k];
}
}
}
if (status === 200) {
const _responseText = response.data;
return Promise.resolve<void>(null as any);
} else if (status === 500) {
const _responseText = response.data;
return throwException("A server side error occurred.", status, _responseText, _headers);
} else if (status !== 200 && status !== 204) {
const _responseText = response.data;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return Promise.resolve<void>(null as any);
}
}
export class DDSClient {
@@ -2840,7 +2888,7 @@ export class ExamClient {
* @param file (optional) 提交的文件
* @return 提交结果
*/
submitCommit(examId: string, file: FileParameter | undefined, cancelToken?: CancelToken): Promise<Commit> {
commit(examId: string, file: FileParameter | undefined, cancelToken?: CancelToken): Promise<ResourceInfo> {
let url_ = this.baseUrl + "/api/Exam/commit/{examId}";
if (examId === undefined || examId === null)
throw new Error("The parameter 'examId' must be defined.");
@@ -2870,11 +2918,11 @@ export class ExamClient {
throw _error;
}
}).then((_response: AxiosResponse) => {
return this.processSubmitCommit(_response);
return this.processCommit(_response);
});
}
protected processSubmitCommit(response: AxiosResponse): Promise<Commit> {
protected processCommit(response: AxiosResponse): Promise<ResourceInfo> {
const status = response.status;
let _headers: any = {};
if (response.headers && typeof response.headers === "object") {
@@ -2888,8 +2936,8 @@ export class ExamClient {
const _responseText = response.data;
let result201: any = null;
let resultData201 = _responseText;
result201 = Commit.fromJS(resultData201);
return Promise.resolve<Commit>(result201);
result201 = ResourceInfo.fromJS(resultData201);
return Promise.resolve<ResourceInfo>(result201);
} else if (status === 400) {
const _responseText = response.data;
@@ -2920,7 +2968,7 @@ export class ExamClient {
const _responseText = response.data;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return Promise.resolve<Commit>(null as any);
return Promise.resolve<ResourceInfo>(null as any);
}
/**
@@ -2928,7 +2976,7 @@ export class ExamClient {
* @param examId 实验ID
* @return 提交记录列表
*/
getCommitsByExamId(examId: string, cancelToken?: CancelToken): Promise<Commit[]> {
getCommitsByExamId(examId: string, cancelToken?: CancelToken): Promise<ResourceInfo[]> {
let url_ = this.baseUrl + "/api/Exam/commits/{examId}";
if (examId === undefined || examId === null)
throw new Error("The parameter 'examId' must be defined.");
@@ -2955,7 +3003,7 @@ export class ExamClient {
});
}
protected processGetCommitsByExamId(response: AxiosResponse): Promise<Commit[]> {
protected processGetCommitsByExamId(response: AxiosResponse): Promise<ResourceInfo[]> {
const status = response.status;
let _headers: any = {};
if (response.headers && typeof response.headers === "object") {
@@ -2972,12 +3020,12 @@ export class ExamClient {
if (Array.isArray(resultData200)) {
result200 = [] as any;
for (let item of resultData200)
result200!.push(Commit.fromJS(item));
result200!.push(ResourceInfo.fromJS(item));
}
else {
result200 = <any>null;
}
return Promise.resolve<Commit[]>(result200);
return Promise.resolve<ResourceInfo[]>(result200);
} else if (status === 400) {
const _responseText = response.data;
@@ -3008,7 +3056,7 @@ export class ExamClient {
const _responseText = response.data;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return Promise.resolve<Commit[]>(null as any);
return Promise.resolve<ResourceInfo[]>(null as any);
}
/**
@@ -6562,7 +6610,7 @@ export class ResourceClient {
* @param file (optional) 资源文件
* @return 添加结果
*/
addResource(resourceType: string | undefined, resourcePurpose: string | undefined, examID: string | null | undefined, file: FileParameter | undefined, cancelToken?: CancelToken): Promise<ResourceInfo> {
addResource(resourceType: string | undefined, resourcePurpose: ResourcePurpose | undefined, examID: string | null | undefined, file: FileParameter | undefined, cancelToken?: CancelToken): Promise<ResourceInfo> {
let url_ = this.baseUrl + "/api/Resource";
url_ = url_.replace(/[?&]$/, "");
@@ -6659,7 +6707,7 @@ export class ResourceClient {
* @param resourcePurpose (optional) 资源用途(可选)
* @return 资源列表
*/
getResourceList(examId: string | null | undefined, resourceType: string | null | undefined, resourcePurpose: string | null | undefined, cancelToken?: CancelToken): Promise<ResourceInfo[]> {
getResourceList(examId: string | null | undefined, resourceType: string | null | undefined, resourcePurpose: ResourcePurpose | null | undefined, cancelToken?: CancelToken): Promise<ResourceInfo[]> {
let url_ = this.baseUrl + "/api/Resource?";
if (examId !== undefined && examId !== null)
url_ += "examId=" + encodeURIComponent("" + examId) + "&";
@@ -8330,18 +8378,24 @@ export interface IExamDto {
isVisibleToUsers: boolean;
}
export class Commit implements ICommit {
/** 资源的唯一标识符 */
/** 资源信息类 */
export class ResourceInfo implements IResourceInfo {
/** 资源ID */
id!: string;
/** 上传资源的用户ID */
userID!: string;
/** 所属实验ID */
/** 资源名称 */
name!: string;
/** 资源类型 */
type!: string;
/** 资源用途template/user */
purpose!: ResourcePurpose;
/** 上传时间 */
uploadTime!: Date;
/** 所属实验ID可选 */
examID?: string | undefined;
type!: CommitType;
resourceID!: string;
createdAt!: Date;
/** MIME类型 */
mimeType?: string | undefined;
constructor(data?: ICommit) {
constructor(data?: IResourceInfo) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
@@ -8353,17 +8407,18 @@ export class Commit implements ICommit {
init(_data?: any) {
if (_data) {
this.id = _data["id"];
this.userID = _data["userID"];
this.examID = _data["examID"];
this.name = _data["name"];
this.type = _data["type"];
this.resourceID = _data["resourceID"];
this.createdAt = _data["createdAt"] ? new Date(_data["createdAt"].toString()) : <any>undefined;
this.purpose = _data["purpose"];
this.uploadTime = _data["uploadTime"] ? new Date(_data["uploadTime"].toString()) : <any>undefined;
this.examID = _data["examID"];
this.mimeType = _data["mimeType"];
}
}
static fromJS(data: any): Commit {
static fromJS(data: any): ResourceInfo {
data = typeof data === 'object' ? data : {};
let result = new Commit();
let result = new ResourceInfo();
result.init(data);
return result;
}
@@ -8371,31 +8426,38 @@ export class Commit implements ICommit {
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["id"] = this.id;
data["userID"] = this.userID;
data["examID"] = this.examID;
data["name"] = this.name;
data["type"] = this.type;
data["resourceID"] = this.resourceID;
data["createdAt"] = this.createdAt ? this.createdAt.toISOString() : <any>undefined;
data["purpose"] = this.purpose;
data["uploadTime"] = this.uploadTime ? this.uploadTime.toISOString() : <any>undefined;
data["examID"] = this.examID;
data["mimeType"] = this.mimeType;
return data;
}
}
export interface ICommit {
/** 资源的唯一标识符 */
/** 资源信息类 */
export interface IResourceInfo {
/** 资源ID */
id: string;
/** 上传资源的用户ID */
userID: string;
/** 所属实验ID */
/** 资源名称 */
name: string;
/** 资源类型 */
type: string;
/** 资源用途template/user */
purpose: ResourcePurpose;
/** 上传时间 */
uploadTime: Date;
/** 所属实验ID可选 */
examID?: string | undefined;
type: CommitType;
resourceID: string;
createdAt: Date;
/** MIME类型 */
mimeType?: string | undefined;
}
export enum CommitType {
Homework = 0,
Project = 1,
Markdown = 2,
export enum ResourcePurpose {
Template = 0,
User = 1,
Homework = 2,
}
export class HdmiVideoStreamEndpoint implements IHdmiVideoStreamEndpoint {
@@ -8913,82 +8975,6 @@ export interface IOscilloscopeDataResponse {
waveformData: string;
}
/** 资源信息类 */
export class ResourceInfo implements IResourceInfo {
/** 资源ID */
id!: string;
/** 资源名称 */
name!: string;
/** 资源类型 */
type!: string;
/** 资源用途template/user */
purpose!: string;
/** 上传时间 */
uploadTime!: Date;
/** 所属实验ID可选 */
examID?: string | undefined;
/** MIME类型 */
mimeType?: string | undefined;
constructor(data?: IResourceInfo) {
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.name = _data["name"];
this.type = _data["type"];
this.purpose = _data["purpose"];
this.uploadTime = _data["uploadTime"] ? new Date(_data["uploadTime"].toString()) : <any>undefined;
this.examID = _data["examID"];
this.mimeType = _data["mimeType"];
}
}
static fromJS(data: any): ResourceInfo {
data = typeof data === 'object' ? data : {};
let result = new ResourceInfo();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["id"] = this.id;
data["name"] = this.name;
data["type"] = this.type;
data["purpose"] = this.purpose;
data["uploadTime"] = this.uploadTime ? this.uploadTime.toISOString() : <any>undefined;
data["examID"] = this.examID;
data["mimeType"] = this.mimeType;
return data;
}
}
/** 资源信息类 */
export interface IResourceInfo {
/** 资源ID */
id: string;
/** 资源名称 */
name: string;
/** 资源类型 */
type: string;
/** 资源用途template/user */
purpose: string;
/** 上传时间 */
uploadTime: Date;
/** 所属实验ID可选 */
examID?: string | undefined;
/** MIME类型 */
mimeType?: string | undefined;
}
/** Package options which to send address to read or write */
export class SendAddrPackOptions implements ISendAddrPackOptions {
/** 突发类型 */

View File

@@ -14,7 +14,7 @@ import {
getHubProxyFactory,
getReceiverRegister,
} from "@/utils/signalR/TypedSignalR.Client";
import type { ResourceInfo } from "@/APIClient";
import { ResourcePurpose, type ResourceInfo } from "@/APIClient";
import type { IJtagHub } from "@/utils/signalR/TypedSignalR.Client/server.Hubs";
export const useEquipments = defineStore("equipments", () => {
@@ -137,7 +137,7 @@ export const useEquipments = defineStore("equipments", () => {
const resourceClient = AuthManager.createAuthenticatedResourceClient();
const resp = await resourceClient.addResource(
"bitstream",
"user",
ResourcePurpose.User,
examId || null,
toFileParameterOrUndefined(bitstream),
);

View File

@@ -3,7 +3,7 @@
/* tslint:disable */
// @ts-nocheck
import type { HubConnection, IStreamResult, Subject } from '@microsoft/signalr';
import type { IJtagHub, IProgressHub, IJtagReceiver, IProgressReceiver } from './server.Hubs';
import type { IDigitalTubesHub, IJtagHub, IProgressHub, IDigitalTubesReceiver, IJtagReceiver, IProgressReceiver } from './server.Hubs';
import type { ProgressInfo } from '../server.Hubs';
@@ -43,11 +43,15 @@ class ReceiverMethodSubscription implements Disposable {
// API
export type HubProxyFactoryProvider = {
(hubType: "IDigitalTubesHub"): HubProxyFactory<IDigitalTubesHub>;
(hubType: "IJtagHub"): HubProxyFactory<IJtagHub>;
(hubType: "IProgressHub"): HubProxyFactory<IProgressHub>;
}
export const getHubProxyFactory = ((hubType: string) => {
if(hubType === "IDigitalTubesHub") {
return IDigitalTubesHub_HubProxyFactory.Instance;
}
if(hubType === "IJtagHub") {
return IJtagHub_HubProxyFactory.Instance;
}
@@ -57,11 +61,15 @@ export const getHubProxyFactory = ((hubType: string) => {
}) as HubProxyFactoryProvider;
export type ReceiverRegisterProvider = {
(receiverType: "IDigitalTubesReceiver"): ReceiverRegister<IDigitalTubesReceiver>;
(receiverType: "IJtagReceiver"): ReceiverRegister<IJtagReceiver>;
(receiverType: "IProgressReceiver"): ReceiverRegister<IProgressReceiver>;
}
export const getReceiverRegister = ((receiverType: string) => {
if(receiverType === "IDigitalTubesReceiver") {
return IDigitalTubesReceiver_Binder.Instance;
}
if(receiverType === "IJtagReceiver") {
return IJtagReceiver_Binder.Instance;
}
@@ -72,6 +80,35 @@ export const getReceiverRegister = ((receiverType: string) => {
// HubProxy
class IDigitalTubesHub_HubProxyFactory implements HubProxyFactory<IDigitalTubesHub> {
public static Instance = new IDigitalTubesHub_HubProxyFactory();
private constructor() {
}
public readonly createHubProxy = (connection: HubConnection): IDigitalTubesHub => {
return new IDigitalTubesHub_HubProxy(connection);
}
}
class IDigitalTubesHub_HubProxy implements IDigitalTubesHub {
public constructor(private connection: HubConnection) {
}
public readonly startScan = async (): Promise<boolean> => {
return await this.connection.invoke("StartScan");
}
public readonly stopScan = async (): Promise<boolean> => {
return await this.connection.invoke("StopScan");
}
public readonly setFrequency = async (frequency: number): Promise<boolean> => {
return await this.connection.invoke("SetFrequency", frequency);
}
}
class IJtagHub_HubProxyFactory implements HubProxyFactory<IJtagHub> {
public static Instance = new IJtagHub_HubProxyFactory();
@@ -125,6 +162,27 @@ class IProgressHub_HubProxy implements IProgressHub {
// Receiver
class IDigitalTubesReceiver_Binder implements ReceiverRegister<IDigitalTubesReceiver> {
public static Instance = new IDigitalTubesReceiver_Binder();
private constructor() {
}
public readonly register = (connection: HubConnection, receiver: IDigitalTubesReceiver): Disposable => {
const __onReceive = (...args: [string]) => receiver.onReceive(...args);
connection.on("OnReceive", __onReceive);
const methodList: ReceiverMethod[] = [
{ methodName: "OnReceive", method: __onReceive }
]
return new ReceiverMethodSubscription(connection, methodList);
}
}
class IJtagReceiver_Binder implements ReceiverRegister<IJtagReceiver> {
public static Instance = new IJtagReceiver_Binder();

View File

@@ -5,6 +5,22 @@
import type { IStreamResult, Subject } from '@microsoft/signalr';
import type { ProgressInfo } from '../server.Hubs';
export type IDigitalTubesHub = {
/**
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
startScan(): Promise<boolean>;
/**
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
stopScan(): Promise<boolean>;
/**
* @param frequency Transpiled from int
* @returns Transpiled from System.Threading.Tasks.Task<bool>
*/
setFrequency(frequency: number): Promise<boolean>;
}
export type IJtagHub = {
/**
* @param freq Transpiled from int
@@ -30,6 +46,14 @@ export type IProgressHub = {
join(taskId: string): Promise<boolean>;
}
export type IDigitalTubesReceiver = {
/**
* @param data Transpiled from byte[]
* @returns Transpiled from System.Threading.Tasks.Task
*/
onReceive(data: string): Promise<void>;
}
export type IJtagReceiver = {
/**
* @param msg Transpiled from System.Collections.Generic.Dictionary<string, bool>

View File

@@ -250,7 +250,7 @@
</div>
</template>
<script setup lang="ts">
import type { Commit, ExamInfo } from "@/APIClient";
import { ResourcePurpose, type ExamInfo, type ResourceInfo } from "@/APIClient";
import { useAlertStore } from "@/components/Alert";
import { AuthManager } from "@/utils/AuthManager";
import { useRequiredInjection } from "@/utils/Common";
@@ -272,7 +272,7 @@ const props = defineProps<{
selectedExam: ExamInfo;
}>();
const commitsList = ref<Commit[]>();
const commitsList = ref<ResourceInfo[]>();
async function updateCommits() {
const client = AuthManager.createAuthenticatedExamClient();
const list = await client.getCommitsByExamId(props.selectedExam.id);
@@ -294,7 +294,7 @@ const downloadResources = async () => {
const resourceList = await resourceClient.getResourceList(
props.selectedExam.id,
"resource",
"template",
ResourcePurpose.Template,
);
if (resourceList && resourceList.length > 0) {