64 lines
2.6 KiB
C++
64 lines
2.6 KiB
C++
#include "VisitorRecordsPage.h"
|
||
#include "BoostLog.h"
|
||
#include "Database/Session.h"
|
||
#include "VisitorRecordTableModel.h"
|
||
#include <Wt/Dbo/QueryModel.h>
|
||
#include <Wt/WBreak.h>
|
||
#include <Wt/WItemDelegate.h>
|
||
#include <Wt/WLabel.h>
|
||
#include <Wt/WMessageBox.h>
|
||
#include <Wt/WPushButton.h>
|
||
#include <Wt/WTableView.h>
|
||
|
||
VisitorRecordsPage::VisitorRecordsPage(Session &session) : m_model{std::make_shared<VisitorRecordTableModel>(session)} {
|
||
addNew<Wt::WLabel>("访客数据统计");
|
||
addNew<Wt::WBreak>();
|
||
auto button = addNew<Wt::WPushButton>("删除");
|
||
button->clicked().connect(this, &VisitorRecordsPage::onDeleteButtonClicked);
|
||
|
||
auto view = addNew<Wt::WTableView>();
|
||
view->setColumnWidth(0, Wt::WLength::Auto);
|
||
view->setColumnWidth(1, Wt::WLength::Auto);
|
||
view->setHeaderHeight(30); // 设置表头的高度
|
||
view->setColumnResizeEnabled(true);
|
||
view->setAlternatingRowColors(true); // 限制于 stripe-40px.gif 类似的文件,wt 有提供脚本生成
|
||
view->setRowHeight(50);
|
||
view->setSelectionMode(Wt::SelectionMode::None);
|
||
view->setColumnAlignment(0, Wt::AlignmentFlag::Center);
|
||
view->setColumnAlignment(2, Wt::AlignmentFlag::Center);
|
||
view->setColumnAlignment(4, Wt::AlignmentFlag::Center);
|
||
|
||
view->setHeaderAlignment(0, Wt::AlignmentFlag::Center);
|
||
view->setHeaderAlignment(1, Wt::AlignmentFlag::Center);
|
||
view->setHeaderAlignment(2, Wt::AlignmentFlag::Center);
|
||
view->setHeaderAlignment(3, Wt::AlignmentFlag::Center);
|
||
view->setHeaderAlignment(4, Wt::AlignmentFlag::Center);
|
||
|
||
view->setSortingEnabled(0, false);
|
||
view->setSortingEnabled(1, false);
|
||
view->setSortingEnabled(3, false);
|
||
view->setSortingEnabled(4, false);
|
||
// view->setEditTriggers(Wt::EditTrigger::None);
|
||
// view->setItemDelegateForColumn(0, std::make_shared<CheckBoxDelegate>());
|
||
// view->setHeaderItemDelegate( std::make_shared<CheckBoxDelegate>());
|
||
|
||
view->setModel(m_model);
|
||
view->setColumnWidth(0, 60);
|
||
view->setColumnWidth(1, 180);
|
||
view->setColumnWidth(2, 180);
|
||
view->setColumnWidth(3, 480);
|
||
}
|
||
|
||
void VisitorRecordsPage::onDeleteButtonClicked() {
|
||
auto selected = m_model->selectedIndexes();
|
||
if (selected.empty()) {
|
||
Wt::WMessageBox::show("删除记录", "请先选择要删除的记录", Wt::StandardButton::Ok);
|
||
} else {
|
||
auto anwser =
|
||
Wt::WMessageBox::show("删除记录", "确定删除选择的记录?", Wt::StandardButton::Ok | Wt::StandardButton::Cancel);
|
||
if (anwser == Wt::StandardButton::Ok) {
|
||
LOG(info) << "remove row: " << selected.size();
|
||
m_model->removeSelectedRows(selected);
|
||
}
|
||
}
|
||
} |