/*
 * @Description: 权限控制
 * @Author: taosu
 * @Date: 2022-01-06 10:08:10
 * @LastEditTime: 2022-01-06 10:54:50
 * @LastEditors: taosu
 */
import { RootState } from 'models';
import { useSelector } from 'react-redux';

export default function useAuth() {
  const user = useSelector((state: RootState) => state.user);
  const { authority = [] } = user;

  const checkAuth = (authCode) => {
    if (authCode) {
      const codes = authCode.split(',');
      const flag = codes.some((value) => authority.some((func) => func == value.trim()));
      return flag;
    } else {
      return false;
    }
  };
  return {
    checkAuth
  };
}
