Browse Source

更换用户登录流程

reedliuqing_i 5 years ago
parent
commit
0826242490
6 changed files with 17 additions and 44 deletions
  1. 1 1
      src/App.vue
  2. 0 12
      src/api/env.js
  3. 6 25
      src/api/user.js
  4. 3 1
      src/layout/components/Navbar.vue
  5. 5 4
      src/utils/request.js
  6. 2 1
      src/views/home/index.vue

+ 1 - 1
src/App.vue

@@ -12,7 +12,7 @@ export default {
   mounted() {
     getUserInfo()
       .then(res => {
-        localStorage.setItem('realname', res.data.realname)
+        localStorage.setItem('realname', res.data.chineseName)
         localStorage.setItem('username', res.data.username)
       })
   }

+ 0 - 12
src/api/env.js

@@ -1,12 +0,0 @@
-import request from '@/utils/request'
-
-const commonUrl = 'http://10.179.209.19:8899'
-
-export function getBusinessLine(data) {
-  return request({
-    url: commonUrl + '/api/business-lines',
-    method: 'get',
-    data
-  })
-}
-

+ 6 - 25
src/api/user.js

@@ -1,33 +1,14 @@
 import request from '@/utils/request'
 
-const envUrl = 'http://10.179.209.19:8899'
+export const requestIp = 'http://10.179.209.19:8762'
 
-export function getUserInfo() {
-  return request({
-    url: envUrl + '/user',
-    method: 'get'
-  })
-}
-
-export function login(data) {
-  return request({
-    url: '/user/login',
-    method: 'post',
-    data
-  })
-}
+export const loginUrl = requestIp + '/sso/login'
 
-export function getInfo(token) {
-  return request({
-    url: '/user/info',
-    method: 'get',
-    params: { token }
-  })
-}
+export const logoutUrl = requestIp + '/sso/logout'
 
-export function logout() {
+export function getUserInfo() {
   return request({
-    url: '/user/logout',
-    method: 'post'
+    url: requestIp + '/sso/user',
+    method: 'get'
   })
 }

+ 3 - 1
src/layout/components/Navbar.vue

@@ -42,6 +42,8 @@ import Hamburger from '@/components/Hamburger'
 import navbarLogo from '@/icons/rabbit-logo.gif'
 import { settingQueryBizTypeList } from '@/api/settingQueryBizTypeList.js'
 import Utils from '../../util.js'
+import { logoutUrl } from '@/api/user.js'
+
 export default {
   components: {
     Breadcrumb,
@@ -78,7 +80,7 @@ export default {
     logout() {
       // await this.$store.dispatch('user/logout')
       // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
-      location.href = 'http://10.179.209.19:8899/logout'
+      location.href = logoutUrl
     },
     handleCommand(command) {
       switch (command) {

+ 5 - 4
src/utils/request.js

@@ -2,6 +2,7 @@ import axios from 'axios'
 import { Message } from 'element-ui'
 import store from '@/store'
 import { getToken } from '@/utils/auth'
+import { loginUrl } from '@/api/user.js'
 
 // create an axios instance
 const service = axios.create({
@@ -121,16 +122,16 @@ service.interceptors.response.use(
         type: 'warning',
         duration: 5 * 1000
       })
+      if (error.response.status === 401) {
+        location.href = loginUrl
+      }
     } else {
-      error.message = '登录中'
+      error.message = 'error'
       Message({
         message: error.message,
         type: 'warning',
         duration: 5 * 1000
       })
-      if (location.href.indexOf('localhost') < 0) {
-        // location.href = 'http://10.179.209.19:8899/'
-      }
     }
     return Promise.reject(error)
   }

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

@@ -274,6 +274,7 @@ img.img-arrow {
 <script>
 import FloatMenu from './floatMenu'
 import { getGlobalInterface } from '@/api/data.js'
+import { logoutUrl } from '@/api/user.js'
 
 export default {
   components: {
@@ -349,7 +350,7 @@ export default {
     handleCommand(command) {
       switch (command) {
         case 'a':
-          location.href = 'http://10.179.209.19:8899/logout'
+          location.href = logoutUrl
           break
       }
     }