mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-09-20 20:02:05 +08:00
- 引入 buyerLogin 工具,优化商品详情页的链接跳转逻辑,确保未登录用户能正确重定向到登录页面 - 更新商品 SKU 详情 API,支持未登录状态下的访问 - 修改支付 API,新增 skipMessage 参数以控制支付提示信息 - 改进商品列表与支付页面的用户体验,确保更流畅的操作流程 - 规范化商品类型与库存提示,提升用户体验
60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
/**
|
|
* 买家端登录态与商品详情跳转校验
|
|
*
|
|
* @author Mike
|
|
* @date 2026-08-05
|
|
*/
|
|
import storage from "@/plugins/storage";
|
|
|
|
export function isBuyerLoggedIn() {
|
|
const rawUserInfo = storage.getItem("userInfo");
|
|
if (rawUserInfo) {
|
|
try {
|
|
return !!JSON.parse(rawUserInfo).username;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
return !!storage.getItem("accessToken");
|
|
}
|
|
|
|
export function parseInternalLink(url) {
|
|
const [path, search = ""] = url.split("?");
|
|
const query = {};
|
|
if (search) {
|
|
new URLSearchParams(search).forEach((value, key) => {
|
|
query[key] = value;
|
|
});
|
|
}
|
|
return { path, query };
|
|
}
|
|
|
|
export function isGoodsDetailPath(path) {
|
|
return path === "/goodsDetail";
|
|
}
|
|
|
|
export function redirectToLogin(router, location) {
|
|
router.push({
|
|
path: "/login",
|
|
query: {
|
|
rePath: location.path,
|
|
query: JSON.stringify(location.query || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
/** 内部链接跳转;访问商品详情前校验登录(首页装修、列表等共用) */
|
|
export function openLink(url, router) {
|
|
if (!url) return;
|
|
if (url.charAt(0) !== "/") {
|
|
window.open(url, "_blank");
|
|
return;
|
|
}
|
|
const location = parseInternalLink(url);
|
|
if (!isBuyerLoggedIn() && isGoodsDetailPath(location.path)) {
|
|
redirectToLogin(router, location);
|
|
return;
|
|
}
|
|
window.open(router.resolve(url).href, "_blank");
|
|
}
|