Browse Source

打开页面后自动加载用户信息

sunjh 6 years ago
parent
commit
999a3d217d
3 changed files with 18 additions and 10 deletions
  1. 16 8
      src/components/commons/Header.vue
  2. 1 1
      src/js/api.js
  3. 1 1
      src/js/http.js

+ 16 - 8
src/components/commons/Header.vue

@@ -57,6 +57,8 @@
 </template>
 
 <script>
+import {getCurrentUser, storageGet, storageSave} from '@/js/index'
+import {notify} from '@/constants/index'
 
 export default {
   name: 'header-container',
@@ -70,18 +72,24 @@ export default {
     openNavBarFunc () {
       this.openNavBar = !this.openNavBar
     },
-    getCurrentUser () {
-      // Http.get(Apis.USER.GET_CURRENT_USER).then((res) => {
-      //   sessionStorage.setItem('user', JSON.stringify(res))
-      // })
+    setUserInfo () {
+      if (storageGet('user') == null) {
+        getCurrentUser().then((res) => {
+          storageSave('user', res)
+        }).catch(error => {
+          console.log(error)
+          if (error.status == 401) {
+            notify('error', error.data)
+          } else {
+            notify('error', error.data)
+          }
+        })
+      }
     },
-    getUserIdentity () {
-
-    }
   },
   mounted () {
     this.$nextTick(() => {
-      this.getCurrentUser()
+      this.setUserInfo()
     })
   },
 }

+ 1 - 1
src/js/api.js

@@ -39,7 +39,7 @@ export default {
     END_PROJECT: '',
     AGENCY_AUTHENTICATION: '/api/user/{userId}/agency/',
     ADD_AGENCY: '/api/greenChannel/agency/',
-    GET_CURRENT_USER: '/api/currentUser/',
+    GET_CURRENT_USER: '/api/common/currentUser/',
     GET_USER_IDENTITY: '',
     GET_AUTH_URLS: '',
   },

+ 1 - 1
src/js/http.js

@@ -83,7 +83,7 @@ export default {
         .then(response => {
           resolve(response.data)
         }).catch(error => {
-        reject(error)
+        reject(error.response)
       })
 
     })