index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div
  3. v-loading="loading"
  4. class="health-dashboard-page"
  5. element-loading-background="rgba(5, 14, 35, 0.75)"
  6. >
  7. <HealthHeader
  8. v-model="companyCode"
  9. :datatime.sync="datatime"
  10. @change="handleQueryChange"
  11. />
  12. <div class="health-page__body">
  13. <main class="dashboard-main">
  14. <div class="dashboard-top-row">
  15. <HealthScorePanel
  16. :distribution="scoreDistribution"
  17. :summary="scoreSummary"
  18. :total-score="totalScore"
  19. />
  20. <HealthSubsystemPanel :chart-data="subsystemData" />
  21. <HealthRankingPanel
  22. :healthy-list="healthyRankList"
  23. :risk-list="riskRankList"
  24. />
  25. </div>
  26. <section class="health-unit-grid">
  27. <HealthUnitCard
  28. v-for="unit in unitCards"
  29. :key="unit.engineId || unit.name"
  30. :unit="unit"
  31. />
  32. </section>
  33. </main>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import HealthHeader from "./components/health/HealthHeader.vue";
  39. import HealthScorePanel from "./components/health/HealthScorePanel.vue";
  40. import HealthSubsystemPanel from "./components/health/HealthSubsystemPanel.vue";
  41. import HealthRankingPanel from "./components/health/HealthRankingPanel.vue";
  42. import HealthUnitCard from "./components/health/HealthUnitCard.vue";
  43. import { getHealthOverview } from "@/api/healthAnalyse";
  44. import {
  45. getEmptyDashboard,
  46. mapHealthOverviewToDashboard,
  47. } from "./utils/healthDashboardMapper";
  48. export default {
  49. name: "HealthDashboard",
  50. components: {
  51. HealthHeader,
  52. HealthScorePanel,
  53. HealthSubsystemPanel,
  54. HealthRankingPanel,
  55. HealthUnitCard,
  56. },
  57. data() {
  58. const empty = getEmptyDashboard();
  59. return {
  60. companyCode: "",
  61. selectedField: null,
  62. datatime: "",
  63. loading: false,
  64. totalScore: empty.totalScore,
  65. scoreDistribution: empty.scoreDistribution,
  66. scoreSummary: empty.scoreSummary,
  67. subsystemData: empty.subsystemData,
  68. healthyRankList: empty.healthyRankList,
  69. riskRankList: empty.riskRankList,
  70. unitCards: empty.unitCards,
  71. };
  72. },
  73. mounted() {
  74. this.$nextTick(() => {
  75. window.dispatchEvent(new Event("resize"));
  76. });
  77. },
  78. methods: {
  79. handleQueryChange(data) {
  80. const fieldCode = data?.fieldCode || data?.codeNumber;
  81. if (!fieldCode) return;
  82. this.selectedField = data;
  83. this.companyCode = fieldCode;
  84. if (data.datatime !== undefined) {
  85. this.datatime = data.datatime;
  86. }
  87. this.fetchDashboard(fieldCode);
  88. },
  89. async fetchDashboard(fieldCode) {
  90. if (!fieldCode) return;
  91. this.loading = true;
  92. try {
  93. const params = { fieldCode };
  94. if (this.datatime) {
  95. params.datatime = this.datatime;
  96. }
  97. const res = await getHealthOverview(params);
  98. const mapped = mapHealthOverviewToDashboard(res.data || {});
  99. this.applyDashboard(mapped);
  100. } catch (error) {
  101. console.error("加载健康概览失败:", error);
  102. const empty = getEmptyDashboard();
  103. this.applyDashboard(empty);
  104. } finally {
  105. this.loading = false;
  106. this.$nextTick(() => {
  107. window.dispatchEvent(new Event("resize"));
  108. });
  109. }
  110. },
  111. applyDashboard(mapped) {
  112. this.totalScore = mapped.totalScore;
  113. this.scoreDistribution = mapped.scoreDistribution;
  114. this.scoreSummary = mapped.scoreSummary;
  115. this.subsystemData = mapped.subsystemData;
  116. this.healthyRankList = mapped.healthyRankList;
  117. this.riskRankList = mapped.riskRankList;
  118. this.unitCards = mapped.unitCards;
  119. },
  120. },
  121. };
  122. </script>
  123. <style lang="scss">
  124. @import "./components/health/health-dashboard.scss";
  125. .health-dashboard-page {
  126. .dashboard-top-row {
  127. display: grid;
  128. grid-template-columns: 1fr;
  129. gap: 24px;
  130. min-width: 0;
  131. }
  132. @media (min-width: 900px) {
  133. .dashboard-top-row {
  134. grid-template-columns: repeat(2, minmax(0, 1fr));
  135. }
  136. .dashboard-top-row > :last-child {
  137. grid-column: span 2;
  138. }
  139. }
  140. @media (min-width: 1280px) {
  141. .dashboard-top-row {
  142. grid-template-columns: repeat(3, minmax(0, 1fr));
  143. }
  144. .dashboard-top-row > :last-child {
  145. grid-column: auto;
  146. }
  147. }
  148. .health-unit-grid {
  149. display: grid;
  150. grid-template-columns: repeat(1, minmax(0, 1fr));
  151. gap: 16px;
  152. min-width: 0;
  153. }
  154. @media (min-width: 768px) {
  155. .health-unit-grid {
  156. grid-template-columns: repeat(2, minmax(0, 1fr));
  157. }
  158. }
  159. @media (min-width: 1024px) {
  160. .health-unit-grid {
  161. grid-template-columns: repeat(3, minmax(0, 1fr));
  162. }
  163. }
  164. @media (min-width: 1280px) {
  165. .health-unit-grid {
  166. grid-template-columns: repeat(5, minmax(0, 1fr));
  167. }
  168. }
  169. }
  170. </style>