|
@@ -27,7 +27,6 @@
|
|
|
|
|
|
<script>
|
|
|
import * as echarts from "echarts";
|
|
|
-require('echarts/theme/macarons') // echarts theme
|
|
|
import resize from '@/utils/resize'
|
|
|
import { getConfig } from '@/api/site/site'
|
|
|
import { getSiteSection } from '@/api/site/berthing'
|
|
@@ -97,7 +96,7 @@ export default {
|
|
|
},
|
|
|
loadCarLocation() {
|
|
|
getCarLocation(this.siteId).then((res) => {
|
|
|
- this.location = res.data?.position || 0;
|
|
|
+ this.location = res.data?.[0].position || 0;
|
|
|
this.setOptions();
|
|
|
})
|
|
|
},
|
|
@@ -126,25 +125,18 @@ export default {
|
|
|
|
|
|
const carWidth = 50; // 小车宽度
|
|
|
const carHeight = 32; // 小车高度
|
|
|
- const gap = carWidth / 2; // 断面左右留的边距,方便绘制立柱
|
|
|
const barWidth = 18; // 立柱宽度
|
|
|
+ const boxWidth = carWidth * 1.2; // 小车充电盒子宽度
|
|
|
|
|
|
const waterlevel = this.waterlevel;
|
|
|
const start = this.config.offset;
|
|
|
const location = this.location;
|
|
|
|
|
|
- const sections = [
|
|
|
- [this.sections[0].x - gap, this.sections[0].y],
|
|
|
- ...this.sections.map(({x, y}) => [x, y]),
|
|
|
- [this.sections[this.sections.length - 1].x + gap, this.sections[this.sections.length - 1].y],
|
|
|
- ];
|
|
|
+ const { sections, bar1X, bar2X } = this.calcSection();
|
|
|
|
|
|
const x = sections.map(([x]) => x);
|
|
|
const maxX = Math.max(...x);
|
|
|
const minX = Math.min(...x);
|
|
|
- const bar1X = start - (carWidth - barWidth) / 2; // 左侧立柱x坐标
|
|
|
- const bar2X = maxX - (start - minX) + (carWidth - barWidth) / 2; // 右侧立柱x坐标
|
|
|
- const boxWidth = (carWidth - barWidth) * 2; // 小车充电盒子宽度
|
|
|
|
|
|
const y = sections.map(([,y]) => y);
|
|
|
const maxY = Math.max(...y);
|
|
@@ -259,7 +251,7 @@ export default {
|
|
|
barWidth: barWidth,
|
|
|
z: 3,
|
|
|
itemStyle: {
|
|
|
- color: '#A6B7C7'
|
|
|
+ color: '#A6B7C7',
|
|
|
}
|
|
|
},
|
|
|
{
|
|
@@ -291,6 +283,42 @@ export default {
|
|
|
};
|
|
|
this.chart.setOption(options);
|
|
|
},
|
|
|
+ calcSection() {
|
|
|
+ const { local, offset } = this.config;
|
|
|
+ const sections = [...this.sections.map(({x, y}) => [x, y])];
|
|
|
+ const firstPoint = this.sections[0];
|
|
|
+ const lastPoint = this.sections[this.sections.length - 1];
|
|
|
+ let bar1X = 0;
|
|
|
+ let bar2X = 0;
|
|
|
+
|
|
|
+ if (local === 1) {
|
|
|
+ bar1X = offset
|
|
|
+ bar2X = lastPoint.x + (firstPoint.x - offset)
|
|
|
+ if (offset < firstPoint.x) {
|
|
|
+ sections.unshift([offset, firstPoint.y])
|
|
|
+ sections.push([bar2X, lastPoint.y])
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ bar1X = firstPoint.x - (offset - lastPoint.x)
|
|
|
+ bar2X = offset
|
|
|
+ if (offset > lastPoint.x) {
|
|
|
+ sections.unshift([bar1X, firstPoint.y])
|
|
|
+ sections.push([offset, lastPoint.y])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const x = sections.map(([x]) => x);
|
|
|
+ const min = Math.min(...x);
|
|
|
+ const max = Math.max(...x);
|
|
|
+
|
|
|
+ const width = max - min;
|
|
|
+ const gap = width * 0.05;
|
|
|
+
|
|
|
+ sections.unshift([min - gap, firstPoint.y]);
|
|
|
+ sections.push([max + gap, lastPoint.y]);
|
|
|
+
|
|
|
+ return { sections, bar1X, bar2X };
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|