提交 220f81ae 编写于 作者: KK's avatar KK

权限菜单

上级 89dafd4d
...@@ -7,6 +7,7 @@ import * as mutations from './mutations'; ...@@ -7,6 +7,7 @@ import * as mutations from './mutations';
import * as getters from './getters'; import * as getters from './getters';
import viewaction from './modules/view-action' import viewaction from './modules/view-action'
import authresource from './modules/auth-resource'
const state = { const state = {
...rootstate ...rootstate
...@@ -20,7 +21,8 @@ const store = new Vuex.Store({ ...@@ -20,7 +21,8 @@ const store = new Vuex.Store({
mutations, mutations,
getters, getters,
modules: { modules: {
viewaction viewaction,
authresource
}, },
}); });
......
/**
* 提交统一资源数据
*
* @param param0
* @param data
*/
export const commitAuthData = ({ commit, state }: { commit: any, state: any }, { unires,appmenu,enablepermissionvalid }: { unires: Array<any>, appmenu: Array<any>, enablepermissionvalid: boolean }) => {
if(unires && unires.length > 0){
commit('setResourceData', unires);
}
if(appmenu && appmenu.length >0){
commit('setMenuData', appmenu);
}
if(enablepermissionvalid){
commit('setEnablePermissionValid', enablepermissionvalid);
}
}
\ No newline at end of file
/**
* 判断指定统一资源是否存在
*
* @param state
*/
export const getResourceData = (state: any) => (resourcetag: string) => {
let itemIndex: any = state.resourceData.findIndex((unirescode: any, objIndex: any, objs: any) => {
return Object.is(unirescode, resourcetag);
})
return itemIndex === -1 ? false : true;
}
/**
* 判断指定菜单权限是否存在
*
* @param state
*/
export const getMenuData = (state: any) => (menutag: string) => {
let itemIndex: any = state.menuData.findIndex((menucode: any, objIndex: any, objs: any) => {
return Object.is(menucode, menutag);
})
return itemIndex === -1 ? false : true;
}
/**
* 获取是否开启权限认证
*
* @param state
*/
export const getEnablePermissionValid = (state: any) => {
return state.enablePermissionValid;
}
/**
* 判断指定菜单是否显示
*
* @param state
*/
export const getAuthMenu = (state: any) => (menu:any) =>{
// 存在权限
let resourceIndex: any;
let menuIndex:any;
if(state.enablePermissionValid){
resourceIndex= state.resourceData.findIndex((resourcetag: any, objIndex: any, objs: any) => {
return Object.is(menu.resourcetag, resourcetag);
})
}
menuIndex= state.menuData.findIndex((menutag: any, objIndex: any, objs: any) => {
return Object.is(menu.authtag, menutag);
})
return (resourceIndex !== -1 || menuIndex !== -1)?true:false;
}
\ No newline at end of file
import { resourcestate } from './state';
import * as actions from './actions';
import * as mutations from './mutations';
import * as getters from './getters';
const state = {
...resourcestate
}
export default {
namespaced: true,
state,
getters,
actions,
mutations
}
\ No newline at end of file
/**
* 设置统一资源数据
*
* @param state
* @param resourceArray
*/
export const setResourceData = (state: any, resourceArray:Array<any>) => {
if(resourceArray && resourceArray.length === 0){
return;
}
state.resourceData = resourceArray;
}
/**
* 设置菜单数据
*
* @param state
* @param resourceArray
*/
export const setMenuData = (state: any, menuArray:Array<any>) => {
if(menuArray && menuArray.length === 0){
return;
}
state.menuData = menuArray;
}
/**
* 设置是否开启权限认证
*
* @param state
* @param resourceArray
*/
export const setEnablePermissionValid = (state: any, enablepermissionvalid:boolean) => {
state.enablePermissionValid = enablepermissionvalid;
}
/**
* 所有资源状态
*/
export const resourcestate: any = {
// 统一资源数据
resourceData: [],
// 菜单数据
menuData:[],
// 是否开启权限认证
enablePermissionValid: false
}
\ No newline at end of file
...@@ -70,22 +70,32 @@ export class AuthGuard { ...@@ -70,22 +70,32 @@ export class AuthGuard {
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
* @memberof AuthGuard * @memberof AuthGuard
*/ */
public async authGuard(url: string, params: any = {}, store: Store<any>): Promise<boolean> { public async authGuard(url: string, params: any = {}, store: Store<any>): Promise<any> {
// const get: Promise<any> = Http.getInstance().get(url); this.loadDictionaryDatas(store);
// get.then((response: any) => { try{
// if (response && response.status === 200) { let response = await Http.getInstance().get(url);
// const { data }: { data: any } = response; if (response && response.status === 200) {
// const { remotetag, localdata }: { remotetag: string, localdata: {} } = data; let { data }: { data: any } = response;
// if (remotetag) { if (data) {
// store.commit('addAppData', remotetag); // token认证把用户信息放入应用级数据
// } if(localStorage.getItem('user')){
// if (localdata) { let user:any = JSON.parse(localStorage.getItem('user') as string);
// store.commit('addLocalData', localdata); let localAppData:any = {};
// } if(user.sessionParams){
// } localAppData = {context:user.sessionParams};
// }).catch((error: any) => { Object.assign(localAppData,data);
// }); }
return await this.loadDictionaryDatas(store) data = JSON.parse(JSON.stringify(localAppData));
}
store.commit('addAppData', data);
// 提交统一资源数据
store.dispatch('authresource/commitAuthData', data);
}
return true;
}
}catch (error) {
console.error("获取应用数据出现异常");
}
} }
/** /**
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册