修改策略分析页面数据查询接口和表格显示数据变化时表格高度异常的问题

This commit is contained in:
lixiaoyuan
2026-05-08 16:57:55 +08:00
parent 27365642d9
commit 72721608e3
5 changed files with 98 additions and 44 deletions

View File

@@ -1981,10 +1981,12 @@ static float SetPeriodRowJson(njson& jsonrow, std::string period, int eIn, int e
Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, std::string& errmsg) Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, std::string& errmsg)
{ {
Fields params; Fields params;
GetRequestParams(req, {"dt", "station_id"}, params); GetRequestParams(req, {"dt_start", "dt_end", "station_id"}, params);
int stationId = params.get<int>("station_id"); int stationId = params.get<int>("station_id");
std::string dt = params.value("dt"); std::string dtStart = params.value("dt_start");
std::string dtEnd = params.value("dt_end");
//int year = 0; //int year = 0;
//int month = 0; //int month = 0;
//int day = 0; //int day = 0;
@@ -1993,7 +1995,7 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
//{ //{
// return Errcode::ERR_PARAM; // return Errcode::ERR_PARAM;
//} //}
if (stationId == 0 || dt.empty()) if (stationId == 0 || dtStart.empty() || dtEnd.empty())
{ {
return Errcode::ERR_PARAM; return Errcode::ERR_PARAM;
} }
@@ -2025,25 +2027,28 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
} }
//std::string sql = std::format("SELECT ep.*, ep2.price FROM egrid_period ep LEFT JOIN egrid_price ep2 ON ep.etype=ep2.etype WHERE ep.`month`={};", month); //std::string sql = std::format("SELECT ep.*, ep2.price FROM egrid_period ep LEFT JOIN egrid_price ep2 ON ep.etype=ep2.etype WHERE ep.`month`={};", month);
std::string sql = std::format("select * from stat_total_day WHERE dt='{}' AND station_id='{}';", dt, stationId); std::string sql = std::format("select * from stat_total_day WHERE dt>='{}' AND dt<='{}' AND station_id='{}';", dtStart, dtEnd, stationId);
err = DAO::exec(NULL, sql, result); err = DAO::exec(NULL, sql, result);
if (err != Errcode::OK) if (err != Errcode::OK)
{ {
return err; return err;
} }
int totalIn {};
int totalOut {};
float totalIncome {0.0f};
njson jsondata = njson::array(); njson jsondata = njson::array();
if (result.size() > 0) for (auto& item: result)
{ {
auto& item = result[0]; std::string dt = item.get<std::string>("dt");
float incomeTotal = 0.0f;
// 谷 // 谷
{ {
njson jsonrow; njson jsonrow;
float income = SetPeriodRowJson(jsonrow, "", item.get<int>("E_in_G"), item.get<int>("E_out_G"), priceG, priceC, dt); float income = SetPeriodRowJson(jsonrow, "", item.get<int>("E_in_G"), item.get<int>("E_out_G"), priceG, priceC, dt);
jsonrow["income"] = Utils::toStr(income); jsonrow["income"] = Utils::toStr(income);
jsondata.push_back(jsonrow); jsondata.push_back(jsonrow);
incomeTotal += income; totalIncome += income;
} }
// 平 // 平
{ {
@@ -2051,7 +2056,7 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
float income = SetPeriodRowJson(jsonrow, "", item.get<int>("E_in_P"), item.get<int>("E_out_P"), priceP, priceC, dt); float income = SetPeriodRowJson(jsonrow, "", item.get<int>("E_in_P"), item.get<int>("E_out_P"), priceP, priceC, dt);
jsonrow["income"] = Utils::toStr(income); jsonrow["income"] = Utils::toStr(income);
jsondata.push_back(jsonrow); jsondata.push_back(jsonrow);
incomeTotal += income; totalIncome += income;
} }
// 峰 // 峰
{ {
@@ -2059,7 +2064,7 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
float income = SetPeriodRowJson(jsonrow, "", item.get<int>("E_in_F"), item.get<int>("E_out_F"), priceF, priceC, dt); float income = SetPeriodRowJson(jsonrow, "", item.get<int>("E_in_F"), item.get<int>("E_out_F"), priceF, priceC, dt);
jsonrow["income"] = Utils::toStr(income); jsonrow["income"] = Utils::toStr(income);
jsondata.push_back(jsonrow); jsondata.push_back(jsonrow);
incomeTotal += income; totalIncome += income;
} }
// 尖 // 尖
{ {
@@ -2067,21 +2072,24 @@ Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, s
float income = SetPeriodRowJson(jsonrow, "", item.get<int>("E_in_J"), item.get<int>("E_out_J"), priceJ, priceC, dt); float income = SetPeriodRowJson(jsonrow, "", item.get<int>("E_in_J"), item.get<int>("E_out_J"), priceJ, priceC, dt);
jsonrow["income"] = Utils::toStr(income); jsonrow["income"] = Utils::toStr(income);
jsondata.push_back(jsonrow); jsondata.push_back(jsonrow);
incomeTotal += income; totalIncome += income;
}
totalIn += item.get<int>("E_in");
totalOut += item.get<int>("E_out");
} }
// 总计 // 总计
{ {
njson jsonrow; njson jsonrow;
jsonrow["dt"] = dt; jsonrow["dt"] = "";
jsonrow["period"] = "总计"; jsonrow["period"] = "总计";
jsonrow["E_in"] = item.get<int>("E_in"); jsonrow["E_in"] = totalIn;
jsonrow["E_out"] = item.get<int>("E_out"); jsonrow["E_out"] = totalOut;
jsonrow["grid_price"] = ""; jsonrow["grid_price"] = "";
jsonrow["charge_price"] = ""; jsonrow["charge_price"] = "";
jsonrow["income"] = Utils::toStr(incomeTotal); jsonrow["income"] = Utils::toStr(totalIncome);
jsondata.push_back(jsonrow); jsondata.push_back(jsonrow);
} }
}
json["data"] = jsondata; json["data"] = jsondata;
return Errcode::OK; return Errcode::OK;
} }

View File

@@ -88,6 +88,7 @@ import {
const comtable = ref('') const comtable = ref('')
const props = defineProps({ const props = defineProps({
tableH: { Number, default: ()=> 500 },
columns: { type: Array, default: () => [] }, columns: { type: Array, default: () => [] },
tableData: { type: Array, default: () => [] }, tableData: { type: Array, default: () => [] },
tableOption: { tableOption: {
@@ -164,10 +165,18 @@ onMounted(async () => {
await nextTick() await nextTick()
scroll.value = { y: comtable.value.offsetHeight - 56 } scroll.value = { y: comtable.value.offsetHeight - 56 }
}) })
watch(
() => props.tableH,
(n, o) => {
if (n) {
const pageH = data.newTableOpt.page ? 42 : 0
scroll.value = { y: n - pageH - 20 }
}
},
{ immediate: true }
)
watch( watch(
() => props.tableData, () => props.tableData,
(n, o) => { (n, o) => {

View File

@@ -122,8 +122,8 @@ export default {
smooth: true, smooth: true,
type: 'line', type: 'line',
barWidth: 10, barWidth: 10,
itemStyle: { borderRadius: 10, color: item.lineColor }, itemStyle: { borderRadius: 10, color: item.lineColor},
emphasis: { focus: 'series' }, emphasis: { focus: 'series'},
global: false, global: false,
showSymbol: false, showSymbol: false,
data: [] data: []

View File

@@ -18,8 +18,8 @@ export default {
name: '', name: '',
props: { props: {
propKey: { type: String, default: '' }, propKey: { type: String, default: '' },
propData: { type: Array, default: () => [] }, propData: { type: Array, default: () => [] },
propOption: { type: Object, default: { series: [] } } propOption: { type: Object, default: { series: [] } }
}, },
data() { data() {
return { return {

View File

@@ -58,9 +58,9 @@
</a-spin> </a-spin>
</div> </div>
<div v-if="activeKey == 4" style="height:800px"> <div v-if="activeKey == 4" class="content-table-4" >
<ComTable <ComTable
:tableH="tableH"
:columns="columns" :columns="columns"
:table-data="tableData" :table-data="tableData"
:table-option="{ page: false, select: false}"> :table-option="{ page: false, select: false}">
@@ -68,7 +68,6 @@
<OperateCom :record="record" :operate-list="operateList" @operateForm="operateForm" /> <OperateCom :record="record" :operate-list="operateList" @operateForm="operateForm" />
</template> </template>
</ComTable> </ComTable>
</div> </div>
</div> </div>
</template> </template>
@@ -676,7 +675,8 @@ export default {
// {period: "尖", gridPrice: "0.8", chargePrice: "0.6", income: "0.2", elect: "35", incomeTotal: "100"}, // {period: "尖", gridPrice: "0.8", chargePrice: "0.6", income: "0.2", elect: "35", incomeTotal: "100"},
// {period: "总计", gridPrice: "0.8", chargePrice: "0.6", income: "0.2", elect: "35", incomeTotal: "100"} // {period: "总计", gridPrice: "0.8", chargePrice: "0.6", income: "0.2", elect: "35", incomeTotal: "100"}
] ],
tableH: 500
} }
}, },
watch: { watch: {
@@ -700,6 +700,10 @@ export default {
} }
else { else {
this.$nextTick(() => { this.$nextTick(() => {
const elementTable = document.getElementsByClassName('content-table-4')[0]
if ( elementTable) {
this.tableH = elementTable.offsetHeight - 20
}
this.getEGridPeriod() this.getEGridPeriod()
}) })
} }
@@ -708,6 +712,7 @@ export default {
} }
}, },
mounted() { mounted() {
window.addEventListener('resize', this.handleResize);
//this.operateList = this.$getBtns(['修改']) //this.operateList = this.$getBtns(['修改'])
console.log('mounted') console.log('mounted')
// 优先加载第一个页面(activeKey=1)所需的数据 // 优先加载第一个页面(activeKey=1)所需的数据
@@ -728,6 +733,13 @@ export default {
clearInterval(this.interval) // 组件销毁时清除定时器 clearInterval(this.interval) // 组件销毁时清除定时器
}, },
methods: { methods: {
handleResize() {
const elementTable = document.getElementsByClassName('content-table-4')[0]
if (elementTable) {
this.tableH = elementTable.offsetHeight - 20
}
},
operateForm(type, record = {}) { operateForm(type, record = {}) {
if (type == 'output') { if (type == 'output') {
this.loading.chart=true this.loading.chart=true
@@ -935,16 +947,20 @@ export default {
async getEGridPeriod() { async getEGridPeriod() {
const query = { const query = {
dt: this.paramsDate.end_date, dt_start:this.paramsDate.start_date,
dt_end: this.paramsDate.end_date,
station_id: this.stationId, station_id: this.stationId,
} }
if (!query.dt) { if (!query.dt_end) {
const today = new Date(); const today = new Date();
const year = today.getFullYear(); const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0'); // 处理月份:先+1因为getMonth返回0-11再补零到2位 const month = String(today.getMonth() + 1).padStart(2, '0'); // 处理月份:先+1因为getMonth返回0-11再补零到2位
const day = String(today.getDate()).padStart(2, '0'); // 处理日期直接补零到2位 const day = String(today.getDate()).padStart(2, '0'); // 处理日期直接补零到2位
query.dt = `${year}-${month}-${day}`; // 拼接成指定格式 query.dt_end = `${year}-${month}-${day}`; // 拼接成指定格式
}
if (!query.dt_start) {
query.dt_start = query.dt_end;
} }
try { try {
@@ -995,6 +1011,18 @@ export default {
color: #a6b8dd; color: #a6b8dd;
background-color: $bg2-color; background-color: $bg2-color;
} }
.content-table-4 {
// overflow: scroll;
width: 100%;
height: calc(100% - 52px);
min-height: 0;
//overflow: hidden;
// :deep(.ant-table-wrapper) {
// min-height: 0px;
// }
}
} }
.main_content { .main_content {
overflow: scroll; overflow: scroll;
@@ -1016,6 +1044,8 @@ export default {
} }
} }
:deep(.ant-modal-body) { :deep(.ant-modal-body) {
:deep(.ant-table-wrapper .ant-table-row-expand-icon) { :deep(.ant-table-wrapper .ant-table-row-expand-icon) {
color: $green !important; color: $green !important;
@@ -1041,5 +1071,12 @@ export default {
:deep(.ant-table-wrapper .ant-table-thead > tr > th) { :deep(.ant-table-wrapper .ant-table-thead > tr > th) {
border-bottom: none !important; border-bottom: none !important;
} }
:deep(.ant-table-container) {
flex: 1; /* 👈 用这个,不要用 % */
margin-top: 0px; /* 👈 这里实现“减去150px”效果 */
//height: calc(100% - 150px);;
// height: 500px;
// overflow-y: auto;
}
</style> </style>