This commit is contained in:
2025-09-27 22:57:59 +08:00
parent 8a458ff0a4
commit ed26244cdb
12585 changed files with 1914308 additions and 3474 deletions

View File

@@ -1,10 +1,24 @@
"use strict";
const common_vendor = require("../../common/vendor.js");
const common_http = require("../../common/http.js");
const common_config = require("../../common/config.js");
const common_assets = require("../../common/assets.js");
function normalizeAvatar(url) {
if (!url)
return "/static/icons/icons8-mitt-24.png";
const s = String(url);
if (/^https?:\/\//i.test(s))
return s;
if (!common_config.API_BASE_URL)
return s;
if (s.startsWith("/"))
return `${common_config.API_BASE_URL}${s}`;
return `${common_config.API_BASE_URL}/${s}`;
}
const _sfc_main = {
data() {
return {
avatarUrl: "/static/logo.png",
avatarUrl: "/static/icons/icons8-mitt-24.png",
shopName: "未登录",
mobile: "",
pendingJsCode: "",
@@ -16,7 +30,7 @@ const _sfc_main = {
},
onShow() {
this.fetchProfile();
this.loadVipFromStorage();
this.loadVip();
try {
if (common_vendor.index.getStorageSync("TOKEN")) {
this.$forceUpdate && this.$forceUpdate();
@@ -32,9 +46,22 @@ const _sfc_main = {
return false;
}
},
mobileDisplay() {
const m = String(this.mobile || "");
return m.length === 11 ? m.slice(0, 3) + "****" + m.slice(7) : m || "未绑定手机号";
avatarDisplay() {
return normalizeAvatar(this.avatarUrl);
},
emailDisplay() {
if (!this.isLoggedIn)
return "";
const e = String(common_vendor.index.getStorageSync("USER_EMAIL") || "");
if (!e)
return "未绑定邮箱";
const at = e.indexOf("@");
if (at > 1) {
const name = e.slice(0, at);
const domain = e.slice(at);
return (name.length <= 2 ? name[0] + "*" : name.slice(0, 2) + "***") + domain;
}
return e;
},
vipStartDisplay() {
return this.formatDisplay(this.vipStart);
@@ -55,35 +82,100 @@ const _sfc_main = {
})();
if (!hasToken) {
this.shopName = "未登录";
this.avatarUrl = "/static/logo.png";
this.avatarUrl = "/static/icons/icons8-mitt-24.png";
this.mobile = "";
return;
}
try {
await common_http.get("/api/dashboard/overview");
} catch (e) {
}
try {
const storeName = common_vendor.index.getStorageSync("SHOP_NAME") || "";
const avatar = common_vendor.index.getStorageSync("USER_AVATAR") || "";
const phone = common_vendor.index.getStorageSync("USER_MOBILE") || "";
if (storeName)
this.shopName = storeName;
if (avatar)
this.avatarUrl = avatar;
const profile = await common_http.get("/api/user/me");
const latestAvatar = (profile == null ? void 0 : profile.avatarUrl) || "";
if (latestAvatar) {
const bust = `${latestAvatar}${latestAvatar.includes("?") ? "&" : "?"}t=${Date.now()}`;
this.avatarUrl = bust;
try {
common_vendor.index.setStorageSync("USER_AVATAR_RAW", latestAvatar);
common_vendor.index.setStorageSync("USER_AVATAR", latestAvatar);
} catch (_) {
}
} else {
const cached = common_vendor.index.getStorageSync("USER_AVATAR") || "";
this.avatarUrl = cached || "/static/icons/icons8-mitt-24.png";
}
const storeName = (profile == null ? void 0 : profile.name) || common_vendor.index.getStorageSync("SHOP_NAME") || "未命名店铺";
this.shopName = storeName;
const phone = (profile == null ? void 0 : profile.phone) || common_vendor.index.getStorageSync("USER_MOBILE") || "";
this.mobile = phone;
} catch (e) {
try {
const storeName = common_vendor.index.getStorageSync("SHOP_NAME") || "";
const avatar = common_vendor.index.getStorageSync("USER_AVATAR") || "";
const phone = common_vendor.index.getStorageSync("USER_MOBILE") || "";
if (storeName)
this.shopName = storeName;
if (avatar)
this.avatarUrl = avatar;
this.mobile = phone;
} catch (_) {
}
}
},
loadVipFromStorage() {
async loadVip() {
try {
const isVip = String(common_vendor.index.getStorageSync("USER_VIP_IS_VIP") || "false").toLowerCase() === "true";
const start = common_vendor.index.getStorageSync("USER_VIP_START") || "";
const end = common_vendor.index.getStorageSync("USER_VIP_END") || "";
this.vipIsVip = isVip;
this.vipStart = start;
this.vipEnd = end;
const hasToken = (() => {
try {
return !!common_vendor.index.getStorageSync("TOKEN");
} catch (e) {
return false;
}
})();
if (!hasToken) {
this.vipIsVip = false;
this.vipStart = "";
this.vipEnd = "";
return;
}
const data = await common_http.get("/api/vip/status");
const active = !!(data == null ? void 0 : data.isVip);
this.vipIsVip = active;
this.vipEnd = (data == null ? void 0 : data.expireAt) || "";
let computedStart = "";
const exp = this.vipEnd;
if (exp) {
const m = String(exp).match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?/);
if (m) {
const y = Number(m[1]);
const mo = Number(m[2]) - 1;
const da = Number(m[3]);
const hh = Number(m[4] || "0");
const mm = Number(m[5] || "0");
const ss = Number(m[6] || "0");
const startDate = new Date(y, mo - 1, da, hh, mm, ss);
const y2 = startDate.getFullYear();
const m2 = (startDate.getMonth() + 1).toString().padStart(2, "0");
const d2 = startDate.getDate().toString().padStart(2, "0");
const h2 = startDate.getHours().toString().padStart(2, "0");
const i2 = startDate.getMinutes().toString().padStart(2, "0");
computedStart = `${y2}-${m2}-${d2} ${h2}:${i2}`;
}
}
this.vipStart = computedStart;
try {
common_vendor.index.setStorageSync("USER_VIP_IS_VIP", String(active));
common_vendor.index.setStorageSync("USER_VIP_END", this.vipEnd);
if (this.vipStart)
common_vendor.index.setStorageSync("USER_VIP_START", this.vipStart);
else
common_vendor.index.removeStorageSync("USER_VIP_START");
} catch (_) {
}
} catch (e) {
try {
const isVip = String(common_vendor.index.getStorageSync("USER_VIP_IS_VIP") || "false").toLowerCase() === "true";
this.vipIsVip = isVip;
this.vipStart = common_vendor.index.getStorageSync("USER_VIP_START") || "";
this.vipEnd = common_vendor.index.getStorageSync("USER_VIP_END") || "";
} catch (_) {
}
}
},
formatDisplay(value) {
@@ -136,9 +228,6 @@ const _sfc_main = {
goLogin() {
common_vendor.index.navigateTo({ url: "/pages/auth/login" });
},
goRegister() {
common_vendor.index.navigateTo({ url: "/pages/auth/register" });
},
onGetPhoneNumber(e) {
if (this.logging)
return;
@@ -161,34 +250,16 @@ const _sfc_main = {
common_vendor.index.navigateTo({ url: "/pages/my/sms-login" });
},
onAvatarError() {
this.avatarUrl = "/static/logo.png";
this.avatarUrl = "/static/icons/icons8-mitt-24.png";
},
goVip() {
common_vendor.index.navigateTo({ url: "/pages/my/vip" });
},
goMyOrders() {
common_vendor.index.switchTab({ url: "/pages/detail/index" });
},
goSupplier() {
common_vendor.index.navigateTo({ url: "/pages/supplier/select" });
},
goCustomer() {
common_vendor.index.navigateTo({ url: "/pages/customer/select" });
},
goCustomerQuote() {
common_vendor.index.showToast({ title: "客户报价(开发中)", icon: "none" });
},
goShop() {
common_vendor.index.showToast({ title: "店铺管理(开发中)", icon: "none" });
common_vendor.index.navigateTo({ url: "/pages/my/orders" });
},
editProfile() {
common_vendor.index.showToast({ title: "账号与安全(开发中)", icon: "none" });
},
goProductSettings() {
common_vendor.index.navigateTo({ url: "/pages/product/settings" });
},
goSystemParams() {
common_vendor.index.showToast({ title: "系统参数(开发中)", icon: "none" });
common_vendor.index.navigateTo({ url: "/pages/my/security" });
},
goAbout() {
common_vendor.index.navigateTo({ url: "/pages/my/about" });
@@ -201,9 +272,14 @@ const _sfc_main = {
common_vendor.index.removeStorageSync("DEFAULT_USER_ID");
common_vendor.index.setStorageSync("ENABLE_DEFAULT_USER", "false");
common_vendor.index.removeStorageSync("USER_AVATAR");
common_vendor.index.removeStorageSync("USER_AVATAR_RAW");
common_vendor.index.removeStorageSync("USER_NAME");
common_vendor.index.removeStorageSync("USER_MOBILE");
common_vendor.index.removeStorageSync("USER_EMAIL");
common_vendor.index.removeStorageSync("SHOP_NAME");
common_vendor.index.removeStorageSync("USER_VIP_IS_VIP");
common_vendor.index.removeStorageSync("USER_VIP_START");
common_vendor.index.removeStorageSync("USER_VIP_END");
common_vendor.index.showToast({ title: "已清理本地信息", icon: "none" });
setTimeout(() => {
common_vendor.index.reLaunch({ url: "/pages/index/index" });
@@ -216,32 +292,32 @@ const _sfc_main = {
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: !$options.isLoggedIn
}, !$options.isLoggedIn ? {
b: common_vendor.o((...args) => $options.goLogin && $options.goLogin(...args)),
c: common_vendor.o((...args) => $options.goRegister && $options.goRegister(...args))
} : {}, {
d: $data.avatarUrl,
e: common_vendor.o((...args) => $options.onAvatarError && $options.onAvatarError(...args)),
f: common_vendor.t($data.shopName),
g: common_vendor.t($options.mobileDisplay),
h: common_vendor.t($data.vipIsVip ? "VIP" : "非VIP"),
i: common_vendor.t($options.vipStartDisplay),
j: common_vendor.t($options.vipEndDisplay),
k: $data.vipIsVip ? 1 : "",
l: common_vendor.o((...args) => $options.goVip && $options.goVip(...args)),
m: common_vendor.o((...args) => $options.goMyOrders && $options.goMyOrders(...args)),
n: common_vendor.o((...args) => $options.goSupplier && $options.goSupplier(...args)),
o: common_vendor.o((...args) => $options.goCustomer && $options.goCustomer(...args)),
p: common_vendor.o((...args) => $options.goCustomerQuote && $options.goCustomerQuote(...args)),
q: common_vendor.o((...args) => $options.goShop && $options.goShop(...args)),
r: common_vendor.o((...args) => $options.editProfile && $options.editProfile(...args)),
s: common_vendor.o((...args) => $options.goProductSettings && $options.goProductSettings(...args)),
t: common_vendor.o((...args) => $options.goSystemParams && $options.goSystemParams(...args)),
v: common_vendor.o((...args) => $options.goAbout && $options.goAbout(...args)),
w: $options.isLoggedIn
a: $options.isLoggedIn
}, $options.isLoggedIn ? {
x: common_vendor.o((...args) => $options.logout && $options.logout(...args))
b: $options.avatarDisplay,
c: common_vendor.o((...args) => $options.onAvatarError && $options.onAvatarError(...args)),
d: common_vendor.t($data.shopName),
e: common_vendor.t($options.emailDisplay)
} : {
f: common_assets._imports_0$1,
g: common_vendor.o((...args) => $options.goLogin && $options.goLogin(...args))
}, {
h: $options.isLoggedIn
}, $options.isLoggedIn ? {
i: common_vendor.t($data.vipIsVip ? "VIP" : "非VIP"),
j: common_vendor.t($options.vipStartDisplay),
k: common_vendor.t($options.vipEndDisplay),
l: $data.vipIsVip ? 1 : ""
} : {}, {
m: $data.vipIsVip
}, $data.vipIsVip ? {} : {}, {
n: common_vendor.o((...args) => $options.goVip && $options.goVip(...args)),
o: common_vendor.o((...args) => $options.goMyOrders && $options.goMyOrders(...args)),
p: common_vendor.o((...args) => $options.editProfile && $options.editProfile(...args)),
q: common_vendor.o((...args) => $options.goAbout && $options.goAbout(...args)),
r: $options.isLoggedIn
}, $options.isLoggedIn ? {
s: common_vendor.o((...args) => $options.logout && $options.logout(...args))
} : {});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);