QueryPermission.js 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var list =[]
  2. function QueryPermission(id) {
  3. if(uni.getStorageSync("jurisdiction")){
  4. list = JSON.parse(uni.getStorageSync("jurisdiction"))
  5. }
  6. for (var i = 0; i < list.length; i++) {
  7. if (list[i].children) {
  8. var data = list[i].children
  9. for (var j = 0; j < data.length; j++) {
  10. var item = data[j]
  11. if (item.pur_id == id) {
  12. return true
  13. }
  14. }
  15. }
  16. }
  17. return false
  18. }
  19. function getUserPermission(){
  20. let list = []
  21. if(uni.getStorageSync("jurisdiction")){
  22. list = JSON.parse(uni.getStorageSync("jurisdiction"))
  23. }
  24. return list
  25. }
  26. function getPermissionById(node = getUserPermission(),id) {
  27. for (const child of node) {
  28. if(id == child.pur_id){
  29. return child.children || []
  30. }
  31. if(child.children){
  32. let result = getPermissionById(child.children,id)
  33. if(result){
  34. return result
  35. }
  36. }
  37. }
  38. return null
  39. }
  40. export {
  41. QueryPermission,getPermissionById,getUserPermission
  42. }