powerFrequencyDistribution.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="power-frequency-distribution-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.stationCode" :options="stationOptions" :multiple="false" />
  7. </a-col>
  8. <a-col :xs="24" :md="5">
  9. <a-date-picker
  10. v-model:value="query.startDay"
  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.endDay"
  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="4">
  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 :bordered="false" class="content-card">
  35. <BusinessDataTable
  36. :columns="columns"
  37. :data-source="rows"
  38. :pagination="{ pageSize: 10 }"
  39. :row-key="'day'"
  40. :scroll-x="'max-content'"
  41. />
  42. </a-card>
  43. </div>
  44. </template>
  45. <script setup name="PowerFrequencyDistribution">
  46. import {computed, onMounted, reactive, ref} from 'vue';
  47. import {message} from 'ant-design-vue';
  48. import dayjs from 'dayjs';
  49. import {saveAs} from 'file-saver';
  50. import {blobValidate} from '@/utils/bearjia';
  51. import {listStation} from '@/api/config/station';
  52. import {
  53. exportPowerFrequencyDistribution,
  54. listPowerFrequencyDistribution
  55. } from '@/api/data/powerFrequencyDistribution';
  56. import BusinessDataTable from '../components/BusinessDataTable.vue';
  57. import StationSelector from '../components/StationSelector.vue';
  58. import {normalizeRows} from '../components/dataAdapter';
  59. import {toStationOptions} from '../components/stationAdapter';
  60. const loading = ref(false);
  61. const exporting = ref(false);
  62. const stationOptions = ref([]);
  63. const rows = ref([]);
  64. const query = reactive({
  65. stationCode: undefined,
  66. startDay: dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
  67. endDay: dayjs().format('YYYY-MM-DD')
  68. });
  69. const queryValid = computed(() => {
  70. if (!query.stationCode || !query.startDay || !query.endDay) return false;
  71. const start = dayjs(query.startDay);
  72. const end = dayjs(query.endDay);
  73. if (!start.isValid() || !end.isValid()) return false;
  74. return !start.isAfter(end);
  75. });
  76. const renderBucket = (key) => ({record}) => {
  77. const num = record[`${key}Num`] ?? 0;
  78. const percent = record[`${key}Percent`] ?? '0.00';
  79. return `${num}(${percent}%)`;
  80. };
  81. const bucketColumn = (key, title) => ({
  82. title,
  83. key: `${key}Text`,
  84. width: 100,
  85. align: 'right',
  86. customRender: renderBucket(key)
  87. });
  88. const columns = [
  89. {title: '时间', dataIndex: 'day', key: 'day', width: 120},
  90. {title: '数据总条数', dataIndex: 'totalRecord', key: 'totalRecord', width: 110, align: 'right'},
  91. bucketColumn('lt2', '[0-2)MW'),
  92. bucketColumn('lt4', '[2-4)MW'),
  93. bucketColumn('lt6', '[4-6)MW'),
  94. bucketColumn('lt8', '[6-8)MW'),
  95. bucketColumn('lt10', '[8-10)MW'),
  96. bucketColumn('lt12', '[10-12)MW'),
  97. bucketColumn('lt14', '[12-14)MW'),
  98. bucketColumn('lt16', '[14-16)MW'),
  99. bucketColumn('lt18', '[16-18)MW'),
  100. bucketColumn('ge18', '≥18MW')
  101. ];
  102. const loadStationOptions = async () => {
  103. const res = await listStation({pageNum: 1, pageSize: 500});
  104. stationOptions.value = toStationOptions(normalizeRows(res));
  105. if (!query.stationCode && stationOptions.value.length) {
  106. query.stationCode = stationOptions.value[0].value;
  107. }
  108. };
  109. const buildParams = () => ({
  110. stationCode: query.stationCode,
  111. startDay: query.startDay,
  112. endDay: query.endDay
  113. });
  114. const fetchList = async () => {
  115. const res = await listPowerFrequencyDistribution(buildParams());
  116. rows.value = normalizeRows(res);
  117. };
  118. const handleQuery = async () => {
  119. if (!query.stationCode) {
  120. message.warning('请先选择场站');
  121. return;
  122. }
  123. if (!queryValid.value) return;
  124. loading.value = true;
  125. try {
  126. await fetchList();
  127. } finally {
  128. loading.value = false;
  129. }
  130. };
  131. const handleExport = async () => {
  132. if (!query.stationCode) {
  133. message.warning('请先选择场站');
  134. return;
  135. }
  136. if (!queryValid.value) return;
  137. exporting.value = true;
  138. try {
  139. const res = await exportPowerFrequencyDistribution(buildParams());
  140. const isFile = await blobValidate(res);
  141. if (isFile) {
  142. const name = `功率频率分布统计-${query.startDay}-${query.endDay}.xlsx`;
  143. saveAs(new Blob([res]), name);
  144. message.success('导出成功');
  145. } else {
  146. const text = await res.text();
  147. let msg = '导出失败';
  148. try {
  149. msg = JSON.parse(text)?.msg || msg;
  150. } catch (e) {
  151. /* ignore */
  152. }
  153. message.error(msg);
  154. }
  155. } finally {
  156. exporting.value = false;
  157. }
  158. };
  159. onMounted(async () => {
  160. await loadStationOptions();
  161. await handleQuery();
  162. });
  163. </script>
  164. <style lang="less" scoped>
  165. .power-frequency-distribution-page {
  166. padding: 16px;
  167. }
  168. .full-control {
  169. width: 100%;
  170. }
  171. .content-card {
  172. margin-top: 16px;
  173. }
  174. </style>