mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
[WEB]1.修改首页场站图标显示颜色不正确的问题,2.修改运行监控页面储能系统的运行模式和预制舱参数在页面切换时数据不显示问题
This commit is contained in:
@@ -45,28 +45,16 @@ QWHome::QWHome(QWidget* parent) : MyWidget(parent)
|
||||
this->addPair("db-h", pw, 20, 50, "主机地址: ", Config::option.database.host);
|
||||
this->addPair("db-u", pw, 20, 80, "用 户 名: ", Config::option.database.user);
|
||||
|
||||
|
||||
table = std::make_shared<QTableWidget>(this);
|
||||
table->setGeometry(10, y += 130, 1190, 265);
|
||||
table->setStyleSheet(QSS_TABLE.c_str());
|
||||
table->horizontalHeader()->setStretchLastSection(true); // 最后一列占满
|
||||
table->verticalHeader()->setVisible(false); // 不显示垂直表头
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers); // 单元格不可编辑
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection); // 设置为单选模式
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows); // 设置为整行选中
|
||||
table->horizontalHeader()->setFixedHeight(50);
|
||||
table->horizontalHeader()->setDefaultSectionSize(60);
|
||||
|
||||
QTableWidgetItem* headerItem;
|
||||
QStringList headerText_Row, headerText_Col;
|
||||
headerText_Row << "ID" << "站名" << "编号" << "状态" << "MQTT状态" << "召测(秒)"
|
||||
QStringList headerTextList;
|
||||
headerTextList << "ID" << "站名" << "编号" << "状态" << "MQTT状态" << "召测(秒)"
|
||||
<< "日充电\n电量" << "日放电\n电量" << "总充电\n电量" << "总放电\n电量"
|
||||
<< "日充电\n费用" << "日放电\n费用" << "总充电\n费用" << "总放电\n费用"
|
||||
<< "日收益" << "总收益" << "--";
|
||||
|
||||
table = MyQUI::TableWidget(this, 10, y += 130, 1190, 265);
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerText_Row.size());
|
||||
table->setHorizontalHeaderLabels(headerText_Row);
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
table->setColumnWidth(0, 50);
|
||||
table->setColumnWidth(1, 120);
|
||||
table->setColumnWidth(2, 50);
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
#include "qt/MyQUI.h"
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
#include <QHBoxLayout>
|
||||
#include <QTableWidget>
|
||||
|
||||
|
||||
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
|
||||
@@ -38,24 +38,13 @@ QWMonitor::QWMonitor(QWidget* parent) : MyWidget(parent)
|
||||
});
|
||||
}
|
||||
|
||||
table = std::make_shared<QTableWidget>(this);
|
||||
table->setGeometry(10, y += 50, 700, 800);
|
||||
table->setStyleSheet(QSS_TABLE.c_str());
|
||||
table->horizontalHeader()->setStretchLastSection(true); // 最后一列占满
|
||||
table->verticalHeader()->setVisible(false); // 不显示垂直表头
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers); // 单元格不可编辑
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection); // 设置为单选模式
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows); // 设置为整行选中
|
||||
table->horizontalHeader()->setFixedHeight(50);
|
||||
table->horizontalHeader()->setDefaultSectionSize(60);
|
||||
|
||||
QTableWidgetItem* headerItem;
|
||||
QStringList headerText_Row, headerText_Col;
|
||||
headerText_Row << "ID" << "类型ID" << "类型名称" << "设备名称" << "编号" << "状态" << "通讯\n状态" << "工作\n状态" << "故障\n状态";
|
||||
QStringList headerTextList;
|
||||
headerTextList << "ID" << "类型ID" << "类型名称" << "设备名称" << "编号" << "状态" << "通讯\n状态" << "工作\n状态" << "故障\n状态";
|
||||
|
||||
table = MyQUI::TableWidget(this, 10, y += 50, 700, 800);
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerText_Row.size());
|
||||
table->setHorizontalHeaderLabels(headerText_Row);
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
table->setColumnWidth(0, 50);
|
||||
table->setColumnWidth(1, 60);
|
||||
table->setColumnWidth(2, 120);
|
||||
@@ -163,7 +152,8 @@ void QWMonitor::onCurrentCellChanged(int row, int col, int oldRow, int oldCol)
|
||||
curDevice = station->getDevice(deviceId);
|
||||
if (curDevice)
|
||||
{
|
||||
string info = curDevice->name;
|
||||
string info = curDevice->name + " ";
|
||||
info += (curDevice->ts > 0) ? Utils::timeStr(curDevice->ts) : "--";
|
||||
labDeviceInfo->setText(info.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
91
src/qt/widgets/QWStatistics.cpp
Normal file
91
src/qt/widgets/QWStatistics.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "QWStatistics.h"
|
||||
|
||||
#include "app/Application.h"
|
||||
#include "app/AppData.h"
|
||||
#include "app/Station.h"
|
||||
#include "database/DAO.h"
|
||||
|
||||
QWStatistics::QWStatistics(QWidget* parent) : MyWidget(parent)
|
||||
{
|
||||
comboxStation = make_shared<QComboBox>(this);
|
||||
comboxStation->setGeometry(10, 10, 200, 28);
|
||||
comboxStation->setStyleSheet(QSS_BTN_COMBOX.c_str());
|
||||
|
||||
QStringList listStation;
|
||||
listStation << "所有";
|
||||
for (auto item: Application::data().mapStation)
|
||||
{
|
||||
listStation << item.second->name.c_str();
|
||||
}
|
||||
comboxStation->addItems(listStation);
|
||||
|
||||
|
||||
QStringList headerTextList;
|
||||
headerTextList << "日期" << "日充电\n电量" << "日放电\n电量"
|
||||
<< "日充电\n电量(尖)" << "日充电\n电量(峰)" << "日充电\n电量(平)" << "日充电\n电量(谷)"
|
||||
<< "日放电\n电量(尖)" << "日放电\n电量(峰)" << "日放电\n电量(平)" << "日放电\n电量(谷)"
|
||||
<< "日充电\n费用" << "日放电\n费用" << "日收益" ;
|
||||
//<< "总充电\n电量" << "总放电\n电量"
|
||||
//<< "总充电\n电量(尖)" << "总充电\n电量(峰)" << "总充电\n电量(平)" << "总充电\n电量(谷)"
|
||||
//<< "总放电\n电量(尖)" << "总放电\n电量(峰)" << "总放电\n电量(平)" << "总放电\n电量(谷)";
|
||||
|
||||
table = MyQUI::TableWidget(this, 10, 50, 1190, 800);
|
||||
table->horizontalHeader()->setDefaultSectionSize(80);
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
table->setColumnWidth(0, 120);
|
||||
|
||||
btnRefresh = make_shared<QPushButton>("刷新", this);
|
||||
btnRefresh->setGeometry(220, 10, 60, 30);
|
||||
//btnRefresh->setStyleSheet();
|
||||
|
||||
connect(comboxStation.get(), &QComboBox::currentIndexChanged, this, &QWStatistics::onCurrentIndexChanged);
|
||||
connect(btnRefresh.get(), &QPushButton::clicked, this, &QWStatistics::onCurrentIndexChanged);
|
||||
}
|
||||
|
||||
QWStatistics::~QWStatistics()
|
||||
{
|
||||
}
|
||||
|
||||
void QWStatistics::onCurrentIndexChanged(int index)
|
||||
{
|
||||
auto& appdata = Application::data();
|
||||
|
||||
string stationName = comboxStation->itemText(index).toStdString();
|
||||
if (stationName == "所有")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
auto station = appdata.getStationByName(stationName);
|
||||
if (station)
|
||||
{
|
||||
string sql = "SELECT * FROM stat_total_day std WHERE station_id='" + std::to_string(station->stationId)
|
||||
+ "' ORDER BY dt DESC LIMIT 100;";
|
||||
vector<Fields> result;
|
||||
DAO::exec(NULL, sql, result);
|
||||
table->clearContents();
|
||||
table->setRowCount(0);
|
||||
for (int i = 0; i<result.size(); ++i)
|
||||
{
|
||||
auto& fields = result[i];
|
||||
MyQUI::setTableCell(table, i, 0, fields.value("dt"));
|
||||
MyQUI::setTableCell(table, i, 1, fields.value("E_in"));
|
||||
MyQUI::setTableCell(table, i, 2, fields.value("E_in_J"));
|
||||
MyQUI::setTableCell(table, i, 3, fields.value("E_in_F"));
|
||||
MyQUI::setTableCell(table, i, 4, fields.value("E_in_P"));
|
||||
MyQUI::setTableCell(table, i, 5, fields.value("E_in_G"));
|
||||
MyQUI::setTableCell(table, i, 6, fields.value("E_out"));
|
||||
MyQUI::setTableCell(table, i, 7, fields.value("E_out_J"));
|
||||
MyQUI::setTableCell(table, i, 8, fields.value("E_out_F"));
|
||||
MyQUI::setTableCell(table, i, 9, fields.value("E_out_P"));
|
||||
MyQUI::setTableCell(table, i, 10, fields.value("E_out_G"));
|
||||
MyQUI::setTableCell(table, i, 11, fields.value("fee_in"));
|
||||
MyQUI::setTableCell(table, i, 12, fields.value("fee_out"));
|
||||
MyQUI::setTableCell(table, i, 13, fields.value("income"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/qt/widgets/QWStatistics.h
Normal file
19
src/qt/widgets/QWStatistics.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "qt/MyQUI.h"
|
||||
|
||||
class QWStatistics : public MyWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QWStatistics(QWidget* parent);
|
||||
~QWStatistics();
|
||||
|
||||
public slots :
|
||||
void onCurrentIndexChanged(int index);
|
||||
|
||||
public:
|
||||
shared_ptr<QComboBox> comboxStation;
|
||||
shared_ptr<QTableWidget> table;
|
||||
shared_ptr<QPushButton> btnRefresh;
|
||||
};
|
||||
241
src/qt/widgets/QWSysmgr.cpp
Normal file
241
src/qt/widgets/QWSysmgr.cpp
Normal file
@@ -0,0 +1,241 @@
|
||||
#include "QWSysmgr.h"
|
||||
#include "common/Fields.h"
|
||||
|
||||
QWSysmgr::QWSysmgr(QWidget* parent) : MyWidget(parent)
|
||||
{
|
||||
std::vector<std::string > vecItems = {"用户管理", "权限管理", "角色管理", "场站管理", "设备管理", "策略管理", "日志管理", "告警管理"};
|
||||
vecBtnFunc.reserve(vecItems.size());
|
||||
int x = 10, y = 10;
|
||||
for (auto& itemName: vecItems)
|
||||
{
|
||||
auto btn = make_shared<QPushButton>(itemName.c_str(), this);
|
||||
btn->setGeometry(x, y, 120, 36);
|
||||
btn->setStyleSheet(QSS_BTN.c_str());
|
||||
vecBtnFunc.push_back(btn);
|
||||
x += 130;
|
||||
connect(btn.get(), &QPushButton::clicked, this, [=]()
|
||||
{
|
||||
if (btn != curActiveBtn)
|
||||
{
|
||||
if (curActiveBtn) { curActiveBtn->setStyleSheet(QSS_BTN.c_str()); }
|
||||
if (btn) { btn->setStyleSheet(QSS_BTN_ACTIVE.c_str()); }
|
||||
curActiveBtn = btn;
|
||||
this->initTable(itemName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QStringList headerTextList;
|
||||
//headerTextList << "ID" << "类型ID" << "类型名称" << "设备名称" << "编号" << "状态" << "通讯\n状态" << "工作\n状态" << "故障\n状态";
|
||||
|
||||
table = MyQUI::TableWidget(this, 10, y += 100, 1190, 740);
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
table->horizontalHeader()->setDefaultSectionSize(80);
|
||||
|
||||
if (vecBtnFunc.size() > 0)
|
||||
{
|
||||
curActiveBtn = vecBtnFunc[0];
|
||||
curActiveBtn->setStyleSheet(QSS_BTN_ACTIVE.c_str());
|
||||
this->initTable(curActiveBtn->text().toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
QWSysmgr::~QWSysmgr()
|
||||
{
|
||||
}
|
||||
|
||||
class TableOper
|
||||
{
|
||||
public:
|
||||
TableOper()
|
||||
{
|
||||
widget = make_shared<QWidget>();
|
||||
//auto btn = make_shared<QPushButton>(widget.get());
|
||||
//btn->setGeometry(10+mapBtn.size()*60, 10, 60, 30);
|
||||
//mapBtn["查看"] = btn;
|
||||
}
|
||||
|
||||
shared_ptr<QWidget> widget;
|
||||
map<string, shared_ptr<QPushButton>> mapBtn;
|
||||
};
|
||||
|
||||
struct VH
|
||||
{
|
||||
string key;
|
||||
string title;
|
||||
int width {0};
|
||||
VH(string k, string t, int w) : key(k), title(t), width(w)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
vector<VH> vecHeaderUser =
|
||||
{
|
||||
VH("user_id", "ID", 160),
|
||||
VH("account", "用户名", 0),
|
||||
VH("name", "姓名", 200),
|
||||
VH("gender", "性别", 0),
|
||||
VH("age", "年龄", 0),
|
||||
VH("phone", "联系方式", 0),
|
||||
VH("role_name", "角色", 200),
|
||||
VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderPermission =
|
||||
{
|
||||
VH("permission_id", "ID", 60),
|
||||
VH("route", "路由", 160),
|
||||
VH("name", "权限名称", 0),
|
||||
VH("describe", "描述", 540),
|
||||
VH("is_open", "是否启用", 0),
|
||||
VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderRole =
|
||||
{
|
||||
VH("role_id", "ID", 60), VH("name", "权限名称", 200), VH("describe", "描述", 600), VH("is_open", "是否启用", 0), VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderStation =
|
||||
{
|
||||
VH("station_id", "ID", 60), VH("name", "场站名称", 160), VH("code", "编号", 60), VH("address", "地址", 280), VH("lon", "经度", 0), VH("lat", "维度", 0), VH("attr", "参数", 200), VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderDevice =
|
||||
{
|
||||
VH("device_id", "ID", 60),
|
||||
VH("station_name", "所属场站", 200),
|
||||
VH("type_name", "设备类型", 200),
|
||||
VH("name", "设备名称", 340),
|
||||
VH("code", "编号", 60),
|
||||
VH("is_open", "是否启用", 0),
|
||||
VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderPolicy =
|
||||
{
|
||||
VH("policy_id", "ID", 0),
|
||||
VH("type_name", "策略类型", 160),
|
||||
VH("name", "策略名称", 0),
|
||||
VH("describe", "描述", 200),
|
||||
VH("value", "参数", 400),
|
||||
VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderLogSys =
|
||||
{
|
||||
VH("", "ID", 0), VH("", "日志类型", 0), VH("", "内容", 0), VH("", "状态", 0), VH("", "操作", 0)
|
||||
};
|
||||
vector<VH> vecHeaderLogAlert =
|
||||
{
|
||||
VH("", "ID", 0), VH("", "告警类型", 0), VH("", "内容", 0), VH("", "状态", 0), VH("", "操作", 0)
|
||||
};
|
||||
map<string, vector<VH>> mapTableHeaderDef =
|
||||
{
|
||||
{"用户管理", vecHeaderUser},
|
||||
{"权限管理", vecHeaderPermission},
|
||||
{"角色管理", vecHeaderRole},
|
||||
{"场站管理", vecHeaderStation},
|
||||
{"设备管理", vecHeaderDevice},
|
||||
{"策略管理", vecHeaderPolicy},
|
||||
{"日志管理", vecHeaderLogSys},
|
||||
{"告警管理", vecHeaderLogAlert},
|
||||
} ;
|
||||
|
||||
#include "database/DAO.h"
|
||||
void QueryDB(const string& name, std::vector<Fields>& result)
|
||||
{
|
||||
string sql;
|
||||
if (name == "用户管理")
|
||||
{
|
||||
sql = "SELECT u.*, ur.role_id, r.name role_name FROM USER u LEFT JOIN user_role ur ON u.user_id=ur.user_id LEFT JOIN ROLE r ON r.role_id=ur.role_id;";
|
||||
|
||||
}
|
||||
else if (name == "权限管理")
|
||||
{
|
||||
sql = "SELECT * FROM permission;";
|
||||
}
|
||||
else if (name == "角色管理")
|
||||
{
|
||||
sql = "SELECT * FROM role;";
|
||||
}
|
||||
else if (name == "场站管理")
|
||||
{
|
||||
sql = "SELECT * FROM station;";
|
||||
}
|
||||
else if (name == "设备管理")
|
||||
{
|
||||
sql = "SELECT d.*, s.name station_name, ddt.name type_name FROM"
|
||||
" device d LEFT JOIN station s ON d.station_id=s.station_id"
|
||||
" LEFT JOIN def_device_type ddt ON ddt.device_type_id = d.`type`;";
|
||||
}
|
||||
else if (name == "策略管理")
|
||||
{
|
||||
sql = "SELECT p.*, dpt.name type_name FROM policy p LEFT JOIN def_policy_type dpt ON dpt.policy_type_id=p.`type`;";
|
||||
}
|
||||
else if (name == "日志管理")
|
||||
{
|
||||
}
|
||||
else if (name == "告警管理")
|
||||
{
|
||||
}
|
||||
DAO::exec(NULL, sql, result);
|
||||
}
|
||||
|
||||
vector<VH>& GetHeaderVec(const string& name)
|
||||
{
|
||||
static vector<VH> vecTmp;
|
||||
auto iter = mapTableHeaderDef.find(name);
|
||||
return (iter != mapTableHeaderDef.end()) ? iter->second : vecTmp;
|
||||
}
|
||||
|
||||
void QWSysmgr::initTable(const string& name)
|
||||
{
|
||||
auto& vecHeader = GetHeaderVec(name);
|
||||
QStringList headerTextList;
|
||||
for (auto& item: vecHeader) { headerTextList << item.title.c_str(); }
|
||||
table->setColumnCount(headerTextList.size());
|
||||
table->setHorizontalHeaderLabels(headerTextList);
|
||||
|
||||
for (int i = 0; i<vecHeader.size(); ++i)
|
||||
{
|
||||
auto& item = vecHeader[i];
|
||||
table->setColumnWidth(i, item.width > 0 ? item.width : 100);
|
||||
}
|
||||
this->initTableData(name);
|
||||
}
|
||||
|
||||
void QWSysmgr::initTableData(std::string name)
|
||||
{
|
||||
table->clearContents();
|
||||
table->setRowCount(0);
|
||||
|
||||
QueryDB(name, rowFields);
|
||||
|
||||
auto& vecHeader = GetHeaderVec(name);
|
||||
for (int row = 0; row<rowFields.size(); ++row)
|
||||
{
|
||||
auto& fields = rowFields[row];
|
||||
int col = 0;
|
||||
for (auto& item : vecHeader)
|
||||
{
|
||||
string key = item.key;
|
||||
if (item.title == "操作")
|
||||
{
|
||||
if (row >= table->rowCount()) { table->insertRow(row); }
|
||||
|
||||
QWidget* cellWidget = new QWidget();
|
||||
QPushButton* btn1 = new QPushButton("查看", cellWidget);
|
||||
btn1->setGeometry(5, 3, 50, 24);
|
||||
btn1->setStyleSheet(QSS_BTN_TAB.c_str());
|
||||
QPushButton* btn2 = new QPushButton("修改", cellWidget);
|
||||
btn2->setGeometry(60, 3, 50, 24);
|
||||
btn2->setStyleSheet(QSS_BTN_TAB.c_str());
|
||||
table->setCellWidget(row, col, cellWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
string val = fields.value(key);
|
||||
if (key == "is_open") { val = (val == "1" ? "启用" : "未启用"); }
|
||||
MyQUI::setTableCell(table, row, col, val);
|
||||
}
|
||||
++col;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/qt/widgets/QWSysmgr.h
Normal file
23
src/qt/widgets/QWSysmgr.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "qt/MyQUI.h"
|
||||
#include "common/Fields.h"
|
||||
|
||||
class QWSysmgr : public MyWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QWSysmgr(QWidget* parent);
|
||||
~QWSysmgr();
|
||||
|
||||
void initTable(const string& name);
|
||||
void initTableData(std::string name);
|
||||
|
||||
public:
|
||||
std::vector<shared_ptr<QPushButton>> vecBtnFunc;
|
||||
shared_ptr<QPushButton> curActiveBtn;
|
||||
|
||||
shared_ptr<QTableWidget> table;
|
||||
|
||||
std::vector<Fields> rowFields;
|
||||
};
|
||||
Reference in New Issue
Block a user