Older/WebApplication/HomePage.cpp
amass 5db649fffd
All checks were successful
Deploy / Build (push) Successful in 5m34s
add wt navbar.
2024-12-15 21:14:57 +08:00

45 lines
1.5 KiB
C++

#include "HomePage.h"
#include "Dialog.h"
#include <Wt/WApplication.h>
#include <Wt/WLineEdit.h>
#include <Wt/WNavigationBar.h>
#include <Wt/WPushButton.h>
HomePage::HomePage() {
auto navigation = addNew<Wt::WNavigationBar>();
navigation->setResponsive(true);
navigation->setTitle("子非鱼", "https://amass.fun");
addStyleClass("bulma-content");
auto p = addWidget(std::make_unique<Wt::WText>("这是一个结合 C++ Web Toolkit 和 CSS Bulma 框架的前后端一体应用程序。"));
p->setInline(false);
auto ul = addWidget(std::make_unique<Wt::WContainerWidget>());
ul->setList(true);
auto li = ul->addWidget(std::make_unique<Wt::WText>(R"(<a href="/wt/login">登录页面</a>)"));
li->setHtmlTagName("li");
li = ul->addWidget(std::make_unique<Wt::WText>(R"(<a href="/wt/visitor/analysis">访客数据</a>)"));
li->setHtmlTagName("li");
addWidget(std::make_unique<Wt::WText>("Your name, please ? "));
m_nameEdit = addWidget(std::make_unique<Wt::WLineEdit>());
m_nameEdit->setFocus();
auto b = addWidget(std::make_unique<Wt::WPushButton>("点击我!"));
b->setMargin(5, Wt::Side::Left);
addWidget(std::make_unique<Wt::WBreak>());
m_greeting = addWidget(std::make_unique<Wt::WText>());
b->clicked().connect(this, &HomePage::greet);
m_nameEdit->enterPressed().connect(this, &HomePage::greet);
addWidget(std::make_unique<Dialog>());
}
void HomePage::greet() {
m_greeting->setText("Hello there, " + m_nameEdit->text());
Wt::WApplication::instance()->setInternalPath("/hello");
}