reportDialog.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <template>
  2. <el-dialog
  3. v-model="showDialog"
  4. custom-class="modal"
  5. id="report"
  6. width="50%"
  7. top="5vh"
  8. :show-close="false"
  9. center
  10. >
  11. <div class="exportPDF">
  12. <el-button type="primary" size="small" @click="savePdf">导出PDF</el-button>
  13. </div>
  14. <div class="reportMain">
  15. <p class="mainTitle">故障诊断报告</p>
  16. <!-- 诊断概述 -->
  17. <div class="reportTitle">
  18. <el-row class="titleRwo">
  19. <el-col :span="16" class="titleCol">
  20. <p>模型名称:</p>
  21. <span>{{ reportMssage.name }}</span>
  22. </el-col>
  23. <el-col :span="8" class="titleCol">
  24. <p>故障时间:</p>
  25. <span>{{ reportMssage.time }}</span>
  26. </el-col>
  27. </el-row>
  28. <el-row class="titleRwo">
  29. <el-col :span="16" class="titleCol">
  30. <p>训练次数:</p>
  31. <span>{{ reportMssage.many }}次</span>
  32. </el-col>
  33. <el-col :span="8" class="titleCol">
  34. <p>故障风机名称:</p>
  35. <span>{{ reportMssage.windname }}</span>
  36. </el-col>
  37. </el-row>
  38. <div class="reportMsg">
  39. <p class="title">检测结论</p>
  40. <div class="mssage titleCol">
  41. <p>本检测结果所使用的模型为:</p>
  42. <span>{{ reportMssage.model }};</span>
  43. <p class="msgStyle">可信度为:</p>
  44. <span>{{ reportMssage.beleve }};</span>
  45. <p class="msgStyle">检测结果为:</p>
  46. <span>{{ reportMssage.result }}。</span>
  47. </div>
  48. </div>
  49. </div>
  50. <!-- 报警详情 -->
  51. <div class="reporttreeDDA">
  52. <div id="main" class="charttreeStyle"></div>
  53. </div>
  54. <!-- 测点权重柱状图 -->
  55. <div class="reportCharts">
  56. <div id="reportChart" class="chartStyle"></div>
  57. </div>
  58. <!-- 测点权重曲线图 -->
  59. <div class="reportLine">
  60. <div id="reportLineChart" class="chartsSty"></div>
  61. </div>
  62. <!-- 测点权重梯度曲线图 -->
  63. <div class="reportLine" v-show="showRemark">
  64. <div id="reportLinetiduChart" class="chartsSty"></div>
  65. </div>
  66. <div class="reportTable">
  67. <el-table :data="reportTable" style="width: 100%" border stripe>
  68. <el-table-column prop="index" align="center" />
  69. <el-table-column prop="precision" label="精确度" align="center" />
  70. <el-table-column prop="recall" label="回归" align="center" />
  71. <el-table-column prop="f1-score" label="F值" align="center" />
  72. <el-table-column prop="support" label="可支持数据" align="center" />
  73. </el-table>
  74. </div>
  75. </div>
  76. </el-dialog>
  77. </template>
  78. <script>
  79. import { getAllReportMsg } from "@api/api.js";
  80. import * as echarts from "echarts";
  81. import Get_PDF from "@tools/htmlToPdf.js";
  82. import BASE from "@tools/basicTool.js";
  83. export default {
  84. data() {
  85. return {
  86. showDialog: false,
  87. reportTable: [],
  88. reportChartsData: [],
  89. reportMssage: {
  90. name: "",
  91. time: "",
  92. many: "",
  93. windname: "",
  94. beleve: "",
  95. model: "",
  96. result: "",
  97. },
  98. autoHeight: "",
  99. allcheckName: [],
  100. curveLineData: {},
  101. treeData: {},
  102. showRemark: true,
  103. };
  104. },
  105. methods: {
  106. init(row) {
  107. this.showDialog = true;
  108. this.getReportDetail(row);
  109. },
  110. savePdf() {
  111. Get_PDF.downloadPDF(
  112. document.querySelector(".reportMain"),
  113. "故障诊断报告" + new Date()
  114. );
  115. },
  116. // 获取诊断报告详情
  117. async getReportDetail(row) {
  118. const { data } = await getAllReportMsg({
  119. id: row.id,
  120. });
  121. console.log(data);
  122. if (data) {
  123. if (data.alarm) {
  124. this.treeData = JSON.stringify(data.alarm);
  125. this.getTreeLiness(this.treeData, data.alarm.count);
  126. }
  127. if (data.fault && data.info) {
  128. if (data.fault.remark) {
  129. this.showRemark = true;
  130. } else {
  131. this.showRemark = false;
  132. }
  133. this.reportMssage = {
  134. name: data.info.name,
  135. time: data.fault.starttime,
  136. many: 200,
  137. windname: data.fault.windturbineid,
  138. beleve: (data.info.accuracy * 1).toFixed(2) * 100 + "%",
  139. model: data.fault.model,
  140. result: data.fault.diagnosetype,
  141. };
  142. if (data.info.indicators) {
  143. this.reportTable = JSON.parse(data.info.indicators);
  144. }
  145. if (data.info.pointweight) {
  146. this.reportChartsData = JSON.parse(data.info.pointweight);
  147. let YaxData = [];
  148. let sericeData = [];
  149. let barSericesData = [];
  150. this.allcheckName = [];
  151. if (this.reportChartsData && this.reportChartsData.length > 0) {
  152. this.reportChartsData.forEach((item, index) => {
  153. if (Number(item.importance).toFixed(2) >= 1) {
  154. let sericeDataObj = {
  155. name: item.measuring_point,
  156. value: (item.importance * 1).toFixed(2),
  157. itemStyle: {
  158. color: "#24bbcb",
  159. },
  160. };
  161. YaxData.unshift(item.measuring_point);
  162. if (index < 4) {
  163. this.allcheckName.push(item.measuring_point);
  164. }
  165. // sericeData.unshift((item.importance*1).toFixed(2))
  166. sericeData.unshift(sericeDataObj);
  167. }
  168. });
  169. let ServiceDataObj = {
  170. name: "测点权重",
  171. barWidth: 20, //最小柱高
  172. type: "bar",
  173. label: {
  174. normal: {
  175. show: true,
  176. position: "right",
  177. textStyle: {
  178. color: "#b3bdc0",
  179. fontSize: 14,
  180. },
  181. formatter: "{c}", //c后面加单位
  182. },
  183. },
  184. barCategoryGap: 30,
  185. data: sericeData,
  186. };
  187. barSericesData.push(ServiceDataObj);
  188. }
  189. this.getAccuracyBar(
  190. "reportChart",
  191. YaxData,
  192. barSericesData,
  193. "测点权重"
  194. );
  195. }
  196. }
  197. if (data.curve) {
  198. this.curveLineData = data.curve;
  199. this.changeLineChartsData(data.curve);
  200. }
  201. if (data.curve && data.fault) {
  202. if (data.fault.remark) {
  203. this.changeLinetiduData(data.fault, data.curve);
  204. }
  205. }
  206. } else {
  207. this.showDialog = false;
  208. BASE.showMsg({
  209. type: "error",
  210. msg: "服务返回失败",
  211. });
  212. }
  213. },
  214. // 处理测点权重曲线
  215. changeLineChartsData(data) {
  216. let that = this;
  217. let lengedData = this.allcheckName;
  218. let xAxis = [];
  219. let servData = [];
  220. let markLineDate = "";
  221. for (let item in data) {
  222. if (item === this.allcheckName[0]) {
  223. data[item].forEach((itv, index) => {
  224. // xAxis.push(index.toString())
  225. xAxis.push(this.getTime(new Date(itv.ts)));
  226. });
  227. markLineDate = that.getTime(
  228. new Date(data[this.allcheckName[0]][0].ts + 10 * 60 * 1000)
  229. );
  230. }
  231. if (lengedData.includes(item)) {
  232. let serviceData = [];
  233. data[item].forEach((itv, index) => {
  234. serviceData.push(Number(itv.doubleValue).toFixed(4));
  235. });
  236. // let savNum = Math.max.apply(null, serviceData)
  237. let serviceobj = {
  238. name: item,
  239. // data: serviceData.map( item =>{ return (item/savNum).toFixed(4)})
  240. data: serviceData,
  241. };
  242. servData.push(serviceobj);
  243. }
  244. }
  245. this.changeServeAndYData(
  246. "reportLineChart",
  247. servData,
  248. xAxis,
  249. lengedData,
  250. markLineDate
  251. );
  252. },
  253. // 折线图service数据与Y轴数据处理
  254. changeServeAndYData(names, servData, xAxis, lengedData, markLineDate) {
  255. let yAxis = [];
  256. let allServce = [];
  257. servData.forEach((iten, index) => {
  258. let seriesObj = {
  259. name: iten.name,
  260. type: "line",
  261. // stack: '总量',
  262. smooth: true,
  263. data: iten.data,
  264. symbol: "none",
  265. yAxisIndex: index,
  266. markLine: {
  267. lineStyle: {
  268. width: 2,
  269. color: "#f7b500",
  270. },
  271. data: [
  272. {
  273. name: "X 轴值为 10min 的竖直线",
  274. xAxis: markLineDate,
  275. },
  276. ],
  277. },
  278. };
  279. allServce.push(seriesObj);
  280. let yaxisObj = {
  281. boundaryGap: ["20%", "20%"],
  282. axisLine: {
  283. show: true,
  284. lineStyle: {
  285. color:
  286. index === 0
  287. ? "#9bbb59"
  288. : index === 1
  289. ? "#0B438B"
  290. : index === 2
  291. ? "#4141F1"
  292. : index === 3
  293. ? "#F81945"
  294. : index === 4
  295. ? "#4bacc6"
  296. : "#F89E19",
  297. },
  298. },
  299. type: "value",
  300. name: iten.name,
  301. position: index % 2 === 0 ? "left" : "right", //Y轴位置
  302. offset: index < 2 ? 20 : 60 + 20, //坐标轴移动
  303. // offset: index === 0 ? 20 : index === 1 ? 20 : index === 2 ? 60+20 : 60+20,//坐标轴移动
  304. axisLabel: {
  305. formatter: function (value, index) {
  306. return value;
  307. },
  308. textStyle: {
  309. color: "#999", // 测点权重曲线 Y 轴内容文字颜色
  310. },
  311. },
  312. splitLine: {
  313. show: false,
  314. },
  315. nameLocation: "middle",
  316. nameGap: 30,
  317. axisTick: {
  318. show: true,
  319. inside: "false",
  320. length: 10,
  321. },
  322. };
  323. yAxis.push(yaxisObj);
  324. });
  325. this.getLine(names, xAxis, lengedData, allServce, yAxis);
  326. },
  327. // 处理测点梯度曲线
  328. changeLinetiduData(obj, data) {
  329. let objremark = {};
  330. let remarkData = [];
  331. let lengedData = [];
  332. let xaxis = [];
  333. let serviceData = [];
  334. let markLineDate = "";
  335. if (obj.remark) {
  336. // objremark = JSON.parse(obj.remark)
  337. objremark = eval("(" + obj.remark + ")");
  338. for (let item in objremark) {
  339. for (let itn in data) {
  340. if (objremark[item] === itn) {
  341. let obj = {
  342. name: itn,
  343. data: data[itn],
  344. };
  345. remarkData.push(obj);
  346. }
  347. }
  348. }
  349. remarkData.forEach((itxc, index) => {
  350. lengedData.push(itxc.name);
  351. let service = [];
  352. itxc.data.forEach((itv, index) => {
  353. service.push(Number(itv.doubleValue).toFixed(4));
  354. });
  355. let serviceobj = {
  356. name: itxc.name,
  357. data: service,
  358. };
  359. serviceData.push(serviceobj);
  360. });
  361. if (remarkData.length > 0) {
  362. remarkData[0].data.forEach((itbb) => {
  363. xaxis.push(this.getTime(new Date(itbb.ts)));
  364. markLineDate = this.getTime(
  365. new Date(remarkData[0].data[0].ts + 10 * 60 * 1000)
  366. );
  367. });
  368. }
  369. }
  370. this.changeServeAndYData(
  371. "reportLinetiduChart",
  372. serviceData,
  373. xaxis,
  374. lengedData,
  375. markLineDate
  376. );
  377. },
  378. getAccuracyBar(item, yaxis, seriesFn, name) {
  379. let myChart = echarts.init(document.getElementById(item));
  380. let that = this;
  381. that.autoHeight = "";
  382. seriesFn[0].data.forEach((item) => {
  383. item.itemStyle.color = "#24bbcb";
  384. });
  385. if (that.allcheckName.length > 0) {
  386. seriesFn[0].data.forEach((item) => {
  387. that.allcheckName.forEach((itv) => {
  388. if (item.name === itv) {
  389. item.itemStyle.color = "#409eff";
  390. }
  391. });
  392. });
  393. }
  394. let option = {
  395. title: {
  396. // top: 20,
  397. left: 20,
  398. text: name,
  399. textStyle: {
  400. fontSize: 14,
  401. color: "#b3bdc0",
  402. },
  403. },
  404. // legend: {
  405. // top: 20,
  406. // },
  407. grid: {
  408. top: "10%",
  409. left: "10%",
  410. right: "10%",
  411. bottom: "3%",
  412. containLabel: true,
  413. },
  414. xAxis: {
  415. type: "value",
  416. boundaryGap: [0, 0.01],
  417. splitLine: {
  418. show: true,
  419. lineStyle: {
  420. type: "dotted",
  421. color: "#aaa",
  422. },
  423. },
  424. },
  425. yAxis: {
  426. type: "category",
  427. data: yaxis,
  428. axisLabel: {
  429. //y轴文字的配置
  430. textStyle: {
  431. color: "#b3bdc0", //Y轴内容文字颜色
  432. },
  433. },
  434. },
  435. series: seriesFn,
  436. };
  437. // 基于准备好的dom,初始化echarts实例
  438. myChart.setOption(option);
  439. that.autoHeight = yaxis.length * 35 + 50;
  440. myChart.getDom().style.height = that.autoHeight + "px";
  441. myChart.getDom().childNodes[0].style.height = that.autoHeight + "px";
  442. myChart
  443. .getDom()
  444. .childNodes[0].childNodes[0].setAttribute("height", that.autoHeight);
  445. myChart.getDom().childNodes[0].childNodes[0].style.height =
  446. that.autoHeight + "px";
  447. myChart.resize();
  448. //解除绑定事件
  449. myChart.off("click");
  450. //点击事件
  451. myChart.on("click", function (params) {
  452. if (that.allcheckName.length === 0) {
  453. that.allcheckName.push(params.name);
  454. } else {
  455. that.allcheckName.forEach((itvc, index) => {
  456. if (that.allcheckName.includes(params.name)) {
  457. if (itvc === params.name) {
  458. if (that.allcheckName.length > 1) {
  459. that.allcheckName.splice(index, 1);
  460. }
  461. }
  462. } else {
  463. if (that.allcheckName.length < 4) {
  464. that.allcheckName.push(params.name);
  465. }
  466. }
  467. });
  468. }
  469. if (that.allcheckName.length === 4) {
  470. BASE.showMsg({
  471. type: "warning",
  472. msg: "最多可查看四个测点权重曲线",
  473. });
  474. }
  475. console.log(that.allcheckName);
  476. that.getAccuracyBar(item, yaxis, seriesFn, name, "no");
  477. that.changeLineChartsData(that.curveLineData);
  478. });
  479. },
  480. getLine(item, xaxis, legendFn, seriesFn, yAxis) {
  481. // 绘制图表
  482. let option = {
  483. title: {
  484. top: 20,
  485. left: 20,
  486. text:
  487. item === "reportLineChart" ? "测点权重曲线" : "测点权重梯度曲线",
  488. textStyle: {
  489. fontSize: 14,
  490. color: "#b3bdc0",
  491. },
  492. },
  493. tooltip: {
  494. trigger: "axis",
  495. },
  496. color: [
  497. "#9bbb59",
  498. "#0B438B",
  499. "#4141F1",
  500. "#F81945",
  501. "#4bacc6",
  502. "#F89E19",
  503. ],
  504. legend: {
  505. data: legendFn,
  506. textStyle: {
  507. color: "#b3bdc0", //字体颜色
  508. },
  509. },
  510. grid: {
  511. // left: '3%',
  512. // right: '4%',
  513. bottom: "3%",
  514. containLabel: true,
  515. },
  516. xAxis: {
  517. type: "category",
  518. boundaryGap: false,
  519. splitNumber: 6,
  520. data: xaxis,
  521. axisLabel: {
  522. textStyle: {
  523. color: "#999", // 测点权重曲线 Y 轴内容文字颜色
  524. },
  525. },
  526. // name: '秒'
  527. },
  528. // yAxis: {
  529. // type: 'value',
  530. // // name: '米/秒(m/s)'
  531. // },
  532. yAxis: yAxis,
  533. series: seriesFn,
  534. };
  535. // 基于准备好的dom,初始化echarts实例
  536. let myChart = echarts.init(document.getElementById(item));
  537. myChart.setOption(option, true);
  538. myChart.resize();
  539. // setTimeout(function (){
  540. // window.onresize = function () {
  541. // myChart.resize();
  542. // }
  543. // },200)
  544. },
  545. getTreeLiness(data, value) {
  546. let alldata = JSON.parse(data);
  547. let domHeight = document.getElementById("main");
  548. domHeight.style.height = "";
  549. let autoHeight = "";
  550. autoHeight = value * 15 + 300 + "px";
  551. domHeight.style.height = autoHeight;
  552. if (domHeight.children.length > 0) {
  553. domHeight.children[0].style.height = autoHeight;
  554. domHeight.children[0].children[0].style.height = autoHeight;
  555. }
  556. // 绘制图表
  557. let option = {
  558. title: {
  559. top: 20,
  560. left: 20,
  561. text: "报警详情",
  562. textStyle: {
  563. fontSize: 14,
  564. color: "#b3bdc0",
  565. },
  566. },
  567. tooltip: {
  568. trigger: "item",
  569. triggerOn: "mousemove",
  570. },
  571. series: [
  572. {
  573. type: "tree",
  574. id: 0,
  575. name: "tree1",
  576. data: [alldata],
  577. // top: '10%',
  578. left: "8%",
  579. // bottom: '22%',
  580. right: "30%",
  581. symbolSize: 7,
  582. edgeShape: "polyline",
  583. edgeForkPosition: "50%",
  584. initialTreeDepth: 3,
  585. lineStyle: {
  586. width: 2,
  587. },
  588. label: {
  589. backgroundColor: "rgb(18,29,28)",
  590. position: "left",
  591. verticalAlign: "middle",
  592. align: "right",
  593. color: "#fff",
  594. },
  595. leaves: {
  596. label: {
  597. position: "right",
  598. verticalAlign: "middle",
  599. align: "left",
  600. },
  601. },
  602. emphasis: {
  603. focus: "descendant",
  604. },
  605. expandAndCollapse: true,
  606. animationDuration: 550,
  607. animationDurationUpdate: 750,
  608. },
  609. ],
  610. };
  611. // 基于准备好的dom,初始化echarts实例
  612. let myChart2 = echarts.init(document.getElementById("main"));
  613. //解除绑定事件
  614. myChart2.off("click");
  615. //点击事件
  616. myChart2.on("click", function (params) {
  617. // myChart2.clear()
  618. });
  619. myChart2.setOption(option, true);
  620. myChart2.resize();
  621. },
  622. //转换时间
  623. getTime(date) {
  624. var y = date.getFullYear();
  625. var m = date.getMonth() + 1;
  626. m = m < 10 ? "0" + m : m;
  627. var d = date.getDate();
  628. d = d < 10 ? "0" + d : d;
  629. var h = date.getHours();
  630. h = h < 10 ? "0" + h : h;
  631. var minute = date.getMinutes();
  632. minute = minute < 10 ? "0" + minute : minute;
  633. var second = date.getSeconds();
  634. second = second < 10 ? "0" + second : second;
  635. return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
  636. },
  637. },
  638. };
  639. </script>
  640. <style lang="less">
  641. .modal {
  642. .el-dialog__body {
  643. max-height: 600px;
  644. overflow-y: scroll;
  645. }
  646. }
  647. .el-dialog {
  648. // margin-top: 5vh !important;
  649. .el-dialog__header {
  650. .el-dialog__title {
  651. font-size: 20px;
  652. font-weight: 600;
  653. margin-top: 50px;
  654. }
  655. }
  656. .el-dialog__body {
  657. .exportPDF {
  658. position: absolute;
  659. right: 50px;
  660. z-index: 100;
  661. }
  662. .reportMain {
  663. padding: 0px 50px;
  664. .mainTitle {
  665. margin: 30px 0;
  666. font-size: 20px;
  667. font-weight: 600;
  668. text-align: center;
  669. color: #b3bdc0;
  670. }
  671. .titleCol {
  672. display: flex;
  673. justify-content: flex-start;
  674. align-items: center;
  675. color: #b3bdc0;
  676. p {
  677. width: 120px;
  678. font-size: 14px;
  679. font-weight: 600;
  680. }
  681. }
  682. .reportTitle {
  683. .titleRwo {
  684. margin-top: 10px;
  685. }
  686. .reportMsg {
  687. margin: 20px 0;
  688. margin-bottom: 10px;
  689. .title {
  690. font-size: 16px;
  691. font-weight: 600;
  692. margin-bottom: 10px;
  693. color: #b3bdc0;
  694. }
  695. .mssage {
  696. span {
  697. color: red;
  698. }
  699. }
  700. .msgStyle {
  701. margin-left: 20px;
  702. }
  703. }
  704. }
  705. .reporttreeDDA {
  706. .charttreeStyle {
  707. width: 100%;
  708. // height: 400px;
  709. }
  710. }
  711. .reportCharts {
  712. .chartStyle {
  713. width: 100%;
  714. // min-height: 500px;
  715. }
  716. }
  717. .reportLine {
  718. margin-top: 20px;
  719. .chartsSty {
  720. width: 100%;
  721. height: 400px;
  722. }
  723. }
  724. .reportTable {
  725. margin: 10px 0;
  726. }
  727. }
  728. }
  729. }
  730. </style>