仿真订阅和操作添加mapId

This commit is contained in:
dong 2023-09-21 15:57:43 +08:00
parent da66269b90
commit 41ec1a763f
6 changed files with 14 additions and 1 deletions

View File

@ -23,6 +23,7 @@ export async function destroySimulation(data: { simulationId: string }) {
/**
*
* @param simulationId 仿id
* @param mapId id
* @param up
* @param id
* @param devicePort
@ -31,6 +32,7 @@ export async function destroySimulation(data: { simulationId: string }) {
*/
export async function addTrain(data: {
simulationId: string;
mapId: number;
up: boolean;
id: string;
devicePort?: string;
@ -47,6 +49,7 @@ export async function addTrain(data: {
*/
export async function removeTrain(data: {
simulationId: string;
mapId: number;
trainId: string;
}) {
const response = await api.post(`${UriBase}/train/remove`, data);
@ -55,6 +58,7 @@ export async function removeTrain(data: {
export async function setSwitchPosition(data: {
simulationId: string;
mapId: number;
switchIndex: string;
turnNormal: boolean;
turnReverse: boolean;

View File

@ -83,6 +83,7 @@ function submitState() {
if (lineStore.simulationId) {
setSwitchPosition({
simulationId: lineStore.simulationId,
mapId: lineStore.mapId as number,
switchIndex: turnoutState.value.index + '',
turnNormal: turnoutState.value.normal,
turnReverse: turnoutState.value.reverse,

View File

@ -170,6 +170,7 @@ export class SectionOperateInteraction extends GraphicInteractionPlugin<Section>
if (!section) return;
this.app.updateSelected(section);
const simulationId = useLineStore().simulationId || '';
const mapId = useLineStore().mapId as number;
addTrainConfig.handler = () => {
const relations =
section.relationManage.getRelationsOfGraphicAndOtherType(
@ -201,6 +202,7 @@ export class SectionOperateInteraction extends GraphicInteractionPlugin<Section>
}).onOk((data: { offset: number; dir: 1 | 0; trainLength: string }) => {
const params = {
simulationId,
mapId,
up: !!data.dir,
id: section.datas.index + '',
headOffset: data.offset,

View File

@ -174,9 +174,11 @@ export class TrainOperateInteraction extends GraphicInteractionPlugin<Train> {
this.app.updateSelected(train);
const lineStore = useLineStore();
const simulationId = lineStore.simulationId || '';
const mapId = lineStore.mapId as number;
removeTrainConfig.handler = () => {
removeTrain({
simulationId,
mapId,
trainId: train.code,
})
.then(() => {

View File

@ -92,9 +92,11 @@ export class TurnoutOperationPlugin extends GraphicInteractionPlugin<Turnout> {
if (!turnout) return;
this.app.updateSelected(turnout);
const simulationId = useLineStore().simulationId || '';
const mapId = useLineStore().mapId as number;
const setPosition = async (normal: boolean) => {
setSwitchPosition({
simulationId,
mapId,
switchIndex: turnout.datas.index + '',
turnNormal: normal,
turnReverse: !normal,
@ -150,6 +152,7 @@ export class TurnoutOperationPlugin extends GraphicInteractionPlugin<Turnout> {
}).onOk((data: { offset: number; dir: 1 | 0 }) => {
addTrain({
simulationId,
mapId,
up: !!data.dir,
id: turnout.datas.index + '',
devicePort: port,

View File

@ -229,6 +229,7 @@ export function initLineScene(lineApp: IGraphicApp) {
function handleSubscribe(lineScene: IGraphicScene, lineApp: IGraphicApp) {
const lineStore = useLineStore();
const simulationId = lineStore.simulationId;
const mapId = lineStore.mapId;
const app = lineScene;
lineApp?.enableWsMassaging({
@ -238,7 +239,7 @@ function handleSubscribe(lineScene: IGraphicScene, lineApp: IGraphicApp) {
});
app.subscribe({
// destination: `/simulation/${simulationId}/devices/status`,
destination: `simulation-${simulationId}-devices-status`,
destination: `simulation-${simulationId}_${mapId}-devices-status`,
messageConverter: (message: Uint8Array) => {
// console.log('收到消息', message);
const states: GraphicState[] = [];