access.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { setItem, getItem } from '@/utils/storage';
  2. export default {
  3. data() {
  4. return {
  5. }
  6. },
  7. computed: {
  8. getUser: function(){
  9. // var user = getItem('user');
  10. var user =JSON.parse(localStorage.getItem('user'))
  11. if(user != null ){
  12. return user;
  13. }else{
  14. return {};
  15. }
  16. },
  17. isAdmin() {
  18. if (this.getUser == null) {
  19. return false
  20. }
  21. return this.getUser.userId === 1
  22. },
  23. opLoginName() {
  24. return this.getUser == null ? '' : this.getUser.userName
  25. },
  26. opNikeName() {
  27. return this.getUser == null ? '' : this.getUser.nikeName
  28. },
  29. opUserType() {
  30. return this.getUser == null ? '' : this.getUser.userType
  31. },
  32. opAuthorities() {
  33. return this.getUser == null ? [] : this.getUser.authorityWithOrgIds
  34. }
  35. },
  36. created() {
  37. },
  38. mounted() {
  39. },
  40. destroyed() {
  41. },
  42. methods: {
  43. hasPermission(permissionStr, orgIds) {
  44. //判断用户权限列表是否为空
  45. if (this.opAuthorities == null) {
  46. return false
  47. }
  48. if(this.isAdmin){
  49. return true;
  50. }
  51. if(permissionStr && permissionStr.indexOf('|') !== -1) {
  52. let flag = false
  53. let arr = permissionStr.split('|')
  54. for(let i=0; i< arr.length; i++) {
  55. let a = arr[i].replace(/(^\s*)|(\s*$)/g, "");
  56. if (this.opAuthorities.hasOwnProperty(a)) {
  57. flag = true
  58. }
  59. }
  60. return flag
  61. }
  62. //登录用户没有某个操作权限
  63. if (!this.opAuthorities.hasOwnProperty(permissionStr)) {
  64. return false
  65. }
  66. //如果当前验证,不包含项目级别验证,直接返回
  67. if (typeof(orgIds) == 'undefined' || orgIds == null) {
  68. return true
  69. }
  70. //验证登录用户是否有某个项目的有操作权限
  71. var orgIdsHasPermission = this.opAuthorities[permissionStr]
  72. //如果projectIds是个数字,只要验证登录用户是否有该项目的操作权限
  73. if (typeof orgIds == 'number') {
  74. if (orgIdsHasPermission.indexOf(orgIds) > -1) {
  75. return true
  76. }else{
  77. return false
  78. }
  79. }else{
  80. var result = false
  81. for (var i in orgIdsHasPermission) {
  82. var flag = orgIds.indexOf(orgIdsHasPermission[i]) > -1
  83. if (flag) {
  84. result = true
  85. }
  86. }
  87. return result
  88. }
  89. },
  90. //从所有字典中,取某个字典的列表
  91. getDict(dictname){
  92. var basecode = JSON.parse(localStorage.getItem('queryForCodeSelect'));
  93. var dictList = basecode[dictname]
  94. return dictList;
  95. },
  96. //从某个字典的列表,获取某个字典对象
  97. getDictCode(dictname, codeValue , value='value'){
  98. //如果 codeValue传过来的是字符串 all 则字典数组返回
  99. var dictList = this.getDict(dictname);
  100. for (var i = 0; i < dictList.length; i++) {
  101. var codeItem = dictList[i]
  102. if(codeItem[value] == codeValue){
  103. return codeItem;
  104. }
  105. if(codeValue =='all'){
  106. return dictList
  107. }
  108. }
  109. return {};
  110. },
  111. }
  112. }