yudao-init/src/views/copilot/yield/components/sub/ring/DoubleRingChart.vue

345 lines
9.8 KiB
Vue
Raw Normal View History

2024-05-08 16:38:05 +08:00
<!--
2024-05-29 17:05:55 +08:00
* @Author: zhp
* @Date: 2024-05-20 13:32:59
2024-06-03 16:42:28 +08:00
* @LastEditTime: 2024-06-03 16:26:24
2024-05-29 17:05:55 +08:00
* @LastEditors: zhp
* @Description:
2024-04-18 17:01:10 +08:00
-->
<template>
<div class="double-ring-chart">
2024-05-20 10:20:37 +08:00
<!-- <div> -->
<div ref="chart" class="double-ring-chart__container"></div>
<!-- </div> -->
2024-04-28 16:55:21 +08:00
<!-- style="{ height: vHeight + 'vh' }" -->
2024-04-18 17:01:10 +08:00
<div class="double-ring-chart__legend">
<div v-for="item in legendItems" :key="item.label" class="legend-item">
<span class="legend-item__label">{{ item.label }}</span>
2024-04-28 10:59:05 +08:00
<span class="legend-item__value">{{ item.value | numberFilter }}</span>
2024-04-18 17:01:10 +08:00
</div>
</div>
</div>
</template>
<script>
import chartMixin from "@/mixins/chart.js";
2024-05-20 10:20:37 +08:00
import screenfull from "screenfull";
2024-04-28 14:54:54 +08:00
import getOptions from "../../../options/double-ring-chart-options";
2024-04-18 17:01:10 +08:00
export default {
name: "DoubleRingChart",
2024-05-20 10:20:37 +08:00
mixins: [chartMixin],
2024-04-18 17:01:10 +08:00
props: {
vHeight: {
type: Number,
default: 24,
},
2024-04-28 10:59:05 +08:00
factoryId: {
type: Number,
required: true,
},
2024-04-24 16:31:27 +08:00
period: {
type: String,
default: "日",
2024-04-18 17:01:10 +08:00
},
2024-04-26 17:05:26 +08:00
dataSource: {
type: String,
default: null,
},
2024-05-29 17:05:55 +08:00
than: {
type: String,
default: "同比",
},
2024-04-18 17:01:10 +08:00
},
data() {
2024-05-20 10:20:37 +08:00
return {
isFullscreen: false,
};
2024-04-18 17:01:10 +08:00
},
2024-04-28 10:59:05 +08:00
filters: {
numberFilter(val) {
if (!isNaN(val)) {
return (+val).toLocaleString();
}
return 0;
},
},
2024-04-24 16:31:27 +08:00
computed: {
2024-04-28 10:59:05 +08:00
dataSourceField() {
switch (this.dataSource) {
case "标准组件产出":
return "stdOutput";
case "芯片产出":
return "chipOutput";
case "BIPV产出":
return "bipvOutput";
}
},
valueTuple() {
// [previousValue, currentValue, sumValue?]
const getter = this.$store.getters.copilot.yield[this.dataSourceField];
if (this.period === "日" || this.period === "周") {
2024-05-08 16:38:05 +08:00
console.log(this.period)
2024-04-28 10:59:05 +08:00
return [
getter.previous[this.factoryId],
getter.current[this.factoryId],
];
}
2024-04-28 16:55:21 +08:00
// [100, 200, 200]
2024-04-28 10:59:05 +08:00
return [
getter.previous[this.factoryId],
getter.current[this.factoryId],
getter.target[this.factoryId],
];
2024-04-24 16:31:27 +08:00
},
2024-04-28 10:59:05 +08:00
2024-04-26 17:05:26 +08:00
options() {
2024-05-29 17:05:55 +08:00
const today = new Date().getDate();
2024-04-28 10:59:05 +08:00
const year = new Date().getFullYear();
const month = new Date().getMonth() + 1;
const vt = this.valueTuple;
2024-05-29 17:05:55 +08:00
let items = [];
var day1 = new Date();
day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000);
var yesterday = (day1.getMonth() + 1) + "月" + day1.getDate()
//今天的时间
// var day2 = new Date();
// day2.setTime(day2.getTime());
// var s2 = (day2.getMonth() + 1) + "月" + day2.getDate() + '日';
// const today = new Date().getDate();
// let yesterday = new Date().getDate() -1;
// const month = new Date().getMonth() + 1;
const lastMonth = new Date().getMonth() + 1 === 12 ? 1 : new Date().getMonth() + 1 - 1;
// const year = new Date().getFullYear();
if (this.period === '日' && this.than === '同比') {
items = [
{ label: `${month}${today}日累计`,},
{ label: `去年${month}${today}日累计` },
];
} else if (this.period === '日' && this.than === '环比') {
items = [
{ label: `${month}${today}日累计`},
{ label: `${yesterday}日累计`},
];
} else if (this.period === '周' && this.than === '同比') {
items = [
{ label: `本周累计`,},
{ label: `去年本周累计`},
];
} else if (this.period === '周' && this.than === '环比') {
items = [
{ label: `本周累计`,},
{ label: `上周累计`,},
];
} else if (this.period === '月' && this.than === '同比') {
items = [
{ label: `${month}月累计`,},
{ label: `去年${month}月累计`, },
{ label: `${month}月目标`,},
];
} else if (this.period === '月' && this.than === '环比') {
items = [
{ label: `${month}月累计`, },
{ label: `${lastMonth}月累计`,},
{ label: `${month}月目标`, },
];
} else {
items = [
{ label: `${year}年累计`, },
{ label: `${year - 1}年累计` },
{ label: `${year}年目标` },
];
}
2024-04-28 10:59:05 +08:00
let titleValue =
2024-06-03 16:42:28 +08:00
vt[1] != null && (vt[2] !== 0 && vt[2] !== undefined)
2024-06-03 08:23:40 +08:00
? this.formatNumber((vt[1] / vt[2] * 100)) + '%'
: (vt[1] != 0 && vt[1] != null) && vt[2] == 0
? "100%" : '0%',
2024-04-28 10:59:05 +08:00
subtitle =
2024-05-29 17:05:55 +08:00
this.period == "日" ? `${month}${today}日累计` : this.period == "周" ? `本周` : this.period == "月" ? `${month}月累计产出` : `${year}年累计产出`;
console.log(this.valueTuple[0], this.valueTuple[1], this.valueTuple[2],)
console.log(items)
2024-04-26 17:05:26 +08:00
return getOptions({
titleValue,
subtitle,
2024-05-29 17:05:55 +08:00
currentName: items[0].label,
preName: items[1].label,
2024-04-28 10:59:05 +08:00
previousSum: this.valueTuple[0],
currentSum: this.valueTuple[1],
2024-05-29 17:05:55 +08:00
targetSum: this.valueTuple[2] ? this.valueTuple[2] :0 ,
2024-04-26 17:05:26 +08:00
});
},
2024-04-28 10:59:05 +08:00
legendItems() {
2024-05-29 17:05:55 +08:00
return calculateItems(this.period, this.valueTuple,this.than);
2024-04-28 10:59:05 +08:00
},
},
watch: {
2024-05-20 10:20:37 +08:00
isFullscreen(val) {
// this.actualOptions.series.map((item) => {
// item.barWidth = val ? 18 : 12;
// });
// this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
this.initOptions(this.options)
},
2024-04-28 10:59:05 +08:00
legendItems() {
this.initOptions(this.options);
},
2024-04-24 16:31:27 +08:00
},
2024-04-18 17:01:10 +08:00
mounted() {
2024-04-26 17:05:26 +08:00
this.initOptions(this.options);
2024-05-20 10:20:37 +08:00
if (screenfull.isEnabled) {
screenfull.on("change", () => {
this.isFullscreen = screenfull.isFullscreen;
});
}
2024-04-18 17:01:10 +08:00
},
methods: {
2024-06-03 08:23:40 +08:00
formatNumber(num) {
// 判断是否为整数
if (Number.isInteger(num)) {
return num; // 如果是整数,直接转换为字符串
} else {
// 如果不是整数,保留两位小数并转换为字符串
return num.toFixed(2);
}
}
2024-04-18 17:01:10 +08:00
// fullscreen mixin 需要的回调
2024-05-20 10:20:37 +08:00
// fullscreenCallback(isFullscreen) {
// console.log("isFullscreen--->", isFullscreen);
// },
2024-04-18 17:01:10 +08:00
},
};
2024-04-24 16:31:27 +08:00
2024-05-29 17:05:55 +08:00
function calculateItems(period, valueTuple,than) {
2024-04-24 16:31:27 +08:00
let items = [];
2024-05-29 17:05:55 +08:00
var day1 = new Date();
day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000);
var yesterday = (day1.getMonth() + 1) + "月" + day1.getDate()
//今天的时间
// var day2 = new Date();
// day2.setTime(day2.getTime());
// var s2 = (day2.getMonth() + 1) + "月" + day2.getDate() + '日';
2024-04-24 16:31:27 +08:00
const today = new Date().getDate();
2024-05-29 17:05:55 +08:00
// let yesterday = new Date().getDate() -1;
2024-04-24 16:31:27 +08:00
const month = new Date().getMonth() + 1;
2024-05-29 17:05:55 +08:00
const lastMonth = new Date().getMonth() + 1 === 12 ? 1 : new Date().getMonth() + 1 -1;
2024-04-24 16:31:27 +08:00
const year = new Date().getFullYear();
2024-05-29 17:05:55 +08:00
if (period === '日' && than === '同比') {
items = [
{ label: `去年${month}${today}日累计`, value: valueTuple[0] },
2024-06-03 08:23:40 +08:00
{ label: `${month}${today}日累计`, value: valueTuple[1] },
2024-05-29 17:05:55 +08:00
];
} else if (period === '日' && than === '环比') {
items = [
{ label: `${yesterday}日累计`, value: valueTuple[0] },
2024-06-03 08:23:40 +08:00
{ label: `${month}${today}日累计`, value: valueTuple[1] },
2024-05-29 17:05:55 +08:00
];
} else if (period === '周' && than === '同比') {
items = [
{ label: `去年本周累计`, value: valueTuple[0] },
2024-06-03 08:23:40 +08:00
{ label: `本周累计`, value: valueTuple[1] },
2024-05-29 17:05:55 +08:00
];
} else if (period === '周' && than === '环比') {
items = [
{ label: `上周累计`, value: valueTuple[0] },
2024-06-03 08:23:40 +08:00
{ label: `本周累计`, value: valueTuple[1] },
2024-05-29 17:05:55 +08:00
];
} else if (period === '月' && than === '同比') {
items = [
{ label: `去年${month}月累计`, value: valueTuple[0] },
2024-06-03 08:23:40 +08:00
{ label: `${month}月累计`, value: valueTuple[1] },
2024-05-29 17:05:55 +08:00
{ label: `${month}月目标`, value: valueTuple[2] },
];
} else if (period === '月' && than === '环比') {
items = [
{ label: `${lastMonth}月累计`, value: valueTuple[0] },
2024-06-03 08:23:40 +08:00
{ label: `${month}月累计`, value: valueTuple[1] },
2024-05-29 17:05:55 +08:00
{ label: `${month}月目标`, value: valueTuple[2] },
];
} else {
items = [
{ label: `${year - 1}年累计`, value: valueTuple[0] },
2024-06-03 08:23:40 +08:00
{ label: `${year}年累计`, value: valueTuple[1] },
2024-05-29 17:05:55 +08:00
{ label: `${year}年目标`, value: valueTuple[2] },
];
2024-04-24 16:31:27 +08:00
}
2024-05-29 17:05:55 +08:00
// switch (period) {
// case "年":
// items = [
// { label: `${year}年累计`, value: valueTuple[1] },
// { label: `${year - 1}年累计`, value: valueTuple[0] },
// { label: `${year}年目标`, value: valueTuple[2] },
// ];
// break;
// }
2024-04-24 16:31:27 +08:00
return items;
}
2024-04-18 17:01:10 +08:00
</script>
<style scoped>
.double-ring-chart {
height: 100%;
display: flex;
flex-direction: column;
}
.double-ring-chart__container {
2024-05-20 10:20:37 +08:00
flex:1 1 auto;
2024-05-10 11:10:42 +08:00
padding: 0 10%;
/* margin: 10%; */
/* min-width: 300px; */
2024-05-30 16:00:18 +08:00
align-self: stretch;
2024-04-18 17:01:10 +08:00
height: 0;
}
.double-ring-chart__legend {
padding: 12px;
color: #fff;
display: flex;
justify-content: center;
gap: 32px;
}
.legend-item {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.legend-item__label {
position: relative;
}
.legend-item__label::before {
content: "";
position: absolute;
width: 12px;
height: 12px;
background: #ccc;
border-radius: 2px;
top: 6px;
left: -18px;
}
2024-06-03 08:23:40 +08:00
.legend-item:nth-child(2) .legend-item__label::before {
2024-04-26 17:05:26 +08:00
background: #12fff5;
2024-04-18 17:01:10 +08:00
}
2024-06-03 08:23:40 +08:00
.legend-item:nth-child(2) .legend-item__value {
2024-04-26 17:05:26 +08:00
color: #12fff5;
2024-04-18 17:01:10 +08:00
}
2024-06-03 08:23:40 +08:00
.legend-item:nth-child(1) .legend-item__label::before {
2024-04-26 17:05:26 +08:00
background: #0f65ff;
2024-04-18 17:01:10 +08:00
}
2024-06-03 08:23:40 +08:00
.legend-item:nth-child(1) .legend-item__value {
2024-04-26 17:05:26 +08:00
color: #0f65ff;
2024-04-18 17:01:10 +08:00
}
.legend-item:nth-child(3) .legend-item__label::before {
background: #003982;
}
</style>