permission.js 739 B

12345678910111213141516171819202122
  1. import Cache from '@/utils/cache';
  2. /**
  3. * 判断传入的 key 是否在数组 arr 中存在
  4. * @param {string} key - 待判断的字符串
  5. * @returns {boolean} - 返回布尔值,表示是否有权限
  6. */
  7. function ActivePermission(key) {
  8. console.log(Cache.get('BASIC_CONFIG').site_func,'site_func')
  9. // seckill 秒杀 bargain 砍价 combination 拼团
  10. let arr = Cache.get('BASIC_CONFIG').site_func || ['seckill', 'bargain', 'combination']; // 定义一个数组,包含三种类型
  11. let index = arr.indexOf(key); // 获取 key 在数组中的索引
  12. if (index > -1) {
  13. // 如果索引大于 -1,说明 key 存在于数组中
  14. return true; // 有权限
  15. } else {
  16. return false; // 无权限
  17. }
  18. }
  19. export default ActivePermission;