liuyg
2021-07-17 631691a4ca47df3be65af0c87f63c84f7be53466
src/permission.js
@@ -4,11 +4,14 @@
 */
import router from './router/router'
import store from './store'
import {validatenull} from '@/util/validate'
import {getToken} from '@/util/auth'
import md5 from 'js-md5'
import request from '@/router/axios';
import { validatenull } from '@/util/validate'
import { getToken } from '@/util/auth'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
NProgress.configure({showSpinner: false});
import cons from 'consolidate';
NProgress.configure({ showSpinner: false });
const lockPage = store.getters.website.lockPage; //锁屏页
router.beforeEach((to, from, next) => {
  const meta = to.meta || {};
@@ -16,14 +19,14 @@
  store.commit('SET_IS_MENU', isMenu === undefined);
  if (getToken()) {
    if (store.getters.isLock && to.path !== lockPage) { //如果系统激活锁屏,全部跳转到锁屏页
      next({path: lockPage})
      next({ path: lockPage })
    } else if (to.path === '/login') { //如果登录成功访问登录页跳转到主页
      next({path: '/'})
      next({ path: '/' })
    } else {
      //如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页
      if (store.getters.token.length === 0) {
        store.dispatch('FedLogOut').then(() => {
          next({path: '/login'})
          next({ path: '/login' })
        })
      } else {
        const value = to.query.src || to.fullPath;
@@ -57,7 +60,71 @@
    if (meta.isAuth === false) {
      next()
    } else {
      next('/login')
      console.log(to, from);
      next();
      if (to.path == '/wel') {
        var a = to.query.main;
        if (typeof a == "string") {
          console.log(to.query.main, 'main');
          console.log("有main");
          var obj = JSON.parse(a);
          console.log(obj, "obj");
          if (typeof obj == "object" && obj) {
            console.log("自动登入");
            var data = {
              tenantId: obj.data.dip,
              username: obj.data.rese,
              password: md5(obj.data.sap),
              grant_type: 'password',
              scope: 'all',
              type: 'account'
            };
            console.log(data, "自动ssss");
            // request({
            //   url: '/api/blade-auth/oauth/token',
            //   method: 'post',
            //   headers: {
            //     'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
            //     "Tenant-Id": "000000"
            //   },
            //   params: data
            // }).then(res => {
            //   console.log(res, 'res')
            // })
            // this.loginForm.username = obj.data.rese;
            // this.loginForm.password = obj.data.admin;
            // this.loginForm.tenantId = obj.data.dip;
            // console.log(this.loginForm1·);
            // const loading = this.$loading({
            //   lock: true,
            //   text: "登录中,请稍后。。。",
            //   spinner: "el-icon-loading",
            // });
            // this.$store
            //   .dispatch("LoginByUsername", data)
            //   .then(() => {
            //     this.$router.push({ path: "/wel" });
            //     loading.close();
            //   })
            //   .catch(() => {
            //     loading.close();
            //     this.refreshCode();
            //   });
            return true;
          } else {
            console.log("手动登入main不是JSON对象");
            return false;
          }
        } else {
          next('/login');
        }
        return;
      }
      next('/login');
    }
  }
})