Files
PartsInquiry/frontend/unpackage/dist/dev/mp-weixin/pages/my/index.js
2025-09-24 20:35:15 +08:00

250 lines
8.7 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_http = require("../../common/http.js");
const _sfc_main = {
data() {
return {
avatarUrl: "/static/logo.png",
shopName: "未登录",
mobile: "",
pendingJsCode: "",
logging: false,
vipIsVip: false,
vipStart: "",
vipEnd: ""
};
},
onShow() {
this.fetchProfile();
this.loadVipFromStorage();
try {
if (common_vendor.index.getStorageSync("TOKEN")) {
this.$forceUpdate && this.$forceUpdate();
}
} catch (e) {
}
},
computed: {
isLoggedIn() {
try {
return !!common_vendor.index.getStorageSync("TOKEN");
} catch (e) {
return false;
}
},
mobileDisplay() {
const m = String(this.mobile || "");
return m.length === 11 ? m.slice(0, 3) + "****" + m.slice(7) : m || "未绑定手机号";
},
vipStartDisplay() {
return this.formatDisplay(this.vipStart);
},
vipEndDisplay() {
return this.formatDisplay(this.vipEnd);
}
},
methods: {
// 登录相关方法已移除
async fetchProfile() {
const hasToken = (() => {
try {
return !!common_vendor.index.getStorageSync("TOKEN");
} catch (e) {
return false;
}
})();
if (!hasToken) {
this.shopName = "未登录";
this.avatarUrl = "/static/logo.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;
this.mobile = phone;
} catch (e) {
}
},
loadVipFromStorage() {
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;
} catch (e) {
}
},
formatDisplay(value) {
if (!value)
return "-";
const s = String(value);
const m = s.match(/^(\d{4}-\d{2}-\d{2})([ T](\d{2}:\d{2}))/);
if (m)
return `${m[1]} ${m[3]}`;
return s;
},
startLogin() {
if (this.logging)
return;
this.logging = true;
const tryOnce = async () => ({});
common_vendor.index.login({ provider: "weixin", success: async (res) => {
this.pendingJsCode = res.code || "";
if (!this.pendingJsCode) {
this.logging = false;
return common_vendor.index.showToast({ title: "获取登录code失败", icon: "none" });
}
try {
await tryOnce();
} catch (e) {
const msg = e && e.message || "";
if (msg.includes("40163") || msg.toLowerCase().includes("been used")) {
common_vendor.index.login({ provider: "weixin", success: async (r2) => {
const fresh = r2.code || "";
if (!fresh) {
this.logging = false;
return;
}
try {
await tryOnce();
} finally {
this.logging = false;
}
} });
return;
}
} finally {
this.logging = false;
}
}, fail: () => {
this.logging = false;
common_vendor.index.showToast({ title: "微信登录失败", icon: "none" });
} });
},
goLogin() {
common_vendor.index.navigateTo({ url: "/pages/auth/login" });
},
goRegister() {
common_vendor.index.navigateTo({ url: "/pages/auth/register" });
},
onGetPhoneNumber(e) {
if (this.logging)
return;
this.logging = true;
common_vendor.index.login({ provider: "weixin", success: (res) => {
const jsCode = res.code || "";
if (!jsCode) {
this.logging = false;
return common_vendor.index.showToast({ title: "获取登录code失败", icon: "none" });
}
Promise.resolve().finally(() => {
this.logging = false;
});
}, fail: () => {
this.logging = false;
common_vendor.index.showToast({ title: "微信登录失败", icon: "none" });
} });
},
goSmsLogin() {
common_vendor.index.navigateTo({ url: "/pages/my/sms-login" });
},
onAvatarError() {
this.avatarUrl = "/static/logo.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" });
},
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" });
},
goAbout() {
common_vendor.index.navigateTo({ url: "/pages/my/about" });
},
logout() {
try {
common_vendor.index.removeStorageSync("TOKEN");
common_vendor.index.removeStorageSync("LOGINED");
common_vendor.index.removeStorageSync("LOGIN_PHONE");
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_NAME");
common_vendor.index.removeStorageSync("USER_MOBILE");
common_vendor.index.removeStorageSync("SHOP_NAME");
common_vendor.index.showToast({ title: "已清理本地信息", icon: "none" });
setTimeout(() => {
common_vendor.index.reLaunch({ url: "/pages/index/index" });
}, 300);
} catch (e) {
common_vendor.index.reLaunch({ url: "/pages/index/index" });
}
}
}
};
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
}, $options.isLoggedIn ? {
x: common_vendor.o((...args) => $options.logout && $options.logout(...args))
} : {});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/index.js.map