hookehuyr

头部组件显示登录状态接口联调

<!--
* @Date: 2024-09-26 13:42:11
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-10-24 14:34:58
* @LastEditTime: 2024-10-25 14:21:41
* @FilePath: /hager/src/components/common/hagerHeader.vue
* @Description: 文件描述
-->
......@@ -138,7 +138,7 @@ import mixin from 'common/mixin';
import { parseQueryString } from '@/utils/tools';
import $ from 'jquery';
import hagerMenu from '../hagerMenu.vue';
import { getProductCateAPI } from "@/api/hager.js";
import { getProductCateAPI, getUserInfoAPI } from "@/api/hager.js";
export default {
components: { hagerMenu },
......@@ -154,7 +154,7 @@ export default {
margin_top: 0,
// choose_country: false, // 主动选择了国家地区
keyword: '',
is_login: true,
is_login: false,
show_border: false,
}
},
......@@ -171,6 +171,8 @@ export default {
} else {
this.show_border = false;
}
// 检查登录状态
this.getUserInfo();
},
'is_xs' (val) {
if (!val) {
......@@ -190,7 +192,8 @@ export default {
// 修改数据结构显示
this.product_info = this.splitProductList(this.product_info);
}
//
// 获取用户信息
this.getUserInfo();
// let margin_top = 5; // 默认高度
// let once_header_height = 5; // 选择国家地区高度
// // let hidden_header_height = 2; // 可隐藏高度s
......@@ -215,6 +218,16 @@ export default {
},
methods: {
async getUserInfo () {
const { code, data } = await getUserInfoAPI();
if (code) {
if (data) {
this.is_login = true; // 已登录
} else {
this.is_login = false; // 未登录
}
}
},
splitProductList (products) {
const maxLength = 5; // 超过5个需要拆分
let result = [];
......@@ -328,9 +341,15 @@ export default {
window.open('https://hager.com/', '_blank')
},
goToLogin () {
this.$router.push({
path: '/user/login'
});
if (this.is_login) {
this.$router.push({
path: '/user/info'
});
} else {
this.$router.push({
path: '/user/login'
});
}
},
openMenu () {
this.show_menu = !this.show_menu;
......