Older/WebApplication/VisitorRecordsPage.cpp
amass f3d211a109
All checks were successful
Deploy / Build (push) Successful in 6m12s
add search for record.
2025-01-17 02:55:03 +08:00

70 lines
2.9 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "VisitorRecordsPage.h"
#include "BoostLog.h"
#include "Database/Session.h"
#include "model/VisitorRecordTableModel.h"
#include <Wt/Dbo/QueryModel.h>
#include <Wt/WBreak.h>
#include <Wt/WItemDelegate.h>
#include <Wt/WLabel.h>
#include <Wt/WLineEdit.h>
#include <Wt/WMessageBox.h>
#include <Wt/WPushButton.h>
#include <Wt/WTableView.h>
VisitorRecordsPage::VisitorRecordsPage(Session &session)
: Wt::WTemplate(tr("Wt.VisitorRecords.Home")), m_model{std::make_shared<VisitorRecordTableModel>(session)} {
auto button = bindNew<Wt::WPushButton>("remove-button", "删除");
button->clicked().connect(this, &VisitorRecordsPage::onDeleteButtonClicked);
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");
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);
}
}
}