Score.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div class="score-layout">
  3. <div class="score-left">
  4. <div class="score-header">
  5. <span class="score-title">综合评分</span>
  6. <el-radio-group v-model="timeSelect" class="score-select" @change="changeTime">
  7. <el-radio-button v-for="item in ScoreTimeList" :label="item.label" :value="item.value" />
  8. </el-radio-group>
  9. </div>
  10. <el-divider />
  11. <div class="score-show">
  12. <VChart class="pic-show" :option="options" />
  13. </div>
  14. </div>
  15. <div class="score-divider"></div>
  16. <div class="score-right">
  17. <div class="concern-title">重点关注车间</div>
  18. <ul v-if="workshopList.length > 0" class="concern-workspace">
  19. <li v-for="workshop in workshopList">{{ workshop }}</li>
  20. </ul>
  21. <div class="score-tip">
  22. <el-icon><Warning /></el-icon>
  23. <div class="tip-content">动态显示当前安全评分最低的三个车间</div>
  24. </div>
  25. </div>
  26. </div>
  27. </template>
  28. <script setup lang="ts">
  29. import { ref, onMounted } from 'vue';
  30. import { ScoreTimeList, TimeEnum } from '../types';
  31. import { computed } from 'vue';
  32. import VChart from 'vue-echarts';
  33. import { use } from 'echarts/core';
  34. import { CanvasRenderer } from 'echarts/renderers';
  35. import { BarChart } from 'echarts/charts';
  36. import { Warning } from '@element-plus/icons-vue';
  37. import {
  38. TooltipComponent,
  39. LegendComponent,
  40. GridComponent,
  41. DataZoomComponent,
  42. } from 'echarts/components';
  43. import useScore from '../hooks/useScoreInfo';
  44. import useWorkshopTop from '../hooks/useWorkshopTop';
  45. const useTop = useWorkshopTop();
  46. const { openTopWs, workshopList } = useTop;
  47. onMounted(() => {
  48. openTopWs();
  49. console.log('workshopList', workshopList.value);
  50. });
  51. const useHomeScore = useScore();
  52. const {
  53. scoreInfoList,
  54. getDailyScoreList,
  55. getWeeklyScoreList,
  56. getMonthlyScoreList,
  57. getQuarterlyScoreList,
  58. } = useHomeScore;
  59. use([
  60. CanvasRenderer,
  61. BarChart,
  62. TooltipComponent,
  63. LegendComponent,
  64. GridComponent,
  65. DataZoomComponent,
  66. ]);
  67. const timeSelect = ref<TimeEnum>(TimeEnum.DAY);
  68. //const workspaceList = ['车间1', '车间2', '车间3'];
  69. const dataZoomConfig = computed(() => [
  70. {
  71. type: 'slider',
  72. show: true,
  73. showDetail: false,
  74. showDataShadow: false,
  75. xAxisIndex: [0],
  76. start: 0,
  77. end: Number(10 / scoreInfoList.value.length) * 100,
  78. handleSize: 1,
  79. height: 7,
  80. bottom: 2,
  81. brushSelect: false,
  82. handleStyle: {
  83. opacity: 0,
  84. },
  85. },
  86. {
  87. // 没有下面这块的话,只能拖动滚动条,
  88. // 鼠标滚轮在区域内不能控制外部滚动条
  89. type: 'inside',
  90. // 控制哪个轴,如果是number表示控制一个轴,
  91. // 如果是Array表示控制多个轴。此处控制第二根轴
  92. xAxisIndex: [0, 1],
  93. // 滚轮是否触发缩放
  94. zoomOnMouseWheel: false,
  95. // 鼠标移动能否触发平移
  96. moveOnMouseMove: true,
  97. // 鼠标滚轮能否触发平移
  98. moveOnMouseWheel: true,
  99. },
  100. ]);
  101. const options = computed(() => {
  102. return {
  103. tooltip: {
  104. trigger: 'axis',
  105. axisPointer: {
  106. type: 'none',
  107. },
  108. formatter: (v) => {
  109. let [a] = v;
  110. const workshopList = scoreInfoList.value.find(
  111. (item) => item.date === a.name,
  112. )?.workshopList;
  113. return `
  114. <div class='u-p-2'>
  115. <div>评分最低的三个车间</div>
  116. ${workshopList?.map((t) => `<span style="color: blue;">•</span> ${t}`).join('<br>')}
  117. </div>
  118. `;
  119. },
  120. },
  121. grid: {
  122. left: '3%',
  123. right: '4%',
  124. bottom: '4%',
  125. top: '10%',
  126. containLabel: true,
  127. },
  128. xAxis: {
  129. type: 'category',
  130. data: scoreInfoList.value.map((item) => item.date),
  131. axisLabel: {
  132. interval: 0, // 强制显示所有标签
  133. //rotate: dataChart.value.map((item) => item.name).length > 10 ? 45 : 0, // 旋转角度
  134. margin: 20, // 调整标签与轴线的距离,避免标签被遮挡
  135. },
  136. },
  137. yAxis: {
  138. type: 'value',
  139. },
  140. series: [
  141. {
  142. data: scoreInfoList.value.map((item) => item.score),
  143. type: 'bar',
  144. },
  145. ],
  146. dataZoom: scoreInfoList.value.length > 10 ? dataZoomConfig.value : null,
  147. // 启用数据区域缩放
  148. };
  149. });
  150. const changeTime = () => {
  151. switch (timeSelect.value) {
  152. case TimeEnum.DAY:
  153. getDailyScoreList();
  154. break;
  155. case TimeEnum.WEEK:
  156. getWeeklyScoreList();
  157. break;
  158. case TimeEnum.MONTH:
  159. getMonthlyScoreList();
  160. break;
  161. case TimeEnum.QUARTER:
  162. getQuarterlyScoreList();
  163. break;
  164. }
  165. };
  166. </script>
  167. <style scoped>
  168. .score-layout {
  169. display: flex;
  170. }
  171. .score-left {
  172. display: flex;
  173. /* width: 965px; */
  174. flex-grow: 1;
  175. flex-direction: column;
  176. }
  177. .score-right {
  178. width: 158px;
  179. flex-shrink: 0;
  180. }
  181. .score-header {
  182. display: flex;
  183. justify-content: space-between;
  184. height: 50px;
  185. }
  186. .score-show {
  187. flex-grow: 1;
  188. width: calc(100%-660px);
  189. overflow-x: auto;
  190. }
  191. .score-title {
  192. font-size: 16px;
  193. margin-top: 17px;
  194. margin-left: 18px;
  195. }
  196. .score-select {
  197. /* flex-grow: 1; */
  198. margin-right: 10px;
  199. }
  200. .score-divider {
  201. width: 1px;
  202. height: 320px;
  203. background: #e9e9e9;
  204. /* margin-left: 29px;
  205. margin-right: 27px; */
  206. }
  207. .el-divider--horizontal {
  208. margin: 0px;
  209. }
  210. .pic-show {
  211. flex-grow: 1;
  212. height: 270px;
  213. }
  214. .concern-title {
  215. margin-left: 20px;
  216. margin-top: 51px;
  217. font-size: 14px;
  218. }
  219. .concern-workspace {
  220. margin-left: 23px;
  221. margin-top: 24px;
  222. font-size: 14px;
  223. color: rgba(0, 0, 0, 0.65);
  224. }
  225. li {
  226. margin-bottom: 16px;
  227. }
  228. li:before {
  229. content: '•';
  230. color: red;
  231. display: inline-block;
  232. margin-right: 20px;
  233. width: 8px;
  234. height: 8px;
  235. font-size: 16px;
  236. line-height: 1;
  237. }
  238. .score-tip {
  239. display: flex;
  240. margin-top: 20px;
  241. margin-left: 14px;
  242. }
  243. .tip-content {
  244. margin-left: 16px;
  245. margin-right: 14px;
  246. color: rgba(0, 0, 0, 0.45);
  247. font-size: 10px;
  248. }
  249. </style>