Older/WebApplication/VisitorRecordsPage.cpp

70 lines
2.9 KiB
C++
Raw Permalink Normal View History

2024-11-28 19:34:24 +08:00
#include "VisitorRecordsPage.h"
#include "BoostLog.h"
#include "Database/Session.h"
2025-01-03 14:12:02 +08:00
#include "model/VisitorRecordTableModel.h"
2024-11-28 19:34:24 +08:00
#include <Wt/Dbo/QueryModel.h>
2024-11-29 20:01:10 +08:00
#include <Wt/WBreak.h>
2024-11-28 19:34:24 +08:00
#include <Wt/WItemDelegate.h>
#include <Wt/WLabel.h>
2025-01-17 02:55:03 +08:00
#include <Wt/WLineEdit.h>
2024-11-29 20:01:10 +08:00
#include <Wt/WMessageBox.h>
#include <Wt/WPushButton.h>
2024-11-28 19:34:24 +08:00
#include <Wt/WTableView.h>
2025-01-17 02:55:03 +08:00
VisitorRecordsPage::VisitorRecordsPage(Session &session)
: Wt::WTemplate(tr("Wt.VisitorRecords.Home")), m_model{std::make_shared<VisitorRecordTableModel>(session)} {
auto button = bindNew<Wt::WPushButton>("remove-button", "删除");
2024-11-29 20:01:10 +08:00
button->clicked().connect(this, &VisitorRecordsPage::onDeleteButtonClicked);
2024-11-28 19:34:24 +08:00
2025-01-17 02:55:03 +08:00
auto searchInput = bindNew<Wt::WLineEdit>("search-input");
searchInput->setPlaceholderText("请输入文章标题");
auto searchButton = bindNew<Wt::WPushButton>("search-button", "搜索");
searchButton->clicked().connect(this, [this, searchInput]() { m_model->filter(searchInput->text().toUTF8()); });
auto view = bindNew<Wt::WTableView>("records");
2024-11-28 19:34:24 +08:00
view->setColumnWidth(0, Wt::WLength::Auto);
view->setColumnWidth(1, Wt::WLength::Auto);
view->setHeaderHeight(30); // 设置表头的高度
view->setColumnResizeEnabled(true);
2024-11-29 20:01:10 +08:00
view->setAlternatingRowColors(true); // 限制于 stripe-40px.gif 类似的文件wt 有提供脚本生成
2024-11-28 19:34:24 +08:00
view->setRowHeight(50);
2024-11-28 23:39:15 +08:00
view->setSelectionMode(Wt::SelectionMode::None);
view->setColumnAlignment(0, Wt::AlignmentFlag::Center);
2024-11-29 20:01:10 +08:00
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);
2024-11-28 19:34:24 +08:00
// view->setEditTriggers(Wt::EditTrigger::None);
// view->setItemDelegateForColumn(0, std::make_shared<CheckBoxDelegate>());
// view->setHeaderItemDelegate( std::make_shared<CheckBoxDelegate>());
2024-11-29 20:01:10 +08:00
view->setModel(m_model);
view->setColumnWidth(0, 60);
view->setColumnWidth(1, 180);
view->setColumnWidth(2, 180);
view->setColumnWidth(3, 480);
2024-11-28 19:34:24 +08:00
}
2024-11-29 20:01:10 +08:00
void VisitorRecordsPage::onDeleteButtonClicked() {
2024-12-01 15:10:25 +08:00
auto selected = m_model->selectedIndexes();
2024-11-29 20:01:10 +08:00
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) {
2024-12-01 15:10:25 +08:00
LOG(info) << "remove row: " << selected.size();
m_model->removeSelectedRows(selected);
2024-11-29 20:01:10 +08:00
}
}
}