38 lines
1.0 KiB
C++
38 lines
1.0 KiB
C++
#include "RedirectPage.h"
|
|
#include "BoostLog.h"
|
|
#include <Wt/WTimer.h>
|
|
|
|
constexpr auto Template = R"(
|
|
<p>${message}</p>
|
|
<div>您将在${seconds}秒后返回上一页。</div>
|
|
)";
|
|
|
|
RedirectPage::RedirectPage() : Wt::WTemplate(Template) {
|
|
m_timer = addChild(std::make_unique<Wt::WTimer>());
|
|
m_timer->setInterval(std::chrono::milliseconds(1000));
|
|
m_timer->timeout().connect(this, &RedirectPage::onTimeout);
|
|
m_timer->start();
|
|
bindInt("seconds", m_time / 1000);
|
|
}
|
|
|
|
void RedirectPage::setRedirect(const std::string &path, const std::string &message) {
|
|
bindString("message", message);
|
|
if (m_redirect != path) {
|
|
m_redirect = path;
|
|
}
|
|
}
|
|
|
|
void RedirectPage::onTimeout() {
|
|
m_time -= 1000;
|
|
bindInt("seconds", m_time / 1000);
|
|
if (m_time <= 0) {
|
|
m_timer->stop();
|
|
auto app = Wt::WApplication::instance();
|
|
if (m_redirect.starts_with("/wt")) {
|
|
app->setInternalPath(m_redirect, true);
|
|
} else {
|
|
app->redirect(m_redirect);
|
|
}
|
|
}
|
|
}
|