1f4a091dbed233a28b7bf7b1f61312af11942b4e.svn-base 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. export function hasPriv(code) {
  2. let privObj = JSON.parse(sessionStorage.getItem('privItem'));
  3. let result = hasPermission(privObj, code);
  4. return result;
  5. }
  6. function hasPermission(privItem, code) {
  7. if (code == privItem.code) {
  8. return true;
  9. } else {
  10. if (privItem.privList.length && privItem.privList.length > 0) {
  11. for (var index = 0; index < privItem.privList.length; index++) {
  12. var result = hasPermission(privItem.privList[index], code);
  13. if (result) {
  14. return true;
  15. }
  16. }
  17. }
  18. }
  19. return false;
  20. }
  21. export function hasMenu(router) {
  22. let list = []
  23. let privCollect = JSON.parse(sessionStorage.getItem('privCollect'))
  24. if(privCollect){
  25. hasMenuList(list,privCollect)
  26. if(router.fullPath && list.length>0){
  27. return list.indexOf(removeURLParams(router.fullPath))>-1
  28. }else{
  29. return false
  30. }
  31. }else{
  32. return true;
  33. }
  34. }
  35. export function hasMenuList(list,privCollect) {
  36. if(privCollect && privCollect.length>0){
  37. privCollect.forEach((item,index)=>{
  38. if(item.flagLeaf==="1" && item.privUri){
  39. list.push(item.privUri)
  40. }
  41. if(item.privList && item.privList.length>0){
  42. hasMenuList(list,item.privList)
  43. }
  44. })
  45. }
  46. }
  47. export function removeURLParams(url) {
  48. const index = url.indexOf('?');
  49. if (index !== -1) {
  50. return url.substr(0, index);
  51. }
  52. return url;
  53. }