| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932 |
- <template>
- <div class="ranking-farm">
- <!-- 顶部筛选(对齐原型 filter-bar) -->
- <div class="farm-filter">
- <el-select v-model="farmId" size="small" @change="onFarmChange">
- <el-option
- v-for="f in farms"
- :key="f.id"
- :value="f.id"
- :label="f.name"
- />
- </el-select>
- <el-select v-model="projectId" size="small" @change="onProjectChange">
- <el-option
- v-for="p in farmProjects"
- :key="p.id"
- :value="p.id"
- :label="p.name"
- />
- </el-select>
- <div class="diag-filters">
- <div class="diag-field">
- <span>机型</span>
- <el-select
- v-model="filterModelId"
- size="small"
- @change="onModelFilterChange"
- >
- <el-option
- value=""
- :label="'全部机型(' + projectModels.length + ')'"
- />
- <el-option
- v-for="m in projectModels"
- :key="m[0]"
- :value="m[0]"
- :label="m[1]"
- />
- </el-select>
- </div>
- <div class="diag-field">
- <span>机组</span>
- <div class="multi-select" :class="{ open: unitMultiOpen }">
- <button
- type="button"
- class="multi-trigger"
- :aria-expanded="unitMultiOpen ? 'true' : 'false'"
- @click.stop="toggleUnitMulti"
- >
- {{ filterUnitLabel }}
- </button>
- <div
- v-show="unitMultiOpen"
- class="multi-panel"
- role="listbox"
- @click.stop
- >
- <label class="multi-all">
- <input
- type="checkbox"
- :checked="filterUnitIds == null"
- @change="toggleAllUnits($event.target.checked)"
- />
- <span>全部机组({{ diagFilterPool.length }})</span>
- </label>
- <template v-if="diagFilterPool.length">
- <div
- v-for="group in unitGroups"
- :key="group.modelId || '_'"
- class="multi-group-block"
- >
- <div class="multi-group">
- {{ group.name }} · {{ group.units.length }} 台
- </div>
- <label v-for="u in group.units" :key="u.id">
- <input
- type="checkbox"
- :checked="isUnitChecked(u.id)"
- @change="toggleUnit(u.id, $event.target.checked)"
- />
- <span>{{ u.engineName || u.no }}号</span>
- <em>{{ modelName(u.modelId) }}</em>
- </label>
- </div>
- </template>
- <div v-else class="multi-empty">当前项目/机型下暂无机组</div>
- </div>
- </div>
- </div>
- </div>
- <div class="date-field">
- <el-date-picker
- v-model="periodValue"
- type="month"
- value-format="yyyy-MM"
- :clearable="false"
- :editable="false"
- size="small"
- prefix-icon="el-icon-date"
- placeholder="选择月份"
- :picker-options="periodPickerOptions"
- />
- </div>
- <div class="spacer"></div>
- <button type="button" class="rk-btn primary" @click="onDownloadReport">
- 下载报告
- </button>
- </div>
- <report-export-dialog
- v-model="reportOpen"
- :year="periodYear"
- :number="periodNumber"
- :project-id="projectId"
- :project-name="currentProject ? currentProject.name : ''"
- :farm-id="farmId"
- :model-id="filterModelId"
- :units="units"
- :models="models"
- />
- <div class="cards-3">
- <!-- 概览 -->
- <section class="rk-card farm-overview">
- <h2>风电项目异常概览</h2>
- <p class="rk-muted">
- {{ currentProject ? currentProject.name + " · " + farmName(currentProject.farmId) : "" }}
- · {{ periodLabel }}
- </p>
- <div class="rk-kpis">
- <div class="rk-kpi">
- <span>机组总数</span>
- <b>{{ scopedUnits.length }}</b>
- </div>
- <div class="rk-kpi alert">
- <span>异常台数</span>
- <b>{{ abnormalCount }}</b>
- </div>
- </div>
- <div class="radar-pair">
- <div v-for="r in radars" :key="r.title" class="radar-block">
- <div class="radar-header">
- <h3 class="radar-title" :style="{ '--dot': r.stroke }">{{ r.title }}</h3>
- <span class="radar-abnormal">异常台数</span>
- </div>
- <div class="radar-wrap" :data-tip="r.data.tip">
- <svg class="radar" viewBox="0 0 200 200">
- <polygon
- v-for="(pts, i) in r.data.grid.rings"
- :key="'ring' + i"
- :points="pts"
- fill="none"
- stroke="rgba(186,196,210,.18)"
- stroke-width="0.6"
- />
- <line
- v-for="(s, i) in r.data.grid.spokes"
- :key="'spoke' + i"
- :x1="s.x1"
- :y1="s.y1"
- :x2="s.x2"
- :y2="s.y2"
- stroke="rgba(186,196,210,.12)"
- stroke-width="0.5"
- />
- <text
- v-for="(t, i) in r.data.grid.ticks"
- :key="'tick' + i"
- :x="t.x"
- :y="t.y"
- fill="rgba(186,196,210,.55)"
- font-size="4"
- >
- {{ t.text }}
- </text>
- <polygon
- :points="r.data.points"
- :fill="r.fill"
- :stroke="r.stroke"
- stroke-width="1.6"
- stroke-linejoin="round"
- />
- <text
- v-for="(l, i) in r.data.labels"
- :key="'lab' + i"
- :text-anchor="l.anchor"
- fill="rgba(186,196,210,.75)"
- font-size="9.5"
- >
- <tspan
- v-for="(line, j) in l.lines"
- :key="j"
- :x="l.x"
- :y="line.y"
- >{{ line.text }}</tspan>
- </text>
- </svg>
- </div>
- </div>
- </div>
- </section>
- <!-- 数据感知热力图 -->
- <section class="rk-card heat-card sensor-card">
- <h2 class="heat-title">
- 数据感知
- <span class="heat-sub">有效率</span>
- <span class="rk-tip" tabindex="0" aria-label="有效率说明">
- ?
- <span class="rk-tip-pop">
- 模型数据质量表明数据质量是否足够支撑对应传感器数据质量有效率,反映各传感器数据的可靠性。通常有效率在
- 70% 以上更能保证结果的合理产生。颜色越绿表示数据质量越好。
- </span>
- </span>
- </h2>
- <div class="sensor-legend">
- <span v-for="item in sensorLegend" :key="item[0]">
- <i :style="{ background: item[1] }"></i>{{ item[0] }}
- </span>
- </div>
- <div class="heat-wrap">
- <table class="heat">
- <tr>
- <th></th>
- <th v-for="u in scopedUnits" :key="u.id">{{ u.engineName || u.no }}号</th>
- </tr>
- <tr v-for="row in sensorRows" :key="row.name">
- <th>{{ row.name }}</th>
- <td v-for="(v, i) in row.values" :key="i" :style="sensorCellStyle(v)">
- {{ fmtPct(v) }}
- </td>
- </tr>
- </table>
- </div>
- </section>
- <!-- 功能诊断热力图 -->
- <section class="rk-card heat-card">
- <h2 class="heat-title">功能诊断</h2>
- <div class="diag-legend">
- <span><i class="sym-miss">/</i>数据缺失</span>
- <span><i class="sym-normal">—</i>正常</span>
- <span><i class="sym-warn">?</i>可能异常</span>
- <span><i class="sym-alert">1</i>异常</span>
- </div>
- <div class="heat-wrap">
- <table class="heat diag-heat">
- <tr>
- <th></th>
- <th v-for="u in scopedUnits" :key="u.id">{{ u.engineName || u.no }}号</th>
- </tr>
- <tr v-for="row in heatDiag" :key="row.mod + row.det">
- <th>{{ row.name }}</th>
- <td
- v-for="cell in row.cells"
- :key="cell.unitId"
- class="heat-cell"
- :title="cell.title"
- :style="{ background: cell.mark.bg, color: cell.mark.color }"
- @click="onHeatClick(cell.unitId, row.mod, row.det)"
- >
- {{ cell.mark.symbol }}
- </td>
- </tr>
- </table>
- </div>
- </section>
- </div>
- <!-- 风机列表 -->
- <section class="rk-card section-gap">
- <h2>风机列表</h2>
- <div class="turbine-grid">
- <button
- v-for="u in sortedUnits"
- :key="u.id"
- type="button"
- class="turbine-cell"
- :class="[isUnitBad(u) ? 'abnormal' : 'normal', { 'is-on': farmPane === 'unit' && u.id === unitId }]"
- @click="enterUnit(u.id, true)"
- >
- <img class="turbine-icon" :src="turbineIcon" alt="" />
- <span class="turbine-name">{{ u.engineName || u.no }}号</span>
- </button>
- </div>
- </section>
- <!-- 功能诊断图表(对齐原型 det-panel + det-tabs) -->
- <section ref="charts" class="rk-card section-gap farm-diag-charts" id="farmDiagCharts">
- <div class="chart-head">
- <h2>风电项目功能诊断图表</h2>
- </div>
- <div class="rk-tabs module-tabs">
- <button
- v-for="m in moduleTabs"
- :key="m[0]"
- type="button"
- class="rk-tab"
- :class="{ on: m[0] === module }"
- @click="setModule(m[0])"
- >
- {{ m[1] }}
- </button>
- </div>
- <section class="det-panel">
- <div class="rk-tabs det-tabs">
- <button
- v-for="d in detectorList"
- :key="d[0]"
- type="button"
- class="rk-tab"
- :class="{ on: d[0] === detector }"
- @click="detector = d[0]"
- >
- {{ d[1] }}
- </button>
- </div>
- <div class="det-body">
- <div class="pane-tabs">
- <button
- type="button"
- class="rk-tab"
- :class="{ on: farmPane === 'overview' }"
- @click="farmPane = 'overview'"
- >
- 项目总览
- </button>
- <button
- type="button"
- class="rk-tab"
- :class="{ on: farmPane === 'unit' }"
- @click="enterUnit(unitId || (sortedUnits[0] && sortedUnits[0].id), false)"
- >
- 机组详情
- </button>
- </div>
- <div v-if="farmPane === 'overview'" class="farm-chart-pane">
- <V6FarmCharts
- mode="overview"
- :project-name="v6ProjectName"
- :alg="currentDetectorAlg"
- :unit-ids="scopedUnitIds"
- :year="periodYear"
- :month="periodNumber"
- :field-code="projectId"
- :machine-type-code="overviewMachineType"
- :machine-types="overviewMachineTypes"
- :unit-summaries="unitSummaries"
- :month-key="periodValue"
- @open-unit="onV6OpenUnit"
- />
- </div>
- <div v-else ref="unitPane" class="farm-unit-pane">
- <div class="detail-filters">
- <label class="farm-filter__item">
- <span class="rk-muted">机组</span>
- <el-select
- v-model="unitId"
- size="small"
- filterable
- placeholder="选择机组"
- >
- <el-option
- v-for="u in sortedUnits"
- :key="u.id"
- :value="u.id"
- :label="(u.engineName || u.no) + '号 · ' + modelName(u.modelId)"
- />
- </el-select>
- </label>
- <span class="rk-muted count"
- >可选 {{ sortedUnits.length }} 台</span
- >
- </div>
- <div v-if="currentUnit" class="unit-line">
- <b>{{ farmName(currentUnit.farmId) }}</b>
- <span>{{ projectName(currentUnit.projectId) }}</span>
- <span>{{ modelName(currentUnit.modelId) }}</span>
- <span>风机 {{ currentUnit.engineName || currentUnit.no }}</span>
- </div>
- <V6FarmCharts
- mode="detail"
- :project-name="v6ProjectName"
- :alg="currentDetectorAlg"
- :unit-id="currentUnit ? currentUnit.id : ''"
- :year="periodYear"
- :month="periodNumber"
- :detail-temp="currentDetectorAlg === 'A22' ? detailTemp : ''"
- :field-code="projectId"
- :machine-type-code="currentUnit ? currentUnit.modelId : ''"
- :engine-code="currentUnit ? currentUnit.id : ''"
- :month-key="periodValue"
- @open-unit="onV6OpenUnit"
- @set-temp="detailTemp = $event"
- />
- </div>
- </div>
- </section>
- </section>
- </div>
- </template>
- <script>
- import { FARMS, PROJECTS, MODELS, UNITS } from "./mock";
- import {
- MODULE_TABS,
- DETECTORS,
- DET_ALG,
- PERIOD_YEARS,
- PERIOD_MONTHS,
- } from "./constants";
- import {
- HEAT_DIAG,
- SENSE_RADAR_LABELS,
- DIAG_RADAR_LABELS,
- SENSOR_LEGEND,
- heatMark,
- sensorCellStyle,
- senseEffectiveness,
- senseRadarCounts,
- diagRadarCounts,
- radarData,
- detectorStatus,
- isUnitBad,
- abnormalOf,
- } from "./utils/farmDiagHelpers";
- import turbineIcon from "@/assets/ranking/iconFJ2-fit.png";
- import ReportExportDialog from "./components/ReportExportDialog.vue";
- import V6FarmCharts from "./components/V6FarmCharts.vue";
- import { loadFarmDiagBoard } from "./services/boardData";
- function firstDetector(module) {
- const list = DETECTORS[module] || [];
- return list[0] ? list[0][0] : "";
- }
- export default {
- name: "FarmDiagView",
- components: { ReportExportDialog, V6FarmCharts },
- data() {
- return {
- farms: FARMS,
- projects: PROJECTS,
- models: MODELS,
- units: UNITS,
- moduleTabs: MODULE_TABS,
- sensorLegend: SENSOR_LEGEND,
- turbineIcon,
- periodYears: PERIOD_YEARS,
- projectId: PROJECTS[0] ? PROJECTS[0].id : "",
- farmId: PROJECTS[0] ? PROJECTS[0].farmId : "",
- filterModelId: "",
- filterUnitIds: null,
- unitMultiOpen: false,
- periodYear: 2026,
- periodNumber: 8,
- module: "windRes",
- detector: firstDetector("windRes"),
- farmPane: "overview",
- unitId: "",
- detailTemp: "",
- sort: "asc",
- reportOpen: false,
- dataSource: "mock",
- catalogReady: false,
- boardSeq: 0,
- scopedKey: "",
- };
- },
- computed: {
- currentProject() {
- return this.projects.find((p) => p.id === this.projectId) || null;
- },
- farmProjects() {
- return this.projects.filter((p) => p.farmId === this.farmId);
- },
- periodMonths() {
- return PERIOD_MONTHS[this.periodYear] || PERIOD_MONTHS[2026];
- },
- periodLabel() {
- return this.periodYear + "年" + this.periodNumber + "月";
- },
- periodValue: {
- get() {
- return this.periodYear + "-" + String(this.periodNumber).padStart(2, "0");
- },
- set(val) {
- if (!val) return;
- const parts = String(val).split("-");
- this.periodYear = Number(parts[0]);
- this.periodNumber = Number(parts[1]);
- },
- },
- periodPickerOptions() {
- return {
- disabledDate: (date) => {
- const months = PERIOD_MONTHS[date.getFullYear()];
- if (!months) return true;
- return !months.includes(date.getMonth() + 1);
- },
- };
- },
- projectModels() {
- const projectUnits = this.units.filter((u) => u.projectId === this.projectId);
- const map = new Map();
- projectUnits.forEach((u) => {
- if (u.modelId) map.set(u.modelId, this.modelName(u.modelId) || u.modelId);
- });
- return [...map.entries()].sort((a, b) =>
- String(a[1]).localeCompare(String(b[1]), "zh"),
- );
- },
- diagFilterPool() {
- let list = this.units.filter((u) => u.projectId === this.projectId);
- if (this.filterModelId) {
- list = list.filter((u) => u.modelId === this.filterModelId);
- }
- return list
- .slice()
- .sort((a, b) => {
- const am = this.modelName(a.modelId) || "";
- const bm = this.modelName(b.modelId) || "";
- const byModel = am.localeCompare(bm, "zh");
- if (byModel) return byModel;
- return String(a.no).localeCompare(String(b.no), "zh", {
- numeric: true,
- });
- });
- },
- unitGroups() {
- const groups = [];
- const map = new Map();
- this.diagFilterPool.forEach((u) => {
- const key = u.modelId || "_";
- if (!map.has(key)) {
- const g = {
- modelId: u.modelId,
- name: this.modelName(u.modelId) || "机型",
- units: [],
- };
- map.set(key, g);
- groups.push(g);
- }
- map.get(key).units.push(u);
- });
- return groups;
- },
- filterUnitLabel() {
- const total = this.diagFilterPool.length;
- if (!total) return "暂无机组";
- if (this.filterUnitIds == null) return `全部机组(${total})`;
- if (!this.filterUnitIds.length) return "未选机组";
- const names = this.diagFilterPool
- .filter((u) => this.filterUnitIds.includes(u.id))
- .map((u) => `${u.engineName || u.no}号`);
- if (!names.length) return "未选机组";
- return names.length <= 2
- ? names.join("、")
- : `已选 ${names.length}/${total} 台`;
- },
- scopedUnits() {
- let list = this.units.filter((u) => u.projectId === this.projectId);
- if (this.filterModelId) {
- list = list.filter((u) => u.modelId === this.filterModelId);
- }
- if (Array.isArray(this.filterUnitIds)) {
- const allow = new Set(this.filterUnitIds);
- list = list.filter((u) => allow.has(u.id));
- }
- return list;
- },
- sortedUnits() {
- const list = this.scopedUnits
- .slice()
- .sort((a, b) => String(a.no).localeCompare(String(b.no), "zh", { numeric: true }));
- return this.sort === "desc" ? list.reverse() : list;
- },
- abnormalCount() {
- return abnormalOf(this.scopedUnits);
- },
- radars() {
- const us = this.scopedUnits;
- return [
- {
- title: "数据感知",
- stroke: "#3ee0ff",
- fill: "rgba(62,224,255,.14)",
- data: radarData(SENSE_RADAR_LABELS, senseRadarCounts(us)),
- },
- {
- title: "功能诊断",
- stroke: "#4aa3ff",
- fill: "rgba(74,163,255,.12)",
- data: radarData(DIAG_RADAR_LABELS, diagRadarCounts(us)),
- },
- ];
- },
- sensorRows() {
- return senseEffectiveness(this.scopedUnits);
- },
- heatDiag() {
- return HEAT_DIAG.map(([key, name, mod, det]) => ({
- key,
- name,
- mod,
- det,
- cells: this.scopedUnits.map((u) => {
- const status = detectorStatus(u, det);
- return {
- unitId: u.id,
- mark: heatMark(status, true),
- title: `${u.engineName || u.no} · ${name} · ${status || "无数据"}`,
- };
- }),
- }));
- },
- detectorList() {
- return DETECTORS[this.module] || [];
- },
- currentDetectorAlg() {
- return DET_ALG[this.detector] || "";
- },
- overviewMachineType() {
- if (this.filterModelId) return this.filterModelId;
- const unit = this.scopedUnits[0];
- return unit && unit.modelId ? unit.modelId : "";
- },
- overviewMachineTypes() {
- if (this.filterModelId) {
- return [{ id: this.filterModelId, name: this.modelName(this.filterModelId) || this.filterModelId }];
- }
- return this.projectModels.map(([id, name]) => ({ id, name: name || id }));
- },
- unitSummaries() {
- return this.scopedUnits.map((unit) => ({
- id: unit.id,
- no: unit.no,
- engineName: unit.engineName,
- modelId: unit.modelId,
- modelName: this.modelName(unit.modelId) || unit.modelId,
- status: detectorStatus(unit, this.detector),
- }));
- },
- v6ProjectName() {
- const project = this.currentProject;
- if (!project) return "";
- if (project.v6) return project.v6;
- const name = project.name || "";
- if (name.indexOf("乐坪") >= 0) return "乐坪";
- if (name.indexOf("赵家梁子") >= 0) return "赵家梁子";
- if (name.indexOf("梅花山") >= 0) return "梅花山";
- return name;
- },
- scopedUnitIds() {
- return this.scopedUnits.map((u) => u.id);
- },
- currentUnit() {
- return this.sortedUnits.find((u) => u.id === this.unitId) || null;
- },
- },
- watch: {
- "$route.query": {
- handler() {
- this.applyRouteQuery();
- },
- },
- periodYear() {
- this.clampPeriodMonth();
- this.scheduleScopedReload();
- },
- periodNumber() {
- this.scheduleScopedReload();
- },
- projectId() {
- this.scheduleScopedReload();
- },
- farmId() {
- this.scheduleScopedReload();
- },
- detector() {
- if (this.currentDetectorAlg !== "A22") this.detailTemp = "";
- },
- },
- mounted() {
- this.applyRouteQuery();
- this.clampPeriodMonth();
- this.loadBoardData();
- document.addEventListener("click", this.closeUnitMulti);
- },
- beforeDestroy() {
- clearTimeout(this._boardTimer);
- document.removeEventListener("click", this.closeUnitMulti);
- },
- methods: {
- farmName(id) {
- return (this.farms.find((f) => f.id === id) || {}).name || "";
- },
- projectName(id) {
- return (this.projects.find((p) => p.id === id) || {}).name || "";
- },
- modelName(id) {
- return (this.models.find((m) => m.id === id) || {}).name || "";
- },
- heatMark,
- sensorCellStyle,
- isUnitBad,
- fmtPct(v) {
- return v == null || !Number.isFinite(Number(v)) ? "/" : Number(v).toFixed(2) + "%";
- },
- clampPeriodMonth() {
- const months = this.periodMonths;
- if (!months.includes(this.periodNumber)) {
- this.periodNumber = months.includes(8)
- ? 8
- : months[months.length - 1];
- }
- },
- applyRouteQuery() {
- const { projectId, farmId, fieldCode } = this.$route.query || {};
- let project = null;
- const pid = projectId || fieldCode;
- if (pid) project = this.projects.find((p) => p.id === pid);
- if (!project && farmId) project = this.projects.find((p) => p.farmId === farmId);
- if (project) {
- this.projectId = project.id;
- this.farmId = project.farmId;
- this.unitId = "";
- this.filterModelId = "";
- this.filterUnitIds = null;
- }
- },
- onFarmChange() {
- const list = this.farmProjects;
- const hit = list.find((p) => p.id === this.projectId) || list[0];
- this.projectId = hit ? hit.id : "";
- this.filterModelId = "";
- this.filterUnitIds = null;
- this.unitId = "";
- this.farmPane = "overview";
- this.closeUnitMulti();
- },
- onProjectChange() {
- const project = this.currentProject;
- if (project) this.farmId = project.farmId;
- this.filterModelId = "";
- this.filterUnitIds = null;
- this.unitId = "";
- this.farmPane = "overview";
- this.closeUnitMulti();
- },
- onModelFilterChange() {
- this.pruneFilterUnits();
- this.unitId = "";
- this.closeUnitMulti();
- },
- pruneFilterUnits() {
- if (!Array.isArray(this.filterUnitIds)) return;
- const allow = new Set(this.diagFilterPool.map((u) => u.id));
- this.filterUnitIds = this.filterUnitIds.filter((id) => allow.has(id));
- if (
- this.filterUnitIds.length === this.diagFilterPool.length &&
- this.diagFilterPool.every((u) => this.filterUnitIds.includes(u.id))
- ) {
- this.filterUnitIds = null;
- }
- },
- toggleUnitMulti() {
- this.unitMultiOpen = !this.unitMultiOpen;
- },
- closeUnitMulti() {
- this.unitMultiOpen = false;
- },
- isUnitChecked(id) {
- if (this.filterUnitIds == null) return true;
- return this.filterUnitIds.indexOf(id) >= 0;
- },
- toggleAllUnits(checked) {
- this.filterUnitIds = checked ? null : [];
- },
- toggleUnit(id, checked) {
- const pool = this.diagFilterPool.map((u) => u.id);
- let next =
- this.filterUnitIds == null ? pool.slice() : this.filterUnitIds.slice();
- if (checked) {
- if (next.indexOf(id) < 0) next.push(id);
- } else {
- next = next.filter((x) => x !== id);
- }
- if (next.length === pool.length && pool.every((x) => next.indexOf(x) >= 0)) {
- this.filterUnitIds = null;
- } else {
- this.filterUnitIds = next;
- }
- },
- scheduleScopedReload() {
- if (!this.catalogReady) return;
- const key = [this.projectId, this.farmId, this.periodYear, this.periodNumber].join("|");
- if (key === this.scopedKey) return;
- clearTimeout(this._boardTimer);
- this._boardTimer = setTimeout(() => {
- const seq = ++this.boardSeq;
- this.loadScopedBoard(seq);
- }, 60);
- },
- async loadBoardData() {
- const seq = ++this.boardSeq;
- try {
- if (!this.catalogReady) {
- const cat = await loadFarmDiagBoard({
- year: this.periodYear,
- number: this.periodNumber,
- });
- if (seq !== this.boardSeq) return;
- const catalog = cat && cat.data;
- if (catalog) {
- if (Array.isArray(catalog.farms) && catalog.farms.length) {
- this.farms = catalog.farms;
- }
- if (Array.isArray(catalog.projects) && catalog.projects.length) {
- this.projects = catalog.projects;
- }
- if (Array.isArray(catalog.models) && catalog.models.length) {
- this.models = catalog.models;
- }
- }
- this.applyRouteQuery();
- if (!this.farms.some((farm) => farm.id === this.farmId)) {
- this.farmId = this.farms[0] ? this.farms[0].id : "";
- }
- const inFarm = this.farmId
- ? this.projects.filter((project) => project.farmId === this.farmId)
- : this.projects;
- if (!inFarm.some((project) => project.id === this.projectId)) {
- const first = inFarm[0] || this.projects[0];
- this.projectId = first ? first.id : "";
- if (first && first.farmId) this.farmId = first.farmId;
- }
- this.units = [];
- this.catalogReady = true;
- }
- await this.loadScopedBoard(seq);
- } catch (_e) {
- if (seq !== this.boardSeq) return;
- this.dataSource = "empty";
- this.farms = [];
- this.projects = [];
- this.models = [];
- this.units = [];
- }
- },
- async loadScopedBoard(seq) {
- this.scopedKey = [this.projectId, this.farmId, this.periodYear, this.periodNumber].join("|");
- if (!this.projectId) {
- this.units = [];
- this.dataSource = "empty";
- return;
- }
- try {
- const { source, data } = await loadFarmDiagBoard({
- year: this.periodYear,
- number: this.periodNumber,
- projectId: this.projectId,
- farmId: this.farmId,
- });
- if (seq !== this.boardSeq) return;
- this.dataSource = source;
- if (!data) return;
- if (Array.isArray(data.models) && data.models.length) {
- this.models = data.models;
- }
- if (Array.isArray(data.units)) {
- this.units = data.units;
- }
- } catch (_e) {
- if (seq !== this.boardSeq) return;
- this.dataSource = "empty";
- this.units = [];
- }
- },
- onDownloadReport() {
- this.reportOpen = true;
- },
- setModule(id) {
- this.module = id;
- const group = DETECTORS[id] || [];
- if (!group.some((d) => d[0] === this.detector)) this.detector = firstDetector(id);
- },
- onV6OpenUnit({ id, temp, alg }) {
- if (alg === "A22" || temp) {
- this.module = "partTemp";
- this.detector = "partTemp";
- this.detailTemp = temp || "";
- } else {
- this.detailTemp = "";
- }
- this.enterUnit(id, true);
- },
- enterUnit(id, scroll) {
- const key = String(id);
- const u = this.units.find((item) => String(item.id) === key || String(item.no) === key);
- if (!u) return;
- this.unitId = u.id;
- this.farmId = u.farmId;
- this.projectId = u.projectId;
- this.farmPane = "unit";
- if (scroll) this.scrollToUnitDetail();
- },
- onHeatClick(unitId, mod, det) {
- this.module = mod;
- this.detector = det;
- this.enterUnit(unitId, true);
- },
- scrollToCharts() {
- this.scrollToUnitDetail();
- },
- scrollToUnitDetail() {
- this.$nextTick(() => {
- this.$nextTick(() => {
- const el = this.$refs.unitPane || this.$refs.charts;
- if (el && el.scrollIntoView) el.scrollIntoView({ behavior: "smooth", block: "start" });
- });
- });
- },
- },
- };
- </script>
|