import store from '@/store';
/**
 * 获取用户权限节点
 * @returns {*}
 */
export function getUserAccess() {
	return store.state.access.custom
}
/**
 * 获取用户数据域权限
 * @returns {*}
 */
export function getDataField() {
	return store.state.access.dataField
}

/**
 * 是否超级管理员
 * @returns {boolean}
 */
export function isSuperAdmin() {
	return store.state.access.isAdministrator
}


/**
 * 检查操作权限
 * @param role
 * @returns {boolean}
 */
export function checkActionAccess(role) {
	if (isSuperAdmin()) {
		return true;
	}
	if (role === undefined) {
		return true;
	}
	const roles = getUserAccess();
	return checkAccess(role, roles);
}

/**
 * 检查权限
 * @param role
 * @param rolescheckRouterAccess
 * @returns {boolean}
 */
export function checkAccess(role, roles = []) {
	let isCheck = false;
	for (let i in roles) {
		const item = roles[i];
		if (item === role) {
			isCheck = true;
			break;
		}
	}
	return isCheck;
}
