f113e2bdc9fd1515a289197f20b69979b32b6aef.svn-base 5.6 KB

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