DiagChartPanel.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div class="diag-chart-panel">
  3. <section v-if="showConclusion" class="diag-conclusion">
  4. <h3>{{ mode === "overview" ? "项目结论" : "本机结论" }}</h3>
  5. <div class="diag-conclusion__row">
  6. <div class="diag-conclusion__cell">
  7. <label>检测结果</label>
  8. <b :class="{ bad: isBad }">{{ statusText }}</b>
  9. </div>
  10. <div class="diag-conclusion__cell">
  11. <label>算法</label>
  12. <b>{{ alg || "—" }}</b>
  13. </div>
  14. <div class="diag-conclusion__cell">
  15. <label>周期</label>
  16. <b>{{ periodText }}</b>
  17. </div>
  18. <div v-for="(m, i) in metricCells" :key="'m' + i" class="diag-conclusion__cell">
  19. <label>{{ m.label || "指标" }}</label>
  20. <b>{{ m.value }}</b>
  21. </div>
  22. <div v-for="(t, i) in thresholdCells" :key="'t' + i" class="diag-conclusion__cell">
  23. <label>{{ t.label || "判断线" }}</label>
  24. <b>{{ t.value }}</b>
  25. </div>
  26. </div>
  27. <p class="diag-conclusion__reason">{{ reasonText }}</p>
  28. </section>
  29. <section v-for="view in chartViews" :key="view.chart.id" class="diag-chart-block">
  30. <div class="diag-chart-block__head">
  31. <h3>{{ view.chart.title }}</h3>
  32. <span v-if="view.chart.plotted_turbine_count" class="rk-muted">
  33. {{ view.chart.plotted_turbine_count }} 台
  34. </span>
  35. </div>
  36. <div class="chart-stage">
  37. <EChart v-if="view.desc.type === 'chart'" :option="view.desc.option" />
  38. <div v-else class="chart-empty">
  39. <div class="chart-empty-mark" aria-hidden="true">
  40. <i class="el-icon-data-analysis"></i>
  41. </div>
  42. <p>暂无图表数据</p>
  43. </div>
  44. </div>
  45. <p v-if="view.desc.notes && view.desc.notes.length" class="diag-chart-block--note rk-muted">
  46. {{ view.desc.notes[0] }}
  47. </p>
  48. </section>
  49. <section v-if="emptyReasons.length" class="diag-chart-block diag-chart-block--note">
  50. <p v-for="(r, i) in emptyReasons" :key="i" class="rk-muted">{{ r }}</p>
  51. </section>
  52. <section v-for="(t, ti) in tableViews" :key="'tab' + ti" class="diag-chart-block">
  53. <div class="diag-chart-block__head">
  54. <h3>逐机判据与结果</h3>
  55. </div>
  56. <div class="chart-stage chart-stage--table">
  57. <table class="rk-table">
  58. <thead>
  59. <tr>
  60. <th v-for="c in t.columns" :key="c.key">{{ c.label }}</th>
  61. </tr>
  62. </thead>
  63. <tbody>
  64. <tr v-for="(r, ri) in t.rows" :key="ri">
  65. <td v-for="c in t.columns" :key="c.key">{{ fmtCell(r[c.key]) }}</td>
  66. </tr>
  67. </tbody>
  68. </table>
  69. </div>
  70. </section>
  71. <section v-if="!chartViews.length && !showConclusion" class="chart-stage">
  72. <div class="chart-empty">
  73. <div class="chart-empty-mark" aria-hidden="true">
  74. <i class="el-icon-data-analysis"></i>
  75. </div>
  76. <p>当前检测器未接入实测数据</p>
  77. <em>{{ detectorName || "当前检测器" }}</em>
  78. </div>
  79. </section>
  80. </div>
  81. </template>
  82. <script>
  83. import { isBadStatus } from "../utils/rankHelpers";
  84. import { renderContractChart } from "../utils/contractChart";
  85. import { splitScopeTitle } from "../utils/sourceFunctionView";
  86. import {
  87. fetchDiagnosisProjectFunction,
  88. fetchDiagnosisTurbineFunction,
  89. } from "@/api/rankingApp";
  90. import { periodMonth } from "../utils/diagnosisAdapter";
  91. import EChart from "./EChart.vue";
  92. export default {
  93. name: "DiagChartPanel",
  94. components: { EChart },
  95. props: {
  96. mode: { type: String, default: "detail" },
  97. alg: { type: String, default: "" },
  98. detectorName: { type: String, default: "" },
  99. unitLabel: { type: String, default: "" },
  100. status: { type: String, default: "" },
  101. year: { type: [Number, String], default: "" },
  102. month: { type: [Number, String], default: "" },
  103. fieldCode: { type: String, default: "" },
  104. machineTypeCode: { type: String, default: "" },
  105. engineCode: { type: String, default: "" },
  106. },
  107. data() {
  108. return { realBundle: null, paintSeq: 0 };
  109. },
  110. computed: {
  111. bundle() {
  112. return this.realBundle || {};
  113. },
  114. graph() {
  115. return this.bundle.graph || {};
  116. },
  117. showConclusion() {
  118. return !!this.conclusionText;
  119. },
  120. conclusionText() {
  121. const c = this.bundle.conclusion;
  122. return (c && c.text) || "";
  123. },
  124. statusText() {
  125. const r = this.bundle.result || {};
  126. const s = this.bundle.status || {};
  127. return r.status || s.source_status || this.status || "—";
  128. },
  129. isBad() {
  130. return isBadStatus(this.statusText);
  131. },
  132. display() {
  133. return (this.bundle.result && this.bundle.result.display) || {};
  134. },
  135. metricCells() {
  136. const d = this.display;
  137. if (Array.isArray(d.metrics) && d.metrics.length) {
  138. return d.metrics.map((m) => ({
  139. label: m.label,
  140. value: m.formatted != null ? m.formatted : m.value != null ? String(m.value) + (m.unit || "") : "—",
  141. }));
  142. }
  143. if (d.metric_label || d.metric != null) return [{ label: d.metric_label, value: d.metric }];
  144. return [];
  145. },
  146. thresholdCells() {
  147. const d = this.display;
  148. if (Array.isArray(d.thresholds) && d.thresholds.length) {
  149. return d.thresholds.map((t) => ({
  150. label: t.label,
  151. value: t.formatted != null ? t.formatted : t.value != null ? String(t.value) + (t.unit || "") : "—",
  152. }));
  153. }
  154. if (d.threshold_label || d.threshold != null) return [{ label: d.threshold_label, value: d.threshold }];
  155. return [];
  156. },
  157. reasonText() {
  158. const r = this.bundle.result || {};
  159. return this.conclusionText || r.reason || "";
  160. },
  161. chartViews() {
  162. const charts = this.graph.charts || [];
  163. const datasets = this.graph.datasets || {};
  164. return charts
  165. .filter((c) => c.renderable && c.observation_count > 0)
  166. .map((c) => {
  167. const chart = Object.assign({}, c, { title: splitScopeTitle(c.title, c.scope) });
  168. return { chart, desc: renderContractChart(chart, datasets) };
  169. });
  170. },
  171. emptyReasons() {
  172. const charts = this.graph.charts || [];
  173. const hidden = this.graph.hidden_charts || [];
  174. const reasons = [];
  175. charts
  176. .filter((c) => !(c.renderable && c.observation_count > 0))
  177. .forEach((c) => {
  178. if (c.empty_reason && !reasons.includes(c.empty_reason)) reasons.push(c.empty_reason);
  179. });
  180. hidden.forEach((h) => {
  181. if (h && h.empty_reason && !reasons.includes(h.empty_reason)) reasons.push(h.empty_reason);
  182. });
  183. return reasons;
  184. },
  185. tableViews() {
  186. return (this.bundle.tables || []).map((t) => ({
  187. columns: (t.columns || []).map((c) => ({ key: c.key, label: c.label })),
  188. rows: t.rows || [],
  189. }));
  190. },
  191. periodText() {
  192. if (!this.year) return "—";
  193. const m = this.month != null && this.month !== "" ? Number(this.month) : null;
  194. return m ? `${this.year}年${m}月` : String(this.year);
  195. },
  196. },
  197. watch: {
  198. alg: "load",
  199. mode: "load",
  200. year: "load",
  201. month: "load",
  202. fieldCode: "load",
  203. machineTypeCode: "load",
  204. engineCode: "load",
  205. },
  206. created() {
  207. this.load();
  208. },
  209. methods: {
  210. fmtCell(v) {
  211. if (v == null) return "—";
  212. return v;
  213. },
  214. async load() {
  215. const seq = ++this.paintSeq;
  216. const alg = this.alg;
  217. const fieldCode = this.fieldCode;
  218. const machineTypeCode = this.machineTypeCode;
  219. if (!alg || !fieldCode || !machineTypeCode) {
  220. this.realBundle = null;
  221. return;
  222. }
  223. if (this.mode === "detail" && !this.engineCode) {
  224. this.realBundle = null;
  225. return;
  226. }
  227. const year = Number(this.year) || 2026;
  228. const month = Number(this.month) || 8;
  229. const params = {
  230. fieldCode,
  231. machineTypeCode,
  232. month: periodMonth(year, month),
  233. functionCode: alg,
  234. };
  235. try {
  236. const res =
  237. this.mode === "overview"
  238. ? await fetchDiagnosisProjectFunction(params)
  239. : await fetchDiagnosisTurbineFunction(
  240. Object.assign({}, params, { engineCode: this.engineCode }),
  241. );
  242. if (seq !== this.paintSeq) return;
  243. this.realBundle = (res && res.data) || null;
  244. } catch (_e) {
  245. if (seq !== this.paintSeq) return;
  246. this.realBundle = null;
  247. }
  248. },
  249. },
  250. };
  251. </script>