410f69de6676f3e3bba1d08d9a8079f9ada074fe.svn-base 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { USER_AUTH,SYS_BUTTON_AUTH } from "@/store/mutation-types"
  2. const hasPermission = {
  3. install (Vue, options) {
  4. //console.log(options);
  5. Vue.directive('has', {
  6. inserted: (el, binding, vnode)=>{
  7. //console.log("页面权限控制----");
  8. //console.time()
  9. //节点权限处理,如果命中则不进行全局权限处理
  10. if(!filterNodePermission(el, binding, vnode)){
  11. filterGlobalPermission(el, binding, vnode);
  12. }
  13. //console.timeEnd() //计时结束并输出时长
  14. }
  15. });
  16. }
  17. };
  18. /**
  19. * 流程节点权限控制
  20. */
  21. export function filterNodePermission(el, binding, vnode) {
  22. let permissionList = [];
  23. try {
  24. let obj = vnode.context.$props.formData;
  25. if (obj) {
  26. let bpmList = obj.permissionList;
  27. for (let bpm of bpmList) {
  28. if(bpm.type != '2') {
  29. permissionList.push(bpm);
  30. }
  31. }
  32. }else{
  33. return false;
  34. }
  35. } catch (e) {
  36. //console.log("页面权限异常----", e);
  37. }
  38. if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
  39. //el.parentNode.removeChild(el)
  40. return false;
  41. }
  42. console.log("流程节点页面权限--NODE--");
  43. let permissions = [];
  44. for (let item of permissionList) {
  45. if(item.type != '2') {
  46. permissions.push(item.action);
  47. }
  48. }
  49. //console.log("页面权限----"+permissions);
  50. //console.log("页面权限----"+binding.value);
  51. if (!permissions.includes(binding.value)) {
  52. //el.parentNode.removeChild(el)
  53. return false;
  54. }else{
  55. for (let item2 of permissionList) {
  56. if(binding.value === item2.action){
  57. return true;
  58. }
  59. }
  60. }
  61. return false;
  62. }
  63. /**
  64. * 全局权限控制
  65. */
  66. export function filterGlobalPermission(el, binding, vnode) {
  67. //console.log("全局页面权限--Global--");
  68. let permissionList = [];
  69. let allPermissionList = [];
  70. //let authList = Vue.ls.get(USER_AUTH);
  71. let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
  72. for (let auth of authList) {
  73. if(auth.type != '2') {
  74. permissionList.push(auth);
  75. }
  76. }
  77. //console.log("页面权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
  78. let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
  79. for (let gauth of allAuthList) {
  80. if(gauth.type != '2') {
  81. allPermissionList.push(gauth);
  82. }
  83. }
  84. //设置全局配置是否有命中
  85. let invalidFlag = false;//无效命中
  86. if(allPermissionList != null && allPermissionList != "" && allPermissionList != undefined && allPermissionList.length > 0){
  87. for (let itemG of allPermissionList) {
  88. if(binding.value === itemG.action){
  89. if(itemG.status == '0'){
  90. invalidFlag = true;
  91. break;
  92. }
  93. }
  94. }
  95. }
  96. if(invalidFlag){
  97. return;
  98. }
  99. if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
  100. el.parentNode.removeChild(el);
  101. return;
  102. }
  103. let permissions = [];
  104. for (let item of permissionList) {
  105. //权限策略1显示2禁用
  106. if(item.type != '2'){
  107. //update--begin--autor:wangshuai-----date:20200729------for:按钮权限,授权标识的提示信息是多个用逗号分隔逻辑处理 gitee#I1OUGU-------
  108. if(item.action){
  109. if(item.action.includes(",")){
  110. let split = item.action.split(",")
  111. for (let i = 0; i <split.length ; i++) {
  112. if(!split[i] ||split[i].length==0){
  113. continue;
  114. }
  115. permissions.push(split[i]);
  116. }
  117. }else{
  118. permissions.push(item.action);
  119. }
  120. }
  121. //update--end--autor:wangshuai-----date:20200729------for:按钮权限,授权标识的提示信息是多个用逗号分隔逻辑处理 gitee#I1OUGU------
  122. }
  123. }
  124. if (!permissions.includes(binding.value)) {
  125. el.parentNode.removeChild(el);
  126. }
  127. }
  128. export default hasPermission;