zengh
2022-06-21 4fde32f8037fef94e41c65ab62a186477e3ccd16
免密登录
2 files modified
78 ■■■■■ changed files
src/permission.js 74 ●●●●● patch | view | raw | blame | history
vue.config.js 4 ●●●● patch | view | raw | blame | history
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')
    }
  }
vue.config.js
@@ -41,10 +41,10 @@
        // target: 'http://192.168.0.114:82/',
        // target: 'http://192.168.0.108:83/',//曾
        //target: 'http://localhost:82/',
        target: 'http://61.131.136.25:2082/api/',
        //target: 'http://61.131.136.25:2082/api/',
        // target: 'http://192.168.0.107:85/',//唐
        //target: 'http://localhost:83/',
        //target: 'http://61.131.136.25:2082/api/',
        target: 'http://61.131.136.25:2082/api/',
        //target: 'http://localhost:83/',
        //target: 'https://web.byisf.com/api/',
        //远程演示服务地址,可用于直接启动项目