mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-08-07 03:15:01 +08:00
feat: 增强用户登录体验与组件逻辑优化
- 在多个组件中添加用户登录状态检查,确保用户在进行特定操作前已登录。 - 更新购物车、消息中心等组件的点击事件,未登录时提示用户登录。 - 优化优惠券领取逻辑,未登录时引导用户登录。 - 调整样式以提升组件一致性,确保用户界面友好。
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
</template>
|
||||
<script>
|
||||
import { Modal } from "@/utils/message";
|
||||
import storage from "@/plugins/storage";
|
||||
import { couponList, receiveCoupon } from "@/api/member.js";
|
||||
export default {
|
||||
data() {
|
||||
@@ -115,6 +116,26 @@ export default {
|
||||
},
|
||||
// 领取优惠券
|
||||
receive(item) {
|
||||
const userInfo = storage.getItem("userInfo");
|
||||
const isLogin = userInfo && JSON.parse(userInfo).username;
|
||||
if (!isLogin) {
|
||||
Modal.confirm({
|
||||
title: "温馨提示",
|
||||
content: "请登录后执行此操作",
|
||||
okText: "立即登录",
|
||||
cancelText: "取消",
|
||||
onOk: () => {
|
||||
this.$router.push({
|
||||
path: "/login",
|
||||
query: {
|
||||
rePath: this.$route.path,
|
||||
query: JSON.stringify(this.$route.query),
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
receiveCoupon(item.id)
|
||||
.then((res) => {
|
||||
if (!res || !res.success) return;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
ref="formRegist"
|
||||
:model="formRegist"
|
||||
:rules="ruleInline"
|
||||
style="width:300px;"
|
||||
class="signup-form"
|
||||
>
|
||||
<el-form-item prop="username">
|
||||
<el-input
|
||||
@@ -66,7 +66,7 @@
|
||||
>注册</el-button
|
||||
>
|
||||
</el-form-item>
|
||||
<el-form-item><span class="color999 ml_20">点击注册,表示您同意《<router-link to="/article?id=1371992704333905920" target="_blank">商城用户协议</router-link>》</span></el-form-item>
|
||||
<el-form-item><span class="color999">点击注册,表示您同意《<router-link to="/article?id=1371992704333905920" target="_blank">商城用户协议</router-link>》</span></el-form-item>
|
||||
</el-form>
|
||||
<!-- 拼图验证码 -->
|
||||
<Verify
|
||||
@@ -240,7 +240,15 @@ export default {
|
||||
margin: 0 auto;
|
||||
width: 600px;
|
||||
background-color: #fff;
|
||||
padding: 20px 150px;
|
||||
padding: 20px 40px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
.signup-form {
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
.login-btn{
|
||||
position: absolute;
|
||||
right: 20px;
|
||||
@@ -250,8 +258,9 @@ export default {
|
||||
|
||||
.verify-con{
|
||||
position: absolute;
|
||||
left: 140px;
|
||||
left: 50%;
|
||||
top: 80px;
|
||||
transform: translateX(-50%);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
<script>
|
||||
import { Message } from "@/utils/message";
|
||||
import { editMemberInfo } from '@/api/account.js';
|
||||
import { getMemberMsg } from '@/api/login.js';
|
||||
import { commonUrl } from '@/plugins/request.js';
|
||||
import storage from '@/plugins/storage.js';
|
||||
import { User } from '@element-plus/icons-vue';
|
||||
@@ -64,11 +65,44 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.formItem = JSON.parse(storage.getItem('userInfo'))
|
||||
this.formItem.birthday = this.normalizeBirthday(this.formItem.birthday)
|
||||
this.accessToken.accessToken = storage.getItem('accessToken');
|
||||
this.loadUserInfo();
|
||||
},
|
||||
methods: {
|
||||
loadUserInfo () {
|
||||
const rawUserInfo = storage.getItem('userInfo');
|
||||
if (rawUserInfo) {
|
||||
this.applyUserInfo(JSON.parse(rawUserInfo));
|
||||
return;
|
||||
}
|
||||
if (!storage.getItem('accessToken')) {
|
||||
this.redirectToLogin();
|
||||
return;
|
||||
}
|
||||
getMemberMsg().then(res => {
|
||||
if (res.success && res.result) {
|
||||
storage.setItem('userInfo', res.result);
|
||||
this.applyUserInfo(res.result);
|
||||
} else {
|
||||
this.redirectToLogin();
|
||||
}
|
||||
}).catch(() => {
|
||||
this.redirectToLogin();
|
||||
});
|
||||
},
|
||||
applyUserInfo (userInfo) {
|
||||
this.formItem = { ...userInfo };
|
||||
this.formItem.birthday = this.normalizeBirthday(this.formItem.birthday);
|
||||
},
|
||||
redirectToLogin () {
|
||||
this.$router.push({
|
||||
path: '/login',
|
||||
query: {
|
||||
rePath: this.$route.path,
|
||||
query: JSON.stringify(this.$route.query || {}),
|
||||
},
|
||||
});
|
||||
},
|
||||
normalizeBirthday (value) {
|
||||
if (!value) return ''
|
||||
if (value instanceof Date) return value
|
||||
|
||||
@@ -182,7 +182,7 @@
|
||||
}}</span>折</span>
|
||||
<span class="describe">满{{ item.consumeThreshold }}元可用</span>
|
||||
</div>
|
||||
<p>使用范围:{{ useScope(item.scopeType) }}</p>
|
||||
<p>使用范围:{{ useScope(item.scopeType, item.storeName) }}</p>
|
||||
<p>有效期:{{ item.endTime }}</p>
|
||||
</div>
|
||||
<img class="used" v-if="usedCouponId.includes(item.id)" src="../../assets/images/geted.png" alt="" />
|
||||
@@ -861,8 +861,10 @@ export default {
|
||||
});
|
||||
},
|
||||
// 优惠券可用范围
|
||||
useScope(type) {
|
||||
useScope(type, storeName) {
|
||||
let shop = "平台";
|
||||
let goods = "全部商品";
|
||||
if (storeName !== "platform") shop = storeName;
|
||||
switch (type) {
|
||||
case "ALL":
|
||||
goods = "全部商品";
|
||||
@@ -874,7 +876,7 @@ export default {
|
||||
goods = "部分分类商品";
|
||||
break;
|
||||
}
|
||||
return `${goods}可用`;
|
||||
return `${shop}${goods}可用`;
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1380,6 +1382,7 @@ export default {
|
||||
.coupon-item {
|
||||
width: 280px;
|
||||
height: 125px;
|
||||
margin-left: 0;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
overflow: hidden;
|
||||
@@ -1470,6 +1473,10 @@ export default {
|
||||
.coupon-list {
|
||||
max-height: 260px;
|
||||
overflow: scroll;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.pay-gcc-module {
|
||||
|
||||
Reference in New Issue
Block a user