authFilter.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { USER_AUTH,SYS_BUTTON_AUTH } from "@/store/mutation-types"
  2. export function disabledAuthFilter(code,formData) {
  3. if(nodeDisabledAuth(code,formData)){
  4. return true;
  5. }else{
  6. return globalDisabledAuth(code);
  7. }
  8. }
  9. function nodeDisabledAuth(code,formData){
  10. let permissionList = [];
  11. try {
  12. //console.log("页面权限禁用--NODE--开始",obj);
  13. if (formData) {
  14. let bpmList = formData.permissionList;
  15. permissionList = bpmList.filter(item=>item.type=='2')
  16. // for (let bpm of bpmList) {
  17. // if(bpm.type == '2') {
  18. // permissionList.push(bpm);
  19. // }
  20. // }
  21. }else{
  22. return false;
  23. }
  24. } catch (e) {
  25. //console.log("页面权限异常----", e);
  26. }
  27. if (permissionList.length == 0) {
  28. return false;
  29. }
  30. console.log("流程节点页面权限禁用--NODE--开始");
  31. let permissions = [];
  32. for (let item of permissionList) {
  33. if(item.type == '2') {
  34. permissions.push(item.action);
  35. }
  36. }
  37. //console.log("页面权限----"+code);
  38. if (!permissions.includes(code)) {
  39. return false;
  40. }else{
  41. for (let item2 of permissionList) {
  42. if(code === item2.action){
  43. console.log("流程节点页面权限禁用--NODE--生效");
  44. return true;
  45. }
  46. }
  47. }
  48. return false;
  49. }
  50. function globalDisabledAuth(code){
  51. //console.log("全局页面禁用权限--Global--开始");
  52. var permissionList = [];
  53. var allPermissionList = [];
  54. //let authList = Vue.ls.get(USER_AUTH);
  55. let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
  56. for (let auth of authList) {
  57. if(auth.type == '2') {
  58. permissionList.push(auth);
  59. }
  60. }
  61. //console.log("页面禁用权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
  62. let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
  63. for (let gauth of allAuthList) {
  64. if(gauth.type == '2') {
  65. allPermissionList.push(gauth);
  66. }
  67. }
  68. //设置全局配置是否有命中
  69. var gFlag = false;//禁用命中
  70. var invalidFlag = false;//无效命中
  71. if(allPermissionList != null && allPermissionList != "" && allPermissionList != undefined && allPermissionList.length > 0){
  72. for (let itemG of allPermissionList) {
  73. if(code === itemG.action){
  74. if(itemG.status == '0'){
  75. invalidFlag = true;
  76. break;
  77. }else{
  78. gFlag = true;
  79. break;
  80. }
  81. }
  82. }
  83. }
  84. if(invalidFlag){
  85. return false;
  86. }
  87. if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
  88. return gFlag;
  89. }
  90. let permissions = [];
  91. for (let item of permissionList) {
  92. if(item.type == '2') {
  93. permissions.push(item.action);
  94. }
  95. }
  96. //console.log("页面禁用权限----"+code);
  97. if (!permissions.includes(code)) {
  98. return gFlag;
  99. }else{
  100. for (let item2 of permissionList) {
  101. if(code === item2.action){
  102. console.log("全局页面权限解除禁用--Global--生效");
  103. gFlag = false;
  104. }
  105. }
  106. return gFlag;
  107. }
  108. }
  109. export function colAuthFilter(columns,pre) {
  110. var authList = getNoAuthCols(pre);
  111. const cols = columns.filter(item => {
  112. if (hasColoum(item,authList)) {
  113. return true
  114. }
  115. return false
  116. })
  117. return cols
  118. }
  119. function hasColoum(item,authList){
  120. if (authList.includes(item.dataIndex)) {
  121. return false
  122. }
  123. return true
  124. }
  125. //权限无效时不做控制,有效时控制,只能控制 显示不显示
  126. //根据授权码前缀获取未授权的列信息
  127. function getNoAuthCols(pre){
  128. let permissionList = [];
  129. let allPermissionList = [];
  130. //let authList = Vue.ls.get(USER_AUTH);
  131. let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
  132. for (let auth of authList) {
  133. //显示策略,有效状态
  134. if(auth.type == '1'&&startWith(auth.action,pre)) {
  135. permissionList.push(substrPre(auth.action,pre));
  136. }
  137. }
  138. //console.log("页面禁用权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
  139. let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
  140. for (let gauth of allAuthList) {
  141. //显示策略,有效状态
  142. if(gauth.type == '1'&&gauth.status == '1'&&startWith(gauth.action,pre)) {
  143. allPermissionList.push(substrPre(gauth.action,pre));
  144. }
  145. }
  146. const cols = allPermissionList.filter(item => {
  147. if (permissionList.includes(item)) {
  148. return false;
  149. }
  150. return true;
  151. })
  152. return cols;
  153. }
  154. function startWith(str,pre) {
  155. if (pre == null || pre == "" || str==null|| str==""|| str.length == 0 || pre.length > str.length)
  156. return false;
  157. if (str.substr(0, pre.length) == pre)
  158. return true;
  159. else
  160. return false;
  161. }
  162. function substrPre(str,pre) {
  163. return str.substr(pre.length);
  164. }