#include "RedirectPage.h" #include "BoostLog.h" #include constexpr auto Template = R"(

${message}

您将在${seconds}秒后返回上一页。
)"; RedirectPage::RedirectPage() : Wt::WTemplate(Template) { m_timer = addChild(std::make_unique()); 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); } } }