1
This commit is contained in:
@@ -5,21 +5,60 @@ const _sfc_main = {
|
||||
data() {
|
||||
return {
|
||||
avatarUrl: "/static/logo.png",
|
||||
shopName: "我的店铺",
|
||||
mobile: ""
|
||||
shopName: "未登录",
|
||||
mobile: "",
|
||||
pendingJsCode: "",
|
||||
logging: false,
|
||||
vipIsVip: false,
|
||||
vipStart: "",
|
||||
vipEnd: ""
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
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) {
|
||||
@@ -36,11 +75,96 @@ const _sfc_main = {
|
||||
} 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.showToast({ title: "VIP会员(开发中)", icon: "none" });
|
||||
common_vendor.index.navigateTo({ url: "/pages/my/vip" });
|
||||
},
|
||||
goMyOrders() {
|
||||
common_vendor.index.switchTab({ url: "/pages/detail/index" });
|
||||
@@ -72,11 +196,15 @@ const _sfc_main = {
|
||||
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" });
|
||||
common_vendor.index.showToast({ title: "已清理本地信息", icon: "none" });
|
||||
setTimeout(() => {
|
||||
common_vendor.index.reLaunch({ url: "/pages/index/index" });
|
||||
}, 300);
|
||||
@@ -87,23 +215,34 @@ const _sfc_main = {
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {
|
||||
a: $data.avatarUrl,
|
||||
b: common_vendor.o((...args) => $options.onAvatarError && $options.onAvatarError(...args)),
|
||||
c: common_vendor.t($data.shopName),
|
||||
d: common_vendor.t($options.mobileDisplay),
|
||||
e: common_vendor.o((...args) => $options.goVip && $options.goVip(...args)),
|
||||
f: common_vendor.o((...args) => $options.goMyOrders && $options.goMyOrders(...args)),
|
||||
g: common_vendor.o((...args) => $options.goSupplier && $options.goSupplier(...args)),
|
||||
h: common_vendor.o((...args) => $options.goCustomer && $options.goCustomer(...args)),
|
||||
i: common_vendor.o((...args) => $options.goCustomerQuote && $options.goCustomerQuote(...args)),
|
||||
j: common_vendor.o((...args) => $options.goShop && $options.goShop(...args)),
|
||||
k: common_vendor.o((...args) => $options.editProfile && $options.editProfile(...args)),
|
||||
l: common_vendor.o((...args) => $options.goProductSettings && $options.goProductSettings(...args)),
|
||||
m: common_vendor.o((...args) => $options.goSystemParams && $options.goSystemParams(...args)),
|
||||
n: common_vendor.o((...args) => $options.goAbout && $options.goAbout(...args)),
|
||||
o: common_vendor.o((...args) => $options.logout && $options.logout(...args))
|
||||
};
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user