permission.js 677 B

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