report.vue 4.7 KB

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