From 4fde32f8037fef94e41c65ab62a186477e3ccd16 Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Tue, 21 Jun 2022 13:06:14 +0800
Subject: [PATCH] 免密登录

---
 src/permission.js |   74 +++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/src/permission.js b/src/permission.js
index d55aa37..d80aa21 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -2,6 +2,10 @@
  * 全站权限配置
  *
  */
+import md5 from 'js-md5'
+import request from '@/router/axios';
+import { Message } from 'element-ui'
+
 import router from './router/router'
 import store from './store'
 import {validatenull} from '@/util/validate'
@@ -57,6 +61,76 @@
     if (meta.isAuth === false) {
       next()
     } else {
+      if (to.path == '/wel/index') {
+        // console.log('进入首页-----')
+        var a = to.query.securitySupervisionSystem;
+        if (a == undefined || typeof a != "string") {
+          // console.log("无securitySupervisionSystem参数  跳回登入");
+          next('/login');
+          next('/login');
+          return;
+        }
+        // console.log("有securitySupervisionSystem参数");
+        try {
+          // console.log("判断securitySupervisionSystem是否能被JSOn解码");
+          var obj = JSON.parse(a);
+          if (typeof obj == "object" && obj && obj.tokenMY == '987654321S') {
+            // console.log("成功解码 并为对象");
+            debugger
+            var data = {
+              tenantId: obj.data.dip,
+              username: obj.data.rese,
+              password: md5(obj.data.sap),
+              grant_type: 'password',
+              scope: 'all',
+              type: 'account'
+            };
+            request({
+              url: '/api/blade-auth/oauth/token',
+              method: 'post',
+              headers: {
+                'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
+                "Tenant-Id": "000000"
+              },
+              params: data
+            }).then(res => {
+              const data = res.data;
+              if (data.error_description) {
+                // console.log("登入失败");
+                Message({
+                  message: data.error_description,
+                  type: 'error'
+                })
+                next('/login');
+                next('/login');
+                return;
+              } else {
+                // console.log("登入成功");
+                store.commit('SET_TOKEN', data.access_token);
+                store.commit('SET_REFRESH_TOKEN', data.refresh_token);
+                store.commit('SET_TENANT_ID', data.tenant_id);
+                store.commit('SET_USER_INFO', data);
+                store.commit('DEL_ALL_TAG');
+                store.commit('CLEAR_LOCK');
+                next('/wel');
+                return;
+              }
+            })
+            return;
+          } else {
+            // console.log("成功解码 不是对象");
+            next('/login');
+            next('/login');
+            return;
+          }
+        } catch {
+          // console.log('不是Json对象 跳回登入');
+          next('/login');
+          next('/login');
+          return;
+        }
+        // return;
+      }
       next('/login')
     }
   }

--
Gitblit v1.9.3