|
@@ -1,24 +1,29 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div style="height: 60%; min-height: 380px; border: 1px solid #a6afbe;overflow-x: auto;overflow-y: hidden">
|
|
|
|
|
- <canvas ref="canvasRef" width="7460" height="380"></canvas>
|
|
|
|
|
|
|
+ <div ref="canvasBox"
|
|
|
|
|
+ style="height: 100%; min-height: 380px; border: 1px solid #a6afbe;overflow-x: auto;overflow-y: hidden">
|
|
|
|
|
+ <canvas ref="canvasRef" width="7460"></canvas>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
-import {DrawTrack} from './controller/DrawTrack'
|
|
|
|
|
-import {DrewTrain} from './controller/DrewTrain.ts'
|
|
|
|
|
-import {StoreTrain} from '@/store/modules/train.ts'
|
|
|
|
|
-import {useStoreSocket} from '@/store/socket'
|
|
|
|
|
|
|
+import { DrawTrack } from './controller/DrawTrack'
|
|
|
|
|
+import { DrewTrain } from './controller/DrewTrain.ts'
|
|
|
|
|
+import { StoreTrain } from '@/store/modules/train.ts'
|
|
|
|
|
+import { useStoreSocket } from '@/store/socket'
|
|
|
|
|
+import TrainImg from "./controller/train.svg"
|
|
|
|
|
|
|
|
|
|
+const canvasBox = ref<HTMLElement>();
|
|
|
const canvasRef = ref<HTMLCanvasElement>();
|
|
const canvasRef = ref<HTMLCanvasElement>();
|
|
|
const storeTrain = StoreTrain();
|
|
const storeTrain = StoreTrain();
|
|
|
|
|
|
|
|
-
|
|
|
|
|
storeTrain.updateSignal();
|
|
storeTrain.updateSignal();
|
|
|
storeTrain.updateSelection();
|
|
storeTrain.updateSelection();
|
|
|
storeTrain.updateSwitch();
|
|
storeTrain.updateSwitch();
|
|
|
|
|
|
|
|
// 记录定时任务Id
|
|
// 记录定时任务Id
|
|
|
const intervalId = ref<NodeJS.Timeout | null>(null);
|
|
const intervalId = ref<NodeJS.Timeout | null>(null);
|
|
|
|
|
+const run_line_up = ref<number>(0);
|
|
|
|
|
+const run_line_down = ref<number>(0);
|
|
|
|
|
+const image: HTMLImageElement = new Image()
|
|
|
// 绘画画布
|
|
// 绘画画布
|
|
|
const drawAll = function (): void {
|
|
const drawAll = function (): void {
|
|
|
const canvas: HTMLCanvasElement | undefined = canvasRef.value;
|
|
const canvas: HTMLCanvasElement | undefined = canvasRef.value;
|
|
@@ -39,7 +44,7 @@ const drawAll = function (): void {
|
|
|
ctx.closePath();
|
|
ctx.closePath();
|
|
|
|
|
|
|
|
// 绘制车道
|
|
// 绘制车道
|
|
|
- const drawTrack = new DrawTrack(ctx);
|
|
|
|
|
|
|
+ const drawTrack = new DrawTrack(ctx, run_line_up.value, run_line_down.value);
|
|
|
// ctx.translate(INIT_SPACE, 0);
|
|
// ctx.translate(INIT_SPACE, 0);
|
|
|
ctx.save();
|
|
ctx.save();
|
|
|
|
|
|
|
@@ -52,7 +57,7 @@ const drawAll = function (): void {
|
|
|
// 绘制道岔
|
|
// 绘制道岔
|
|
|
drawTrack.drawSwitchList(storeTrain.getSwitchList);
|
|
drawTrack.drawSwitchList(storeTrain.getSwitchList);
|
|
|
|
|
|
|
|
- const drawTrain = new DrewTrain(ctx);
|
|
|
|
|
|
|
+ const drawTrain = new DrewTrain(ctx, image, run_line_up.value, run_line_down.value);
|
|
|
const storeSocket = useStoreSocket();
|
|
const storeSocket = useStoreSocket();
|
|
|
let trainList = storeSocket.trainList;
|
|
let trainList = storeSocket.trainList;
|
|
|
for (let i = 0; i < trainList.length; i++) {
|
|
for (let i = 0; i < trainList.length; i++) {
|
|
@@ -61,11 +66,20 @@ const drawAll = function (): void {
|
|
|
}
|
|
}
|
|
|
// 组件初始化
|
|
// 组件初始化
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
- drawAll();
|
|
|
|
|
- intervalId.value = setInterval(drawAll, 500);
|
|
|
|
|
|
|
+ image.src = TrainImg
|
|
|
|
|
+ image.onload = (): void => {
|
|
|
|
|
+ if (canvasBox.value && canvasRef.value) {
|
|
|
|
|
+ canvasRef.value.height = canvasBox.value?.clientHeight || 380;
|
|
|
|
|
+ run_line_up.value = Math.max(100, canvasRef.value.height - canvasRef.value.height * 0.6);
|
|
|
|
|
+ run_line_down.value = Math.max(300, canvasRef.value.height - canvasRef.value.height * 0.3);
|
|
|
|
|
+ }
|
|
|
|
|
+ drawAll();
|
|
|
|
|
+ intervalId.value = setInterval(drawAll, 500);
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
// 组件被销毁
|
|
// 组件被销毁
|
|
|
onBeforeUnmount(() => {
|
|
onBeforeUnmount(() => {
|
|
|
|
|
+
|
|
|
if (intervalId.value !== null) {
|
|
if (intervalId.value !== null) {
|
|
|
clearInterval(intervalId.value);
|
|
clearInterval(intervalId.value);
|
|
|
}
|
|
}
|