report.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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: 28px;
  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: ["#91cc75", "#fac858"],
  166. grid: {
  167. // left: "3%",
  168. // right: "4%",
  169. bottom: "2%",
  170. top: "20px",
  171. // containLabel: true,
  172. },
  173. radar: {
  174. indicator: this.data.map((d) => ({ name: d.type })),
  175. center: ["28%", "50%"],
  176. radius: 55,
  177. axisName: {
  178. color: "#fff",
  179. },
  180. },
  181. series: [
  182. {
  183. type: "radar",
  184. data: [
  185. {
  186. value: this.data.map((d) => d.total),
  187. name: "应检查",
  188. },
  189. {
  190. value: this.data.map((d) => d.completed),
  191. name: "已检查",
  192. },
  193. ],
  194. },
  195. ],
  196. };
  197. if (option && typeof option === "object") {
  198. this.myChart.setOption(option);
  199. }
  200. },
  201. resetTimer() {
  202. this.timer && clearInterval(this.timer);
  203. this.timer = setInterval(() => {
  204. if (this.isMouseOver) {
  205. return;
  206. }
  207. this.activeName = getNextPeriod(this.types, this.activeName);
  208. this.getData();
  209. }, this.refreshTime);
  210. },
  211. },
  212. };
  213. </script>
  214. <style lang="scss" scoped>
  215. .checkType-item {
  216. font-size: 12px;
  217. // line-height: 22px;
  218. height: 20%;
  219. max-height: 30px;
  220. & > span {
  221. display: inline-block;
  222. width: 40px;
  223. }
  224. & > span:first-child {
  225. width: 80px;
  226. }
  227. }
  228. </style>