From d3b3d501501085fa23ede54fca43a9f383ac8b45 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Fri, 27 Oct 2023 16:54:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/RunconfigApi.ts | 80 +++++++++ src/api/Simulation.ts | 2 + src/layouts/LineLayout.vue | 12 +- src/layouts/MainLayout.vue | 3 - src/pages/CategoryManage.vue | 4 +- src/pages/RunconfigManage.vue | 285 +++++++++++++++++++++++++++++++++ src/pages/TestManage.vue | 173 ++++++++++---------- src/protos/device_state.ts | 202 +++++------------------ src/router/routes.ts | 9 ++ src/stores/testManage-store.ts | 43 +++-- 10 files changed, 533 insertions(+), 280 deletions(-) create mode 100644 src/api/RunconfigApi.ts create mode 100644 src/pages/RunconfigManage.vue diff --git a/src/api/RunconfigApi.ts b/src/api/RunconfigApi.ts new file mode 100644 index 0000000..9ae939e --- /dev/null +++ b/src/api/RunconfigApi.ts @@ -0,0 +1,80 @@ +import { api } from 'src/boot/axios'; +import { PageDto, PageQueryDto } from './ApiCommon'; + +const UriBase = '/api/v1/runconfig'; + +export interface createParams { + name: string; + config: string; + description: string; +} + +export interface RunconfigItem extends createParams { + id: number; + createdAt: string; + updateAt: string; +} + +export class PagingQueryParams extends PageQueryDto { + name?: string; +} + +/** + * 分页查询 + * @param params + * @returns + */ +export async function pageQuery( + params: PagingQueryParams +): Promise> { + const response = await api.get(`${UriBase}/paging`, { + params: params, + }); + return response.data; +} + +/** + * 创建运行环境 + * @param data + * @returns + */ +export function createRunconfig(data: createParams) { + return api.post(`${UriBase}`, data); +} + +/** + * 删除运行环境 + * @param id 运行环境id + */ +export function deleteRunconfig(id: number) { + return api.delete(`${UriBase}/${id}`); +} + +/** + * 修改运行环境数据 + * @param id 运行环境id + * @param data + */ +export function saveRunconfigData(id: number, data: createParams) { + return api.put(`${UriBase}/${id}`, data); +} + +/** + * 获取运行环境数据详情 + * @param id 运行环境id + * @returns + */ +export async function getRunconfigInfo(id: number): Promise { + const response = await api.get(`${UriBase}/${id}`); + return response.data; +} + +/** + * 获取运行环境信息列表 + * @param + * @returns + */ +export async function getRunconfigList(): Promise> { + const response = await api.get(`${UriBase}/list`); + return response.data; +} diff --git a/src/api/Simulation.ts b/src/api/Simulation.ts index d8458bc..0b6c382 100644 --- a/src/api/Simulation.ts +++ b/src/api/Simulation.ts @@ -109,6 +109,7 @@ export interface SimulationIem { projectId: number; simulationId: string; mapIds: number[]; + runConfigId: number; } /** @@ -123,6 +124,7 @@ export async function getSimulationList(): Promise> { export interface createByProject { projectId: number; + runConfigId: number; } /** * 按照项目创建仿真 diff --git a/src/layouts/LineLayout.vue b/src/layouts/LineLayout.vue index a831121..f80b44e 100644 --- a/src/layouts/LineLayout.vue +++ b/src/layouts/LineLayout.vue @@ -92,6 +92,7 @@ import { useTestManageStore } from 'src/stores/testManage-store'; import { CategoryType } from 'src/components/CategoryType'; import TrainInfoEcharts from 'src/components/line-app/infos/TrainInfoEcharts.vue'; import { useIbpStore } from 'src/stores/ibp-store'; +import { state } from 'src/protos/device_state'; const $q = useQuasar(); const canvasWidth = ref(0); @@ -141,11 +142,11 @@ const lineApp = lineStore.initLineApp(); let scene: null | IGraphicScene = null; onMounted(async () => { - testManageStore.socketConnect(); const dom = document.getElementById('line-app-container'); if (dom && defaultMapId && simulationId) { lineStore.setMapId(+defaultMapId); lineStore.setSimulationId(simulationId); + testManageStore.socketConnect(); try { if (projectId) { const res = await getProjectLinkInfo(+projectId); @@ -202,6 +203,7 @@ onUnmounted(() => { echartsDialog.value.hide(); lineStore.setEchartsTrainId(''); } + testManageStore.socketClose(); lineStore.clearTrainStateMap(); lineStore.setSimulationId(null); lineStore.destroy(); @@ -272,10 +274,10 @@ watch( watch( () => testManageStore.socketInfo, (val) => { - const removeS = val.removeSimulations.find((item) => { - return item.simulationId == simulationId; - }); - if (removeS) { + if ( + val.simulationId == simulationId && + val.state == state.SimulationStatus.SimulationState.DESTROY + ) { $q.dialog({ title: '确认', message: `【${projectName.value}】项目仿真已经结束,是否确认退出?`, diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index a54c8c9..16dbb47 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -123,10 +123,8 @@ import { useRouter } from 'vue-router'; import { clearJwtToken } from 'src/configs/TokenManage'; import { Dialog } from 'quasar'; import { useAuthStore } from 'src/stores/auth-store'; -import { useTestManageStore } from 'src/stores/testManage-store'; const router = useRouter(); -const testManageStore = useTestManageStore(); const leftDrawerOpen = ref(false); @@ -171,7 +169,6 @@ function logOut() { cancel: true, persistent: true, }).onOk(() => { - testManageStore.socketClose(); clearJwtToken(); authStore.clearCurrentUser(); router.push({ name: 'login' }); diff --git a/src/pages/CategoryManage.vue b/src/pages/CategoryManage.vue index f8aa3b7..b59712a 100644 --- a/src/pages/CategoryManage.vue +++ b/src/pages/CategoryManage.vue @@ -219,7 +219,7 @@ function onCreate() { const params: createParams = { name: editInfo.categoryName, code: editInfo.code, - config: JSON.stringify(editInfo.config), + config: editInfo.config, }; if (editInfo.id) { await saveCategoryData(+editInfo.id, params); @@ -286,7 +286,7 @@ function editData(row: CategoryItem) { editInfo.id = res.id + ''; editInfo.categoryName = res.name; editInfo.code = res.code; - editInfo.config = res.config ? JSON.parse(res.config) : ''; + editInfo.config = res.config || ''; createFormShow.value = true; }) .catch((err) => { diff --git a/src/pages/RunconfigManage.vue b/src/pages/RunconfigManage.vue new file mode 100644 index 0000000..b11da71 --- /dev/null +++ b/src/pages/RunconfigManage.vue @@ -0,0 +1,285 @@ + + + diff --git a/src/pages/TestManage.vue b/src/pages/TestManage.vue index 9eca3c6..d6466ee 100644 --- a/src/pages/TestManage.vue +++ b/src/pages/TestManage.vue @@ -16,7 +16,6 @@ :loading="loading" :filter="filter" binary-state-sort - @request="onRequest" > diff --git a/src/protos/device_state.ts b/src/protos/device_state.ts index 3046ba3..5509507 100644 --- a/src/protos/device_state.ts +++ b/src/protos/device_state.ts @@ -3355,24 +3355,20 @@ export namespace state { #one_of_decls: number[][] = []; constructor(data?: any[] | { simulationId?: string; - mapId?: number; - projectId?: number; - mapIds?: number[]; + state?: SimulationStatus.SimulationState; + description?: string; }) { super(); - pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4], this.#one_of_decls); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); if (!Array.isArray(data) && typeof data == "object") { if ("simulationId" in data && data.simulationId != undefined) { this.simulationId = data.simulationId; } - if ("mapId" in data && data.mapId != undefined) { - this.mapId = data.mapId; + if ("state" in data && data.state != undefined) { + this.state = data.state; } - if ("projectId" in data && data.projectId != undefined) { - this.projectId = data.projectId; - } - if ("mapIds" in data && data.mapIds != undefined) { - this.mapIds = data.mapIds; + if ("description" in data && data.description != undefined) { + this.description = data.description; } } } @@ -3382,63 +3378,49 @@ export namespace state { set simulationId(value: string) { pb_1.Message.setField(this, 1, value); } - get mapId() { - return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; + get state() { + return pb_1.Message.getFieldWithDefault(this, 2, SimulationStatus.SimulationState.PAUSE) as SimulationStatus.SimulationState; } - set mapId(value: number) { + set state(value: SimulationStatus.SimulationState) { pb_1.Message.setField(this, 2, value); } - get projectId() { - return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; + get description() { + return pb_1.Message.getFieldWithDefault(this, 3, "") as string; } - set projectId(value: number) { + set description(value: string) { pb_1.Message.setField(this, 3, value); } - get mapIds() { - return pb_1.Message.getFieldWithDefault(this, 4, []) as number[]; - } - set mapIds(value: number[]) { - pb_1.Message.setField(this, 4, value); - } static fromObject(data: { simulationId?: string; - mapId?: number; - projectId?: number; - mapIds?: number[]; + state?: SimulationStatus.SimulationState; + description?: string; }): SimulationStatus { const message = new SimulationStatus({}); if (data.simulationId != null) { message.simulationId = data.simulationId; } - if (data.mapId != null) { - message.mapId = data.mapId; + if (data.state != null) { + message.state = data.state; } - if (data.projectId != null) { - message.projectId = data.projectId; - } - if (data.mapIds != null) { - message.mapIds = data.mapIds; + if (data.description != null) { + message.description = data.description; } return message; } toObject() { const data: { simulationId?: string; - mapId?: number; - projectId?: number; - mapIds?: number[]; + state?: SimulationStatus.SimulationState; + description?: string; } = {}; if (this.simulationId != null) { data.simulationId = this.simulationId; } - if (this.mapId != null) { - data.mapId = this.mapId; + if (this.state != null) { + data.state = this.state; } - if (this.projectId != null) { - data.projectId = this.projectId; - } - if (this.mapIds != null) { - data.mapIds = this.mapIds; + if (this.description != null) { + data.description = this.description; } return data; } @@ -3448,12 +3430,10 @@ export namespace state { const writer = w || new pb_1.BinaryWriter(); if (this.simulationId.length) writer.writeString(1, this.simulationId); - if (this.mapId != 0) - writer.writeInt32(2, this.mapId); - if (this.projectId != 0) - writer.writeInt32(3, this.projectId); - if (this.mapIds.length) - writer.writePackedInt32(4, this.mapIds); + if (this.state != SimulationStatus.SimulationState.PAUSE) + writer.writeEnum(2, this.state); + if (this.description.length) + writer.writeString(3, this.description); if (!w) return writer.getResultBuffer(); } @@ -3467,13 +3447,10 @@ export namespace state { message.simulationId = reader.readString(); break; case 2: - message.mapId = reader.readInt32(); + message.state = reader.readEnum(); break; case 3: - message.projectId = reader.readInt32(); - break; - case 4: - message.mapIds = reader.readPackedInt32(); + message.description = reader.readString(); break; default: reader.skipField(); } @@ -3487,117 +3464,12 @@ export namespace state { return SimulationStatus.deserialize(bytes); } } - export class MemoryDataStatus extends pb_1.Message { - #one_of_decls: number[][] = []; - constructor(data?: any[] | { - allSimulations?: SimulationStatus[]; - addSimulations?: SimulationStatus[]; - removeSimulations?: SimulationStatus[]; - }) { - super(); - pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1, 2, 3], this.#one_of_decls); - if (!Array.isArray(data) && typeof data == "object") { - if ("allSimulations" in data && data.allSimulations != undefined) { - this.allSimulations = data.allSimulations; - } - if ("addSimulations" in data && data.addSimulations != undefined) { - this.addSimulations = data.addSimulations; - } - if ("removeSimulations" in data && data.removeSimulations != undefined) { - this.removeSimulations = data.removeSimulations; - } - } - } - get allSimulations() { - return pb_1.Message.getRepeatedWrapperField(this, SimulationStatus, 1) as SimulationStatus[]; - } - set allSimulations(value: SimulationStatus[]) { - pb_1.Message.setRepeatedWrapperField(this, 1, value); - } - get addSimulations() { - return pb_1.Message.getRepeatedWrapperField(this, SimulationStatus, 2) as SimulationStatus[]; - } - set addSimulations(value: SimulationStatus[]) { - pb_1.Message.setRepeatedWrapperField(this, 2, value); - } - get removeSimulations() { - return pb_1.Message.getRepeatedWrapperField(this, SimulationStatus, 3) as SimulationStatus[]; - } - set removeSimulations(value: SimulationStatus[]) { - pb_1.Message.setRepeatedWrapperField(this, 3, value); - } - static fromObject(data: { - allSimulations?: ReturnType[]; - addSimulations?: ReturnType[]; - removeSimulations?: ReturnType[]; - }): MemoryDataStatus { - const message = new MemoryDataStatus({}); - if (data.allSimulations != null) { - message.allSimulations = data.allSimulations.map(item => SimulationStatus.fromObject(item)); - } - if (data.addSimulations != null) { - message.addSimulations = data.addSimulations.map(item => SimulationStatus.fromObject(item)); - } - if (data.removeSimulations != null) { - message.removeSimulations = data.removeSimulations.map(item => SimulationStatus.fromObject(item)); - } - return message; - } - toObject() { - const data: { - allSimulations?: ReturnType[]; - addSimulations?: ReturnType[]; - removeSimulations?: ReturnType[]; - } = {}; - if (this.allSimulations != null) { - data.allSimulations = this.allSimulations.map((item: SimulationStatus) => item.toObject()); - } - if (this.addSimulations != null) { - data.addSimulations = this.addSimulations.map((item: SimulationStatus) => item.toObject()); - } - if (this.removeSimulations != null) { - data.removeSimulations = this.removeSimulations.map((item: SimulationStatus) => item.toObject()); - } - return data; - } - serialize(): Uint8Array; - serialize(w: pb_1.BinaryWriter): void; - serialize(w?: pb_1.BinaryWriter): Uint8Array | void { - const writer = w || new pb_1.BinaryWriter(); - if (this.allSimulations.length) - writer.writeRepeatedMessage(1, this.allSimulations, (item: SimulationStatus) => item.serialize(writer)); - if (this.addSimulations.length) - writer.writeRepeatedMessage(2, this.addSimulations, (item: SimulationStatus) => item.serialize(writer)); - if (this.removeSimulations.length) - writer.writeRepeatedMessage(3, this.removeSimulations, (item: SimulationStatus) => item.serialize(writer)); - if (!w) - return writer.getResultBuffer(); - } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): MemoryDataStatus { - const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new MemoryDataStatus(); - while (reader.nextField()) { - if (reader.isEndGroup()) - break; - switch (reader.getFieldNumber()) { - case 1: - reader.readMessage(message.allSimulations, () => pb_1.Message.addToRepeatedWrapperField(message, 1, SimulationStatus.deserialize(reader), SimulationStatus)); - break; - case 2: - reader.readMessage(message.addSimulations, () => pb_1.Message.addToRepeatedWrapperField(message, 2, SimulationStatus.deserialize(reader), SimulationStatus)); - break; - case 3: - reader.readMessage(message.removeSimulations, () => pb_1.Message.addToRepeatedWrapperField(message, 3, SimulationStatus.deserialize(reader), SimulationStatus)); - break; - default: reader.skipField(); - } - } - return message; - } - serializeBinary(): Uint8Array { - return this.serialize(); - } - static deserializeBinary(bytes: Uint8Array): MemoryDataStatus { - return MemoryDataStatus.deserialize(bytes); + export namespace SimulationStatus { + export enum SimulationState { + PAUSE = 0, + START = 1, + ERROR = 2, + DESTROY = 3 } } } diff --git a/src/router/routes.ts b/src/router/routes.ts index 3ca9dbd..523632d 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -130,6 +130,15 @@ export const asyncRoutes: RouteRecordRaw[] = [ icon: 'apps', }, }, + { + path: 'runconfig', + name: 'runconfig', + component: () => import('pages/RunconfigManage.vue'), + meta: { + label: '环境配置', + icon: 'settings_suggest', + }, + }, ], }, { diff --git a/src/stores/testManage-store.ts b/src/stores/testManage-store.ts index c6ffb02..0c931c6 100644 --- a/src/stores/testManage-store.ts +++ b/src/stores/testManage-store.ts @@ -1,45 +1,44 @@ import { defineStore } from 'pinia'; import { CentrifugeMessagingClient } from 'src/jl-graphic/message/CentrifugeBroker'; -import { getSimulationChannelName } from 'src/api/Simulation'; import { getWebsocketUrl } from 'src/configs/UrlManage'; import { getOnlyToken } from 'src/configs/TokenManage'; import { state } from 'src/protos/device_state'; +import { useLineStore } from './line-store'; export const useTestManageStore = defineStore('testManage', { state: () => ({ socket: null as CentrifugeMessagingClient | null, // 启动项目的socket - destination: '', // 启动项目的socket订阅路径 - socketInfo: new state.MemoryDataStatus(), + socketInfo: new state.SimulationStatus(), }), actions: { socketHandler(message: Uint8Array) { - const storage = state.MemoryDataStatus.deserialize(message); + const storage = state.SimulationStatus.deserialize(message); this.socketInfo = storage; }, socketConnect() { if (this.socket) return; - getSimulationChannelName() - .then((res) => { - this.destination = res; - this.socket = new CentrifugeMessagingClient({ - wsUrl: `${getWebsocketUrl()}`, - token: getOnlyToken() as string, - protocol: 'protobuf', - }); - this.socket.on('connected', () => { - this.socket?.subscribe(this.destination, this.socketHandler); - }); - }) - .catch((err) => { - console.log(err, '获取仿真信息更新通道名称失败!'); - }); + const lineStore = useLineStore(); + const simulationId = lineStore.simulationId; + const destination = `simulation-${simulationId}-status`; + this.socket = new CentrifugeMessagingClient({ + wsUrl: `${getWebsocketUrl()}`, + token: getOnlyToken() as string, + protocol: 'protobuf', + }); + this.socket.on('connected', () => { + this.socket?.subscribe(destination, this.socketHandler); + }); }, socketClose() { - this.socket?.unsubscribe0(this.destination); + const lineStore = useLineStore(); + const simulationId = lineStore.simulationId; + const destination = `simulation-${simulationId}-status`; + if (destination) { + this.socket?.unsubscribe0(destination); + } this.socket?.close(); this.socket = null; - this.destination = ''; - this.socketInfo = new state.MemoryDataStatus(); + this.socketInfo = new state.SimulationStatus(); }, }, });