| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- <template>
- <div class="score-layout">
- <div class="score-left">
- <div class="score-header">
- <span class="score-title">综合评分</span>
- <el-radio-group v-model="timeSelect" class="score-select" @change="changeTime">
- <el-radio-button v-for="item in ScoreTimeList" :label="item.label" :value="item.value" />
- </el-radio-group>
- </div>
- <el-divider />
- <div class="score-show">
- <VChart class="pic-show" :option="options" />
- </div>
- </div>
- <div class="score-divider"></div>
- <div class="score-right">
- <div class="concern-title">重点关注车间</div>
- <ul v-if="workshopList.length > 0" class="concern-workspace">
- <li v-for="workshop in workshopList">{{ workshop }}</li>
- </ul>
- <div class="score-tip">
- <el-icon><Warning /></el-icon>
- <div class="tip-content">动态显示当前安全评分最低的三个车间</div>
- </div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { ref, onMounted } from 'vue';
- import { ScoreTimeList, TimeEnum } from '../types';
- import { computed } from 'vue';
- import VChart from 'vue-echarts';
- import { use } from 'echarts/core';
- import { CanvasRenderer } from 'echarts/renderers';
- import { BarChart } from 'echarts/charts';
- import { Warning } from '@element-plus/icons-vue';
- import {
- TooltipComponent,
- LegendComponent,
- GridComponent,
- DataZoomComponent,
- } from 'echarts/components';
- import useScore from '../hooks/useScoreInfo';
- import useWorkshopTop from '../hooks/useWorkshopTop';
- const useTop = useWorkshopTop();
- const { openTopWs, workshopList } = useTop;
- onMounted(() => {
- openTopWs();
- console.log('workshopList', workshopList.value);
- });
- const useHomeScore = useScore();
- const {
- scoreInfoList,
- getDailyScoreList,
- getWeeklyScoreList,
- getMonthlyScoreList,
- getQuarterlyScoreList,
- } = useHomeScore;
- use([
- CanvasRenderer,
- BarChart,
- TooltipComponent,
- LegendComponent,
- GridComponent,
- DataZoomComponent,
- ]);
- const timeSelect = ref<TimeEnum>(TimeEnum.DAY);
- //const workspaceList = ['车间1', '车间2', '车间3'];
- const dataZoomConfig = computed(() => [
- {
- type: 'slider',
- show: true,
- showDetail: false,
- showDataShadow: false,
- xAxisIndex: [0],
- start: 0,
- end: Number(10 / scoreInfoList.value.length) * 100,
- handleSize: 1,
- height: 7,
- bottom: 2,
- brushSelect: false,
- handleStyle: {
- opacity: 0,
- },
- },
- {
- // 没有下面这块的话,只能拖动滚动条,
- // 鼠标滚轮在区域内不能控制外部滚动条
- type: 'inside',
- // 控制哪个轴,如果是number表示控制一个轴,
- // 如果是Array表示控制多个轴。此处控制第二根轴
- xAxisIndex: [0, 1],
- // 滚轮是否触发缩放
- zoomOnMouseWheel: false,
- // 鼠标移动能否触发平移
- moveOnMouseMove: true,
- // 鼠标滚轮能否触发平移
- moveOnMouseWheel: true,
- },
- ]);
- const options = computed(() => {
- return {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'none',
- },
- formatter: (v) => {
- let [a] = v;
- const workshopList = scoreInfoList.value.find(
- (item) => item.date === a.name,
- )?.workshopList;
- return `
- <div class='u-p-2'>
- <div>评分最低的三个车间</div>
- ${workshopList?.map((t) => `<span style="color: blue;">•</span> ${t}`).join('<br>')}
- </div>
- `;
- },
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '4%',
- top: '10%',
- containLabel: true,
- },
- xAxis: {
- type: 'category',
- data: scoreInfoList.value.map((item) => item.date),
- axisLabel: {
- interval: 0, // 强制显示所有标签
- //rotate: dataChart.value.map((item) => item.name).length > 10 ? 45 : 0, // 旋转角度
- margin: 20, // 调整标签与轴线的距离,避免标签被遮挡
- },
- },
- yAxis: {
- type: 'value',
- },
- series: [
- {
- data: scoreInfoList.value.map((item) => item.score),
- type: 'bar',
- },
- ],
- dataZoom: scoreInfoList.value.length > 10 ? dataZoomConfig.value : null,
- // 启用数据区域缩放
- };
- });
- const changeTime = () => {
- switch (timeSelect.value) {
- case TimeEnum.DAY:
- getDailyScoreList();
- break;
- case TimeEnum.WEEK:
- getWeeklyScoreList();
- break;
- case TimeEnum.MONTH:
- getMonthlyScoreList();
- break;
- case TimeEnum.QUARTER:
- getQuarterlyScoreList();
- break;
- }
- };
- </script>
- <style scoped>
- .score-layout {
- display: flex;
- }
- .score-left {
- display: flex;
- /* width: 965px; */
- flex-grow: 1;
- flex-direction: column;
- }
- .score-right {
- width: 158px;
- flex-shrink: 0;
- }
- .score-header {
- display: flex;
- justify-content: space-between;
- height: 50px;
- }
- .score-show {
- flex-grow: 1;
- width: calc(100%-660px);
- overflow-x: auto;
- }
- .score-title {
- font-size: 16px;
- margin-top: 17px;
- margin-left: 18px;
- }
- .score-select {
- /* flex-grow: 1; */
- margin-right: 10px;
- }
- .score-divider {
- width: 1px;
- height: 320px;
- background: #e9e9e9;
- /* margin-left: 29px;
- margin-right: 27px; */
- }
- .el-divider--horizontal {
- margin: 0px;
- }
- .pic-show {
- flex-grow: 1;
- height: 270px;
- }
- .concern-title {
- margin-left: 20px;
- margin-top: 51px;
- font-size: 14px;
- }
- .concern-workspace {
- margin-left: 23px;
- margin-top: 24px;
- font-size: 14px;
- color: rgba(0, 0, 0, 0.65);
- }
- li {
- margin-bottom: 16px;
- }
- li:before {
- content: '•';
- color: red;
- display: inline-block;
- margin-right: 20px;
- width: 8px;
- height: 8px;
- font-size: 16px;
- line-height: 1;
- }
- .score-tip {
- display: flex;
- margin-top: 20px;
- margin-left: 14px;
- }
- .tip-content {
- margin-left: 16px;
- margin-right: 14px;
- color: rgba(0, 0, 0, 0.45);
- font-size: 10px;
- }
- </style>
|