report.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <!-- -->
  2. <template>
  3. <div class="chart-template chart-template-withperiod">
  4. <p>
  5. <span>安全检查</span>
  6. </p>
  7. <div>
  8. <el-tabs v-model="activeName" @tab-click="handleClick">
  9. <el-tab-pane
  10. v-for="t in types"
  11. :key="t.value"
  12. :label="t.text"
  13. :name="t.value"
  14. ></el-tab-pane>
  15. </el-tabs>
  16. </div>
  17. <div style="position: relative">
  18. <div ref="chart" style="height: 100%"></div>
  19. <div
  20. style="
  21. position: absolute;
  22. right: 0px;
  23. top: 35px;
  24. height: calc(100% - 50px);
  25. "
  26. >
  27. <div v-for="item in this.data" :key="item.type" class="checkType-item">
  28. <span>{{ item.type }}</span>
  29. <span>{{ item.total }}</span>
  30. <span>{{ item.completed }}</span>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import "./../../board.scss";
  38. import * as echarts from "echarts";
  39. import { safetyCheck } from "@/api/board/cockpit.js";
  40. import {
  41. findMaxIndex,
  42. getChartDOMSize,
  43. getNextPeriod,
  44. getPeriodText,
  45. } from "../../utils.js";
  46. const types = [
  47. {
  48. text: "今天",
  49. value: "1",
  50. },
  51. {
  52. text: "近7天",
  53. value: "2",
  54. },
  55. {
  56. text: "近30天",
  57. value: "3",
  58. },
  59. {
  60. text: "近90天",
  61. value: "4",
  62. },
  63. {
  64. text: "本年",
  65. value: "5",
  66. },
  67. ];
  68. export default {
  69. props: {
  70. orgId: {
  71. type: String,
  72. isRequired: true,
  73. },
  74. },
  75. data() {
  76. return {
  77. data: {
  78. all: [],
  79. completed: [],
  80. name: [],
  81. },
  82. activeName: types[0].value,
  83. };
  84. },
  85. components: {},
  86. computed: {},
  87. watch: {
  88. orgId: {
  89. deep: true,
  90. handler(val) {
  91. this.resetTimer();
  92. this.getData();
  93. },
  94. },
  95. data: {
  96. deep: true,
  97. handler() {
  98. this.initMap();
  99. },
  100. },
  101. },
  102. created() {
  103. this.types = types;
  104. this.maxDisplay = 16;
  105. this.refreshTime = 1 * 10 * 1000;
  106. this.isMouseOver = false;
  107. },
  108. async mounted() {
  109. window.addEventListener("resize", this.windowResize);
  110. },
  111. beforeDestroy() {
  112. this.timer && clearInterval(this.timer);
  113. this.timer = null;
  114. window.removeEventListener("resize", this.windowResize);
  115. },
  116. methods: {
  117. handleClick() {
  118. this.resetTimer();
  119. this.getData();
  120. },
  121. handleMouseEnter() {
  122. this.isMouseOver = true;
  123. },
  124. handleMouseLeave() {
  125. this.isMouseOver = false;
  126. },
  127. async getData() {
  128. let r = (
  129. await safetyCheck({ orgId: this.orgId, period: this.activeName })
  130. ).data;
  131. this.data = r;
  132. // console.info(this.data);
  133. },
  134. windowResize() {
  135. this.myChart && this.myChart.resize();
  136. },
  137. initMap() {
  138. this.myChart && this.myChart.dispose();
  139. let c = this.$refs["chart"];
  140. // 基于准备好的dom,初始化echarts实例
  141. this.myChart = echarts.init(
  142. c
  143. // document.getElementById("commAlarmEvent_Chart")
  144. );
  145. let t = this;
  146. // 指定图表的配置项和数据
  147. var option = {
  148. // color: ["#82D5AE"],
  149. // tooltip: {
  150. // trigger: "axis",
  151. // confine: true,
  152. // axisPointer: {
  153. // type: "shadow",
  154. // },
  155. // formatter: "完成率:{c}%",
  156. // },
  157. legend: {
  158. // true: true,
  159. textStyle: {
  160. color: "rgb(245, 245, 245)",
  161. },
  162. type: "scroll",
  163. right: 5,
  164. },
  165. color:['#5470c6','#91cc75','#ee6666'],
  166. grid: {
  167. // left: "3%",
  168. // right: "4%",
  169. bottom: "0",
  170. top: "0",
  171. // containLabel: true,
  172. },
  173. radar: {
  174. indicator: this.data.map((d) => ({ name: d.type })),
  175. center: ["28%", "51%"],
  176. radius: 60,
  177. splitNumber:4,
  178. axisName: {
  179. color: "#fff",
  180. },
  181. axisLine:{
  182. lineStyle:{
  183. color:'rgb(230,230,230)'
  184. }
  185. },
  186. splitLine:{
  187. lineStyle:{
  188. color:'rgb(230,230,230)'
  189. }
  190. }
  191. },
  192. series: [
  193. {
  194. type: "radar",
  195. data: [
  196. {
  197. value: this.data.map((d) => d.total),
  198. name: "应检查",
  199. },
  200. {
  201. value: this.data.map((d) => d.completed),
  202. name: "已检查",
  203. },
  204. ],
  205. },
  206. ],
  207. };
  208. if (option && typeof option === "object") {
  209. this.myChart.setOption(option);
  210. }
  211. },
  212. resetTimer() {
  213. this.timer && clearInterval(this.timer);
  214. this.timer = setInterval(() => {
  215. if (this.isMouseOver) {
  216. return;
  217. }
  218. this.activeName = getNextPeriod(this.types, this.activeName);
  219. this.getData();
  220. }, this.refreshTime);
  221. },
  222. },
  223. };
  224. </script>
  225. <style lang="scss" scoped>
  226. .checkType-item {
  227. font-size: 12px;
  228. // line-height: 22px;
  229. height: 20%;
  230. max-height: 30px;
  231. & > span {
  232. display: inline-block;
  233. width: 40px;
  234. }
  235. & > span:first-child {
  236. width: 80px;
  237. }
  238. }
  239. </style>