浏览代码

盲改免登录对接

Karsa 5 月之前
父节点
当前提交
b4104f801b
共有 6 个文件被更改,包括 46 次插入11 次删除
  1. 7 1
      src/api/http.js
  2. 5 0
      src/api/modules/oldApi.js
  3. 9 5
      src/main.js
  4. 24 3
      src/utils/loginTransfer.js
  5. 0 1
      src/utils/storage.js
  6. 1 1
      src/views/Login.vue

+ 7 - 1
src/api/http.js

@@ -2,6 +2,9 @@
 import axios from "axios";
 import axios from "axios";
 import bus from "./bus.js";
 import bus from "./bus.js";
 import {router} from '../main'
 import {router} from '../main'
+import storage from '@/utils/storage'
+import { setLoginCookieInfo } from '@/utils/loginTransfer'
+
 let store=null
 let store=null
 // 异步加载store模块 不异步加载的话,@/api/modules/oldApi.js的导入导出写法会有问题
 // 异步加载store模块 不异步加载的话,@/api/modules/oldApi.js的导入导出写法会有问题
 import('@/vuex/index.js')
 import('@/vuex/index.js')
@@ -21,6 +24,9 @@ axios.interceptors.request.use(
     if (auth) {
     if (auth) {
       config.headers.Authorization = auth;
       config.headers.Authorization = auth;
     }
     }
+    if(storage.getCookie('ai_token')) {
+      config.headers.CookieVal = storage.getCookie('ai_token')
+    }
     const uuid = localStorage.getItem("uuid") || "";
     const uuid = localStorage.getItem("uuid") || "";
     config.headers.Uuid = uuid;
     config.headers.Uuid = uuid;
     config.headers.AccessToken = uuid + "--zheshiyigename";
     config.headers.AccessToken = uuid + "--zheshiyigename";
@@ -93,7 +99,7 @@ function checkStatus(response,closableErrMsg) {
       // localStorage.setItem("auth", "")
       // localStorage.setItem("auth", "")
       
       
     }else if(res.Ret === 4014) {
     }else if(res.Ret === 4014) {
-      
+      return setLoginCookieInfo(res.Data)
     }
     }
     return res;
     return res;
   } else {
   } else {

+ 5 - 0
src/api/modules/oldApi.js

@@ -346,6 +346,11 @@ const report2PdfImg=params=>{
 	return http.post('/smart_report/get_pdf_url',params)
 	return http.post('/smart_report/get_pdf_url',params)
 }
 }
 
 
+/* 据cookie ai_token静默登录 */
+export const loginTransferByCookie = params => {
+	return http.post('/user_login/username_login',params)
+}
+
 export {
 export {
 	userLogin,
 	userLogin,
 	modifyPwd,
 	modifyPwd,

+ 9 - 5
src/main.js

@@ -144,6 +144,9 @@ Vue.use(VueMasonryPlugin);
 import * as permissionBtn from "@/utils/buttonConfig";
 import * as permissionBtn from "@/utils/buttonConfig";
 Vue.prototype.permissionBtn = permissionBtn
 Vue.prototype.permissionBtn = permissionBtn
 
 
+
+import { transferLoginByCookie } from '@/utils/loginTransfer'
+
 // flat
 // flat
 Array.prototype.flat = function (count) {
 Array.prototype.flat = function (count) {
   let c = count || 1;
   let c = count || 1;
@@ -202,12 +205,13 @@ router.beforeEach(async(to, from, next) => {
   } */
   } */
 
 
   let auth = localStorage.getItem("auth") || false;
   let auth = localStorage.getItem("auth") || false;
-  if (to.path != "/login" && to.path!='/temppage' &&to.path!='/fogetpassword' && !auth) {
-    if(storage.getCookie('ai_token')) {
+  if(!auth && storage.getCookie('ai_token')) {
+    transferLoginByCookie();
+    return
+  }
 
 
-    }else {
-      next('/login')
-    }
+  if (to.path != "/login" && to.path!='/temppage' &&to.path!='/fogetpassword' && !auth) {
+    next('/login')
     return false;
     return false;
   }
   }
 
 

+ 24 - 3
src/utils/loginTransfer.js

@@ -1,11 +1,32 @@
 /* 各个子系统cookie共享实现免登录 */
 /* 各个子系统cookie共享实现免登录 */
 import storage from '@/utils/storage'
 import storage from '@/utils/storage'
+import { loginTransferByCookie } from '@/api/modules/oldApi'
+import {router} from '../main'
 
 
 // 有cookie换token免登录
 // 有cookie换token免登录
-export function transferLoginByCookie() {
+export async function transferLoginByCookie() {
+  const res = await loginTransferByCookie({AdminName: storage.getCookie('ai_token')})
+  if(res.Ret !== 200) return
+  setLoginCookieInfo(res.Data)
 }
 }
 
 
-export function setLoginCookieInfo(cookie,token) {
-  // storage.setCookie()
+export function setLoginCookieInfo(data) {
+  const {  Authorization,RealName,RoleTypeCode,SysRoleTypeCode,ProductName,Authority,AdminId,AdminName } = data;
+  localStorage.setItem("auth", Authorization);
+  localStorage.setItem("userName", RealName);
+  localStorage.setItem("Role", RoleTypeCode);
+  localStorage.setItem("RoleIdentity", SysRoleTypeCode);
+  localStorage.setItem("RoleType", ProductName);
+  localStorage.setItem("ManageType", Authority);
+  localStorage.setItem("AdminId", AdminId);
+  localStorage.setItem("AdminName", AdminName);
+  localStorage.setItem("loginTime",new Date())
+  storage.setCookie('ai_token',AdminName)
+
+  if(['/login','/fogetpassword'].includes(location.pathname)) {
+    router.replace({path:'/home'})
+  }else {
+    window.location.reload();
+  }
   
   
 }
 }

+ 0 - 1
src/utils/storage.js

@@ -26,7 +26,6 @@ export default {
         date.setTime(date.getTime() + (hours * 60 * 60 * 1000));
         date.setTime(date.getTime() + (hours * 60 * 60 * 1000));
         expires = ';expires=' + date.toUTCString();
         expires = ';expires=' + date.toUTCString();
     }
     }
-		console.log( key + '=' + value + expires + ('; path=/'))
     document.cookie = key + '=' + value + expires + (';path=/');
     document.cookie = key + '=' + value + expires + (';path=/');
 	},
 	},
 
 

+ 1 - 1
src/views/Login.vue

@@ -604,7 +604,7 @@ export default {
             localStorage.setItem("AdminId", res.Data.AdminId);
             localStorage.setItem("AdminId", res.Data.AdminId);
             localStorage.setItem("AdminName", res.Data.AdminName);
             localStorage.setItem("AdminName", res.Data.AdminName);
             localStorage.setItem("loginTime",new Date())
             localStorage.setItem("loginTime",new Date())
-            storage.setCookie('ai_token','dwqdwqdwqd')
+            storage.setCookie('ai_token',res.Data.AdminName)
             // 清除最近登录时长
             // 清除最近登录时长
             recordActiveLogin({ActiveTime:0}).then(res=>{
             recordActiveLogin({ActiveTime:0}).then(res=>{
                 if(res.Ret!==200) return
                 if(res.Ret!==200) return