| | |
| | | * 全站权限配置 |
| | | * |
| | | */ |
| | | 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' |
| | | import {getToken} from '@/util/auth' |
| | | 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}); |
| | | NProgress.configure({ showSpinner: false }); |
| | | const lockPage = store.getters.website.lockPage; //锁屏页 |
| | | router.beforeEach((to, from, next) => { |
| | | const meta = to.meta || {}; |
| | |
| | | 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; |
| | |
| | | if (meta.isAuth === false) { |
| | | next() |
| | | } else { |
| | | next('/login') |
| | | // console.log(to, from); |
| | | next(); |
| | | if (to.path == '/wel') { |
| | | var a = to.query.securitySupervisionSystem; |
| | | if (typeof a == "string") { |
| | | console.log(to.query.securitySupervisionSystem, 'securitySupervisionSystem'); |
| | | // 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: 'http://192.168.109:80/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) { |
| | | Message({ |
| | | message: data.error_description, |
| | | type: 'error' |
| | | }) |
| | | } else { |
| | | 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'); |
| | | } |
| | | }) |
| | | return true; |
| | | } else { |
| | | // console.log("手动登入main不是JSON对象"); |
| | | return false; |
| | | } |
| | | |
| | | } else { |
| | | next('/login'); |
| | | } |
| | | |
| | | return; |
| | | } |
| | | next('/login'); |
| | | } |
| | | } |
| | | }) |