hookehuyr

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

1 <!-- 1 <!--
2 * @Date: 2024-09-26 13:42:11 2 * @Date: 2024-09-26 13:42:11
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-10-24 14:34:58 4 + * @LastEditTime: 2024-10-25 14:21:41
5 * @FilePath: /hager/src/components/common/hagerHeader.vue 5 * @FilePath: /hager/src/components/common/hagerHeader.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -138,7 +138,7 @@ import mixin from 'common/mixin'; ...@@ -138,7 +138,7 @@ import mixin from 'common/mixin';
138 import { parseQueryString } from '@/utils/tools'; 138 import { parseQueryString } from '@/utils/tools';
139 import $ from 'jquery'; 139 import $ from 'jquery';
140 import hagerMenu from '../hagerMenu.vue'; 140 import hagerMenu from '../hagerMenu.vue';
141 -import { getProductCateAPI } from "@/api/hager.js"; 141 +import { getProductCateAPI, getUserInfoAPI } from "@/api/hager.js";
142 142
143 export default { 143 export default {
144 components: { hagerMenu }, 144 components: { hagerMenu },
...@@ -154,7 +154,7 @@ export default { ...@@ -154,7 +154,7 @@ export default {
154 margin_top: 0, 154 margin_top: 0,
155 // choose_country: false, // 主动选择了国家地区 155 // choose_country: false, // 主动选择了国家地区
156 keyword: '', 156 keyword: '',
157 - is_login: true, 157 + is_login: false,
158 show_border: false, 158 show_border: false,
159 } 159 }
160 }, 160 },
...@@ -171,6 +171,8 @@ export default { ...@@ -171,6 +171,8 @@ export default {
171 } else { 171 } else {
172 this.show_border = false; 172 this.show_border = false;
173 } 173 }
174 + // 检查登录状态
175 + this.getUserInfo();
174 }, 176 },
175 'is_xs' (val) { 177 'is_xs' (val) {
176 if (!val) { 178 if (!val) {
...@@ -190,7 +192,8 @@ export default { ...@@ -190,7 +192,8 @@ export default {
190 // 修改数据结构显示 192 // 修改数据结构显示
191 this.product_info = this.splitProductList(this.product_info); 193 this.product_info = this.splitProductList(this.product_info);
192 } 194 }
193 - // 195 + // 获取用户信息
196 + this.getUserInfo();
194 // let margin_top = 5; // 默认高度 197 // let margin_top = 5; // 默认高度
195 // let once_header_height = 5; // 选择国家地区高度 198 // let once_header_height = 5; // 选择国家地区高度
196 // // let hidden_header_height = 2; // 可隐藏高度s 199 // // let hidden_header_height = 2; // 可隐藏高度s
...@@ -215,6 +218,16 @@ export default { ...@@ -215,6 +218,16 @@ export default {
215 218
216 }, 219 },
217 methods: { 220 methods: {
221 + async getUserInfo () {
222 + const { code, data } = await getUserInfoAPI();
223 + if (code) {
224 + if (data) {
225 + this.is_login = true; // 已登录
226 + } else {
227 + this.is_login = false; // 未登录
228 + }
229 + }
230 + },
218 splitProductList (products) { 231 splitProductList (products) {
219 const maxLength = 5; // 超过5个需要拆分 232 const maxLength = 5; // 超过5个需要拆分
220 let result = []; 233 let result = [];
...@@ -328,9 +341,15 @@ export default { ...@@ -328,9 +341,15 @@ export default {
328 window.open('https://hager.com/', '_blank') 341 window.open('https://hager.com/', '_blank')
329 }, 342 },
330 goToLogin () { 343 goToLogin () {
331 - this.$router.push({ 344 + if (this.is_login) {
332 - path: '/user/login' 345 + this.$router.push({
333 - }); 346 + path: '/user/info'
347 + });
348 + } else {
349 + this.$router.push({
350 + path: '/user/login'
351 + });
352 + }
334 }, 353 },
335 openMenu () { 354 openMenu () {
336 this.show_menu = !this.show_menu; 355 this.show_menu = !this.show_menu;
......