addPrivilege.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. (function(vc){
  2. vc.extends({
  3. data:{
  4. addPrivilegeInfo:{
  5. _currentPgId:'',
  6. name:'',
  7. description:'',
  8. errorInfo:'',
  9. _noAddPrivilege:[],
  10. selectPrivileges:[]
  11. }
  12. },
  13. watch: { // 监视双向绑定的数据数组
  14. checkData: {
  15. handler(){ // 数据数组有变化将触发此函数
  16. if(vc.component.addPrivilegeInfo.selectPrivileges.length == vc.component.addPrivilegeInfo._noAddPrivilege.length){
  17. document.querySelector('#quan').checked = true;
  18. }else {
  19. document.querySelector('#quan').checked = false;
  20. }
  21. },
  22. deep: true // 深度监视
  23. }
  24. },
  25. _initMethod:function(){
  26. },
  27. _initEvent:function(){
  28. vc.component.$on('addPrivilege_openPrivilegeModel',function(_params){
  29. $('#addPrivilegeModel').modal('show');
  30. vc.component.addPrivilegeInfo._currentPgId = _params.pgId;
  31. //查询没有添加的权限
  32. vc.component.listNoAddPrivilege();
  33. });
  34. },
  35. methods:{
  36. listNoAddPrivilege:function(){
  37. vc.component.addPrivilegeInfo._noAddPrivilege=[];
  38. var param = {
  39. params:{
  40. pgId:vc.component.addPrivilegeInfo._currentPgId
  41. }
  42. }
  43. vc.http.get(
  44. 'addPrivilege',
  45. 'listNoAddPrivilege',
  46. param,
  47. function(json,res){
  48. //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
  49. if(res.status == 200){
  50. vc.component.addPrivilegeInfo._noAddPrivilege = JSON.parse(json);
  51. return ;
  52. }
  53. vc.component.addPrivilegeInfo.errorInfo = json;
  54. },
  55. function(errInfo,error){
  56. console.log('请求失败处理');
  57. vc.component.addPrivilegeInfo.errorInfo = errInfo;
  58. });
  59. },
  60. addPrivilegeToPrivilegeGroup:function(){
  61. vc.component.addPrivilegeInfo.errorInfo = "";
  62. var _selectPrivileges = vc.component.addPrivilegeInfo.selectPrivileges;
  63. if(_selectPrivileges.length < 1){
  64. vc.toast("请先选择权限");
  65. return ;
  66. }
  67. var _pIds = [];
  68. for(var selectIndex = 0;selectIndex < _selectPrivileges.length;selectIndex ++){
  69. var _pId = {
  70. pId: _selectPrivileges[selectIndex]
  71. };
  72. _pIds.push(_pId);
  73. }
  74. var _objData = {
  75. pgId:vc.component.addPrivilegeInfo._currentPgId,
  76. pIds:_pIds
  77. };
  78. vc.http.post(
  79. 'addPrivilege',
  80. 'addPrivilegeToPrivilegeGroup',
  81. JSON.stringify(_objData),
  82. {
  83. emulateJSON:true
  84. },
  85. function(json,res){
  86. //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
  87. if(res.status == 200){
  88. //关闭model
  89. vc.component.listNoAddPrivilege();
  90. vc.component.$emit('privilege_loadPrivilege',vc.component.addPrivilegeInfo._currentPgId);
  91. return ;
  92. }
  93. vc.component.addPrivilegeInfo.errorInfo = json;
  94. },
  95. function(errInfo,error){
  96. console.log('请求失败处理');
  97. vc.component.addPrivilegeInfo.errorInfo = errInfo;
  98. });
  99. },
  100. checkAll:function(e){
  101. var checkObj = document.querySelectorAll('.checkItem'); // 获取所有checkbox项
  102. if(e.target.checked){ // 判定全选checkbox的勾选状态
  103. for(var i=0;i<checkObj.length;i++){
  104. if(!checkObj[i].checked){ // 将未勾选的checkbox选项push到绑定数组中
  105. vc.component.addPrivilegeInfo.selectPrivileges.push(checkObj[i].value);
  106. }
  107. }
  108. }else { // 如果是去掉全选则清空checkbox选项绑定数组
  109. vc.component.addPrivilegeInfo.selectPrivileges = [];
  110. }
  111. }
  112. }
  113. });
  114. })(window.vc);