Older/WebApplication/HomePage.cpp

40 lines
1.4 KiB
C++
Raw Normal View History

2024-12-02 01:18:57 +08:00
#include "HomePage.h"
#include "Dialog.h"
#include <Wt/WApplication.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
HomePage::HomePage() {
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");
}