bdf7a9af3cf0e455c24d3067480bb452f0eaa58f.svn-base 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <a-drawer
  3. :title="title"
  4. :maskClosable="true"
  5. width=650
  6. placement="right"
  7. :closable="true"
  8. @close="close"
  9. :visible="visible"
  10. style="overflow: auto;padding-bottom: 53px;">
  11. <a-form>
  12. <a-form-item label='所拥有的部门权限'>
  13. <a-tree
  14. v-if="treeData.length>0"
  15. checkable
  16. @check="onCheck"
  17. :checkedKeys="checkedKeys"
  18. :treeData="treeData"
  19. @expand="onExpand"
  20. @select="onTreeNodeSelect"
  21. :selectedKeys="selectedKeys"
  22. :expandedKeys="expandedKeysss"
  23. :checkStrictly="checkStrictly">
  24. <span slot="hasDatarule" slot-scope="{slotTitle,ruleFlag}">
  25. {{ slotTitle }}<a-icon v-if="ruleFlag" type="align-left" style="margin-left:5px;color: red;"></a-icon>
  26. </span>
  27. </a-tree>
  28. <div v-else><h3>无可配置部门权限!</h3></div>
  29. </a-form-item>
  30. </a-form>
  31. <div class="drawer-bootom-button">
  32. <a-dropdown style="float: left" :trigger="['click']" placement="topCenter">
  33. <a-menu slot="overlay">
  34. <a-menu-item key="1" @click="switchCheckStrictly(1)">父子关联</a-menu-item>
  35. <a-menu-item key="2" @click="switchCheckStrictly(2)">取消关联</a-menu-item>
  36. <a-menu-item key="3" @click="checkALL">全部勾选</a-menu-item>
  37. <a-menu-item key="4" @click="cancelCheckALL">取消全选</a-menu-item>
  38. <a-menu-item key="5" @click="expandAll">展开所有</a-menu-item>
  39. <a-menu-item key="6" @click="closeAll">合并所有</a-menu-item>
  40. </a-menu>
  41. <a-button>
  42. 树操作 <a-icon type="up" />
  43. </a-button>
  44. </a-dropdown>
  45. <a-popconfirm title="确定放弃编辑?" @confirm="close" okText="确定" cancelText="取消">
  46. <a-button style="margin-right: .8rem">取消</a-button>
  47. </a-popconfirm>
  48. <a-button @click="handleSubmit(false)" type="primary" :loading="loading" ghost style="margin-right: 0.8rem">仅保存</a-button>
  49. <a-button @click="handleSubmit(true)" type="primary" :loading="loading">保存并关闭</a-button>
  50. </div>
  51. <dept-role-datarule-modal ref="datarule"></dept-role-datarule-modal>
  52. </a-drawer>
  53. </template>
  54. <script>
  55. import {queryTreeListForDeptRole,queryDeptRolePermission,saveDeptRolePermission} from '@/api/api'
  56. import RoleDataruleModal from './RoleDataruleModal.vue'
  57. import DeptRoleDataruleModal from './DeptRoleDataruleModal'
  58. export default {
  59. name: "DeptRoleAuthModal",
  60. components:{
  61. DeptRoleDataruleModal,
  62. RoleDataruleModal
  63. },
  64. data(){
  65. return {
  66. departId:"",
  67. roleId:"",
  68. treeData: [],
  69. defaultCheckedKeys:[],
  70. checkedKeys:[],
  71. halfCheckedKeys:[],
  72. expandedKeysss:[],
  73. allTreeKeys:[],
  74. autoExpandParent: true,
  75. checkStrictly: true,
  76. title:"部门角色权限配置",
  77. visible: false,
  78. loading: false,
  79. selectedKeys:[]
  80. }
  81. },
  82. methods: {
  83. switchCheckStrictly (v) {
  84. if(v==1){
  85. this.checkStrictly = false
  86. }else if(v==2){
  87. this.checkStrictly = true
  88. }
  89. },
  90. onTreeNodeSelect(id){
  91. if(id && id.length>0){
  92. this.selectedKeys = id
  93. }
  94. this.$refs.datarule.show(this.selectedKeys[0],this.departId,this.roleId)
  95. },
  96. onCheck (o) {
  97. if(this.checkStrictly){
  98. this.checkedKeys = o.checked;
  99. }else{
  100. this.checkedKeys = o
  101. }
  102. },
  103. show(roleId,departId){
  104. this.departId = departId
  105. this.roleId=roleId
  106. this.visible = true;
  107. },
  108. close () {
  109. this.reset()
  110. this.$emit('close');
  111. this.visible = false;
  112. },
  113. onExpand(expandedKeys){
  114. this.expandedKeysss = expandedKeys;
  115. this.autoExpandParent = false
  116. },
  117. reset () {
  118. this.expandedKeysss = []
  119. this.checkedKeys = []
  120. this.defaultCheckedKeys = []
  121. this.loading = false
  122. },
  123. expandAll () {
  124. this.expandedKeysss = this.allTreeKeys
  125. },
  126. closeAll () {
  127. this.expandedKeysss = []
  128. },
  129. checkALL () {
  130. this.checkedKeys = this.allTreeKeys
  131. },
  132. cancelCheckALL () {
  133. this.checkedKeys = []
  134. },
  135. handleCancel () {
  136. this.close()
  137. },
  138. handleSubmit(exit) {
  139. let that = this;
  140. let params = {
  141. roleId:that.roleId,
  142. permissionIds:that.checkedKeys.join(","),
  143. lastpermissionIds:that.defaultCheckedKeys.join(","),
  144. };
  145. that.loading = true;
  146. console.log("请求参数:",params);
  147. saveDeptRolePermission(params).then((res)=>{
  148. if(res.success){
  149. that.$message.success(res.message);
  150. that.loading = false;
  151. if (exit) {
  152. that.close()
  153. }
  154. }else {
  155. that.$message.error(res.message);
  156. that.loading = false;
  157. if (exit) {
  158. that.close()
  159. }
  160. }
  161. this.loadData();
  162. })
  163. },
  164. convertTreeListToKeyLeafPairs(treeList, keyLeafPair = []) {
  165. for(const {key, isLeaf, children} of treeList) {
  166. keyLeafPair.push({key, isLeaf})
  167. if(children && children.length > 0) {
  168. this.convertTreeListToKeyLeafPairs(children, keyLeafPair)
  169. }
  170. }
  171. return keyLeafPair;
  172. },
  173. loadData(){
  174. queryTreeListForDeptRole({departId:this.departId}).then((res) => {
  175. this.treeData = res.result.treeList
  176. this.allTreeKeys = res.result.ids
  177. queryDeptRolePermission({roleId:this.roleId}).then((res)=>{
  178. this.checkedKeys = [...res.result];
  179. this.defaultCheckedKeys = [...res.result];
  180. this.expandedKeysss = this.allTreeKeys;
  181. })
  182. })
  183. }
  184. },
  185. watch: {
  186. visible () {
  187. if (this.visible ) {
  188. this.loadData();
  189. }
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="less" scoped>
  195. .drawer-bootom-button {
  196. position: absolute;
  197. bottom: 0;
  198. width: 100%;
  199. border-top: 1px solid #e8e8e8;
  200. padding: 10px 16px;
  201. text-align: right;
  202. left: 0;
  203. background: #fff;
  204. border-radius: 0 0 2px 2px;
  205. }
  206. </style>