103 lines
2.2 KiB
Vue
103 lines
2.2 KiB
Vue
<script setup>
|
|
import { ref, onMounted, nextTick } from "vue";
|
|
import * as echarts from "echarts";
|
|
import Container from "../Base/Container.vue";
|
|
import { useWsStore } from "../../store";
|
|
import setupFn from "./LineTodayOptions";
|
|
|
|
const show = ref(false);
|
|
const chartContainer = ref(null);
|
|
const chartInstance = ref(null);
|
|
const store = useWsStore();
|
|
|
|
onMounted(() => {
|
|
chartContainer.value.classList.add("h-full");
|
|
const d = loadData(store.data2.dailyTarget);
|
|
// const d = loadData([
|
|
// {
|
|
// targetProduction: 100,
|
|
// nowProduction: 66,
|
|
// targetYield: 13,
|
|
// nowYield: 3,
|
|
// },
|
|
// ]);
|
|
if (!d) {
|
|
show.value = false;
|
|
if (chartInstance.value) {
|
|
chartInstance.value.dispose();
|
|
chartInstance.value = null;
|
|
}
|
|
} else {
|
|
if (!chartInstance.value)
|
|
chartInstance.value = echarts.init(chartContainer.value);
|
|
setupFn(chartInstance.value, d);
|
|
show.value = true;
|
|
}
|
|
});
|
|
|
|
// 订阅
|
|
store.$subscribe((mutation, state) => {
|
|
const d = loadData(state.data2.dailyTarget);
|
|
// const d = loadData([
|
|
// {
|
|
// targetProduction: 100,
|
|
// nowProduction: 66,
|
|
// targetYield: 13,
|
|
// nowYield: 3,
|
|
// },
|
|
// ]);
|
|
if (!d) {
|
|
show.value = false;
|
|
if (chartInstance.value) {
|
|
chartInstance.value.dispose();
|
|
chartInstance.value = null;
|
|
}
|
|
} else {
|
|
if (!chartInstance.value)
|
|
chartInstance.value = echarts.init(chartContainer.value);
|
|
setupFn(chartInstance.value, d);
|
|
show.value = true;
|
|
}
|
|
});
|
|
|
|
// utils
|
|
function loadData(dailyTarget) {
|
|
if (
|
|
dailyTarget == undefined ||
|
|
// dailyTarget?.length == 0 ||
|
|
!dailyTarget[0]
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
targetProduction: dailyTarget[0].targetProduction,
|
|
nowProduction: dailyTarget[0].nowProduction,
|
|
targetYield: dailyTarget[0].targetYield,
|
|
nowYield: dailyTarget[0].nowYield,
|
|
};
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<Container class="chart" title="本日生产线情况" icon="cube">
|
|
<div
|
|
ref="chartContainer"
|
|
class="chart-chart"
|
|
:style="{ opacity: show ? 1 : 0 }"
|
|
></div>
|
|
<p v-show="!show" class="empty-data-hint">暂无数据</p>
|
|
</Container>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.chart {
|
|
/* height: 300px; */
|
|
height: auto;
|
|
}
|
|
|
|
.chart-chart {
|
|
height: 100%;
|
|
}
|
|
</style>
|