feat: HEL-68 手机端 P0 同网址分流闸门与手机壳
在电脑端 index.html head 加极早分流闸门(?ui 覆盖优先,720px/移动 UA 判定,首屏前跳转 /m/);新建 frontend/m/ 手机壳(index.html、tokens/shell CSS、api/session/router/boot JS、nav.config),首页五入口、占位图标页/功能页、登录页、日/夜主题与栈式返回。未改电脑 DOM/样式,未碰问天。 Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
(function (global) {
|
||||
"use strict";
|
||||
|
||||
let csrfToken = "";
|
||||
|
||||
function setCsrfToken(token) {
|
||||
csrfToken = token || "";
|
||||
}
|
||||
|
||||
function requestOptions(method, body) {
|
||||
const normalized = String(method || "GET").toUpperCase();
|
||||
const options = { method: normalized, headers: {} };
|
||||
if (!["GET", "HEAD", "OPTIONS"].includes(normalized) && csrfToken) {
|
||||
options.headers["X-CSRF-Token"] = csrfToken;
|
||||
}
|
||||
if (body !== null && body !== undefined) {
|
||||
options.headers["Content-Type"] = "application/json";
|
||||
options.body = JSON.stringify(body);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
async function request(url, method, body) {
|
||||
const response = await fetch(url, requestOptions(method, body));
|
||||
let payload = {};
|
||||
try {
|
||||
payload = await response.json();
|
||||
} catch (_error) {
|
||||
payload = {};
|
||||
}
|
||||
if (!response.ok || payload.error) {
|
||||
const error = new Error(payload.error || "请求失败");
|
||||
error.status = response.status;
|
||||
error.payload = payload;
|
||||
throw error;
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
global.MobileAPI = { setCsrfToken, request };
|
||||
})(window);
|
||||
Reference in New Issue
Block a user