This commit is contained in:
fan 2023-10-20 16:04:32 +08:00
commit 6eb227972c
3 changed files with 211 additions and 17 deletions

View File

@ -137,6 +137,24 @@ export async function setRelayState(data: {
return await api.post(`${UriBase}/relay/operation`, data); return await api.post(`${UriBase}/relay/operation`, data);
} }
interface KilometerRange {
Coordinate: string;
MinCoordinate: number;
MaxCoordinate: number;
}
/**
*
* @param
* @returns
*/
export async function getMapKilometerRange(
id: string
): Promise<KilometerRange> {
const response = await api.get(`${UriBase}/${id}/getMapKilometerRange`);
return response.data;
}
/** /**
* PSL操作 * PSL操作
*/ */

View File

@ -3,39 +3,52 @@
seamless seamless
title="列车属性曲线图" title="列车属性曲线图"
@show="onDialogShow" @show="onDialogShow"
:height="510" :height="546"
:width="710" :width="710"
> >
<div style="height: 510px; width: 710px"> <div class="overflow-hidden">
<q-tabs v-model="tab" dense align="left" @update:model-value="changeTab">
<q-tab name="time" label="时间" />
<q-tab name="km" label="公里标" />
</q-tabs>
<q-separator />
<div <div
id="train-echarts" id="train-echarts"
class="overflow-hidden" class="q-pa-sm overflow-hidden"
style="height: 100%; width: 100%" style="height: 510px; width: 710px"
></div> ></div>
</div> </div>
</DraggableDialog> </DraggableDialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { watch } from 'vue'; import { ref, watch } from 'vue';
import { useLineStore } from 'src/stores/line-store'; import { useLineStore } from 'src/stores/line-store';
import DraggableDialog from 'src/components/common/DraggableDialog.vue'; import DraggableDialog from 'src/components/common/DraggableDialog.vue';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import 'default-passive-events'; import 'default-passive-events';
import { date } from 'quasar'; import { date } from 'quasar';
import { getMapKilometerRange } from 'src/api/Simulation';
const lineStore = useLineStore(); const lineStore = useLineStore();
const tab = ref('time');
let speedList: [Date, number][] = []; let speedList: [Date, number][] = [];
let accelerationList: [Date, number][] = []; let accelerationList: [Date, number][] = [];
let tractionForceList: [Date, number][] = []; let tractionForceList: [Date, number][] = [];
let brakeForceList: [Date, number][] = []; let brakeForceList: [Date, number][] = [];
let kmList: number[] = [];
let km_speedList: [number, number][] = [];
let maxKm: number;
let minKm: number;
const props = defineProps<{ const props = defineProps<{
trainId: string; trainId: string;
}>(); }>();
function onDialogShow() { function onDialogShow() {
getKilometerRange();
if (props.trainId) { if (props.trainId) {
getDataList(); getDataList();
initEcharts(); initEcharts();
@ -47,6 +60,8 @@ function getDataList() {
accelerationList = []; accelerationList = [];
tractionForceList = []; tractionForceList = [];
brakeForceList = []; brakeForceList = [];
kmList = [];
km_speedList = [];
lineStore.trainStateMap.forEach((list, key) => { lineStore.trainStateMap.forEach((list, key) => {
const find = list.find((ii) => { const find = list.find((ii) => {
return ii.id == props.trainId; return ii.id == props.trainId;
@ -56,11 +71,18 @@ function getDataList() {
accelerationList.push([key, find.dynamicState.acceleration]); accelerationList.push([key, find.dynamicState.acceleration]);
tractionForceList.push([key, find.vobcState.tractionForce / 100]); tractionForceList.push([key, find.vobcState.tractionForce / 100]);
brakeForceList.push([key, find.vobcState.brakeForce / 100]); brakeForceList.push([key, find.vobcState.brakeForce / 100]);
if (!kmList.includes(find.trainKilometer)) {
kmList.push(find.trainKilometer);
km_speedList.push([find.trainKilometer, find.dynamicState.speed / 100]);
}
} }
}); });
} }
let series = [ type SeriesObj = echarts.SeriesOption & {
unit?: string;
};
let series: SeriesObj[] = [
{ {
name: '速度', name: '速度',
type: 'line', type: 'line',
@ -72,6 +94,7 @@ let series = [
name: '加速度', name: '加速度',
type: 'line', type: 'line',
showSymbol: false, showSymbol: false,
yAxisIndex: 1,
data: accelerationList, data: accelerationList,
unit: 'm/s', unit: 'm/s',
}, },
@ -90,6 +113,32 @@ let series = [
unit: 'kn', unit: 'kn',
}, },
]; ];
let km_series: SeriesObj[] = [
{
name: '速度',
type: 'line',
showSymbol: false,
data: km_speedList,
unit: 'km/h',
},
];
function trainKilometerFormat(v: number) {
const f = v.toFixed();
const r = f.split('').reverse();
const x = r.slice(0, 3).reverse();
const m = r.slice(3, 6).reverse();
const k = r.slice(6).reverse();
let n = '';
if (k.length) {
n = `k${k.join('')}+${m.join('')}.${x.join('')}`;
} else if (m.length) {
n = `${m.join('')}.${x.join('')}`;
} else if (x.length) {
n = `0.${x.join('')}`;
}
return n;
}
let myChart: echarts.EChartsType; let myChart: echarts.EChartsType;
function initEcharts() { function initEcharts() {
@ -99,7 +148,8 @@ function initEcharts() {
renderer: 'canvas', renderer: 'canvas',
useDirtyRect: false, useDirtyRect: false,
}); });
const option = { let option: echarts.EChartsOption = {
animation: false,
title: { title: {
text: '', text: '',
}, },
@ -139,6 +189,7 @@ function initEcharts() {
`; `;
// eslint-disable-next-line // eslint-disable-next-line
params.forEach((item: any, index: number) => { params.forEach((item: any, index: number) => {
let val = item.value[1].toFixed(2);
result += result +=
"<div style='height: 28px;line-height:28px'>" + "<div style='height: 28px;line-height:28px'>" +
'<span style="display:inline-block;margin-right:5px;border-radius:20px;width:10px;height:10px;background-color:' + '<span style="display:inline-block;margin-right:5px;border-radius:20px;width:10px;height:10px;background-color:' +
@ -147,7 +198,7 @@ function initEcharts() {
item.seriesName + item.seriesName +
' : ' + ' : ' +
'<span style="float:right;margin-left:20px;font-size:14px;color:#666;font-weight:bold">' + '<span style="float:right;margin-left:20px;font-size:14px;color:#666;font-weight:bold">' +
item.value[1].toFixed(2) + val +
' ' + ' ' +
series[index].unit + series[index].unit +
'</span>' + '</span>' +
@ -169,13 +220,106 @@ function initEcharts() {
show: false, show: false,
}, },
}, },
yAxis: { yAxis: [
type: 'value', {
boundaryGap: [0, '100%'], type: 'value',
}, // max: 100,
boundaryGap: [0, 0.1],
},
{
type: 'value',
scale: true,
name: '加速度 m/s',
boundaryGap: [0, 0.4],
},
],
series: series, series: series,
}; };
if (tab.value == 'km') {
option = {
animation: false,
title: {
text: '',
},
tooltip: {
trigger: 'axis',
// eslint-disable-next-line
formatter: function (params: any) {
const title = trainKilometerFormat(params[0].value[0]);
let result = `<div
style="height:100%;
min-height:${30 + 28 * params.length}px;
width: 200px;
background: rgba(255, 255, 255, 0.27);
"
>
<div
style="width: 100%;
height: 30px;
padding-left:10px;
font-size: 14px;
line-height: 30px;
"
>
${title}
</div>
<div
style="
height: 100%;
padding-left:10px;
width: 100%;
border-radius: 3px;
"
>
`;
// eslint-disable-next-line
params.forEach((item: any, index: number) => {
let val = item.value[1].toFixed(2);
result +=
"<div style='height: 28px;line-height:28px'>" +
'<span style="display:inline-block;margin-right:5px;border-radius:20px;width:10px;height:10px;background-color:' +
item.color +
'"></span>' +
item.seriesName +
' : ' +
'<span style="float:right;margin-left:20px;font-size:14px;color:#666;font-weight:bold">' +
val +
' ' +
km_series[index].unit +
'</span>' +
'<div style="clear:both"></div>' +
'</div>';
});
result += '</div>';
return result;
},
},
legend: {
data: ['速度'],
},
xAxis: {
type: 'value',
min: minKm,
max: maxKm,
splitLine: {
show: false,
},
},
yAxis: [
{
type: 'value',
max: 100,
axisLine: {
show: false,
},
axisTick: {
show: false,
},
},
],
series: km_series,
};
}
myChart.setOption(option); myChart.setOption(option);
} }
@ -183,7 +327,7 @@ watch(
() => lineStore.socketStates, () => lineStore.socketStates,
() => { () => {
getDataList(); getDataList();
myChart?.setOption({ let op: echarts.EChartsOption = {
series: [ series: [
{ {
data: speedList, data: speedList,
@ -198,8 +342,38 @@ watch(
data: brakeForceList, data: brakeForceList,
}, },
], ],
}); };
if (tab.value == 'km') {
op = {
series: [
{
data: km_speedList,
},
],
};
}
myChart?.setOption(op);
} }
); );
function changeTab() {
myChart.dispose();
initEcharts();
}
function getKilometerRange() {
if (lineStore.simulationId) {
getMapKilometerRange(lineStore.simulationId)
.then((res) => {
console.log(res);
const d = (res.MaxCoordinate - res.MinCoordinate) * 0.05;
maxKm = res.MaxCoordinate + d;
minKm = res.MinCoordinate - d;
})
.catch((err) => {
console.log(err);
});
}
}
</script> </script>
<style scoped></style> <style scoped></style>

View File

@ -182,6 +182,9 @@ export const layerList = [
export function initLineScene(lineApp: IGraphicApp, sceneName: string) { export function initLineScene(lineApp: IGraphicApp, sceneName: string) {
const options: GraphicAppOptions = { const options: GraphicAppOptions = {
dataLoader: loadLineDatas, dataLoader: loadLineDatas,
};
const lineScene = lineApp.initScene(sceneName, options);
lineScene.setOptions({
mouseToolOptions: { mouseToolOptions: {
boxSelect: false, boxSelect: false,
viewportDrag: true, viewportDrag: true,
@ -197,8 +200,7 @@ export function initLineScene(lineApp: IGraphicApp, sceneName: string) {
Section.Type, Section.Type,
Transponder.Type, Transponder.Type,
], ],
}; });
const lineScene = lineApp.initScene(sceneName, options);
const categoryType = useLineStore().categoryType; const categoryType = useLineStore().categoryType;
if (!categoryType) { if (!categoryType) {
throw new Error('未获取到厂商信息'); throw new Error('未获取到厂商信息');