2d0436efddec67cd445b87adfface4815aabc473.svn-base 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. //console.log("页面权限禁用--NODE--开始");
  11. let permissionList = [];
  12. try {
  13. //console.log("页面权限禁用--NODE--开始",formData);
  14. if (formData) {
  15. let bpmList = formData.permissionList;
  16. permissionList = bpmList.filter(item=>item.type=='2')
  17. // for (let bpm of bpmList) {
  18. // if(bpm.type == '2') {
  19. // permissionList.push(bpm);
  20. // }
  21. // }
  22. }else{
  23. return false;
  24. }
  25. } catch (e) {
  26. //console.log("页面权限异常----", e);
  27. }
  28. if (permissionList.length == 0) {
  29. return false;
  30. }
  31. console.log("流程节点页面权限禁用--NODE--开始");
  32. let permissions = [];
  33. for (let item of permissionList) {
  34. if(item.type == '2') {
  35. permissions.push(item.action);
  36. }
  37. }
  38. //console.log("页面权限----"+code);
  39. if (!permissions.includes(code)) {
  40. return false;
  41. }else{
  42. for (let item2 of permissionList) {
  43. if(code === item2.action){
  44. console.log("流程节点页面权限禁用--NODE--生效");
  45. return true;
  46. }
  47. }
  48. }
  49. return false;
  50. }
  51. function globalDisabledAuth(code){
  52. //console.log("全局页面禁用权限--Global--开始");
  53. let permissionList = [];
  54. let allPermissionList = [];
  55. //let authList = Vue.ls.get(USER_AUTH);
  56. let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
  57. for (let auth of authList) {
  58. if(auth.type == '2') {
  59. permissionList.push(auth);
  60. }
  61. }
  62. //console.log("页面禁用权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
  63. let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
  64. for (let gauth of allAuthList) {
  65. if(gauth.type == '2') {
  66. allPermissionList.push(gauth);
  67. }
  68. }
  69. //设置全局配置是否有命中
  70. let gFlag = false;//禁用命中
  71. let invalidFlag = false;//无效命中
  72. if(allPermissionList != null && allPermissionList != "" && allPermissionList != undefined && allPermissionList.length > 0){
  73. for (let itemG of allPermissionList) {
  74. if(code === itemG.action){
  75. if(itemG.status == '0'){
  76. invalidFlag = true;
  77. break;
  78. }else{
  79. gFlag = true;
  80. break;
  81. }
  82. }
  83. }
  84. }
  85. if(invalidFlag){
  86. return false;
  87. }
  88. if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
  89. return gFlag;
  90. }
  91. let permissions = [];
  92. for (let item of permissionList) {
  93. if(item.type == '2') {
  94. permissions.push(item.action);
  95. }
  96. }
  97. //console.log("页面禁用权限----"+code);
  98. if (!permissions.includes(code)) {
  99. return gFlag;
  100. }else{
  101. for (let item2 of permissionList) {
  102. if(code === item2.action){
  103. //console.log("全局页面权限解除禁用--Global--生效");
  104. gFlag = false;
  105. }
  106. }
  107. return gFlag;
  108. }
  109. }
  110. export function colAuthFilter(columns,pre) {
  111. let authList = getNoAuthCols(pre);
  112. const cols = columns.filter(item => {
  113. if (hasColoum(item,authList)) {
  114. return true
  115. }
  116. return false
  117. })
  118. return cols
  119. }
  120. /**
  121. * 【子表行编辑】实现两个功能:
  122. * 1、隐藏JEditableTable无权限的字段
  123. * 2、禁用JEditableTable无权限的字段
  124. * @param columns
  125. * @param pre
  126. * @returns {*}
  127. */
  128. export function colAuthFilterJEditableTable(columns,pre) {
  129. let authList = getAllShowAndDisabledAuthCols(pre);
  130. const cols = columns.filter(item => {
  131. let oneAuth = authList.find(auth => {
  132. return auth.action === pre + item.key;
  133. });
  134. if(!oneAuth){
  135. return true
  136. }
  137. //代码严谨处理,防止一个授权标识,配置多次
  138. if(oneAuth instanceof Array){
  139. oneAuth = oneAuth[0]
  140. }
  141. //禁用逻辑
  142. if (oneAuth.type == '2' && !oneAuth.isAuth) {
  143. item["disabled"] = true
  144. return true
  145. }
  146. //隐藏逻辑逻辑
  147. if (oneAuth.type == '1' && !oneAuth.isAuth) {
  148. return false
  149. }
  150. return true
  151. })
  152. return cols
  153. }
  154. function hasColoum(item,authList){
  155. if (authList.includes(item.dataIndex)) {
  156. return false
  157. }
  158. return true
  159. }
  160. //权限无效时不做控制,有效时控制,只能控制 显示不显示
  161. //根据授权码前缀获取未授权的列信息
  162. export function getNoAuthCols(pre){
  163. if(!pre || pre.length==0){
  164. return []
  165. }
  166. let permissionList = [];
  167. let allPermissionList = [];
  168. //let authList = Vue.ls.get(USER_AUTH);
  169. let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
  170. for (let auth of authList) {
  171. //显示策略,有效状态
  172. if(auth.type == '1'&&startWith(auth.action,pre)) {
  173. permissionList.push(substrPre(auth.action,pre));
  174. }
  175. }
  176. //console.log("页面禁用权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
  177. let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
  178. for (let gauth of allAuthList) {
  179. //显示策略,有效状态
  180. if(gauth.type == '1'&&gauth.status == '1'&&startWith(gauth.action,pre)) {
  181. allPermissionList.push(substrPre(gauth.action,pre));
  182. }
  183. }
  184. const cols = allPermissionList.filter(item => {
  185. if (permissionList.includes(item)) {
  186. return false;
  187. }
  188. return true;
  189. })
  190. return cols;
  191. }
  192. /**
  193. * 将Online的行编辑按钮权限,添加至本地存储
  194. */
  195. export function addOnlineBtAuth2Storage(pre, authList){
  196. let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
  197. let newAuthList = allAuthList.filter(item=>{
  198. if(!item.action){
  199. return true
  200. }
  201. return item.action.indexOf(pre)<0
  202. })
  203. if(authList && authList.length>0){
  204. for(let item of authList){
  205. newAuthList.push({
  206. action: pre+item,
  207. type:1,
  208. status:1
  209. })
  210. }
  211. let temp = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
  212. let newArr = temp.filter(item=>{
  213. if(!item.action){
  214. return true
  215. }
  216. return item.action.indexOf(pre)<0 || authList.indexOf(item.action.replace(pre, ''))<0
  217. })
  218. sessionStorage.setItem(USER_AUTH, JSON.stringify(newArr))
  219. }
  220. sessionStorage.setItem(SYS_BUTTON_AUTH, JSON.stringify(newAuthList))
  221. }
  222. /**
  223. * 额外增加方法【用于行编辑组件】
  224. * date: 2020-04-05
  225. * author: scott
  226. * @param pre
  227. * @returns {*[]}
  228. */
  229. function getAllShowAndDisabledAuthCols(pre){
  230. //用户拥有的权限
  231. let userAuthList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
  232. //全部权限配置
  233. let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
  234. let newAllAuthList = allAuthList.map(function (item, index) {
  235. let hasAuthArray = userAuthList.filter(u => u.action===item.action );
  236. if (hasAuthArray && hasAuthArray.length>0) {
  237. item["isAuth"] = true
  238. }
  239. return item;
  240. })
  241. return newAllAuthList;
  242. }
  243. function startWith(str,pre) {
  244. if (pre == null || pre == "" || str==null|| str==""|| str.length == 0 || pre.length > str.length)
  245. return false;
  246. if (str.substr(0, pre.length) == pre)
  247. return true;
  248. else
  249. return false;
  250. }
  251. function substrPre(str,pre) {
  252. return str.substr(pre.length);
  253. }