From 1652dae4658228642748ff69ee0fdaa3dfafdfe8 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Mon, 31 Mar 2025 21:45:33 +0800
Subject: [PATCH] refactor: 重构代码前后顺序
---
src/views/Home/components/HomeRight/EventOverview.vue | 212 ++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 161 insertions(+), 51 deletions(-)
diff --git a/src/views/Home/components/HomeRight/EventOverview.vue b/src/views/Home/components/HomeRight/EventOverview.vue
index 22e5042..426573d 100644
--- a/src/views/Home/components/HomeRight/EventOverview.vue
+++ b/src/views/Home/components/HomeRight/EventOverview.vue
@@ -1,6 +1,42 @@
+<template>
+ <CommonTitle title="事件概况" />
+ <div :style="{ marginLeft: pxToRem(14) }">
+ <div class="eventOverview">
+ <div class="overviewData">
+ <div class="totalBox">
+ <div class="totalNumber">{{ total }}</div>
+ <div class="totalLabel">总事件数</div>
+ </div>
+ <div class="contentBox">
+ <div class="overviewItem" v-for="item in list" :key="item.name">
+ <div class="itemName"><img :src="item.img" alt="" />{{ item.name }}</div>
+ <div class="itemValue" :style="{ color: item.color }">{{ item.value }}</div>
+ </div>
+ </div>
+ </div>
+ <CommonDateTime class="dateTime" v-model="newTime" @change="dateChange" />
+
+ <el-select class="homeRightSelect" v-model="value" placeholder="请选择" size="large">
+ <el-option
+ v-for="item in options"
+ :key="item.value"
+ :label="item.label"
+ :value="item.value"
+ />
+ </el-select>
+ <div class="completion">
+ <img class="completion-left-img" :src="completionLeft" alt="" />
+ <div class="completion-text">事件类型完成率情况</div>
+ <div class="completion-separator"></div>
+ <img class="completion-left-img" :src="completionLeft" alt="" />
+ </div>
+
+ <div class="chart" ref="echartsRef"></div>
+ </div>
+ </div>
+</template>
<script setup>
import CommonTitle from '@/components/CommonTitle.vue';
-import { pxToRem } from '@/utils/rem';
import overviewImg1 from '@/assets/images/home/homeRight/overview1.png';
import overviewImg2 from '@/assets/images/home/homeRight/overview2.png';
import overviewImg3 from '@/assets/images/home/homeRight/overview3.png';
@@ -10,6 +46,14 @@
import completionLeft from '@/assets/images/home/homeRight/completionLeft.png';
import * as echarts from 'echarts';
import CommonDateTime from '@/components/CommonDateTime.vue';
+import {
+ getJobEventBrokerLine,
+ getJobEventByStatus,
+ getJobEventTotal,
+ getJobNumBar,
+ getJobStatistics,
+} from '@/api/home';
+import dayjs from 'dayjs';
const list = ref([
{ name: '待审核', value: 265, img: overviewImg1, color: '#FF8E8E' },
@@ -20,7 +64,7 @@
{ name: '已完结', value: 262, img: overviewImg6, color: '#8EFFAC' },
]);
const value = ref('');
-const echartsRef = ref('');
+const echartsRef = ref(null);
const options = [
{
@@ -28,6 +72,8 @@
label: 'Option1',
},
];
+const currenDate = dayjs().format('YYYY-MM-DD');
+const newTime = ref([currenDate, currenDate]);
const option = {
tooltip: {
trigger: 'axis',
@@ -35,22 +81,48 @@
type: 'shadow',
},
},
- legend: {},
grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
+ top: '5%',
+ left: 0,
+ right: 0,
+ bottom: 0,
containLabel: true,
},
xAxis: [
{
type: 'category',
- data: ['暴露垃圾', '占道'],
+ axisLabel: {
+ rotate: -45, // 旋转角度
+ interval: 0, // 显示所有标签
+ color: '#FFFFFF',
+ fontFamily: 'Source Han Sans CN, Source Han Sans CN',
+ fontWeight: 400,
+ fontSize: 10,
+ },
+ data: ['暴露垃圾', '占道', '暴露垃圾', '占道', '暴露垃圾', '占道', '暴露垃圾', '占道'],
},
],
yAxis: [
{
type: 'value',
+ axisLabel: {
+ interval: 0, // 显示所有标签
+ color: '#FFFFFF',
+ fontFamily: 'Source Han Sans CN, Source Han Sans CN',
+ fontWeight: 400,
+ fontSize: 10,
+ },
+ axisLine: {
+ lineStyle: {
+ color: '#ffffff',
+ },
+ },
+ splitLine: {
+ lineStyle: {
+ color: 'rgba(255, 255, 255, 0.1)',
+ type: 'dashed', // 设置为虚线
+ },
+ },
},
],
series: [
@@ -61,7 +133,10 @@
emphasis: {
focus: 'series',
},
- data: [120, 132],
+ itemStyle: {
+ color: '#FF8E8E', // 设置颜色
+ },
+ data: [120, 132, 120, 132, 120, 132, 120, 132],
},
{
name: '已完成',
@@ -70,56 +145,85 @@
emphasis: {
focus: 'series',
},
- data: [220, 182],
+ data: [120, 132, 120, 132, 120, 132, 120, 132],
+ },
+ {
+ name: '已完成1',
+ type: 'bar',
+ stack: 'Ad',
+ emphasis: {
+ focus: 'series',
+ },
+ data: [120, 132, 120, 132, 120, 132, 120, 132],
+ },
+ {
+ name: '已完成2',
+ type: 'bar',
+ stack: 'Ad',
+ emphasis: {
+ focus: 'series',
+ },
+ data: [120, 132, 120, 132, 120, 132, 120, 132],
+ },
+ {
+ name: '完成率',
+ type: 'line',
+ itemStyle: {
+ color: '#0CEBF7', // 设置颜色
+ },
+ lineStyle: {
+ width: 2, // 线条宽度
+ type: 'solid', // 线条类型
+ },
+ symbol: 'circle', // 数据点符号
+ symbolSize: 6, // 数据点符号大小
+ emphasis: {
+ focus: 'series',
+ },
+ data: [50, 55, 60, 65, 70, 75, 80, 85], // 示例数据,根据实际完成率计算
},
],
+};
+const total = ref(0);
+
+const getData = () => {
+ const params = {
+ date_enum: 'TODAY',
+ // start_date: newTime.value[0],
+ // end_date: newTime.value[1]
+ };
+ getJobEventByStatus(params).then(res => {
+ const resList = res?.data?.data || [];
+ resList.forEach(item => {
+ list.value.forEach(item1 => {
+ if (item1.name === item.name) {
+ item1.value = item.num;
+ }
+ });
+ });
+ });
+ // todo 未对接
+ getJobEventBrokerLine(params).then(res => {});
+};
+
+const dateChange = value => {
+ console.log(value);
+ newTime.value = value;
+ getData();
};
onMounted(() => {
const chart = echarts.init(echartsRef.value);
-
chart.setOption(option);
+ window.addEventListener('resize', () => {
+ chart.resize();
+ });
+ getJobEventTotal().then(res => {
+ total.value = res?.data?.data || 0;
+ });
+ getData();
});
</script>
-
-<template>
- <CommonTitle title="事件概况" />
- <div :style="{ marginLeft: pxToRem(14) }">
- <div class="eventOverview">
- <div class="overviewData">
- <div class="totalBox">
- <div class="totalNumber">8096</div>
- <div class="totalLabel">总事件数</div>
- </div>
- <div class="contentBox">
- <div class="overviewItem" v-for="item in list" :key="item.name">
- <div class="itemName"><img :src="item.img" alt="" />{{ item.name }}</div>
- <div class="itemValue" :style="{ color: item.color }">{{ item.value }}</div>
- </div>
- </div>
- </div>
- <CommonDateTime class="dateTime" />
-
- <el-select class="homeRightSelect" v-model="value" placeholder="请选择" size="large">
- <el-option
- v-for="item in options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
-
- <div class="completion">
- <img class="completion-left-img" :src="completionLeft" />
- <div class="completion-text">事件类型完成率情况</div>
- <div class="completion-separator"></div>
- <img class="completion-left-img" :src="completionLeft" />
- </div>
-
- <div class="chart" ref="echartsRef"></div>
- </div>
- </div>
-</template>
<style scoped lang="scss">
.homeRightSelect {
@@ -129,6 +233,7 @@
.el-select__wrapper {
background: linear-gradient(90deg, #195bad 0%, rgba(25, 91, 173, 0) 100%);
min-height: 28px;
+ height: 28px;
box-shadow: none;
border: 1px solid #306fca;
}
@@ -136,6 +241,7 @@
.el-select__placeholder {
font-family: Microsoft YaHei, Microsoft YaHei, serif;
color: #ffffff;
+ font-size: 14px;
}
}
}
@@ -157,8 +263,9 @@
flex-direction: column;
align-items: center;
- .dateTime{
+ .dateTime {
width: 356px;
+ margin: 15px 0 8px 0;
}
.overviewData {
@@ -171,6 +278,8 @@
padding-left: 11px;
.totalBox {
+ width: 77px;
+
.totalNumber {
font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
font-weight: 400;
@@ -231,6 +340,7 @@
justify-content: space-between;
width: 356px;
height: 23px;
+ margin-top: 16px;
&--left-img {
width: 16px;
@@ -255,7 +365,7 @@
.chart {
width: 356px;
- height: 182px;
+ height: 190px;
}
}
</style>
--
Gitblit v1.9.3