| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <template>
- <div class="diag-chart-panel">
- <section v-if="showConclusion" class="diag-conclusion">
- <h3>{{ mode === "overview" ? "项目结论" : "本机结论" }}</h3>
- <div class="diag-conclusion__row">
- <div class="diag-conclusion__cell">
- <label>检测结果</label>
- <b :class="{ bad: isBad }">{{ statusText }}</b>
- </div>
- <div class="diag-conclusion__cell">
- <label>算法</label>
- <b>{{ alg || "—" }}</b>
- </div>
- <div class="diag-conclusion__cell">
- <label>周期</label>
- <b>{{ periodText }}</b>
- </div>
- <div v-for="(m, i) in metricCells" :key="'m' + i" class="diag-conclusion__cell">
- <label>{{ m.label || "指标" }}</label>
- <b>{{ m.value }}</b>
- </div>
- <div v-for="(t, i) in thresholdCells" :key="'t' + i" class="diag-conclusion__cell">
- <label>{{ t.label || "判断线" }}</label>
- <b>{{ t.value }}</b>
- </div>
- </div>
- <p class="diag-conclusion__reason">{{ reasonText }}</p>
- </section>
- <section v-for="view in chartViews" :key="view.chart.id" class="diag-chart-block">
- <div class="diag-chart-block__head">
- <h3>{{ view.chart.title }}</h3>
- <span v-if="view.chart.plotted_turbine_count" class="rk-muted">
- {{ view.chart.plotted_turbine_count }} 台
- </span>
- </div>
- <div class="chart-stage">
- <EChart v-if="view.desc.type === 'chart'" :option="view.desc.option" />
- <div v-else class="chart-empty">
- <div class="chart-empty-mark" aria-hidden="true">
- <i class="el-icon-data-analysis"></i>
- </div>
- <p>暂无图表数据</p>
- </div>
- </div>
- <p v-if="view.desc.notes && view.desc.notes.length" class="diag-chart-block--note rk-muted">
- {{ view.desc.notes[0] }}
- </p>
- </section>
- <section v-if="emptyReasons.length" class="diag-chart-block diag-chart-block--note">
- <p v-for="(r, i) in emptyReasons" :key="i" class="rk-muted">{{ r }}</p>
- </section>
- <section v-for="(t, ti) in tableViews" :key="'tab' + ti" class="diag-chart-block">
- <div class="diag-chart-block__head">
- <h3>逐机判据与结果</h3>
- </div>
- <div class="chart-stage chart-stage--table">
- <table class="rk-table">
- <thead>
- <tr>
- <th v-for="c in t.columns" :key="c.key">{{ c.label }}</th>
- </tr>
- </thead>
- <tbody>
- <tr v-for="(r, ri) in t.rows" :key="ri">
- <td v-for="c in t.columns" :key="c.key">{{ fmtCell(r[c.key]) }}</td>
- </tr>
- </tbody>
- </table>
- </div>
- </section>
- <section v-if="!chartViews.length && !showConclusion" class="chart-stage">
- <div class="chart-empty">
- <div class="chart-empty-mark" aria-hidden="true">
- <i class="el-icon-data-analysis"></i>
- </div>
- <p>当前检测器未接入实测数据</p>
- <em>{{ detectorName || "当前检测器" }}</em>
- </div>
- </section>
- </div>
- </template>
- <script>
- import { isBadStatus } from "../utils/rankHelpers";
- import { renderContractChart } from "../utils/contractChart";
- import { splitScopeTitle } from "../utils/sourceFunctionView";
- import {
- fetchDiagnosisProjectFunction,
- fetchDiagnosisTurbineFunction,
- } from "@/api/rankingApp";
- import { periodMonth } from "../utils/diagnosisAdapter";
- import EChart from "./EChart.vue";
- export default {
- name: "DiagChartPanel",
- components: { EChart },
- props: {
- mode: { type: String, default: "detail" },
- alg: { type: String, default: "" },
- detectorName: { type: String, default: "" },
- unitLabel: { type: String, default: "" },
- status: { type: String, default: "" },
- year: { type: [Number, String], default: "" },
- month: { type: [Number, String], default: "" },
- fieldCode: { type: String, default: "" },
- machineTypeCode: { type: String, default: "" },
- engineCode: { type: String, default: "" },
- },
- data() {
- return { realBundle: null, paintSeq: 0 };
- },
- computed: {
- bundle() {
- return this.realBundle || {};
- },
- graph() {
- return this.bundle.graph || {};
- },
- showConclusion() {
- return !!this.conclusionText;
- },
- conclusionText() {
- const c = this.bundle.conclusion;
- return (c && c.text) || "";
- },
- statusText() {
- const r = this.bundle.result || {};
- const s = this.bundle.status || {};
- return r.status || s.source_status || this.status || "—";
- },
- isBad() {
- return isBadStatus(this.statusText);
- },
- display() {
- return (this.bundle.result && this.bundle.result.display) || {};
- },
- metricCells() {
- const d = this.display;
- if (Array.isArray(d.metrics) && d.metrics.length) {
- return d.metrics.map((m) => ({
- label: m.label,
- value: m.formatted != null ? m.formatted : m.value != null ? String(m.value) + (m.unit || "") : "—",
- }));
- }
- if (d.metric_label || d.metric != null) return [{ label: d.metric_label, value: d.metric }];
- return [];
- },
- thresholdCells() {
- const d = this.display;
- if (Array.isArray(d.thresholds) && d.thresholds.length) {
- return d.thresholds.map((t) => ({
- label: t.label,
- value: t.formatted != null ? t.formatted : t.value != null ? String(t.value) + (t.unit || "") : "—",
- }));
- }
- if (d.threshold_label || d.threshold != null) return [{ label: d.threshold_label, value: d.threshold }];
- return [];
- },
- reasonText() {
- const r = this.bundle.result || {};
- return this.conclusionText || r.reason || "";
- },
- chartViews() {
- const charts = this.graph.charts || [];
- const datasets = this.graph.datasets || {};
- return charts
- .filter((c) => c.renderable && c.observation_count > 0)
- .map((c) => {
- const chart = Object.assign({}, c, { title: splitScopeTitle(c.title, c.scope) });
- return { chart, desc: renderContractChart(chart, datasets) };
- });
- },
- emptyReasons() {
- const charts = this.graph.charts || [];
- const hidden = this.graph.hidden_charts || [];
- const reasons = [];
- charts
- .filter((c) => !(c.renderable && c.observation_count > 0))
- .forEach((c) => {
- if (c.empty_reason && !reasons.includes(c.empty_reason)) reasons.push(c.empty_reason);
- });
- hidden.forEach((h) => {
- if (h && h.empty_reason && !reasons.includes(h.empty_reason)) reasons.push(h.empty_reason);
- });
- return reasons;
- },
- tableViews() {
- return (this.bundle.tables || []).map((t) => ({
- columns: (t.columns || []).map((c) => ({ key: c.key, label: c.label })),
- rows: t.rows || [],
- }));
- },
- periodText() {
- if (!this.year) return "—";
- const m = this.month != null && this.month !== "" ? Number(this.month) : null;
- return m ? `${this.year}年${m}月` : String(this.year);
- },
- },
- watch: {
- alg: "load",
- mode: "load",
- year: "load",
- month: "load",
- fieldCode: "load",
- machineTypeCode: "load",
- engineCode: "load",
- },
- created() {
- this.load();
- },
- methods: {
- fmtCell(v) {
- if (v == null) return "—";
- return v;
- },
- async load() {
- const seq = ++this.paintSeq;
- const alg = this.alg;
- const fieldCode = this.fieldCode;
- const machineTypeCode = this.machineTypeCode;
- if (!alg || !fieldCode || !machineTypeCode) {
- this.realBundle = null;
- return;
- }
- if (this.mode === "detail" && !this.engineCode) {
- this.realBundle = null;
- return;
- }
- const year = Number(this.year) || 2026;
- const month = Number(this.month) || 8;
- const params = {
- fieldCode,
- machineTypeCode,
- month: periodMonth(year, month),
- functionCode: alg,
- };
- try {
- const res =
- this.mode === "overview"
- ? await fetchDiagnosisProjectFunction(params)
- : await fetchDiagnosisTurbineFunction(
- Object.assign({}, params, { engineCode: this.engineCode }),
- );
- if (seq !== this.paintSeq) return;
- this.realBundle = (res && res.data) || null;
- } catch (_e) {
- if (seq !== this.paintSeq) return;
- this.realBundle = null;
- }
- },
- },
- };
- </script>
|