mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-08-06 10:57:26 +08:00
feat: 增强用户登录体验与组件逻辑优化
- 在多个组件中添加用户登录状态检查,确保用户在进行特定操作前已登录。 - 更新购物车、消息中心等组件的点击事件,未登录时提示用户登录。 - 优化优惠券领取逻辑,未登录时引导用户登录。 - 调整样式以提升组件一致性,确保用户界面友好。
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
<script>
|
||||
import { getIconUrl } from "@/assets/iconfont/iconMap";
|
||||
import storage from "@/plugins/storage.js";
|
||||
|
||||
export default {
|
||||
name: "fixed-index",
|
||||
@@ -19,22 +20,26 @@ export default {
|
||||
{
|
||||
icon:"user",
|
||||
label:"会员中心",
|
||||
path:"/home"
|
||||
path:"/home",
|
||||
requireLogin: true,
|
||||
},
|
||||
{
|
||||
icon:"carts",
|
||||
label:"购物车",
|
||||
path:"/cart"
|
||||
path:"/cart",
|
||||
requireLogin: true,
|
||||
},
|
||||
{
|
||||
icon:"notification",
|
||||
label:"消息",
|
||||
path:"/home/MsgList"
|
||||
path:"/home/MsgList",
|
||||
requireLogin: true,
|
||||
},
|
||||
{
|
||||
icon:"collage",
|
||||
label:"收藏",
|
||||
path:"/home/Favorites"
|
||||
path:"/home/Favorites",
|
||||
requireLogin: true,
|
||||
},
|
||||
{
|
||||
icon:"back",
|
||||
@@ -71,13 +76,37 @@ export default {
|
||||
this.isScrolling = false;
|
||||
}
|
||||
},
|
||||
handleClickIcon(val){
|
||||
if(val.path === 'back'){
|
||||
this.scrollToTop()
|
||||
}else{
|
||||
this.$router.push(val.path)
|
||||
isLoggedIn () {
|
||||
const rawUserInfo = storage.getItem('userInfo');
|
||||
if (rawUserInfo) {
|
||||
try {
|
||||
return !!JSON.parse(rawUserInfo).username;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return !!storage.getItem('accessToken');
|
||||
},
|
||||
goLogin (rePath) {
|
||||
this.$router.push({
|
||||
path: '/login',
|
||||
query: {
|
||||
rePath,
|
||||
query: JSON.stringify(this.$route.query || {}),
|
||||
},
|
||||
});
|
||||
},
|
||||
handleClickIcon (val) {
|
||||
if (val.path === 'back') {
|
||||
this.scrollToTop();
|
||||
return;
|
||||
}
|
||||
if (val.requireLogin && !this.isLoggedIn()) {
|
||||
this.goLogin(val.path);
|
||||
return;
|
||||
}
|
||||
this.$router.push(val.path);
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -124,9 +124,27 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
goToPay() { // 跳转购物车
|
||||
let url = this.$router.resolve({
|
||||
path: '/cart'
|
||||
goToPay() {
|
||||
if (!this.userInfo.username) {
|
||||
Modal.confirm({
|
||||
title: '温馨提示',
|
||||
content: '请登录后执行此操作',
|
||||
okText: '立即登录',
|
||||
cancelText: '取消',
|
||||
onOk: () => {
|
||||
this.$router.push({
|
||||
path: '/login',
|
||||
query: {
|
||||
rePath: '/cart',
|
||||
query: JSON.stringify(this.$route.query || {}),
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
const url = this.$router.resolve({
|
||||
path: '/cart',
|
||||
});
|
||||
window.open(url.href, '_blank');
|
||||
},
|
||||
@@ -169,16 +187,29 @@ export default {
|
||||
}
|
||||
},
|
||||
shopEntry() {
|
||||
// 店铺入驻
|
||||
if (storage.getItem('accessToken')) {
|
||||
let routeUrl = this.$router.resolve({
|
||||
const routeUrl = this.$router.resolve({
|
||||
path: '/shopEntry',
|
||||
query: {id: 1}
|
||||
query: { id: 1 },
|
||||
});
|
||||
window.open(routeUrl.href, '_blank');
|
||||
} else {
|
||||
this.$router.push('login');
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '温馨提示',
|
||||
content: '请登录后执行此操作',
|
||||
okText: '立即登录',
|
||||
cancelText: '取消',
|
||||
onOk: () => {
|
||||
this.$router.push({
|
||||
path: '/login',
|
||||
query: {
|
||||
rePath: '/shopEntry',
|
||||
query: JSON.stringify({ id: 1 }),
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
handleCartDropdownVisible(visible) {
|
||||
if (visible) {
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</div> -->
|
||||
</div>
|
||||
<div v-else class="flex flex-a-c ">
|
||||
<div class="btns" @click="$router.push('login')">登录</div>
|
||||
<div class="btns" @click="goLogin">登录</div>
|
||||
<div class="btns sign-up" @click="$router.push('signUp')">注册</div>
|
||||
</div>
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
|
||||
<script>
|
||||
|
||||
import { Modal } from "@/utils/message";
|
||||
import storage from "@/plugins/storage";
|
||||
import config from "@/config";
|
||||
import defaultAvatar from "@/assets/images/default.png";
|
||||
@@ -182,17 +183,34 @@ export default {
|
||||
query: Object.fromEntries(new URLSearchParams(search)),
|
||||
};
|
||||
},
|
||||
isMemberRoute(location) {
|
||||
return location.path.startsWith("/home/") || location.path === "/cart";
|
||||
},
|
||||
promptLoginThenNavigate(location) {
|
||||
Modal.confirm({
|
||||
title: "温馨提示",
|
||||
content: "请登录后执行此操作",
|
||||
okText: "立即登录",
|
||||
cancelText: "取消",
|
||||
onOk: () => {
|
||||
this.$router.push({
|
||||
path: "/login",
|
||||
query: {
|
||||
rePath: location.path,
|
||||
query: JSON.stringify(location.query || {}),
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
goLogin() {
|
||||
this.$router.push("/login");
|
||||
},
|
||||
// 快捷跳转中心
|
||||
entryControl(val) {
|
||||
const location = this.resolveRoute(val.path);
|
||||
if (location.path.startsWith("/home/") && !storage.getItem("userInfo")) {
|
||||
this.$router.push({
|
||||
path: "/login",
|
||||
query: {
|
||||
rePath: location.path,
|
||||
query: JSON.stringify(location.query || {}),
|
||||
},
|
||||
});
|
||||
if (this.isMemberRoute(location) && !storage.getItem("userInfo")) {
|
||||
this.promptLoginThenNavigate(location);
|
||||
return;
|
||||
}
|
||||
const url = this.$router.resolve(location);
|
||||
|
||||
Reference in New Issue
Block a user