Browse Source

减少userInfo请求

林旭祥 1 week ago
parent
commit
704a6229d6
2 changed files with 17 additions and 11 deletions
  1. 16 10
      src/components/Header/index.vue
  2. 1 1
      src/views/home/index.vue

+ 16 - 10
src/components/Header/index.vue

@@ -136,16 +136,22 @@ const getMusic = async () => {
 
 //获取个人信息
 const getUserInfo = () => {
-  let params = {};
-  proxy?.$http.common.getUserInfo(params).then((res: any) => {
-    //保存信息
-    if (res.data.length) {
-      let myData = res.data[0];
-      userInfo.value = myData;
-      let info: any = JSON.stringify(myData);
-      localStorage.setItem("userInfo", info);
-    }
-  });
+  //用户信息
+  const myInfo: any = localStorage.getItem('userInfo');
+  if (myInfo && props.type != 'home') {
+    userInfo.value = JSON.parse(myInfo);
+  } else {
+    let params = {};
+    proxy?.$http.common.getUserInfo(params).then((res: any) => {
+      //保存信息
+      if (res.data.length) {
+        let myData = res.data[0];
+        userInfo.value = myData;
+        let info: any = JSON.stringify(myData);
+        localStorage.setItem("userInfo", info);
+      }
+    });
+  }
 };
 
 onBeforeMount(() => {

+ 1 - 1
src/views/home/index.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="home">
-    <Header :showClose="false" :showTool="true" logoClass="logo2"></Header>
+    <Header :showClose="false" :showTool="true" type="home" logoClass="logo2"></Header>
     <div class="menu">
       <div class="left">
         <div class="li" @click="getJump('/train', '自助锻炼')"><img src="@/assets/images/home/train.png" /></div>