54 lines
1.5 KiB
JavaScript
Raw Normal View History

// 公共配置和工具函数
const AppConfig = {
// 基础地址配置(如需调整,只在这里改)
sPayMallUrl: "http://127.0.0.1:8092",
groupBuyMarketUrl: "http://127.0.0.1:8091",
goodsId: "9890001"
};
// 工具函数(无副作用:不做跳转)
const AppUtils = {
// 读取 Cookie
getCookie(name) {
const v = `; ${document.cookie}`;
const p = v.split(`; ${name}=`);
return p.length === 2 ? p.pop().split(";").shift() : "";
},
// 读取 URL 参数
getQueryParam(key) {
return new URLSearchParams(location.search).get(key) || "";
},
// localStorage 中的用户ID
getUserIdLocal() {
return localStorage.getItem("userId") || "";
},
// 从多个来源解析用户IDURL > localStorage > cookie(loginToken)
resolveUserId() {
return (
this.getQueryParam("userId") ||
this.getUserIdLocal() ||
this.getCookie("loginToken") ||
""
);
},
// 混淆用户ID显示通用且一致
obfuscateUserId(id) {
if (!id) return "";
if (id.length <= 2) return id;
if (id.length <= 4) {
// 保留首尾各1
return id[0] + "*".repeat(id.length - 2) + id[id.length - 1];
}
// 长ID保留前2后2
return id.slice(0, 2) + "*".repeat(Math.max(1, id.length - 4)) + id.slice(-2);
}
};
// 导出到全局
window.AppConfig = AppConfig;
window.AppUtils = AppUtils;