pvPlantCumulativeDailyReport.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <div class="pv-plant-cumulative-daily-page">
  3. <a-card :bordered="false">
  4. <a-row :gutter="[12, 12]" align="middle">
  5. <a-col :xs="24" :md="6">
  6. <StationSelector v-model:value="query.stationId" :options="stationOptions" :multiple="false" />
  7. </a-col>
  8. <a-col :xs="24" :md="5">
  9. <a-date-picker
  10. v-model:value="query.startTime"
  11. format="YYYY-MM-DD"
  12. value-format="YYYY-MM-DD"
  13. placeholder="起始时间"
  14. class="full-control"
  15. />
  16. </a-col>
  17. <a-col :xs="24" :md="5">
  18. <a-date-picker
  19. v-model:value="query.endTime"
  20. format="YYYY-MM-DD"
  21. value-format="YYYY-MM-DD"
  22. placeholder="截止时间"
  23. class="full-control"
  24. />
  25. </a-col>
  26. <a-col :xs="24" :md="8">
  27. <a-space>
  28. <a-button type="primary" :loading="loading" :disabled="!queryValid" @click="handleQuery">确认</a-button>
  29. <a-button :loading="exporting" :disabled="!queryValid" @click="handleExport">导出</a-button>
  30. </a-space>
  31. </a-col>
  32. </a-row>
  33. </a-card>
  34. <a-card title="数据详情" :bordered="false" style="margin-top: 16px">
  35. <BusinessDataTable
  36. :columns="tableColumns"
  37. :data-source="tableRows"
  38. :pagination="{ pageSize: 10 }"
  39. :scroll-x="'max-content'"
  40. />
  41. </a-card>
  42. </div>
  43. </template>
  44. <script setup name="pvPlantCumulativeDailyReport">
  45. import { computed, onMounted, reactive, ref } from 'vue';
  46. import { message } from 'ant-design-vue';
  47. import dayjs from 'dayjs';
  48. import { saveAs } from 'file-saver';
  49. import { blobValidate } from '@/utils/bearjia';
  50. import { listStation } from '@/api/config/station';
  51. import { queryPvPlantCumulativeReport, exportPvPlantCumulativeReport } from '@/api/data/pvPlantCumulativeReport';
  52. import BusinessDataTable from '../electricity/components/BusinessDataTable.vue';
  53. import StationSelector from '../electricity/components/StationSelector.vue';
  54. import { normalizeRows, toStationOptions } from '../electricity/components/dataAdapter';
  55. const loading = ref(false);
  56. const exporting = ref(false);
  57. const stationOptions = ref([]);
  58. const tableRows = ref([]);
  59. const query = reactive({
  60. stationId: undefined,
  61. startTime: dayjs(),
  62. endTime: dayjs(),
  63. type: 'daily'
  64. });
  65. const tableColumns = [
  66. { title: '时间', dataIndex: 'time', width: 120 },
  67. { title: '平均辐照度(W/m²)', dataIndex: 'avgIrradiance', width: 160 },
  68. { title: '最大辐照度(W/m²)', dataIndex: 'maxIrradiance', width: 160 },
  69. { title: '累计辐照量(MJ/㎡)', dataIndex: 'totalIrradiation', width: 140 },
  70. { title: '并网功率最大对应时间', dataIndex: 'gridMaxPowerTime', width: 170 },
  71. { title: '并网功率最大值(MW)', dataIndex: 'gridMaxPowder', width: 150 },
  72. { title: '实际发电量(万千瓦时)', dataIndex: 'actualPower', width: 160 },
  73. { title: '理论发电量(万千瓦时)', dataIndex: 'theoreticalPower', width: 160 },
  74. { title: '有效利用小时数', dataIndex: 'validHours', width: 130 },
  75. { title: '累计日照小时数', dataIndex: 'totalHours', width: 120 },
  76. { title: '平均风速(m/s)', dataIndex: 'avgWindSpeed', width: 120 },
  77. { title: '平均温度(℃)', dataIndex: 'avgTemperature', width: 120 },
  78. { title: '组件平均温度(℃)', dataIndex: 'avgBoardTemperature', width: 150 }
  79. ];
  80. const queryValid = computed(() => {
  81. if (!query.startTime || !query.endTime) return false;
  82. const start = dayjs(query.startTime);
  83. const end = dayjs(query.endTime);
  84. if (!start.isValid() || !end.isValid()) return false;
  85. return !end.isBefore(start);
  86. });
  87. const loadStationOptions = async () => {
  88. const res = await listStation({ pageNum: 1, pageSize: 500 });
  89. stationOptions.value = toStationOptions(normalizeRows(res));
  90. if (!query.stationId && stationOptions.value.length) {
  91. query.stationId = stationOptions.value[0].value;
  92. }
  93. };
  94. const buildParams = () => ({
  95. type: query.type,
  96. entityId: query.stationId,
  97. startTime: dayjs(query.startTime).format('YYYY-MM-DD'),
  98. endTime: dayjs(query.endTime).format('YYYY-MM-DD')
  99. });
  100. const handleQuery = async () => {
  101. if (!query.stationId) {
  102. message.warning('请先选择场站');
  103. return;
  104. }
  105. if (!queryValid.value) return;
  106. loading.value = true;
  107. try {
  108. const res = await queryPvPlantCumulativeReport(buildParams());
  109. tableRows.value = normalizeRows(res);
  110. } finally {
  111. loading.value = false;
  112. }
  113. };
  114. const handleExport = async () => {
  115. if (!query.stationId) {
  116. message.warning('请先选择场站');
  117. return;
  118. }
  119. if (!queryValid.value) return;
  120. exporting.value = true;
  121. try {
  122. const res = await exportPvPlantCumulativeReport(buildParams());
  123. const isFile = await blobValidate(res);
  124. if (isFile) {
  125. const name = `光伏电场累计日报-${dayjs(query.startTime).format('YYYYMMDD')}-${dayjs(query.endTime).format('YYYYMMDD')}.xlsx`;
  126. saveAs(new Blob([res]), name);
  127. message.success('导出成功');
  128. } else {
  129. const text = await res.text();
  130. let msg = '导出失败';
  131. try { msg = JSON.parse(text)?.msg || msg; } catch (e) { /* ignore */ }
  132. message.error(msg);
  133. }
  134. } finally {
  135. exporting.value = false;
  136. }
  137. };
  138. onMounted(async () => {
  139. await loadStationOptions();
  140. await handleQuery();
  141. });
  142. </script>
  143. <style lang="less" scoped>
  144. .pv-plant-cumulative-daily-page {
  145. padding: 16px;
  146. }
  147. .full-control {
  148. width: 100%;
  149. }
  150. </style>