window.__cbs = {}; window.__wompCb = function (id, ok, body) { var fn = window.__cbs[id]; delete window.__cbs[id]; if (!fn) return; var data = body; if (typeof body === "string") { try { data = JSON.parse(body); } catch (e) { data = body; } } fn(ok, data); }; function callNative(name, a, b, c) { return new Promise(function (resolve, reject) { var id = "cb_" + Date.now() + "_" + Math.random().toString(16).slice(2); window.__cbs[id] = function (ok, data) { if (ok === false) reject(data); else resolve(data); }; if (name === "request") Womp.request(a, b || "{}", id); else if (name === "scan") Womp.scan(id); else if (name === "getLocation") Womp.getLocation(id); }); } function api(path, body) { var payload = body || {}; try { var sorter = JSON.parse(Womp.getSorter() || "{}"); if (sorter.sorterId && payload.sorterId == null) payload.sorterId = sorter.sorterId; } catch (e) {} return callNative("request", path, JSON.stringify(payload)).then(function (res) { if (res && typeof res === "object" && res.code && res.code !== 1000) { var err = new Error(res.message || "请求失败"); err.code = res.code; throw err; } return res && res.data !== undefined ? res.data : res; }); } function errMsg(e, fallback) { if (!e) return fallback || "操作失败"; if (typeof e === "string") return e; if (e.message) return e.message; return fallback || "操作失败"; } function loginErrMsg(e) { var msg = errMsg(e, "登录失败,请稍后重试"); if (msg.length > 80 || /暂无用户信息"; return "
" + (u.nickName || "-") + " · " + (u.role || "") + "
" + "
手机 " + (u.phone || "-") + " · 积分 " + (u.carbonBalance == null ? "-" : u.carbonBalance) + "
" + (u.collegeName || u.className ? "
" + (u.collegeName || "") + " " + (u.className || "") + "
" : "") + (extra ? "
" + extra + "
" : ""); }