| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Redirecting...</title>
- <style>
- body {
- margin: 0;
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
- background: #f5f5f5;
- display: flex;
- justify-content: center;
- align-items: center;
- min-height: 100vh;
- }
- .error-box {
- display: none;
- background: #fff;
- padding: 40px 48px;
- border-radius: 12px;
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
- text-align: center;
- color: #333;
- font-size: 16px;
- line-height: 1.6;
- }
- </style>
- </head>
- <body>
- <div id="error" class="error-box"></div>
- <script>
- (function () {
- var redirectMap = %VITE_REDIRECT_MAP%;
- // hash 为 target key,支持 /redirect.html#demo?credit_code=123 和 /redirect.html?from=wx#demo 两种形式
- var rawHash = location.hash;
- var hashBody = rawHash ? rawHash.slice(1) : ""; // "demo?credit_code=123" 或 "demo"
- var hashParts = hashBody.split("?");
- var targetKey = hashParts[0];
- // hash 中 ? 之后的部分作为额外 querystring
- var hashQuery = hashParts.length > 1 ? "?" + hashParts.slice(1).join("?") : "";
- if (!targetKey) {
- showError("\u672a\u6307\u5b9a\u8df3\u8f6c\u76ee\u6807\uff0c\u8bf7\u901a\u8fc7 hash \u6307\u5b9a target");
- return;
- }
- var targetUrl = redirectMap[targetKey];
- if (targetUrl) {
- // .env 中 # 为注释符,URL 中的 # 使用 %23 编码,此处解码还原
- targetUrl = targetUrl.replace(/%23/g, "#");
- } else {
- showError("\u672a\u627e\u5230\u8df3\u8f6c\u76ee\u6807\uff1a" + targetKey);
- return;
- }
- // 合并 location.search 和 hash 中的 querystring,原样透传
- var queryString;
- if (location.search && hashQuery) {
- queryString = location.search + "&" + hashQuery.slice(1);
- } else {
- queryString = location.search || hashQuery;
- }
- // querystring 直接追加到目标 URL 末尾
- var finalUrl = targetUrl + queryString;
- location.replace(finalUrl);
- function showError(msg) {
- var el = document.getElementById("error");
- el.textContent = msg;
- el.style.display = "block";
- }
- })();
- </script>
- </body>
- </html>
|