573 lines
14 KiB
Vue
Raw Normal View History

2024-10-22 09:55:33 +08:00
<!--
* @Author: SunTao 328867980@qq.com
* @Date: 2024-10-21 09:59:32
* @LastEditors: SunTao 328867980@qq.com
2024-11-13 15:37:25 +08:00
* @LastEditTime: 2024-11-13 13:39:33
2024-10-22 09:55:33 +08:00
* @FilePath: \znxjxt-ui\src\views\big-screen\traffic-components\traffic-safety.vue
2024-11-13 15:37:25 +08:00
* @Description: 病害巡检大屏-今日巡查
2024-10-22 09:55:33 +08:00
-->
<template>
<div class="content">
<div class="traffic-left">
<span>{{ today }}</span>
</div>
2024-10-22 09:55:33 +08:00
<div class="traffic-right">
2024-11-13 15:37:25 +08:00
<div class="right-sum" @click="showDialog">
<span>{{ all }}</span
>
</div>
<div class="right-rate">
<span> {{ scale }} </span>%
</div>
2024-10-22 09:55:33 +08:00
</div>
2024-11-13 15:37:25 +08:00
<!-- 病害巡检弹窗 -->
<el-dialog
title="当前病害查看"
:visible.sync="showDialogVisible"
width="75rem"
append-to-body
:close-on-click-modal="false"
destroy-on-close
@close="screenCancel"
>
<div class="today-content">
<div ref="leftChart" class="dialog-div"></div>
<div ref="rightChart" class="dialog-div"></div>
</div>
</el-dialog>
2024-10-22 09:55:33 +08:00
</div>
</template>
<script>
2024-11-13 15:37:25 +08:00
import * as echarts from "echarts";
import { roadToday, roadTodayDetail } from "@/api/xj/screen/traffic-screen";
2024-10-22 09:55:33 +08:00
export default {
name: "TrafficSafety",
props: {
// 病害巡检中4种类型点击绑定
bottomTipClick: {
type: String,
default: "",
},
},
data() {
return {
2024-11-13 15:37:25 +08:00
// 新增病害数
today: 0,
2024-11-13 15:37:25 +08:00
// 病害总数
all: 0,
2024-11-13 15:37:25 +08:00
// 病害增长率
scale: 0,
2024-11-13 15:37:25 +08:00
// 弹窗显隐控制
showDialogVisible: false,
// 左侧图表数据
leftChartData: [],
// 右侧图表数据
rightChartData: [],
};
},
2024-11-13 15:37:25 +08:00
watch: {
bottomTipClick: {
handler() {
this.getData();
},
},
},
created() {
this.getData();
},
methods: {
2024-11-13 15:37:25 +08:00
/* 获取数据 */
getData() {
2024-11-13 15:37:25 +08:00
roadToday({ classType: this.bottomTipClick }).then(({ code, data }) => {
if (code === 200) {
this.today = data.today;
this.all = data.all;
this.scale = data.scale;
}
});
},
2024-11-13 15:37:25 +08:00
/* 点击打开弹窗 */
showDialog() {
this.getChartData();
this.showDialogVisible = true;
},
/* 请求弹窗数据 */
getChartData() {
roadTodayDetail({ classType: this.bottomTipClick }).then(
({ code, data }) => {
if (code === 200) {
this.leftChartData = data[0];
this.rightChartData = data[1];
this.$nextTick(() => {
this.drawLeftChart();
this.drawRightChart();
});
}
}
);
},
/* 绘制左侧echart图 */
drawLeftChart() {
const xData = this.leftChartData.map((item) => {
return item.name;
});
const y1Data = this.leftChartData.map((item) => {
return item.road;
});
const y2Data = this.leftChartData.map((item) => {
return item.bridge;
});
const y3Data = this.leftChartData.map((item) => {
return item.event;
});
const y4Data = this.leftChartData.map((item) => {
return item.green;
});
if (this.$refs.leftChart) {
const chart = echarts.init(this.$refs.leftChart);
chart.setOption({
color: [
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "#8DF2FF" }, // 0% 处的颜色
{ offset: 1, color: "#82B3FD" }, // 100% 处的颜色
],
},
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "#8087FF" }, // 0% 处的颜色
{ offset: 1, color: "#532EFF" }, // 100% 处的颜色
],
},
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "#FFB3B3" }, // 0% 处的颜色
{ offset: 1, color: "#FF2E2E" }, // 100% 处的颜色
],
},
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "#F7DA15" }, // 0% 处的颜色
{ offset: 1, color: "#FCC105" }, // 100% 处的颜色
],
},
],
title: {
text: "",
},
tooltip: {
trigger: "axis",
show: true,
confine: false,
backgroundColor: "rgba(9, 24, 48, 0.5)",
borderColor: "rgba(75, 253, 238, 0.4)",
textStyle: {
fontSize: 12,
color: "#ffffff",
},
},
grid: {
left: "3%",
right: "%",
bottom: "3%",
containLabel: true,
},
legend: {
orient: "horizontal",
left: "right",
textStyle: {
color: "#fff",
},
itemWidth: 8,
itemHeight: 8,
},
xAxis: {
type: "category",
axisLabel: {
interval: 0,
color: "#fff",
formatter: (params) => {
if (params.length > 4) {
return `${params.slice(0, 4)}...`;
}
return params;
},
},
axisTick: {
show: false,
},
axisLine: {
show: false,
},
data: xData,
},
yAxis: {
type: "value",
axisLabel: {
color: "rgba(255,255,255,0.65)",
},
splitLine: {
lineStyle: {
color: "rgba(255,255,255,0.2)",
},
},
name: "单位:个",
nameTextStyle: {
color: "rgba(255,255,255,0.65)",
},
},
series: [
{
barWidth: 10,
name: "路面",
type: "bar",
data: y1Data,
},
{
barWidth: 10,
name: "交安",
type: "bar",
data: y3Data,
},
{
barWidth: 10,
name: "道桥",
type: "bar",
data: y2Data,
},
{
barWidth: 10,
name: "绿化",
type: "bar",
data: y4Data,
},
],
});
window.addEventListener("resize", () => {
chart.resize();
});
}
},
/* 绘制右侧echart图 */
drawRightChart() {
const xData = this.rightChartData.map((item) => {
return item.name;
});
const y1Data = this.rightChartData.map((item) => {
return item.road;
});
const y2Data = this.rightChartData.map((item) => {
return item.bridge;
});
const y3Data = this.rightChartData.map((item) => {
return item.event;
});
const y4Data = this.rightChartData.map((item) => {
return item.green;
});
if (this.$refs.rightChart) {
const chart = echarts.init(this.$refs.rightChart);
chart.setOption({
color: [
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "#8DF2FF" }, // 0% 处的颜色
{ offset: 1, color: "#82B3FD" }, // 100% 处的颜色
],
},
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "#8087FF" }, // 0% 处的颜色
{ offset: 1, color: "#532EFF" }, // 100% 处的颜色
],
},
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "#FFB3B3" }, // 0% 处的颜色
{ offset: 1, color: "#FF2E2E" }, // 100% 处的颜色
],
},
{
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "#F7DA15" }, // 0% 处的颜色
{ offset: 1, color: "#FCC105" }, // 100% 处的颜色
],
},
],
title: {
text: "",
},
tooltip: {
trigger: "axis",
show: true,
confine: false,
backgroundColor: "rgba(9, 24, 48, 0.5)",
borderColor: "rgba(75, 253, 238, 0.4)",
textStyle: {
fontSize: 12,
color: "#ffffff",
},
},
grid: {
left: "3%",
right: "%",
bottom: "3%",
containLabel: true,
},
legend: {
orient: "horizontal",
left: "right",
textStyle: {
color: "#fff",
},
itemWidth: 8,
itemHeight: 8,
},
xAxis: {
type: "category",
axisLabel: {
color: "#fff",
},
axisTick: {
show: false,
},
axisLine: {
show: false,
},
data: xData,
},
yAxis: {
type: "value",
axisLabel: {
color: "rgba(255,255,255,0.65)",
},
splitLine: {
lineStyle: {
color: "rgba(255,255,255,0.2)",
},
},
name: "单位:个",
nameTextStyle: {
color: "rgba(255,255,255,0.65)",
},
},
series: [
{
barWidth: 10,
name: "路面",
type: "bar",
data: y1Data,
},
{
barWidth: 10,
name: "交安",
type: "bar",
data: y3Data,
},
{
barWidth: 10,
name: "道桥",
type: "bar",
data: y2Data,
},
{
barWidth: 10,
name: "绿化",
type: "bar",
data: y4Data,
},
],
});
window.addEventListener("resize", () => {
chart.resize();
});
}
},
/* 关闭 弹窗事件 */
screenCancel() {
this.showDialogVisible = false;
},
},
2024-10-22 09:55:33 +08:00
};
</script>
<style lang="scss" scoped>
.content {
width: 100%;
height: 100%;
display: flex;
.traffic-left {
width: 45%;
height: 100%;
color: #ffffff;
display: flex;
align-items: center;
justify-content: center;
padding-left: 1.5rem;
font-size: 2rem;
2024-11-13 15:37:25 +08:00
// background-image: url("../../../assets/screen/traffic/traffic-left.png");
background-image: url("~@/assets/screen/disease/today-left.png");
2024-10-22 09:55:33 +08:00
background-repeat: no-repeat;
background-size: 85%;
background-position: 100% 60%;
span {
font-family: "DouYu";
background: linear-gradient(
to bottom,
#ffffff,
#2773d0
); /*设置渐变的方向从左到右 颜色从ff0000到ffff00*/
background-clip: text; /*将设置的背景颜色限制在文字中*/
-webkit-text-fill-color: transparent; /*给文字设置成透明*/
}
}
.traffic-right {
width: 55%;
height: 100%;
padding: 1rem;
display: flex;
flex-direction: column;
justify-content: space-around;
2024-10-22 09:55:33 +08:00
color: #ffffff;
.right-sum {
2024-11-13 15:37:25 +08:00
cursor: pointer;
2024-10-22 09:55:33 +08:00
width: 100%;
height: 4rem;
display: flex;
padding-left: 1rem;
justify-content: center;
line-height: 3rem;
2024-11-13 15:37:25 +08:00
// background-image: url("../../../assets/screen/traffic/right-sum.png");
background-image: url("~@/assets/screen/disease/right-sum.png");
2024-10-22 09:55:33 +08:00
background-repeat: no-repeat;
background-size: 100%;
background-position: 100% 50%;
color: #aac6c7;
2024-10-22 09:55:33 +08:00
font-size: 0.9rem;
span {
margin-right: 0.5rem;
font-size: 1.2rem;
font-family: "DouYu";
background: linear-gradient(
to bottom,
#ffffff,
#21f1e1
); /*设置渐变的方向从左到右 颜色从ff0000到ffff00*/
background-clip: text; /*将设置的背景颜色限制在文字中*/
-webkit-text-fill-color: transparent; /*给文字设置成透明*/
}
}
.right-rate {
width: 100%;
height: 4rem;
display: flex;
justify-content: center;
padding-left: 1rem;
line-height: 3rem;
2024-11-13 15:37:25 +08:00
// background-image: url("../../../assets/screen/traffic/right-rate.png");
background-image: url("~@/assets/screen/disease/right-rate.png");
2024-10-22 09:55:33 +08:00
background-repeat: no-repeat;
background-size: 100%;
background-position: 100% 50%;
color: #aac6c7;
2024-10-22 09:55:33 +08:00
font-size: 0.9rem;
span {
margin-right: 0.5rem;
font-size: 1.2rem;
font-family: "DouYu";
background: linear-gradient(
to bottom,
#ffffff,
#e9bc5c
); /*设置渐变的方向从左到右 颜色从ff0000到ffff00*/
background-clip: text; /*将设置的背景颜色限制在文字中*/
-webkit-text-fill-color: transparent; /*给文字设置成透明*/
}
}
}
}
2024-11-13 15:37:25 +08:00
// 弹窗内容样式
.today-content {
height: 30rem;
display: flex;
.dialog-div {
width: 50%;
height: 100%;
margin: 0 1rem;
}
}
/* 修改弹窗样式 */
::v-deep .el-dialog__header {
padding: 10px;
background-color: #113463;
span,
i {
color: #ffffff;
}
}
::v-deep .el-dialog__body {
padding: 0;
background-color: #113463;
}
2024-10-22 09:55:33 +08:00
</style>