安虹睿
1 year ago
21 changed files with 281 additions and 1100 deletions
@ -0,0 +1,21 @@ |
|||||
|
import Oidc from "oidc-client"; |
||||
|
|
||||
|
export const identityServerBase = localStorage.getItem('oidcLogin_url');//目标服务器登录地址
|
||||
|
export const vueBase = window.location.origin |
||||
|
|
||||
|
// 参考文档 https://github.com/IdentityModel/oidc-client-js/wiki
|
||||
|
export const mgr = new Oidc.UserManager({ |
||||
|
authority: `${identityServerBase}`, // 认证服务器
|
||||
|
client_id: localStorage.getItem('oidcLogin_clientId'), // 表示客户端的ID,必选项
|
||||
|
redirect_uri: `${vueBase}/callback`,// 表示重定向URI,认证服务器回调的客户端页面。可选项
|
||||
|
response_type: `code`, |
||||
|
scope: localStorage.getItem('oidcLogin_scopes'), // 表示申请的权限范围,可选项
|
||||
|
post_logout_redirect_uri: `${vueBase}/home?action=logout`, |
||||
|
automaticSilentRenew: false, |
||||
|
|
||||
|
// accessTokenExpiringNotificationTime: 10,
|
||||
|
// filterProtocolClaims: false,
|
||||
|
// loadUserInfo: true,
|
||||
|
// monitorSession: false,
|
||||
|
// includeIdTokenInSilentRenew : false,
|
||||
|
}); |
@ -1,140 +0,0 @@ |
|||||
// 第一版token路由
|
|
||||
import router from './router' |
|
||||
import store from './store' |
|
||||
import { Message } from 'element-ui' |
|
||||
import NProgress from 'nprogress' // progress bar
|
|
||||
import 'nprogress/nprogress.css' // progress bar style
|
|
||||
import { getToken } from '@/utils/auth' // get token from cookie
|
|
||||
import getPageTitle from '@/utils/get-page-title' |
|
||||
|
|
||||
NProgress.configure({ |
|
||||
showSpinner: false |
|
||||
}) // NProgress Configuration
|
|
||||
|
|
||||
const whiteList = ['/login', '/auth-redirect', '/testForm'] // no redirect whitelist
|
|
||||
|
|
||||
// 跳转登录页
|
|
||||
const pageToLogin = (to, from, next) => { |
|
||||
if (whiteList.indexOf(to.path) !== -1) { |
|
||||
// in the free login whitelist, go directly
|
|
||||
next() |
|
||||
NProgress.done() |
|
||||
} else { |
|
||||
// other pages that do not have permission to access are redirected to the login page.
|
|
||||
next(`/login?redirect=${to.path}`) |
|
||||
NProgress.done() |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 首次进入页面加载数据处理
|
|
||||
const toPageInit = async (to, from, next) => { |
|
||||
let isFresh = false |
|
||||
|
|
||||
// 获取表头转义
|
|
||||
if(!store.getters.columZHList){ |
|
||||
await store.dispatch('definition/getColumZHList') |
|
||||
} |
|
||||
|
|
||||
// 获取菜单数据
|
|
||||
if(!store.getters.permission_routes || store.getters.permission_routes.length <= 0){ |
|
||||
isFresh = true |
|
||||
await store.dispatch('permission/getApiColumnsNames') |
|
||||
} |
|
||||
|
|
||||
// 获取枚举数据
|
|
||||
if(!store.getters.enumList || store.getters.enumList.length <= 0){ |
|
||||
await store.dispatch('definition/getDefinitionConfig') |
|
||||
} |
|
||||
|
|
||||
// 获取用户信息
|
|
||||
let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("loginName") |
|
||||
if(!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0){ |
|
||||
await store.dispatch('user/getUserInfo',_username) |
|
||||
.then(()=>{ |
|
||||
toNextHandle(to, from, next,isFresh) |
|
||||
}) |
|
||||
.catch(()=>{ |
|
||||
toNextHandle(to, from, next,isFresh) |
|
||||
}) |
|
||||
}else{ |
|
||||
toNextHandle(to, from, next,isFresh) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 跳转处理
|
|
||||
const toNextHandle = (to, from, next,isFresh) => { |
|
||||
if(isFresh){ |
|
||||
next({...to,replace:true}) |
|
||||
}else{ |
|
||||
next() |
|
||||
} |
|
||||
NProgress.done() |
|
||||
} |
|
||||
|
|
||||
router.beforeEach(async (to, from, next) => { |
|
||||
|
|
||||
// start progress bar
|
|
||||
NProgress.start() |
|
||||
// set page title
|
|
||||
document.title = getPageTitle() |
|
||||
|
|
||||
const hasToken = getToken() |
|
||||
// 判断是否自动登录
|
|
||||
let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin')) |
|
||||
// 如果路径中有isAutoLogin参数则优先,否则读取配置文件中的isAutoLogin参数
|
|
||||
let _url_isAutoLogin = to.query.isAutoLogin |
|
||||
if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ |
|
||||
isAutoLogin = JSON.parse(_url_isAutoLogin) |
|
||||
} |
|
||||
|
|
||||
if(hasToken){ |
|
||||
if (to.path === '/login') { |
|
||||
console.log('有token,是登录页,将跳转至/') |
|
||||
// if is logged in, redirect to the home page
|
|
||||
next({ |
|
||||
path: '/' |
|
||||
}) |
|
||||
NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
|
||||
} else { |
|
||||
console.log('有token,不是登录页,toPageInit') |
|
||||
await toPageInit(to, from, next) |
|
||||
} |
|
||||
}else{ |
|
||||
if (to.path === '/login') { |
|
||||
console.log('没有token,是登录页,pageToLogin') |
|
||||
pageToLogin(to, from, next) |
|
||||
} else { |
|
||||
if(isAutoLogin){ |
|
||||
console.log('没有token,不是登录页,是自动登录,自动登录是否成功都将继续toPageInit') |
|
||||
let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("loginName") |
|
||||
let _password = to.query.loginPass || localStorage.getItem("client_secret") |
|
||||
// todo-fast:password确定
|
|
||||
await store.dispatch('user/login', {password:_password,username:_username}) |
|
||||
.then(()=>{ |
|
||||
toPageInit(to, from, next) |
|
||||
}) |
|
||||
.catch(()=>{ |
|
||||
toPageInit(to, from, next) |
|
||||
}) |
|
||||
}else{ |
|
||||
console.log('没有token,不是登录页,不是自动登录,pageToLogin') |
|
||||
pageToLogin(to, from, next) |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
}) |
|
||||
|
|
||||
router.afterEach(() => { |
|
||||
// element-ui 使用 Tooltip 提示时候,更换页面,提示依旧存在偶现bug处理。
|
|
||||
const mytooltipList = document.querySelectorAll('.el-tooltip__popper') // 获取页面所有tooltip的dom集合
|
|
||||
setTimeout(() => { |
|
||||
mytooltipList.forEach((value) => { |
|
||||
value.style.display = 'none' |
|
||||
if(value.parentElement){ |
|
||||
value.parentElement.removeChild(value) |
|
||||
} |
|
||||
}) |
|
||||
}, 1000) |
|
||||
// finish progress bar
|
|
||||
NProgress.done() |
|
||||
}) |
|
@ -1,146 +0,0 @@ |
|||||
// 加token之前版本
|
|
||||
import router from './router' |
|
||||
import store from './store' |
|
||||
import { Message } from 'element-ui' |
|
||||
import NProgress from 'nprogress' // progress bar
|
|
||||
import 'nprogress/nprogress.css' // progress bar style
|
|
||||
import { getToken } from '@/utils/auth' // get token from cookie
|
|
||||
import getPageTitle from '@/utils/get-page-title' |
|
||||
import { asyncRoutes } from '@/router' |
|
||||
|
|
||||
NProgress.configure({ |
|
||||
showSpinner: false |
|
||||
}) // NProgress Configuration
|
|
||||
|
|
||||
router.beforeEach(async (to, from, next) => { |
|
||||
// start progress bar
|
|
||||
NProgress.start() |
|
||||
// set page title
|
|
||||
document.title = getPageTitle() |
|
||||
|
|
||||
const hasToken = getToken() |
|
||||
console.log(21,'hasToken',hasToken,!hasToken) |
|
||||
|
|
||||
// 获取表头转义
|
|
||||
if(!store.getters.columZHList || store.getters.columZHList.length <= 0){ |
|
||||
await store.dispatch('definition/getColumZHList',()=>{ |
|
||||
NProgress.done() |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
// 获取菜单数据
|
|
||||
if(!store.getters.permission_routes || store.getters.permission_routes.length <= 0){ |
|
||||
const accessRoutes = await store.dispatch('permission/getApiColumnsNames') |
|
||||
router.addRoutes(accessRoutes) |
|
||||
console.log(35,router) |
|
||||
} |
|
||||
|
|
||||
// 获取枚举数据
|
|
||||
if(!store.getters.enumList || store.getters.enumList.length <= 0){ |
|
||||
await store.dispatch('definition/getDefinitionConfig') |
|
||||
} |
|
||||
|
|
||||
// 是否已尝试过自动登录
|
|
||||
const alreadyTryLogin = localStorage.getItem('alreadyTryLogin') |
|
||||
// 是否有用户信息:
|
|
||||
const userInfo = store.getters.currentUserInfo |
|
||||
// 判断是否自动登录
|
|
||||
let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin')) |
|
||||
// 如果路径中有isAutoLogin参数则优先,否则读取配置文件中的isAutoLogin参数
|
|
||||
let _url_isAutoLogin = to.query.isAutoLogin |
|
||||
if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ |
|
||||
isAutoLogin = JSON.parse(_url_isAutoLogin) |
|
||||
} |
|
||||
if(to.path == '/login'){ |
|
||||
console.log('-------当前路由为登录页-------') |
|
||||
next() |
|
||||
}else{ |
|
||||
console.log('-------当前路由不是登录页-------') |
|
||||
if((userInfo && userInfo.id) || alreadyTryLogin == 'true'){ |
|
||||
if(userInfo && userInfo.id){ |
|
||||
console.log('-------当前有用户信息-------',userInfo) |
|
||||
}else{ |
|
||||
console.log('-------当前没有用户信息,但是已尝试过登录-------') |
|
||||
} |
|
||||
next() |
|
||||
}else{ |
|
||||
console.log('-------当前没有用户信息-------') |
|
||||
if(isAutoLogin || to.query.loginName){ |
|
||||
let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("loginName") |
|
||||
console.log('-------要求自动登录-------',isAutoLogin,to.query.loginName,_username) |
|
||||
// let loginForm= {
|
|
||||
// userNameOrEmailAddress:localStorage.getItem("loginName"),
|
|
||||
// password:localStorage.getItem("client_secret"),
|
|
||||
// // rememberMe:true,
|
|
||||
// // grant_type: 'password',
|
|
||||
// // client_id: 'Auth_App',
|
|
||||
// }
|
|
||||
// // store.dispatch('user/login', loginForm).then(() => {
|
|
||||
// login(loginForm).then(()=>{
|
|
||||
await store.dispatch('user/getUserInfo',_username).then(()=>{ |
|
||||
console.log("-------用户信息获取成功-------") |
|
||||
localStorage.setItem('alreadyTryLogin',true) |
|
||||
next(to) |
|
||||
NProgress.done() |
|
||||
// next({
|
|
||||
// ...to,
|
|
||||
// query:{
|
|
||||
// loginName:to.query.loginName,
|
|
||||
// isAutoLogin:to.query.isAutoLogin,
|
|
||||
// isSinglePage:to.query.isSinglePage
|
|
||||
// },
|
|
||||
// replace: true
|
|
||||
// })
|
|
||||
}).catch(()=>{ |
|
||||
localStorage.setItem('alreadyTryLogin',true) |
|
||||
next() |
|
||||
// next({
|
|
||||
// path:'/login',
|
|
||||
// query:{
|
|
||||
// isAutoLogin:to.query.isAutoLogin,
|
|
||||
// isSinglePage:to.query.isSinglePage
|
|
||||
// },
|
|
||||
// replace: true
|
|
||||
// })
|
|
||||
// next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`)
|
|
||||
// next(`/login`)
|
|
||||
localStorage.setItem("isLoginName",_username) |
|
||||
// Message.error('获取用户信息失败,请重试!')
|
|
||||
}) |
|
||||
// })
|
|
||||
// .catch((error) => {
|
|
||||
// console.log('登录失败')
|
|
||||
// })
|
|
||||
}else{ |
|
||||
console.log('-------不需要自动登录-------',isAutoLogin,to.query.loginName) |
|
||||
next({ |
|
||||
path:'/login', |
|
||||
query:{ |
|
||||
loginName:to.query.loginName, |
|
||||
isAutoLogin:to.query.isAutoLogin, |
|
||||
isSinglePage:to.query.isSinglePage |
|
||||
}, |
|
||||
replace: true |
|
||||
}) |
|
||||
NProgress.done() |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
localStorage.setItem('alreadyTryLogin',false) |
|
||||
}) |
|
||||
|
|
||||
router.afterEach(() => { |
|
||||
// element-ui 使用 Tooltip 提示时候,更换页面,提示依旧存在偶现bug处理。
|
|
||||
const mytooltipList = document.querySelectorAll('.el-tooltip__popper') // 获取页面所有tooltip的dom集合
|
|
||||
setTimeout(() => { |
|
||||
mytooltipList.forEach((value) => { |
|
||||
value.style.display = 'none' |
|
||||
if(value.parentElement){ |
|
||||
value.parentElement.removeChild(value) |
|
||||
} |
|
||||
}) |
|
||||
}, 1000) |
|
||||
// finish progress bar
|
|
||||
NProgress.done() |
|
||||
}) |
|
@ -1,319 +0,0 @@ |
|||||
import { |
|
||||
asyncRoutes, |
|
||||
constantRoutes |
|
||||
} from '@/router' |
|
||||
import Layout from '@/layout' |
|
||||
import { getDefinitionMenu } from '@/api/wms-auth' |
|
||||
import store from '@/store' |
|
||||
import router from '@/router' |
|
||||
|
|
||||
/** |
|
||||
* Use meta.role to determine if the current user has permission |
|
||||
* @param roles |
|
||||
* @param route |
|
||||
*/ |
|
||||
function hasPermission(roles, route) { |
|
||||
if (route.meta && route.meta.roles) { |
|
||||
if (route.meta.roles == "skip") { |
|
||||
return true |
|
||||
} else { |
|
||||
return roles.some(role => route.meta.roles.includes(role)) |
|
||||
} |
|
||||
} else { |
|
||||
return false |
|
||||
} |
|
||||
} |
|
||||
const filterAccessedRoutes = (items,indexVal,childrenIndex) => { |
|
||||
const route = JSON.parse(JSON.stringify(items)) |
|
||||
route.forEach((val, index) => { |
|
||||
// debugger;
|
|
||||
if(val.meta && val.meta.roles == "skip"){ |
|
||||
if (val.children && val.children.length != 0) { |
|
||||
filterAccessedRoutes(items[index-indexVal].children,childrenIndex) |
|
||||
} |
|
||||
if(items[index-indexVal].children && items[index-indexVal].children.length == 0){ |
|
||||
items.splice(index-indexVal, 1) |
|
||||
indexVal++ |
|
||||
} |
|
||||
} |
|
||||
}) |
|
||||
indexVal = 0 |
|
||||
} |
|
||||
/** |
|
||||
* Filter asynchronous routing tables by recursion |
|
||||
* @param routes asyncRoutes |
|
||||
* @param roles |
|
||||
*/ |
|
||||
export function filterAsyncRoutes(routes, roles) { |
|
||||
const res = [] |
|
||||
routes.forEach(route => { |
|
||||
const tmp = { |
|
||||
...route |
|
||||
} |
|
||||
if (hasPermission(roles, tmp)) { |
|
||||
if (tmp.children) { |
|
||||
tmp.children = filterAsyncRoutes(tmp.children, roles) |
|
||||
} |
|
||||
res.push(tmp) |
|
||||
} |
|
||||
}) |
|
||||
return res |
|
||||
} |
|
||||
|
|
||||
const state = { |
|
||||
routes: [],//菜单
|
|
||||
// addRoutes: [],
|
|
||||
tablesName:null,//所有的表名
|
|
||||
abpIdentityName:null,//所有身份配置权限
|
|
||||
} |
|
||||
|
|
||||
const mutations = { |
|
||||
SET_ROUTES: (state, routes) => { |
|
||||
// state.addRoutes = routes
|
|
||||
state.routes = constantRoutes.concat(routes) |
|
||||
router.addRoutes(routes) |
|
||||
}, |
|
||||
SET_TABLESNAME: (state, data) => { |
|
||||
state.tablesName = data |
|
||||
}, |
|
||||
SET_AbpIdentity: (state, data) => { |
|
||||
state.abpIdentityName = data |
|
||||
} |
|
||||
} |
|
||||
/** |
|
||||
* 静态路由懒加载 |
|
||||
* @param view 格式必须为 xxx/xxx 开头不要加斜杠 |
|
||||
* @returns |
|
||||
*/ |
|
||||
export const loadView = (view) => { |
|
||||
return (resolve) => require([`@/views/menuList/${view}`], resolve) |
|
||||
} |
|
||||
|
|
||||
const AbpIdentity_mark = 'AbpIdentityMark' |
|
||||
/** |
|
||||
* 把从后端查询的菜单数据拼装成路由格式的数据 |
|
||||
* @param routes |
|
||||
* @param data 后端返回的菜单数据 |
|
||||
*/ |
|
||||
export function generaMenu(routes, data, first) { |
|
||||
// 不显示的菜单配置隐藏
|
|
||||
let _noShowMenus = localStorage.getItem('menuHiddenConfig').split(',') |
|
||||
data.forEach(item => { |
|
||||
let _item = { |
|
||||
path: '/'+item.name, |
|
||||
component: loadView(item.name), |
|
||||
hidden: _noShowMenus.indexOf(item.name) >= 0, // 状态为0的隐藏
|
|
||||
name: item.name, |
|
||||
// meta: item.meta
|
|
||||
meta: { |
|
||||
title: item.title, |
|
||||
icon: item.icon || 'svg_default', |
|
||||
roles: item.permission, |
|
||||
outerFirst:first |
|
||||
}, |
|
||||
} |
|
||||
let menu = _item |
|
||||
if(first && item.component == '@/layout'){ |
|
||||
menu = { |
|
||||
path: '/', |
|
||||
component: Layout, |
|
||||
redirect: '/' + item.name, |
|
||||
children: [], |
|
||||
} |
|
||||
menu.children = [] |
|
||||
menu.children.push(_item) |
|
||||
} |
|
||||
// 一级菜单 二级菜单 特定属性
|
|
||||
// if (item.component == '@/layout' || item.component == 'index') {
|
|
||||
// menu.alwaysShow = true
|
|
||||
// menu.redirect = 'noRedirect'
|
|
||||
// }
|
|
||||
// if (item.sort < 99) {
|
|
||||
// menu.level = 1
|
|
||||
// } else if (item.sort > 99 && item.sort < 9999) {
|
|
||||
// menu.level = 2
|
|
||||
// } else {
|
|
||||
// menu.level = 3
|
|
||||
// }
|
|
||||
// iframe页面处理
|
|
||||
// if (item.permission.indexOf('Report') > -1) {
|
|
||||
// // delete menu.component
|
|
||||
// menu.iframeComponent = item.component === '@/layout' ? Layout : loadView(item.component)
|
|
||||
// menu.hasOpen = false // 是否打开过,默认false
|
|
||||
// }
|
|
||||
if (item.children && item.children.length > 0) { |
|
||||
generaMenu(menu.children, item.children) |
|
||||
} |
|
||||
// if (item.permission == 'skip' && item.children.length == 0) {
|
|
||||
// }
|
|
||||
if(!routes)routes = [] |
|
||||
routes.push(menu) |
|
||||
}) |
|
||||
return routes |
|
||||
} |
|
||||
|
|
||||
// todo:接口返回的层级菜单,与查重后最终显示的菜单数组做查重及组合处理
|
|
||||
export function initTreeMenusHandle(tree, list,first) { |
|
||||
let _res = [] |
|
||||
tree.forEach(item=>{ |
|
||||
// 如果有身份权限的页面
|
|
||||
// if(state.abpIdentityName && state.abpIdentityName.length > 0){
|
|
||||
// // // 身份权限的页面(角色等)
|
|
||||
// if(item.name == '系统权限管理'){
|
|
||||
// let _name = item.name.slice(AbpIdentity_mark.length,item.name.length)
|
|
||||
// console.log(165,item.name,_name)
|
|
||||
// // item.title = store.getters.columZHList[_name] || _name
|
|
||||
// // if(first)item.component = '@/layout'
|
|
||||
// // if (item.children && item.children.length > 0) {
|
|
||||
// // item.children = initTreeMenusHandle(item.children,list)
|
|
||||
// // }
|
|
||||
// // _res.push(item)
|
|
||||
// }
|
|
||||
// }
|
|
||||
//配置权限的页面
|
|
||||
// else{
|
|
||||
if(list.indexOf(item.name) >= 0){ |
|
||||
item.title = store.getters.columZHList[item.name] || item.name |
|
||||
console.log(175,item.name,first) |
|
||||
if(first){ |
|
||||
// if(item.name == AbpIdentity_mark){
|
|
||||
// item.title = '系统权限管理'
|
|
||||
// }
|
|
||||
item.component = '@/layout' |
|
||||
} |
|
||||
if (item.children && item.children.length > 0) { |
|
||||
item.children = initTreeMenusHandle(item.children,list) |
|
||||
} |
|
||||
console.log(186,item) |
|
||||
_res.push(item) |
|
||||
} |
|
||||
// }
|
|
||||
}) |
|
||||
console.log(191,_res) |
|
||||
return _res |
|
||||
} |
|
||||
const actions = { |
|
||||
getApiColumnsNames({ |
|
||||
commit |
|
||||
}, userId) { |
|
||||
return new Promise(resolve => { |
|
||||
let accessedRoutes = asyncRoutes |
|
||||
// accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
|
|
||||
// let indexVal = 0
|
|
||||
// let childrenIndex = 0
|
|
||||
// filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex)
|
|
||||
// commit('SET_ROUTES', accessedRoutes)
|
|
||||
// resolve(accessedRoutes)
|
|
||||
getDefinitionMenu(true).then(res => { |
|
||||
let _allConfig = res.auth.grantedPolicies;//所有配置
|
|
||||
let _menuList = []//接口获取所有的菜单
|
|
||||
let _AbpIdentity = []//接口获取所有的身份配置信息数据
|
|
||||
for(let item in _allConfig){ |
|
||||
let point_number = item.split('.').length - 1 |
|
||||
// 只选择配置项中的数据
|
|
||||
if(point_number == 1 && item.substring(0,item.indexOf('.')) == localStorage.getItem('appClientScope')){ |
|
||||
_menuList.push(item.substring(item.indexOf('.') + 1,item.length)) |
|
||||
} |
|
||||
// 身份配置信息数据(用户、角色)
|
|
||||
if(point_number == 1 && item.substring(0,item.indexOf('.')) == 'AbpIdentity'){ |
|
||||
_AbpIdentity.push(AbpIdentity_mark + item.substring(item.indexOf('.') + 1,item.length)) |
|
||||
} |
|
||||
} |
|
||||
// 存储所有的表名
|
|
||||
commit('SET_TABLESNAME', _menuList) |
|
||||
// 存储身份标识
|
|
||||
commit('SET_AbpIdentity', _AbpIdentity) |
|
||||
|
|
||||
// 数据模拟,todo-new:接口获取
|
|
||||
let _treeMenusAll = null//树形菜单
|
|
||||
_treeMenusAll = [ |
|
||||
{name:"aaaaaaa"}, |
|
||||
{name:"ExportCustomUserSetting" |
|
||||
// ,children:[
|
|
||||
// {name:'OutgoingDataHistory',children:[
|
|
||||
// {name:'IncomingData',children:[
|
|
||||
// {name:'OutgoingDataHistory'},
|
|
||||
// {name:'IncomingData'},
|
|
||||
// {name:'333333'},
|
|
||||
// ]},
|
|
||||
// {name:'eee1111-bbb',children:[
|
|
||||
// {name:'ExportCustomUserSetting'},
|
|
||||
// {name:'MessageReceive'},
|
|
||||
// ]},
|
|
||||
// ]},
|
|
||||
// {name:'eee222'},
|
|
||||
// {name:'eee333'},
|
|
||||
// {name:'eee444'},
|
|
||||
// {name:'eee555'},
|
|
||||
// ]
|
|
||||
}, |
|
||||
{name:"OutgoingDataHistory"}, |
|
||||
{name:"IncomingData"}, |
|
||||
{name:"IncomingDataHistory"}, |
|
||||
{name:"MesProductL7PartsNote"}, |
|
||||
{name:"MessageReceive"}, |
|
||||
{name:"OutgoingData"}, |
|
||||
{name:"AsnDet"}, |
|
||||
{name:"AsnMstr"}, |
|
||||
{name:"Bom"}, |
|
||||
{name:"CustPart"}, |
|
||||
{name:"Cust"}, |
|
||||
{name:"Inventory"}, |
|
||||
{name:"Loc"}, |
|
||||
{name:"Part"}, |
|
||||
{name:"PoDet"}, |
|
||||
{name:"PoMstr"}, |
|
||||
{name:"PrhHist"}, |
|
||||
{name:"ProdLine"}, |
|
||||
{name:"ReceiptDet"}, |
|
||||
{name:"ReceiptMstr"}, |
|
||||
{name:"ReturnDet"}, |
|
||||
{name:"ReturnMstr"}, |
|
||||
{name:"SodDet"}, |
|
||||
{name:"VendPart"}, |
|
||||
{name:"Vend"}, |
|
||||
] |
|
||||
|
|
||||
// 包含配置项中的业务菜单+身份权限菜单(角色用户等)
|
|
||||
// let _menuAndAbpList = [..._menuList,...[AbpIdentity_mark],..._AbpIdentity]
|
|
||||
let _menuAndAbpList = [..._menuList,..._AbpIdentity] |
|
||||
|
|
||||
let _initTreeMenus = [] |
|
||||
if(_treeMenusAll && _treeMenusAll.length > 0){ |
|
||||
_initTreeMenus = initTreeMenusHandle(_treeMenusAll,_menuAndAbpList,true) |
|
||||
}else{ |
|
||||
let _data = [] |
|
||||
if(_AbpIdentity && _AbpIdentity.length > 0){ |
|
||||
_data.push({name:AbpIdentity_mark,children:[]}) |
|
||||
} |
|
||||
for(let i in _menuAndAbpList){ |
|
||||
if(_menuAndAbpList[i].indexOf(AbpIdentity_mark) >= 0){ |
|
||||
_data[0].children.push({ name:_menuAndAbpList[i] }) |
|
||||
} |
|
||||
else{ |
|
||||
_data.push({name:_menuAndAbpList[i]}) |
|
||||
} |
|
||||
} |
|
||||
_initTreeMenus = initTreeMenusHandle(_data,[..._menuAndAbpList,...[AbpIdentity_mark]],true) |
|
||||
} |
|
||||
// 最后查重+层级查重后的菜单
|
|
||||
let _initEndMenus = generaMenu(asyncRoutes, _initTreeMenus,true) |
|
||||
let accessedRoutes = _initEndMenus |
|
||||
// let indexVal = 0
|
|
||||
// let childrenIndex = 0
|
|
||||
// filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex)
|
|
||||
commit('SET_ROUTES', accessedRoutes) |
|
||||
resolve(accessedRoutes) |
|
||||
}).catch(err => { |
|
||||
console.log(err) |
|
||||
}) |
|
||||
}) |
|
||||
}, |
|
||||
} |
|
||||
|
|
||||
export default { |
|
||||
namespaced: true, |
|
||||
state, |
|
||||
mutations, |
|
||||
actions |
|
||||
} |
|
@ -1,267 +0,0 @@ |
|||||
import { |
|
||||
asyncRoutes, |
|
||||
constantRoutes |
|
||||
} from '@/router' |
|
||||
import Layout from '@/layout' |
|
||||
import { getDefinitionMenu } from '@/api/wms-auth' |
|
||||
import store from '@/store' |
|
||||
import router from '@/router' |
|
||||
|
|
||||
/** |
|
||||
* Use meta.role to determine if the current user has permission |
|
||||
* @param roles |
|
||||
* @param route |
|
||||
*/ |
|
||||
function hasPermission(roles, route) { |
|
||||
if (route.meta && route.meta.roles) { |
|
||||
if (route.meta.roles == "skip") { |
|
||||
return true |
|
||||
} else { |
|
||||
return roles.some(role => route.meta.roles.includes(role)) |
|
||||
} |
|
||||
} else { |
|
||||
return false |
|
||||
} |
|
||||
} |
|
||||
const filterAccessedRoutes = (items,indexVal,childrenIndex) => { |
|
||||
const route = JSON.parse(JSON.stringify(items)) |
|
||||
route.forEach((val, index) => { |
|
||||
// debugger;
|
|
||||
if(val.meta && val.meta.roles == "skip"){ |
|
||||
if (val.children && val.children.length != 0) { |
|
||||
filterAccessedRoutes(items[index-indexVal].children,childrenIndex) |
|
||||
} |
|
||||
if(items[index-indexVal].children && items[index-indexVal].children.length == 0){ |
|
||||
items.splice(index-indexVal, 1) |
|
||||
indexVal++ |
|
||||
} |
|
||||
} |
|
||||
}) |
|
||||
indexVal = 0 |
|
||||
} |
|
||||
/** |
|
||||
* Filter asynchronous routing tables by recursion |
|
||||
* @param routes asyncRoutes |
|
||||
* @param roles |
|
||||
*/ |
|
||||
export function filterAsyncRoutes(routes, roles) { |
|
||||
const res = [] |
|
||||
routes.forEach(route => { |
|
||||
const tmp = { |
|
||||
...route |
|
||||
} |
|
||||
if (hasPermission(roles, tmp)) { |
|
||||
if (tmp.children) { |
|
||||
tmp.children = filterAsyncRoutes(tmp.children, roles) |
|
||||
} |
|
||||
res.push(tmp) |
|
||||
} |
|
||||
}) |
|
||||
return res |
|
||||
} |
|
||||
|
|
||||
const state = { |
|
||||
routes: [],//菜单
|
|
||||
addRoutes: [], |
|
||||
tablesName:null,//所有的表名
|
|
||||
} |
|
||||
|
|
||||
const mutations = { |
|
||||
SET_ROUTES: (state, routes) => { |
|
||||
state.addRoutes = routes |
|
||||
state.routes = constantRoutes.concat(routes) |
|
||||
router.addRoutes(routes) |
|
||||
}, |
|
||||
SET_TABLESNAME: (state, data) => { |
|
||||
state.tablesName = data |
|
||||
} |
|
||||
} |
|
||||
/** |
|
||||
* 静态路由懒加载 |
|
||||
* @param view 格式必须为 xxx/xxx 开头不要加斜杠 |
|
||||
* @returns |
|
||||
*/ |
|
||||
export const loadView = (view) => { |
|
||||
return (resolve) => require([`@/views/menuList/${view}`], resolve) |
|
||||
} |
|
||||
/** |
|
||||
* 把从后端查询的菜单数据拼装成路由格式的数据 |
|
||||
* @param routes |
|
||||
* @param data 后端返回的菜单数据 |
|
||||
*/ |
|
||||
export function generaMenu(routes, data, first) { |
|
||||
// 不显示的菜单配置隐藏
|
|
||||
let _noShowMenus = localStorage.getItem('menuHiddenConfig').split(',') |
|
||||
data.forEach(item => { |
|
||||
let _item = { |
|
||||
path: '/'+item.name, |
|
||||
component: loadView(item.name), |
|
||||
hidden: _noShowMenus.indexOf(item.name) >= 0, // 状态为0的隐藏
|
|
||||
name: item.name, |
|
||||
// meta: item.meta
|
|
||||
meta: { |
|
||||
title: item.title, |
|
||||
icon: item.icon || 'svg_default', |
|
||||
roles: item.permission, |
|
||||
outerFirst:first |
|
||||
}, |
|
||||
} |
|
||||
let menu = _item |
|
||||
if(first && item.component == '@/layout'){ |
|
||||
menu = { |
|
||||
path: '/', |
|
||||
component: Layout, |
|
||||
redirect: '/' + item.name, |
|
||||
children: [], |
|
||||
} |
|
||||
menu.children = [] |
|
||||
menu.children.push(_item) |
|
||||
} |
|
||||
// 一级菜单 二级菜单 特定属性
|
|
||||
// if (item.component == '@/layout' || item.component == 'index') {
|
|
||||
// menu.alwaysShow = true
|
|
||||
// menu.redirect = 'noRedirect'
|
|
||||
// }
|
|
||||
// if (item.sort < 99) {
|
|
||||
// menu.level = 1
|
|
||||
// } else if (item.sort > 99 && item.sort < 9999) {
|
|
||||
// menu.level = 2
|
|
||||
// } else {
|
|
||||
// menu.level = 3
|
|
||||
// }
|
|
||||
// iframe页面处理
|
|
||||
// if (item.permission.indexOf('Report') > -1) {
|
|
||||
// // delete menu.component
|
|
||||
// menu.iframeComponent = item.component === '@/layout' ? Layout : loadView(item.component)
|
|
||||
// menu.hasOpen = false // 是否打开过,默认false
|
|
||||
// }
|
|
||||
if (item.children && item.children.length > 0) { |
|
||||
generaMenu(menu.children, item.children) |
|
||||
} |
|
||||
// if (item.permission == 'skip' && item.children.length == 0) {
|
|
||||
// }
|
|
||||
routes.push(menu) |
|
||||
}) |
|
||||
return routes |
|
||||
} |
|
||||
|
|
||||
// todo:接口返回的层级菜单,与查重后最终显示的菜单数组做查重及组合处理
|
|
||||
export function initTreeMenusHandle(tree, list,first) { |
|
||||
let _res = [] |
|
||||
tree.forEach(item=>{ |
|
||||
if(list.indexOf(item.name) >= 0){ |
|
||||
item.title = store.getters.columZHList[item.name] || item.name |
|
||||
if(first)item.component = '@/layout' |
|
||||
if (item.children && item.children.length > 0) { |
|
||||
item.children = initTreeMenusHandle(item.children,list) |
|
||||
} |
|
||||
_res.push(item) |
|
||||
} |
|
||||
}) |
|
||||
return _res |
|
||||
} |
|
||||
const actions = { |
|
||||
getApiColumnsNames({ |
|
||||
commit |
|
||||
}, userId) { |
|
||||
return new Promise(resolve => { |
|
||||
let accessedRoutes = asyncRoutes |
|
||||
// accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
|
|
||||
// let indexVal = 0
|
|
||||
// let childrenIndex = 0
|
|
||||
// filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex)
|
|
||||
// commit('SET_ROUTES', accessedRoutes)
|
|
||||
// resolve(accessedRoutes)
|
|
||||
getDefinitionMenu(true).then(res => { |
|
||||
let _allConfig = res.auth.grantedPolicies;//所有配置
|
|
||||
let _menuList = []//接口获取所有的菜单
|
|
||||
for(let item in _allConfig){ |
|
||||
let point_number = item.split('.').length - 1 |
|
||||
// 只选择配置项中的数据
|
|
||||
if(point_number == 1 && item.substring(0,item.indexOf('.')) == localStorage.getItem('appClientScope')){ |
|
||||
_menuList.push(item.substring(item.indexOf('.') + 1,item.length)) |
|
||||
} |
|
||||
} |
|
||||
// 存储所有的表名
|
|
||||
commit('SET_TABLESNAME', _menuList) |
|
||||
// 数据模拟,todo-new:接口获取
|
|
||||
let _treeMenusAll = null//树形菜单
|
|
||||
// _treeMenusAll = [
|
|
||||
// {name:"aaaaaaa"},
|
|
||||
// {name:"ExportCustomUserSetting"
|
|
||||
// // ,children:[
|
|
||||
// // {name:'OutgoingDataHistory',children:[
|
|
||||
// // {name:'IncomingData',children:[
|
|
||||
// // {name:'OutgoingDataHistory'},
|
|
||||
// // {name:'IncomingData'},
|
|
||||
// // {name:'333333'},
|
|
||||
// // ]},
|
|
||||
// // {name:'eee1111-bbb',children:[
|
|
||||
// // {name:'ExportCustomUserSetting'},
|
|
||||
// // {name:'MessageReceive'},
|
|
||||
// // ]},
|
|
||||
// // ]},
|
|
||||
// // {name:'eee222'},
|
|
||||
// // {name:'eee333'},
|
|
||||
// // {name:'eee444'},
|
|
||||
// // {name:'eee555'},
|
|
||||
// // ]
|
|
||||
// },
|
|
||||
// {name:"OutgoingDataHistory"},
|
|
||||
// {name:"IncomingData"},
|
|
||||
// {name:"IncomingDataHistory"},
|
|
||||
// {name:"MesProductL7PartsNote"},
|
|
||||
// {name:"MessageReceive"},
|
|
||||
// {name:"OutgoingData"},
|
|
||||
// {name:"AsnDet"},
|
|
||||
// {name:"AsnMstr"},
|
|
||||
// {name:"Bom"},
|
|
||||
// {name:"CustPart"},
|
|
||||
// {name:"Cust"},
|
|
||||
// {name:"Inventory"},
|
|
||||
// {name:"Loc"},
|
|
||||
// {name:"Part"},
|
|
||||
// {name:"PoDet"},
|
|
||||
// {name:"PoMstr"},
|
|
||||
// {name:"PrhHist"},
|
|
||||
// {name:"ProdLine"},
|
|
||||
// {name:"ReceiptDet"},
|
|
||||
// {name:"ReceiptMstr"},
|
|
||||
// {name:"ReturnDet"},
|
|
||||
// {name:"ReturnMstr"},
|
|
||||
// {name:"SodDet"},
|
|
||||
// {name:"VendPart"},
|
|
||||
// {name:"Vend"},
|
|
||||
// ]
|
|
||||
|
|
||||
let _initTreeMenus = [] |
|
||||
if(_treeMenusAll && _treeMenusAll.length > 0){ |
|
||||
_initTreeMenus = initTreeMenusHandle(_treeMenusAll,_menuList,true) |
|
||||
}else{ |
|
||||
let _data = [] |
|
||||
for(let i in _menuList){ |
|
||||
_data.push({name:_menuList[i]}) |
|
||||
} |
|
||||
_initTreeMenus = initTreeMenusHandle(_data,_menuList,true) |
|
||||
} |
|
||||
// 最后查重+层级查重后的菜单
|
|
||||
let _initEndMenus = generaMenu(asyncRoutes, _initTreeMenus,true) |
|
||||
let accessedRoutes = _initEndMenus |
|
||||
// let indexVal = 0
|
|
||||
// let childrenIndex = 0
|
|
||||
// filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex)
|
|
||||
commit('SET_ROUTES', accessedRoutes) |
|
||||
resolve(accessedRoutes) |
|
||||
}).catch(err => { |
|
||||
console.log(err) |
|
||||
}) |
|
||||
}) |
|
||||
}, |
|
||||
} |
|
||||
|
|
||||
export default { |
|
||||
namespaced: true, |
|
||||
state, |
|
||||
mutations, |
|
||||
actions |
|
||||
} |
|
@ -1,168 +0,0 @@ |
|||||
import { |
|
||||
token, |
|
||||
logout, |
|
||||
getUsersByUserName |
|
||||
} from '@/api/wms-auth' |
|
||||
import { |
|
||||
getToken, |
|
||||
setToken, |
|
||||
removeToken, |
|
||||
} from '@/utils/auth' |
|
||||
import router, { |
|
||||
resetRouter |
|
||||
} from '@/router' |
|
||||
import qs from 'qs' |
|
||||
import store from '@/store' |
|
||||
|
|
||||
const state = { |
|
||||
token: getToken(), |
|
||||
introduction: '', |
|
||||
roles: [], |
|
||||
userInfo:null |
|
||||
} |
|
||||
|
|
||||
const mutations = { |
|
||||
SET_TOKEN: (state, token) => { |
|
||||
state.token = token |
|
||||
}, |
|
||||
SET_INTRODUCTION: (state, introduction) => { |
|
||||
state.introduction = introduction |
|
||||
}, |
|
||||
// 设置权限(v-permission)
|
|
||||
SET_ROLES: (state, roles) => { |
|
||||
let _roles = [ |
|
||||
'IncomingDataHistory.filter', |
|
||||
'IncomingData.export', |
|
||||
'MesProductL7PartsNote.filter', |
|
||||
'MesProductL7PartsNote.export' |
|
||||
] |
|
||||
state.roles = _roles |
|
||||
}, |
|
||||
SET_USERINFO: (state, data) => { |
|
||||
state.userInfo = data |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
const actions = { |
|
||||
// user login
|
|
||||
login({ |
|
||||
commit, |
|
||||
dispatch |
|
||||
}, userInfo) { |
|
||||
const { |
|
||||
password, |
|
||||
username, |
|
||||
company, |
|
||||
warehouseCode |
|
||||
} = userInfo |
|
||||
let loginData = { |
|
||||
userNameOrEmailAddress: username, |
|
||||
password: password, |
|
||||
rememberMe: true |
|
||||
} |
|
||||
let parseData = JSON.parse(JSON.stringify(userInfo)) |
|
||||
delete parseData.warehouseCode |
|
||||
delete parseData.company |
|
||||
parseData.client_secret = window.SITE_CONFIG['client_secret'] |
|
||||
let tokenData = qs.stringify(parseData) |
|
||||
return new Promise((resolve, reject) => { |
|
||||
// login(loginData).then(response => {
|
|
||||
let params = qs.stringify({ |
|
||||
password: password, |
|
||||
username: username, |
|
||||
client_id:'Z_App', |
|
||||
grant_type:'password', |
|
||||
scopes:'Z' |
|
||||
}); |
|
||||
token(params).then(response => { |
|
||||
const { |
|
||||
access_token, |
|
||||
token_type |
|
||||
} = response |
|
||||
if (access_token == null) { |
|
||||
reject() |
|
||||
} else { |
|
||||
commit('SET_TOKEN', access_token) |
|
||||
setToken(token_type + ' ' + access_token) |
|
||||
store.dispatch('user/getUserInfo',username).then(()=>{ |
|
||||
resolve() |
|
||||
}).catch(()=>{ |
|
||||
reject() |
|
||||
}) |
|
||||
} |
|
||||
}).catch(error => { |
|
||||
reject(error) |
|
||||
}) |
|
||||
// }).catch(error => {
|
|
||||
// reject(error)
|
|
||||
// })
|
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
// user logout
|
|
||||
logout({ |
|
||||
commit, |
|
||||
dispatch |
|
||||
}) { |
|
||||
return new Promise((resolve, reject) => { |
|
||||
// logout().then(() => {
|
|
||||
commit('SET_TOKEN', null) |
|
||||
commit('SET_USERINFO', null) |
|
||||
removeToken() |
|
||||
store.dispatch('permission/clearRouters') |
|
||||
// resetRouter()
|
|
||||
// reset visited views and cached views
|
|
||||
// to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
|
|
||||
dispatch('tagsView/delAllViews', null, { |
|
||||
root: true |
|
||||
}) |
|
||||
resolve() |
|
||||
// 防止路由叠加
|
|
||||
// location.reload()
|
|
||||
// }).catch(error => {
|
|
||||
// reject(error)
|
|
||||
// })
|
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
// remove token
|
|
||||
resetToken({ |
|
||||
commit |
|
||||
}) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('SET_TOKEN', '') |
|
||||
commit('SET_ROLES', []) |
|
||||
removeToken() |
|
||||
resolve() |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
// get userInfo
|
|
||||
getUserInfo({ |
|
||||
commit |
|
||||
},username) { |
|
||||
return new Promise((resolve, reject) => { |
|
||||
getUsersByUserName(username).then(res=>{ |
|
||||
if(res && JSON.stringify(res).length > 0){ |
|
||||
localStorage.setItem('isLoginName',username) |
|
||||
// commit('SET_ROLES', res)
|
|
||||
commit('SET_USERINFO', res) |
|
||||
resolve(res) |
|
||||
}else{ |
|
||||
reject('获取用户信息失败,请重试') |
|
||||
} |
|
||||
}) |
|
||||
.catch(err => { |
|
||||
reject(err) |
|
||||
console.log('获取用户信息失败,请重试') |
|
||||
}) |
|
||||
}) |
|
||||
}, |
|
||||
} |
|
||||
|
|
||||
export default { |
|
||||
namespaced: true, |
|
||||
state, |
|
||||
mutations, |
|
||||
actions |
|
||||
} |
|
@ -0,0 +1,25 @@ |
|||||
|
<template> |
||||
|
<!-- callback.vue(单点登录成功的回调页面) --> |
||||
|
<div |
||||
|
style="height: 100vh;" |
||||
|
v-loading="loading" |
||||
|
element-loading-text="正在加载中" |
||||
|
element-loading-spinner="el-icon-loading" |
||||
|
></div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
export default { |
||||
|
name:'callback', |
||||
|
data() { |
||||
|
return { |
||||
|
loading:true |
||||
|
}; |
||||
|
}, |
||||
|
created() { |
||||
|
this.$store.dispatch("user/loginBySignin").then(()=>{ |
||||
|
this.$router.push("/"); |
||||
|
}) |
||||
|
} |
||||
|
}; |
||||
|
</script> |
Loading…
Reference in new issue