Browse Source

【接口看板】无权限问题确定及404优化开发+用户信息操作处理开发

faster_AG_grid
安虹睿 1 year ago
parent
commit
fdf54f7974
  1. 25
      PC/InterFace.Dash/src/permission.js
  2. 15
      PC/InterFace.Dash/src/router/index.js
  3. 2
      PC/InterFace.Dash/src/store/getters.js
  4. 14
      PC/InterFace.Dash/src/store/modules/permission.js
  5. 10
      PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkUsers.vue

25
PC/InterFace.Dash/src/permission.js

@ -16,6 +16,16 @@ const loginErr = '登录失败,请重新登录 !'
const getErrMsg = '数据获取失败 !' const getErrMsg = '数据获取失败 !'
// 退出登录处理
const logoutHandle = (msg) => {
if(msg){
Message.error(msg)
}
setTimeout(()=>{
store.dispatch("user/logout")
},0)
}
// 跳转登录页 // 跳转登录页
const pageToLogin = (to, from, next) => { const pageToLogin = (to, from, next) => {
if (whiteList.indexOf(to.path) >= 0 ) { if (whiteList.indexOf(to.path) >= 0 ) {
@ -54,8 +64,7 @@ const toPageInit = async (to, from, next) => {
if(getToken()){ if(getToken()){
toNextHandle(to, from, next) toNextHandle(to, from, next)
}else{ }else{
Message.error('暂无token,请重新登录') logoutHandle('暂无token,请重新登录')
store.dispatch("user/logout")
} }
} }
@ -65,11 +74,12 @@ const getErrHandle = (to, from, next) => {
let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName
Message.error(getErrMsg) Message.error(getErrMsg)
if(!isAutoLogin){ if(!isAutoLogin){
store.dispatch("user/logout") logoutHandle()
} }
NProgress.done() NProgress.done()
} }
// 跳转处理 // 跳转处理
const toNextHandle = async (to, from, next) => { const toNextHandle = async (to, from, next) => {
let isFresh = false let isFresh = false
@ -82,14 +92,13 @@ const toNextHandle = async (to, from, next) => {
} }
// 获取菜单数据 permission_routes // 获取菜单数据 permission_routes
if(!store.getters.addRoutes || store.getters.addRoutes.length <= 0){ if(!store.getters.hasApiToken){
isFresh = true isFresh = true
await store.dispatch('permission/getAppConfig') await store.dispatch('permission/getAppConfig')
.then(res=>{ .then((res)=>{
// 没有权限(token失效处理) // 没有权限(token失效处理)
if(!res || res.length <=0){ if(!res || !res.auth || !res.auth.grantedPolicies || JSON.stringify(res.auth.grantedPolicies) == '{}'){
Message.error('用户无权限或者token失效,请配置权限或重新登录') logoutHandle('用户无权限或者token失效,请配置权限或重新登录')
store.dispatch("user/logout")
} }
}) })
.catch(()=>{ .catch(()=>{

15
PC/InterFace.Dash/src/router/index.js

@ -45,11 +45,6 @@ export let constantRoutes = [
component: () => import('@/views/redirect/index') component: () => import('@/views/redirect/index')
}] }]
}, },
{
path: '*',
redirect: '/404',
hidden: true
},
{ {
path: '/login', path: '/login',
component: () => import('@/views/login/index'), component: () => import('@/views/login/index'),
@ -150,11 +145,11 @@ export let constantRoutes = [
export let asyncRoutes = [ export let asyncRoutes = [
/** when your routing map is too long, you can split it into small modules **/ /** when your routing map is too long, you can split it into small modules **/
// 404 page must be placed at the end !!! // 404 page must be placed at the end !!!
// { {
// path: '*', path: '*',
// redirect: '/404', redirect: '/404',
// hidden: true hidden: true
// } }
] ]
const createRouter = () => new Router({ const createRouter = () => new Router({

2
PC/InterFace.Dash/src/store/getters.js

@ -9,7 +9,7 @@ const getters = {
roles: state => state.permission.roles,//当前用户权限 roles: state => state.permission.roles,//当前用户权限
currentUserInfo: state => state.user.userInfo,//当前用户信息 currentUserInfo: state => state.user.userInfo,//当前用户信息
permission_routes: state => state.permission.routes,//全部菜单 permission_routes: state => state.permission.routes,//全部菜单
addRoutes:state => state.permission.addRoutes,//非项目内固定的路由(接口获取的) hasApiToken:state => state.permission.configApiToken,//配置config接口是否有权限
tablesName:state => state.permission.tablesName,//接口获取所有的表名 tablesName:state => state.permission.tablesName,//接口获取所有的表名
errorLogs: state => state.errorLog.logs, errorLogs: state => state.errorLog.logs,
enumList: state => state.definition.enumList,//接口获取的枚举 enumList: state => state.definition.enumList,//接口获取的枚举

14
PC/InterFace.Dash/src/store/modules/permission.js

@ -13,16 +13,19 @@ const AbpIdentity_mark = 'AbpIdentityMark'
const state = { const state = {
routes: [],//菜单 routes: [],//菜单
roles: [],//当前用户权限 roles: [],//当前用户权限
addRoutes: [], configApiToken:false,//配置config接口是否有权限
tablesName:null,//所有的表名 tablesName:null,//所有的表名
} }
const mutations = { const mutations = {
SET_ROUTES: (state, routes) => { SET_ROUTES: (state, routes) => {
state.addRoutes = routes
state.routes = constantRoutes.concat(routes) state.routes = constantRoutes.concat(routes)
router.addRoutes(routes) router.addRoutes(routes)
}, },
// 配置config接口是否为空(即没有权限)
SET_CONFIG_TOKEN: (state, data) => {
state.configApiToken = data
},
// 设置权限(v-permission) // 设置权限(v-permission)
SET_ROLES: (state, roles) => { SET_ROLES: (state, roles) => {
state.roles = roles state.roles = roles
@ -148,6 +151,11 @@ const actions = {
// 存储当前用户信息 // 存储当前用户信息
store.dispatch('user/setUserInfo',res.currentUser) store.dispatch('user/setUserInfo',res.currentUser)
let roles_arr = [] let roles_arr = []
if(!res.auth.grantedPolicies || JSON.stringify(res.auth.grantedPolicies) == '{}'){
commit('SET_CONFIG_TOKEN',false)
}else{
commit('SET_CONFIG_TOKEN',true)
}
for(let r in res.auth.grantedPolicies){ for(let r in res.auth.grantedPolicies){
if(res.auth.grantedPolicies[r])roles_arr.push(r) if(res.auth.grantedPolicies[r])roles_arr.push(r)
} }
@ -244,7 +252,7 @@ const actions = {
let _initEndMenus = generaMenu(asyncRoutes, _initTreeMenus,true) let _initEndMenus = generaMenu(asyncRoutes, _initTreeMenus,true)
let accessedRoutes = _initEndMenus let accessedRoutes = _initEndMenus
commit('SET_ROUTES', accessedRoutes) commit('SET_ROUTES', accessedRoutes)
resolve(accessedRoutes) resolve(res)
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
}) })

10
PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkUsers.vue

@ -141,9 +141,9 @@
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="是否启用" prop="IsActive"> <el-form-item label="是否启用" prop="isActive">
<el-select <el-select
v-model="form.IsActive" v-model="form.isActive"
style="width: 100%" style="width: 100%"
placeholder="请选择" placeholder="请选择"
> >
@ -309,7 +309,7 @@ export default {
password: "", password: "",
surname: "", surname: "",
lockoutEnabled: true, lockoutEnabled: true,
IsActive: true, isActive: true,
}, },
// //
passwordType: "password", passwordType: "password",
@ -442,7 +442,7 @@ export default {
this.form.roleNames = []; this.form.roleNames = [];
this.form.password = ""; this.form.password = "";
this.form.surname = ""; this.form.surname = "";
this.form.IsActive = ""; this.form.isActive = "";
this.$refs.multipleTable.clearSelection(); this.$refs.multipleTable.clearSelection();
}, },
handleCreate() { handleCreate() {
@ -488,7 +488,7 @@ export default {
this.form.surname = row.name; this.form.surname = row.name;
this.form.lockoutEnabled = row.lockoutEnabled this.form.lockoutEnabled = row.lockoutEnabled
this.concurrencyStamp = row.concurrencyStamp; this.concurrencyStamp = row.concurrencyStamp;
this.form.IsActive = row.isActive; this.form.isActive = row.isActive;
usersroles().then((res) => { usersroles().then((res) => {
this.options = res.items; this.options = res.items;
}); });

Loading…
Cancel
Save