FarmDiagView.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. <template>
  2. <div class="ranking-farm">
  3. <!-- 顶部筛选(对齐原型 filter-bar) -->
  4. <div class="farm-filter">
  5. <el-select v-model="farmId" size="small" @change="onFarmChange">
  6. <el-option
  7. v-for="f in farms"
  8. :key="f.id"
  9. :value="f.id"
  10. :label="f.name"
  11. />
  12. </el-select>
  13. <el-select v-model="projectId" size="small" @change="onProjectChange">
  14. <el-option
  15. v-for="p in farmProjects"
  16. :key="p.id"
  17. :value="p.id"
  18. :label="p.name"
  19. />
  20. </el-select>
  21. <div class="diag-filters">
  22. <div class="diag-field">
  23. <span>机型</span>
  24. <el-select
  25. v-model="filterModelId"
  26. size="small"
  27. @change="onModelFilterChange"
  28. >
  29. <el-option
  30. value=""
  31. :label="'全部机型(' + projectModels.length + ')'"
  32. />
  33. <el-option
  34. v-for="m in projectModels"
  35. :key="m[0]"
  36. :value="m[0]"
  37. :label="m[1]"
  38. />
  39. </el-select>
  40. </div>
  41. <div class="diag-field">
  42. <span>机组</span>
  43. <div class="multi-select" :class="{ open: unitMultiOpen }">
  44. <button
  45. type="button"
  46. class="multi-trigger"
  47. :aria-expanded="unitMultiOpen ? 'true' : 'false'"
  48. @click.stop="toggleUnitMulti"
  49. >
  50. {{ filterUnitLabel }}
  51. </button>
  52. <div
  53. v-show="unitMultiOpen"
  54. class="multi-panel"
  55. role="listbox"
  56. @click.stop
  57. >
  58. <label class="multi-all">
  59. <input
  60. type="checkbox"
  61. :checked="filterUnitIds == null"
  62. @change="toggleAllUnits($event.target.checked)"
  63. />
  64. <span>全部机组({{ diagFilterPool.length }})</span>
  65. </label>
  66. <template v-if="diagFilterPool.length">
  67. <div
  68. v-for="group in unitGroups"
  69. :key="group.modelId || '_'"
  70. class="multi-group-block"
  71. >
  72. <div class="multi-group">
  73. {{ group.name }} · {{ group.units.length }} 台
  74. </div>
  75. <label v-for="u in group.units" :key="u.id">
  76. <input
  77. type="checkbox"
  78. :checked="isUnitChecked(u.id)"
  79. @change="toggleUnit(u.id, $event.target.checked)"
  80. />
  81. <span>{{ u.engineName || u.no }}号</span>
  82. <em>{{ modelName(u.modelId) }}</em>
  83. </label>
  84. </div>
  85. </template>
  86. <div v-else class="multi-empty">当前项目/机型下暂无机组</div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <div class="date-field">
  92. <el-date-picker
  93. v-model="periodValue"
  94. type="month"
  95. value-format="yyyy-MM"
  96. :clearable="false"
  97. :editable="false"
  98. size="small"
  99. prefix-icon="el-icon-date"
  100. placeholder="选择月份"
  101. :picker-options="periodPickerOptions"
  102. />
  103. </div>
  104. <div class="spacer"></div>
  105. <button type="button" class="rk-btn primary" @click="onDownloadReport">
  106. 下载报告
  107. </button>
  108. </div>
  109. <report-export-dialog
  110. v-model="reportOpen"
  111. :year="periodYear"
  112. :number="periodNumber"
  113. :project-id="projectId"
  114. :project-name="currentProject ? currentProject.name : ''"
  115. :farm-id="farmId"
  116. :model-id="filterModelId"
  117. :units="units"
  118. :models="models"
  119. />
  120. <div class="cards-3">
  121. <!-- 概览 -->
  122. <section class="rk-card farm-overview">
  123. <h2>风电项目异常概览</h2>
  124. <p class="rk-muted">
  125. {{ currentProject ? currentProject.name + " · " + farmName(currentProject.farmId) : "" }}
  126. · {{ periodLabel }}
  127. </p>
  128. <div class="rk-kpis">
  129. <div class="rk-kpi">
  130. <span>机组总数</span>
  131. <b>{{ scopedUnits.length }}</b>
  132. </div>
  133. <div class="rk-kpi alert">
  134. <span>异常台数</span>
  135. <b>{{ abnormalCount }}</b>
  136. </div>
  137. </div>
  138. <div class="radar-pair">
  139. <div v-for="r in radars" :key="r.title" class="radar-block">
  140. <div class="radar-header">
  141. <h3 class="radar-title" :style="{ '--dot': r.stroke }">{{ r.title }}</h3>
  142. <span class="radar-abnormal">异常台数</span>
  143. </div>
  144. <div class="radar-wrap" :data-tip="r.data.tip">
  145. <svg class="radar" viewBox="0 0 200 200">
  146. <polygon
  147. v-for="(pts, i) in r.data.grid.rings"
  148. :key="'ring' + i"
  149. :points="pts"
  150. fill="none"
  151. stroke="rgba(186,196,210,.18)"
  152. stroke-width="0.6"
  153. />
  154. <line
  155. v-for="(s, i) in r.data.grid.spokes"
  156. :key="'spoke' + i"
  157. :x1="s.x1"
  158. :y1="s.y1"
  159. :x2="s.x2"
  160. :y2="s.y2"
  161. stroke="rgba(186,196,210,.12)"
  162. stroke-width="0.5"
  163. />
  164. <text
  165. v-for="(t, i) in r.data.grid.ticks"
  166. :key="'tick' + i"
  167. :x="t.x"
  168. :y="t.y"
  169. fill="rgba(186,196,210,.55)"
  170. font-size="4"
  171. >
  172. {{ t.text }}
  173. </text>
  174. <polygon
  175. :points="r.data.points"
  176. :fill="r.fill"
  177. :stroke="r.stroke"
  178. stroke-width="1.6"
  179. stroke-linejoin="round"
  180. />
  181. <text
  182. v-for="(l, i) in r.data.labels"
  183. :key="'lab' + i"
  184. :text-anchor="l.anchor"
  185. fill="rgba(186,196,210,.75)"
  186. font-size="9.5"
  187. >
  188. <tspan
  189. v-for="(line, j) in l.lines"
  190. :key="j"
  191. :x="l.x"
  192. :y="line.y"
  193. >{{ line.text }}</tspan>
  194. </text>
  195. </svg>
  196. </div>
  197. </div>
  198. </div>
  199. </section>
  200. <!-- 数据感知热力图 -->
  201. <section class="rk-card heat-card sensor-card">
  202. <h2 class="heat-title">
  203. 数据感知
  204. <span class="heat-sub">有效率</span>
  205. <span class="rk-tip" tabindex="0" aria-label="有效率说明">
  206. ?
  207. <span class="rk-tip-pop">
  208. 模型数据质量表明数据质量是否足够支撑对应传感器数据质量有效率,反映各传感器数据的可靠性。通常有效率在
  209. 70% 以上更能保证结果的合理产生。颜色越绿表示数据质量越好。
  210. </span>
  211. </span>
  212. </h2>
  213. <div class="sensor-legend">
  214. <span v-for="item in sensorLegend" :key="item[0]">
  215. <i :style="{ background: item[1] }"></i>{{ item[0] }}
  216. </span>
  217. </div>
  218. <div class="heat-wrap">
  219. <table class="heat">
  220. <tr>
  221. <th></th>
  222. <th v-for="u in scopedUnits" :key="u.id">{{ u.engineName || u.no }}号</th>
  223. </tr>
  224. <tr v-for="row in sensorRows" :key="row.name">
  225. <th>{{ row.name }}</th>
  226. <td v-for="(v, i) in row.values" :key="i" :style="sensorCellStyle(v)">
  227. {{ fmtPct(v) }}
  228. </td>
  229. </tr>
  230. </table>
  231. </div>
  232. </section>
  233. <!-- 功能诊断热力图 -->
  234. <section class="rk-card heat-card">
  235. <h2 class="heat-title">功能诊断</h2>
  236. <div class="diag-legend">
  237. <span><i class="sym-miss">/</i>数据缺失</span>
  238. <span><i class="sym-normal">—</i>正常</span>
  239. <span><i class="sym-warn">?</i>可能异常</span>
  240. <span><i class="sym-alert">1</i>异常</span>
  241. </div>
  242. <div class="heat-wrap">
  243. <table class="heat diag-heat">
  244. <tr>
  245. <th></th>
  246. <th v-for="u in scopedUnits" :key="u.id">{{ u.engineName || u.no }}号</th>
  247. </tr>
  248. <tr v-for="row in heatDiag" :key="row.mod + row.det">
  249. <th>{{ row.name }}</th>
  250. <td
  251. v-for="cell in row.cells"
  252. :key="cell.unitId"
  253. class="heat-cell"
  254. :title="cell.title"
  255. :style="{ background: cell.mark.bg, color: cell.mark.color }"
  256. @click="onHeatClick(cell.unitId, row.mod, row.det)"
  257. >
  258. {{ cell.mark.symbol }}
  259. </td>
  260. </tr>
  261. </table>
  262. </div>
  263. </section>
  264. </div>
  265. <!-- 风机列表 -->
  266. <section class="rk-card section-gap">
  267. <h2>风机列表</h2>
  268. <div class="turbine-grid">
  269. <button
  270. v-for="u in sortedUnits"
  271. :key="u.id"
  272. type="button"
  273. class="turbine-cell"
  274. :class="[isUnitBad(u) ? 'abnormal' : 'normal', { 'is-on': farmPane === 'unit' && u.id === unitId }]"
  275. @click="enterUnit(u.id, true)"
  276. >
  277. <img class="turbine-icon" :src="turbineIcon" alt="" />
  278. <span class="turbine-name">{{ u.engineName || u.no }}号</span>
  279. </button>
  280. </div>
  281. </section>
  282. <!-- 功能诊断图表(对齐原型 det-panel + det-tabs) -->
  283. <section ref="charts" class="rk-card section-gap farm-diag-charts" id="farmDiagCharts">
  284. <div class="chart-head">
  285. <h2>风电项目功能诊断图表</h2>
  286. </div>
  287. <div class="rk-tabs module-tabs">
  288. <button
  289. v-for="m in moduleTabs"
  290. :key="m[0]"
  291. type="button"
  292. class="rk-tab"
  293. :class="{ on: m[0] === module }"
  294. @click="setModule(m[0])"
  295. >
  296. {{ m[1] }}
  297. </button>
  298. </div>
  299. <section class="det-panel">
  300. <div class="rk-tabs det-tabs">
  301. <button
  302. v-for="d in detectorList"
  303. :key="d[0]"
  304. type="button"
  305. class="rk-tab"
  306. :class="{ on: d[0] === detector }"
  307. @click="detector = d[0]"
  308. >
  309. {{ d[1] }}
  310. </button>
  311. </div>
  312. <div class="det-body">
  313. <div class="pane-tabs">
  314. <button
  315. type="button"
  316. class="rk-tab"
  317. :class="{ on: farmPane === 'overview' }"
  318. @click="farmPane = 'overview'"
  319. >
  320. 项目总览
  321. </button>
  322. <button
  323. type="button"
  324. class="rk-tab"
  325. :class="{ on: farmPane === 'unit' }"
  326. @click="enterUnit(unitId || (sortedUnits[0] && sortedUnits[0].id), false)"
  327. >
  328. 机组详情
  329. </button>
  330. </div>
  331. <div v-if="farmPane === 'overview'" class="farm-chart-pane">
  332. <V6FarmCharts
  333. mode="overview"
  334. :project-name="v6ProjectName"
  335. :alg="currentDetectorAlg"
  336. :unit-ids="scopedUnitIds"
  337. :year="periodYear"
  338. :month="periodNumber"
  339. :field-code="projectId"
  340. :machine-type-code="overviewMachineType"
  341. :machine-types="overviewMachineTypes"
  342. :unit-summaries="unitSummaries"
  343. :month-key="periodValue"
  344. @open-unit="onV6OpenUnit"
  345. />
  346. </div>
  347. <div v-else ref="unitPane" class="farm-unit-pane">
  348. <div class="detail-filters">
  349. <label class="farm-filter__item">
  350. <span class="rk-muted">机组</span>
  351. <el-select
  352. v-model="unitId"
  353. size="small"
  354. filterable
  355. placeholder="选择机组"
  356. >
  357. <el-option
  358. v-for="u in sortedUnits"
  359. :key="u.id"
  360. :value="u.id"
  361. :label="(u.engineName || u.no) + '号 · ' + modelName(u.modelId)"
  362. />
  363. </el-select>
  364. </label>
  365. <span class="rk-muted count"
  366. >可选 {{ sortedUnits.length }} 台</span
  367. >
  368. </div>
  369. <div v-if="currentUnit" class="unit-line">
  370. <b>{{ farmName(currentUnit.farmId) }}</b>
  371. <span>{{ projectName(currentUnit.projectId) }}</span>
  372. <span>{{ modelName(currentUnit.modelId) }}</span>
  373. <span>风机 {{ currentUnit.engineName || currentUnit.no }}</span>
  374. </div>
  375. <V6FarmCharts
  376. mode="detail"
  377. :project-name="v6ProjectName"
  378. :alg="currentDetectorAlg"
  379. :unit-id="currentUnit ? currentUnit.id : ''"
  380. :year="periodYear"
  381. :month="periodNumber"
  382. :detail-temp="currentDetectorAlg === 'A22' ? detailTemp : ''"
  383. :field-code="projectId"
  384. :machine-type-code="currentUnit ? currentUnit.modelId : ''"
  385. :engine-code="currentUnit ? currentUnit.id : ''"
  386. :month-key="periodValue"
  387. @open-unit="onV6OpenUnit"
  388. @set-temp="detailTemp = $event"
  389. />
  390. </div>
  391. </div>
  392. </section>
  393. </section>
  394. </div>
  395. </template>
  396. <script>
  397. import { FARMS, PROJECTS, MODELS, UNITS } from "./mock";
  398. import {
  399. MODULE_TABS,
  400. DETECTORS,
  401. DET_ALG,
  402. PERIOD_YEARS,
  403. PERIOD_MONTHS,
  404. } from "./constants";
  405. import {
  406. HEAT_DIAG,
  407. SENSE_RADAR_LABELS,
  408. DIAG_RADAR_LABELS,
  409. SENSOR_LEGEND,
  410. heatMark,
  411. sensorCellStyle,
  412. senseEffectiveness,
  413. senseRadarCounts,
  414. diagRadarCounts,
  415. radarData,
  416. detectorStatus,
  417. isUnitBad,
  418. abnormalOf,
  419. } from "./utils/farmDiagHelpers";
  420. import turbineIcon from "@/assets/ranking/iconFJ2-fit.png";
  421. import ReportExportDialog from "./components/ReportExportDialog.vue";
  422. import V6FarmCharts from "./components/V6FarmCharts.vue";
  423. import { loadFarmDiagBoard } from "./services/boardData";
  424. function firstDetector(module) {
  425. const list = DETECTORS[module] || [];
  426. return list[0] ? list[0][0] : "";
  427. }
  428. export default {
  429. name: "FarmDiagView",
  430. components: { ReportExportDialog, V6FarmCharts },
  431. data() {
  432. return {
  433. farms: FARMS,
  434. projects: PROJECTS,
  435. models: MODELS,
  436. units: UNITS,
  437. moduleTabs: MODULE_TABS,
  438. sensorLegend: SENSOR_LEGEND,
  439. turbineIcon,
  440. periodYears: PERIOD_YEARS,
  441. projectId: PROJECTS[0] ? PROJECTS[0].id : "",
  442. farmId: PROJECTS[0] ? PROJECTS[0].farmId : "",
  443. filterModelId: "",
  444. filterUnitIds: null,
  445. unitMultiOpen: false,
  446. periodYear: 2026,
  447. periodNumber: 8,
  448. module: "windRes",
  449. detector: firstDetector("windRes"),
  450. farmPane: "overview",
  451. unitId: "",
  452. detailTemp: "",
  453. sort: "asc",
  454. reportOpen: false,
  455. dataSource: "mock",
  456. catalogReady: false,
  457. boardSeq: 0,
  458. scopedKey: "",
  459. };
  460. },
  461. computed: {
  462. currentProject() {
  463. return this.projects.find((p) => p.id === this.projectId) || null;
  464. },
  465. farmProjects() {
  466. return this.projects.filter((p) => p.farmId === this.farmId);
  467. },
  468. periodMonths() {
  469. return PERIOD_MONTHS[this.periodYear] || PERIOD_MONTHS[2026];
  470. },
  471. periodLabel() {
  472. return this.periodYear + "年" + this.periodNumber + "月";
  473. },
  474. periodValue: {
  475. get() {
  476. return this.periodYear + "-" + String(this.periodNumber).padStart(2, "0");
  477. },
  478. set(val) {
  479. if (!val) return;
  480. const parts = String(val).split("-");
  481. this.periodYear = Number(parts[0]);
  482. this.periodNumber = Number(parts[1]);
  483. },
  484. },
  485. periodPickerOptions() {
  486. return {
  487. disabledDate: (date) => {
  488. const months = PERIOD_MONTHS[date.getFullYear()];
  489. if (!months) return true;
  490. return !months.includes(date.getMonth() + 1);
  491. },
  492. };
  493. },
  494. projectModels() {
  495. const projectUnits = this.units.filter((u) => u.projectId === this.projectId);
  496. const map = new Map();
  497. projectUnits.forEach((u) => {
  498. if (u.modelId) map.set(u.modelId, this.modelName(u.modelId) || u.modelId);
  499. });
  500. return [...map.entries()].sort((a, b) =>
  501. String(a[1]).localeCompare(String(b[1]), "zh"),
  502. );
  503. },
  504. diagFilterPool() {
  505. let list = this.units.filter((u) => u.projectId === this.projectId);
  506. if (this.filterModelId) {
  507. list = list.filter((u) => u.modelId === this.filterModelId);
  508. }
  509. return list
  510. .slice()
  511. .sort((a, b) => {
  512. const am = this.modelName(a.modelId) || "";
  513. const bm = this.modelName(b.modelId) || "";
  514. const byModel = am.localeCompare(bm, "zh");
  515. if (byModel) return byModel;
  516. return String(a.no).localeCompare(String(b.no), "zh", {
  517. numeric: true,
  518. });
  519. });
  520. },
  521. unitGroups() {
  522. const groups = [];
  523. const map = new Map();
  524. this.diagFilterPool.forEach((u) => {
  525. const key = u.modelId || "_";
  526. if (!map.has(key)) {
  527. const g = {
  528. modelId: u.modelId,
  529. name: this.modelName(u.modelId) || "机型",
  530. units: [],
  531. };
  532. map.set(key, g);
  533. groups.push(g);
  534. }
  535. map.get(key).units.push(u);
  536. });
  537. return groups;
  538. },
  539. filterUnitLabel() {
  540. const total = this.diagFilterPool.length;
  541. if (!total) return "暂无机组";
  542. if (this.filterUnitIds == null) return `全部机组(${total})`;
  543. if (!this.filterUnitIds.length) return "未选机组";
  544. const names = this.diagFilterPool
  545. .filter((u) => this.filterUnitIds.includes(u.id))
  546. .map((u) => `${u.engineName || u.no}号`);
  547. if (!names.length) return "未选机组";
  548. return names.length <= 2
  549. ? names.join("、")
  550. : `已选 ${names.length}/${total} 台`;
  551. },
  552. scopedUnits() {
  553. let list = this.units.filter((u) => u.projectId === this.projectId);
  554. if (this.filterModelId) {
  555. list = list.filter((u) => u.modelId === this.filterModelId);
  556. }
  557. if (Array.isArray(this.filterUnitIds)) {
  558. const allow = new Set(this.filterUnitIds);
  559. list = list.filter((u) => allow.has(u.id));
  560. }
  561. return list;
  562. },
  563. sortedUnits() {
  564. const list = this.scopedUnits
  565. .slice()
  566. .sort((a, b) => String(a.no).localeCompare(String(b.no), "zh", { numeric: true }));
  567. return this.sort === "desc" ? list.reverse() : list;
  568. },
  569. abnormalCount() {
  570. return abnormalOf(this.scopedUnits);
  571. },
  572. radars() {
  573. const us = this.scopedUnits;
  574. return [
  575. {
  576. title: "数据感知",
  577. stroke: "#3ee0ff",
  578. fill: "rgba(62,224,255,.14)",
  579. data: radarData(SENSE_RADAR_LABELS, senseRadarCounts(us)),
  580. },
  581. {
  582. title: "功能诊断",
  583. stroke: "#4aa3ff",
  584. fill: "rgba(74,163,255,.12)",
  585. data: radarData(DIAG_RADAR_LABELS, diagRadarCounts(us)),
  586. },
  587. ];
  588. },
  589. sensorRows() {
  590. return senseEffectiveness(this.scopedUnits);
  591. },
  592. heatDiag() {
  593. return HEAT_DIAG.map(([key, name, mod, det]) => ({
  594. key,
  595. name,
  596. mod,
  597. det,
  598. cells: this.scopedUnits.map((u) => {
  599. const status = detectorStatus(u, det);
  600. return {
  601. unitId: u.id,
  602. mark: heatMark(status, true),
  603. title: `${u.engineName || u.no} · ${name} · ${status || "无数据"}`,
  604. };
  605. }),
  606. }));
  607. },
  608. detectorList() {
  609. return DETECTORS[this.module] || [];
  610. },
  611. currentDetectorAlg() {
  612. return DET_ALG[this.detector] || "";
  613. },
  614. overviewMachineType() {
  615. if (this.filterModelId) return this.filterModelId;
  616. const unit = this.scopedUnits[0];
  617. return unit && unit.modelId ? unit.modelId : "";
  618. },
  619. overviewMachineTypes() {
  620. if (this.filterModelId) {
  621. return [{ id: this.filterModelId, name: this.modelName(this.filterModelId) || this.filterModelId }];
  622. }
  623. return this.projectModels.map(([id, name]) => ({ id, name: name || id }));
  624. },
  625. unitSummaries() {
  626. return this.scopedUnits.map((unit) => ({
  627. id: unit.id,
  628. no: unit.no,
  629. engineName: unit.engineName,
  630. modelId: unit.modelId,
  631. modelName: this.modelName(unit.modelId) || unit.modelId,
  632. status: detectorStatus(unit, this.detector),
  633. }));
  634. },
  635. v6ProjectName() {
  636. const project = this.currentProject;
  637. if (!project) return "";
  638. if (project.v6) return project.v6;
  639. const name = project.name || "";
  640. if (name.indexOf("乐坪") >= 0) return "乐坪";
  641. if (name.indexOf("赵家梁子") >= 0) return "赵家梁子";
  642. if (name.indexOf("梅花山") >= 0) return "梅花山";
  643. return name;
  644. },
  645. scopedUnitIds() {
  646. return this.scopedUnits.map((u) => u.id);
  647. },
  648. currentUnit() {
  649. return this.sortedUnits.find((u) => u.id === this.unitId) || null;
  650. },
  651. },
  652. watch: {
  653. "$route.query": {
  654. handler() {
  655. this.applyRouteQuery();
  656. },
  657. },
  658. periodYear() {
  659. this.clampPeriodMonth();
  660. this.scheduleScopedReload();
  661. },
  662. periodNumber() {
  663. this.scheduleScopedReload();
  664. },
  665. projectId() {
  666. this.scheduleScopedReload();
  667. },
  668. farmId() {
  669. this.scheduleScopedReload();
  670. },
  671. detector() {
  672. if (this.currentDetectorAlg !== "A22") this.detailTemp = "";
  673. },
  674. },
  675. mounted() {
  676. this.applyRouteQuery();
  677. this.clampPeriodMonth();
  678. this.loadBoardData();
  679. document.addEventListener("click", this.closeUnitMulti);
  680. },
  681. beforeDestroy() {
  682. clearTimeout(this._boardTimer);
  683. document.removeEventListener("click", this.closeUnitMulti);
  684. },
  685. methods: {
  686. farmName(id) {
  687. return (this.farms.find((f) => f.id === id) || {}).name || "";
  688. },
  689. projectName(id) {
  690. return (this.projects.find((p) => p.id === id) || {}).name || "";
  691. },
  692. modelName(id) {
  693. return (this.models.find((m) => m.id === id) || {}).name || "";
  694. },
  695. heatMark,
  696. sensorCellStyle,
  697. isUnitBad,
  698. fmtPct(v) {
  699. return v == null || !Number.isFinite(Number(v)) ? "/" : Number(v).toFixed(2) + "%";
  700. },
  701. clampPeriodMonth() {
  702. const months = this.periodMonths;
  703. if (!months.includes(this.periodNumber)) {
  704. this.periodNumber = months.includes(8)
  705. ? 8
  706. : months[months.length - 1];
  707. }
  708. },
  709. applyRouteQuery() {
  710. const { projectId, farmId, fieldCode } = this.$route.query || {};
  711. let project = null;
  712. const pid = projectId || fieldCode;
  713. if (pid) project = this.projects.find((p) => p.id === pid);
  714. if (!project && farmId) project = this.projects.find((p) => p.farmId === farmId);
  715. if (project) {
  716. this.projectId = project.id;
  717. this.farmId = project.farmId;
  718. this.unitId = "";
  719. this.filterModelId = "";
  720. this.filterUnitIds = null;
  721. }
  722. },
  723. onFarmChange() {
  724. const list = this.farmProjects;
  725. const hit = list.find((p) => p.id === this.projectId) || list[0];
  726. this.projectId = hit ? hit.id : "";
  727. this.filterModelId = "";
  728. this.filterUnitIds = null;
  729. this.unitId = "";
  730. this.farmPane = "overview";
  731. this.closeUnitMulti();
  732. },
  733. onProjectChange() {
  734. const project = this.currentProject;
  735. if (project) this.farmId = project.farmId;
  736. this.filterModelId = "";
  737. this.filterUnitIds = null;
  738. this.unitId = "";
  739. this.farmPane = "overview";
  740. this.closeUnitMulti();
  741. },
  742. onModelFilterChange() {
  743. this.pruneFilterUnits();
  744. this.unitId = "";
  745. this.closeUnitMulti();
  746. },
  747. pruneFilterUnits() {
  748. if (!Array.isArray(this.filterUnitIds)) return;
  749. const allow = new Set(this.diagFilterPool.map((u) => u.id));
  750. this.filterUnitIds = this.filterUnitIds.filter((id) => allow.has(id));
  751. if (
  752. this.filterUnitIds.length === this.diagFilterPool.length &&
  753. this.diagFilterPool.every((u) => this.filterUnitIds.includes(u.id))
  754. ) {
  755. this.filterUnitIds = null;
  756. }
  757. },
  758. toggleUnitMulti() {
  759. this.unitMultiOpen = !this.unitMultiOpen;
  760. },
  761. closeUnitMulti() {
  762. this.unitMultiOpen = false;
  763. },
  764. isUnitChecked(id) {
  765. if (this.filterUnitIds == null) return true;
  766. return this.filterUnitIds.indexOf(id) >= 0;
  767. },
  768. toggleAllUnits(checked) {
  769. this.filterUnitIds = checked ? null : [];
  770. },
  771. toggleUnit(id, checked) {
  772. const pool = this.diagFilterPool.map((u) => u.id);
  773. let next =
  774. this.filterUnitIds == null ? pool.slice() : this.filterUnitIds.slice();
  775. if (checked) {
  776. if (next.indexOf(id) < 0) next.push(id);
  777. } else {
  778. next = next.filter((x) => x !== id);
  779. }
  780. if (next.length === pool.length && pool.every((x) => next.indexOf(x) >= 0)) {
  781. this.filterUnitIds = null;
  782. } else {
  783. this.filterUnitIds = next;
  784. }
  785. },
  786. scheduleScopedReload() {
  787. if (!this.catalogReady) return;
  788. const key = [this.projectId, this.farmId, this.periodYear, this.periodNumber].join("|");
  789. if (key === this.scopedKey) return;
  790. clearTimeout(this._boardTimer);
  791. this._boardTimer = setTimeout(() => {
  792. const seq = ++this.boardSeq;
  793. this.loadScopedBoard(seq);
  794. }, 60);
  795. },
  796. async loadBoardData() {
  797. const seq = ++this.boardSeq;
  798. try {
  799. if (!this.catalogReady) {
  800. const cat = await loadFarmDiagBoard({
  801. year: this.periodYear,
  802. number: this.periodNumber,
  803. });
  804. if (seq !== this.boardSeq) return;
  805. const catalog = cat && cat.data;
  806. if (catalog) {
  807. if (Array.isArray(catalog.farms) && catalog.farms.length) {
  808. this.farms = catalog.farms;
  809. }
  810. if (Array.isArray(catalog.projects) && catalog.projects.length) {
  811. this.projects = catalog.projects;
  812. }
  813. if (Array.isArray(catalog.models) && catalog.models.length) {
  814. this.models = catalog.models;
  815. }
  816. }
  817. this.applyRouteQuery();
  818. if (!this.farms.some((farm) => farm.id === this.farmId)) {
  819. this.farmId = this.farms[0] ? this.farms[0].id : "";
  820. }
  821. const inFarm = this.farmId
  822. ? this.projects.filter((project) => project.farmId === this.farmId)
  823. : this.projects;
  824. if (!inFarm.some((project) => project.id === this.projectId)) {
  825. const first = inFarm[0] || this.projects[0];
  826. this.projectId = first ? first.id : "";
  827. if (first && first.farmId) this.farmId = first.farmId;
  828. }
  829. this.units = [];
  830. this.catalogReady = true;
  831. }
  832. await this.loadScopedBoard(seq);
  833. } catch (_e) {
  834. if (seq !== this.boardSeq) return;
  835. this.dataSource = "empty";
  836. this.farms = [];
  837. this.projects = [];
  838. this.models = [];
  839. this.units = [];
  840. }
  841. },
  842. async loadScopedBoard(seq) {
  843. this.scopedKey = [this.projectId, this.farmId, this.periodYear, this.periodNumber].join("|");
  844. if (!this.projectId) {
  845. this.units = [];
  846. this.dataSource = "empty";
  847. return;
  848. }
  849. try {
  850. const { source, data } = await loadFarmDiagBoard({
  851. year: this.periodYear,
  852. number: this.periodNumber,
  853. projectId: this.projectId,
  854. farmId: this.farmId,
  855. });
  856. if (seq !== this.boardSeq) return;
  857. this.dataSource = source;
  858. if (!data) return;
  859. if (Array.isArray(data.models) && data.models.length) {
  860. this.models = data.models;
  861. }
  862. if (Array.isArray(data.units)) {
  863. this.units = data.units;
  864. }
  865. } catch (_e) {
  866. if (seq !== this.boardSeq) return;
  867. this.dataSource = "empty";
  868. this.units = [];
  869. }
  870. },
  871. onDownloadReport() {
  872. this.reportOpen = true;
  873. },
  874. setModule(id) {
  875. this.module = id;
  876. const group = DETECTORS[id] || [];
  877. if (!group.some((d) => d[0] === this.detector)) this.detector = firstDetector(id);
  878. },
  879. onV6OpenUnit({ id, temp, alg }) {
  880. if (alg === "A22" || temp) {
  881. this.module = "partTemp";
  882. this.detector = "partTemp";
  883. this.detailTemp = temp || "";
  884. } else {
  885. this.detailTemp = "";
  886. }
  887. this.enterUnit(id, true);
  888. },
  889. enterUnit(id, scroll) {
  890. const key = String(id);
  891. const u = this.units.find((item) => String(item.id) === key || String(item.no) === key);
  892. if (!u) return;
  893. this.unitId = u.id;
  894. this.farmId = u.farmId;
  895. this.projectId = u.projectId;
  896. this.farmPane = "unit";
  897. if (scroll) this.scrollToUnitDetail();
  898. },
  899. onHeatClick(unitId, mod, det) {
  900. this.module = mod;
  901. this.detector = det;
  902. this.enterUnit(unitId, true);
  903. },
  904. scrollToCharts() {
  905. this.scrollToUnitDetail();
  906. },
  907. scrollToUnitDetail() {
  908. this.$nextTick(() => {
  909. this.$nextTick(() => {
  910. const el = this.$refs.unitPane || this.$refs.charts;
  911. if (el && el.scrollIntoView) el.scrollIntoView({ behavior: "smooth", block: "start" });
  912. });
  913. });
  914. },
  915. },
  916. };
  917. </script>