yudao-init/src/views/copilot/factoryData/components/Store.vue

171 lines
4.1 KiB
Vue
Raw Normal View History

2024-05-09 15:43:02 +08:00
<template>
2024-05-09 18:35:12 +08:00
<div id="factoryStoreChart" style="width: 100%; height: 100%"></div>
2024-05-09 15:43:02 +08:00
</template>
<script>
2024-05-09 18:35:12 +08:00
import { debounce } from "@/utils/debounce";
import * as echarts from "echarts";
2024-05-09 15:43:02 +08:00
export default {
name: "Store",
props: {
vHeight: {
type: Number,
default: 34,
},
xAxis: {
type: Array,
required: true,
},
series: {
type: Array,
required: true,
},
},
data() {
return {
isFullscreen: false,
actualOptions: null,
2024-05-09 18:35:12 +08:00
chart: "",
2024-05-09 15:43:02 +08:00
options: {
grid: {
left: "3%",
right: "1%",
bottom: "0",
top: "10%",
containLabel: true,
},
tooltip: {},
xAxis: {
axisTick: {
show: false,
},
axisLine: {
lineStyle: {
color: "#4561AE",
},
},
axisLabel: {
color: "rgba(255, 255, 255, 0.7)",
fontSize: 12,
},
data: this.xAxis,
},
yAxis: {
name: "单位/片",
nameTextStyle: {
color: "rgba(255, 255, 255, 0.7)",
fontSize: 12,
align: "right",
},
axisTick: {
show: false,
},
axisLabel: {
color: "rgba(255, 255, 255, 0.7)",
fontSize: 12,
},
axisLine: {
show: true,
lineStyle: {
color: "#4561AE",
},
},
splitLine: {
lineStyle: {
color: "#4561AE",
},
},
},
series: [
{
name: "", // this.series[0].name,
type: "bar",
barWidth: 12,
itemStyle: {
borderRadius: [10, 10, 0, 0],
color: {
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "#12f7f1", // 0% 处的颜色
},
{
offset: 0.35,
color: "#12f7f177", // 100% 处的颜色
},
{
offset: 0.75,
color: "#12f7f133", // 100% 处的颜色
},
{
offset: 1,
color: "transparent", // 100% 处的颜色
},
],
global: false, // 缺省为 false
},
},
data: [], // this.series[0].data,
},
],
},
};
},
watch: {
series(val) {
if (!val) {
this.initOptions(this.options);
return;
}
const actualOptions = JSON.parse(JSON.stringify(this.options));
actualOptions.series[0].data = val[0].data;
actualOptions.series[0].name = val[0].name;
actualOptions.series[1].data = val[1].data;
actualOptions.series[1].name = val[1].name;
this.actualOptions = actualOptions;
this.initOptions(actualOptions);
},
},
mounted() {
// if (screenfull.isEnabled) {
// screenfull.on("change", () => {
// this.isFullscreen = screenfull.isFullscreen;
// });
// }
2024-05-09 18:35:12 +08:00
this.canvasReset();
window.addEventListener("resize", this.canvasReset);
},
beforeDestroy() {
if (this.chart) {
this.chart.dispose();
}
},
destroyed() {
window.removeEventListener("resize", this.canvasReset);
},
methods: {
canvasReset() {
debounce(() => {
this.initChart();
}, 500)();
},
initChart() {
if (this.chart) {
this.chart.dispose();
}
this.chart = echarts.init(document.getElementById("factoryStoreChart"));
const actualOptions = JSON.parse(JSON.stringify(this.options));
actualOptions.series[0].data = this.series[0].data;
actualOptions.series[0].name = this.series[0].name;
this.actualOptions = actualOptions;
this.chart.setOption(actualOptions);
},
2024-05-09 15:43:02 +08:00
},
};
</script>
<style></style>