2024-05-09 15:43:02 +08:00
|
|
|
<template>
|
2024-05-20 14:54:18 +08:00
|
|
|
<div>
|
|
|
|
<NotMsg v-show="notMsg" />
|
|
|
|
<div
|
|
|
|
id="factoryStoreChart"
|
|
|
|
style="width: 100%; height: 100%"
|
|
|
|
v-show="!notMsg"
|
|
|
|
></div>
|
|
|
|
</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-20 14:54:18 +08:00
|
|
|
import NotMsg from "./../../components/NotMsg";
|
2024-05-09 15:43:02 +08:00
|
|
|
export default {
|
|
|
|
name: "Store",
|
2024-05-20 14:54:18 +08:00
|
|
|
components: { NotMsg },
|
2024-05-09 15:43:02 +08:00
|
|
|
props: {
|
2024-05-20 14:54:18 +08:00
|
|
|
stock: {
|
|
|
|
type: Object,
|
2024-05-09 15:43:02 +08:00
|
|
|
required: true,
|
|
|
|
},
|
2024-05-20 14:54:18 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isOpen() {
|
|
|
|
return this.$store.getters.sidebar.opened;
|
2024-05-09 15:43:02 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isFullscreen: false,
|
|
|
|
actualOptions: null,
|
2024-05-20 14:54:18 +08:00
|
|
|
notMsg: false,
|
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",
|
2024-05-20 14:54:18 +08:00
|
|
|
top: "15%",
|
2024-05-09 15:43:02 +08:00
|
|
|
containLabel: true,
|
|
|
|
},
|
|
|
|
tooltip: {},
|
|
|
|
xAxis: {
|
|
|
|
axisTick: {
|
|
|
|
show: false,
|
|
|
|
},
|
|
|
|
axisLine: {
|
|
|
|
lineStyle: {
|
|
|
|
color: "#4561AE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
axisLabel: {
|
|
|
|
color: "rgba(255, 255, 255, 0.7)",
|
|
|
|
fontSize: 12,
|
|
|
|
},
|
2024-05-20 14:54:18 +08:00
|
|
|
data: [],
|
2024-05-09 15:43:02 +08:00
|
|
|
},
|
|
|
|
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: {
|
2024-05-20 14:54:18 +08:00
|
|
|
stock(val) {
|
|
|
|
this.initChart();
|
|
|
|
},
|
|
|
|
isOpen(val) {
|
|
|
|
this.canvasReset();
|
2024-05-09 15:43:02 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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() {
|
2024-05-20 14:54:18 +08:00
|
|
|
let xAxis = Object.keys(this.stock) || [];
|
|
|
|
let data = [];
|
|
|
|
if (xAxis.length > 0) {
|
|
|
|
this.notMsg = false;
|
|
|
|
data = xAxis.map((item) => {
|
|
|
|
return this.stock[item].total;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.notMsg = true;
|
|
|
|
}
|
2024-05-09 18:35:12 +08:00
|
|
|
if (this.chart) {
|
|
|
|
this.chart.dispose();
|
|
|
|
}
|
|
|
|
this.chart = echarts.init(document.getElementById("factoryStoreChart"));
|
|
|
|
const actualOptions = JSON.parse(JSON.stringify(this.options));
|
2024-05-20 14:54:18 +08:00
|
|
|
actualOptions.xAxis.data = xAxis;
|
|
|
|
actualOptions.series[0].data = data;
|
2024-05-09 18:35:12 +08:00
|
|
|
this.actualOptions = actualOptions;
|
|
|
|
this.chart.setOption(actualOptions);
|
|
|
|
},
|
2024-05-09 15:43:02 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style></style>
|