列车轮径调整

This commit is contained in:
dong 2023-11-13 16:09:25 +08:00
parent 440e2c096e
commit fa80491484
4 changed files with 66 additions and 2 deletions

View File

@ -42,6 +42,24 @@ export async function addTrain(data: {
const response = await api.post(`${UriBase}/train/add`, data);
return response.data;
}
/**
*
* @param id id
* @param simulationId 仿id
* @param trainLength
* @param wheelDiameter
*/
export async function updateTrain(data: {
id: string;
simulationId: string;
trainLength?: number;
wheelDiameter?: number;
}) {
const response = await api.post(`${UriBase}/train/update`, data);
return response.data;
}
/**
*
* @param simulationId 仿id

View File

@ -90,6 +90,11 @@ const list: KeyType[] = [
key: 'controlDelayTime',
formatFn: controlDelayTimeFormat,
},
{
label: '列车轮径',
key: 'wheelDiameter',
formatFn: wheelDiameterFormat,
},
];
const list2: DynamicKeyType[] = [
//
@ -191,6 +196,9 @@ function upslopeFormat(v: boolean) {
// function runningUpFormat(v: boolean) {
// return v ? '' : '';
// }
function wheelDiameterFormat(v: number) {
return `${v} mm`;
}
function offsetFormat(v: number) {
return `${v / 1000} m`;
}

View File

@ -10,9 +10,10 @@ import {
JlGraphic,
} from 'src/jl-graphic';
import { DisplayObject, FederatedMouseEvent } from 'pixi.js';
import { removeTrain } from 'src/api/Simulation';
import { removeTrain, updateTrain } from 'src/api/Simulation';
import { useLineStore } from 'src/stores/line-store';
import { successNotify, errorNotify } from '../../utils/CommonNotify';
import { Dialog } from 'quasar';
export class TrainState extends GraphicStateBase implements ITrainState {
constructor(proto?: state.TrainState) {
let states;
@ -122,6 +123,12 @@ export class TrainState extends GraphicStateBase implements ITrainState {
set controlDelayTime(v: number) {
this.states.controlDelayTime = v;
}
get wheelDiameter(): number {
return this.states.wheelDiameter;
}
set wheelDiameter(v: number) {
this.states.wheelDiameter = v;
}
clone(): TrainState {
return new TrainState(this.states.cloneMessage());
}
@ -133,6 +140,9 @@ export class TrainState extends GraphicStateBase implements ITrainState {
}
}
const wheelDiameterChange: MenuItemOptions = {
name: '列车轮径调整',
};
const removeTrainConfig: MenuItemOptions = {
name: '清除列车',
};
@ -140,7 +150,7 @@ const TrainOperateMenu: ContextMenu = ContextMenu.init({
name: '列车操作菜单',
groups: [
{
items: [removeTrainConfig],
items: [wheelDiameterChange, removeTrainConfig],
},
],
});
@ -181,6 +191,32 @@ export class TrainOperateInteraction extends GraphicInteractionPlugin<Train> {
const lineStore = useLineStore();
const simulationId = lineStore.simulationId || '';
const mapId = lineStore.mapId as number;
wheelDiameterChange.handler = () => {
Dialog.create({
title: '列车轮径调整',
message: '列车轮径(mm)范围【长度770-840mm】, 请调整!',
prompt: {
model: train.states.wheelDiameter + '',
isValid: (val) => +val >= 770 && +val <= 840,
type: 'number',
},
cancel: true,
persistent: true,
}).onOk((data) => {
const params = {
id: train.states.id,
simulationId: simulationId,
wheelDiameter: +data,
};
updateTrain(params)
.then(() => {
successNotify('列车轮径调整成功!');
})
.catch((err) => {
errorNotify('列车轮径调整失败!', err);
});
});
};
removeTrainConfig.handler = () => {
removeTrain({
simulationId,

View File

@ -54,6 +54,8 @@ export interface ITrainState extends GraphicState {
set trainKilometer(v: number);
get controlDelayTime(): number;
set controlDelayTime(v: number);
get wheelDiameter(): number;
set wheelDiameter(v: number);
}
interface bodyWH {