| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <template>
- <div class="pv-station-logic-check-page">
- <a-card :bordered="false">
- <a-row :gutter="[12, 12]" align="middle">
- <a-col :xs="24" :md="6">
- <StationSelector v-model:value="query.stationCode" :options="stationOptions" :multiple="false" />
- </a-col>
- <a-col :xs="24" :md="6">
- <a-radio-group v-model:value="query.dataType" button-style="solid">
- <a-radio value="sampleMachine">样板法</a-radio>
- <a-radio value="photometricMethod">测光法</a-radio>
- </a-radio-group>
- </a-col>
- <a-col :xs="24" :md="5">
- <a-date-picker
- v-model:value="query.day"
- format="YYYY-MM-DD"
- value-format="YYYY-MM-DD"
- placeholder="选择日期"
- class="full-control"
- />
- </a-col>
- <a-col :xs="24" :md="7">
- <a-space>
- <a-button type="primary" :loading="loading" @click="handleQuery">确认</a-button>
- <a-button :loading="exporting" @click="handleExport">导出</a-button>
- </a-space>
- </a-col>
- </a-row>
- </a-card>
- <a-card title="数据详情" :bordered="false" style="margin-top: 16px">
- <BusinessDataTable
- row-key="time"
- :columns="tableColumns"
- :data-source="tableRows"
- :pagination="{ pageSize: 20 }"
- :scroll-x="'max-content'"
- />
- </a-card>
- </div>
- </template>
- <script setup name="PvStationLogicCheck">
- import { h, onMounted, reactive, ref } from 'vue'
- import { message } from 'ant-design-vue'
- import dayjs from 'dayjs'
- import { saveAs } from 'file-saver'
- import { blobValidate } from '@/utils/bearjia'
- import { listStation } from '@/api/config/station'
- import { logicCheckList, exportLogicCheck } from '@/api/theoretical/power'
- import BusinessDataTable from '../electricity/components/BusinessDataTable.vue'
- import StationSelector from '../electricity/components/StationSelector.vue'
- import { normalizeRows } from '../electricity/components/dataAdapter.js'
- const loading = ref(false)
- const exporting = ref(false)
- const stationOptions = ref([])
- const tableRows = ref([])
- const query = reactive({
- stationCode: undefined,
- dataType: 'sampleMachine',
- day: dayjs().format('YYYY-MM-DD')
- })
- const renderRatioCell = (value, desc) => {
- const bad = desc === '不合格'
- return h('span', {}, [
- h('span', {}, `${Number(value || 0).toFixed(2)} `),
- h('span', { style: bad ? { color: '#f5222d' } : {} }, desc || '')
- ])
- }
- const tableColumns = [
- { title: '时间', dataIndex: 'time', width: 100 },
- {
- title: '装机比理论',
- dataIndex: 'installed2TheoreticalPercent',
- width: 180,
- customRender: ({ record }) => renderRatioCell(record.installed2TheoreticalPercent, record.installed2TheoreticalDesc)
- },
- {
- title: '理论比可用',
- dataIndex: 'theoretical2AvailablePercent',
- width: 180,
- customRender: ({ record }) => renderRatioCell(record.theoretical2AvailablePercent, record.theoretical2AvailableDesc)
- },
- {
- title: '可用比实际',
- dataIndex: 'available2ActualPercent',
- width: 180,
- customRender: ({ record }) => renderRatioCell(record.available2ActualPercent, record.available2ActualDesc)
- }
- ]
- const checkStation = () => {
- if (!query.stationCode) {
- message.warning('请先选择电厂')
- return false
- }
- return true
- }
- const buildParams = () => ({
- stationCode: query.stationCode,
- dataType: query.dataType,
- day: query.day
- })
- const loadStationOptions = async () => {
- const res = await listStation({ pageNum: 1, pageSize: 500 })
- const rows = normalizeRows(res)
- stationOptions.value = rows.map((item, index) => ({
- label: item.stationName || `站点${index + 1}`,
- value: item.stationCode
- }))
- if (!query.stationCode && stationOptions.value.length) {
- query.stationCode = stationOptions.value[0].value
- }
- }
- const handleQuery = async () => {
- if (!checkStation()) return
- loading.value = true
- try {
- const res = await logicCheckList(buildParams())
- tableRows.value = normalizeRows(res)
- } finally {
- loading.value = false
- }
- }
- const handleExport = async () => {
- if (!checkStation()) return
- exporting.value = true
- try {
- const res = await exportLogicCheck(buildParams())
- const isFile = await blobValidate(res)
- if (isFile) {
- saveAs(new Blob([res]), `光伏场站逻辑校核_${dayjs(query.day).format('YYYYMMDD')}.xlsx`)
- message.success('导出成功')
- } else {
- const text = await res.text()
- let msg = '导出失败'
- try { msg = JSON.parse(text)?.msg || msg } catch (e) { /* ignore */ }
- message.error(msg)
- }
- } finally {
- exporting.value = false
- }
- }
- onMounted(async () => {
- await loadStationOptions()
- await handleQuery()
- })
- </script>
- <style lang="less" scoped>
- .pv-station-logic-check-page {
- padding: 16px;
- }
- .full-control {
- width: 100%;
- }
- </style>
|