¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <a-card :bordered="false"> |
| | | <template v-if="this.departId"> |
| | | <a-spin :spinning="loading"> |
| | | <a-form> |
| | | <a-form-item label='ææ¥æçæé'> |
| | | <a-tree |
| | | checkable |
| | | @check="onCheck" |
| | | :checkedKeys="checkedKeys" |
| | | :treeData="treeData" |
| | | @expand="onExpand" |
| | | @select="onTreeNodeSelect" |
| | | :selectedKeys="selectedKeys" |
| | | :expandedKeys="expandedKeysss" |
| | | :checkStrictly="checkStrictly" |
| | | style="height:500px;overflow: auto;"> |
| | | <span slot="hasDatarule" slot-scope="{slotTitle,ruleFlag}"> |
| | | {{ slotTitle }} |
| | | <a-icon v-if="ruleFlag" type="align-left" style="margin-left:5px;color: red;"></a-icon> |
| | | </span> |
| | | </a-tree> |
| | | </a-form-item> |
| | | </a-form> |
| | | </a-spin> |
| | | <div class="anty-form-btn"> |
| | | <a-dropdown style="float: left" :trigger="['click']" placement="topCenter"> |
| | | <a-menu slot="overlay"> |
| | | <!-- ç®åTreeé»è¾ï¼ä½¿ç¨é»è®¤checkStrictly为falseçè¡ä¸ºï¼å³é»è®¤ç¶åå
³è |
| | | <a-menu-item key="1" @click="switchCheckStrictly(1)">ç¶åå
³è</a-menu-item> |
| | | <a-menu-item key="2" @click="switchCheckStrictly(2)">åæ¶å
³è</a-menu-item> |
| | | --> |
| | | <a-menu-item key="3" @click="checkALL">å
¨é¨å¾é</a-menu-item> |
| | | <a-menu-item key="4" @click="cancelCheckALL">åæ¶å
¨é</a-menu-item> |
| | | <a-menu-item key="5" @click="expandAll">å±å¼ææ</a-menu-item> |
| | | <a-menu-item key="6" @click="closeAll">åå¹¶ææ</a-menu-item> |
| | | </a-menu> |
| | | <a-button> |
| | | æ æä½ <a-icon type="up" /> |
| | | </a-button> |
| | | </a-dropdown> |
| | | <a-button style="float: right" @click="handleSubmit" type="primary" htmlType="button" icon="form">ä¿å</a-button> |
| | | </div> |
| | | </template> |
| | | <a-card v-else :bordered="false" style="height:200px"> |
| | | <a-empty> |
| | | <span slot="description"> 请å
éæ©ä¸ä¸ªé¨é¨! </span> |
| | | </a-empty> |
| | | </a-card> |
| | | <depart-datarule-modal ref="datarule"/> |
| | | </a-card> |
| | | </template> |
| | | |
| | | <script> |
| | | import {queryTreeListForRole,queryDepartPermission,saveDepartPermission} from '@/api/api' |
| | | import DepartDataruleModal from './DepartDataruleModal' |
| | | |
| | | export default { |
| | | name: 'DepartAuthModal', |
| | | components: { DepartDataruleModal }, |
| | | data(){ |
| | | return { |
| | | departId:"", |
| | | treeData: [], |
| | | defaultCheckedKeys:[], |
| | | checkedKeys:[], |
| | | halfCheckedKeys:[], |
| | | expandedKeysss:[], |
| | | allTreeKeys:[], |
| | | autoExpandParent: true, |
| | | checkStrictly: false, |
| | | title:"é¨é¨æéé
ç½®", |
| | | visible: false, |
| | | loading: false, |
| | | selectedKeys:[] |
| | | } |
| | | }, |
| | | methods: { |
| | | onTreeNodeSelect(id){ |
| | | if(id && id.length>0){ |
| | | this.selectedKeys = id |
| | | } |
| | | this.$refs.datarule.show(this.selectedKeys[0],this.departId) |
| | | }, |
| | | onCheck (checkedKeys, { halfCheckedKeys }) { |
| | | // ä¿åéä¸çååéä¸çï¼åé¢ä¿åçæ¶ååå¹¶æäº¤ |
| | | this.checkedKeys = checkedKeys |
| | | this.halfCheckedKeys = halfCheckedKeys |
| | | }, |
| | | show(departId){ |
| | | this.departId=departId |
| | | this.loadData(); |
| | | }, |
| | | close () { |
| | | this.reset() |
| | | this.$emit('close'); |
| | | this.visible = false; |
| | | }, |
| | | onExpand(expandedKeys){ |
| | | this.expandedKeysss = expandedKeys; |
| | | this.autoExpandParent = false |
| | | }, |
| | | reset () { |
| | | this.expandedKeysss = [] |
| | | this.checkedKeys = [] |
| | | this.defaultCheckedKeys = [] |
| | | this.loading = false |
| | | }, |
| | | expandAll () { |
| | | this.expandedKeysss = this.allTreeKeys |
| | | }, |
| | | closeAll () { |
| | | this.expandedKeysss = [] |
| | | }, |
| | | checkALL () { |
| | | this.checkedKeys = this.allTreeKeys |
| | | }, |
| | | cancelCheckALL () { |
| | | this.checkedKeys = [] |
| | | }, |
| | | handleCancel () { |
| | | this.close() |
| | | }, |
| | | handleSubmit() { |
| | | let that = this; |
| | | if(!that.departId){ |
| | | this.$message.warning('请ç¹å»éæ©ä¸ä¸ªé¨é¨!') |
| | | } |
| | | let checkedKeys = [...that.checkedKeys, ...that.halfCheckedKeys] |
| | | const permissionIds = checkedKeys.join(",") |
| | | let params = { |
| | | departId:that.departId, |
| | | permissionIds, |
| | | lastpermissionIds:that.defaultCheckedKeys.join(","), |
| | | }; |
| | | that.loading = true; |
| | | saveDepartPermission(params).then((res)=>{ |
| | | if(res.success){ |
| | | // that.$message.success(res.message); |
| | | that.$notification.warning({ |
| | | message:'æ¶æ¯', |
| | | description:res.message |
| | | }); |
| | | that.loading = false; |
| | | that.loadData(); |
| | | }else { |
| | | // that.$message.error(res.message); |
| | | that.$notification.warning({ |
| | | message:'æ¶æ¯', |
| | | description:res.message |
| | | }); |
| | | that.loading = false; |
| | | } |
| | | }) |
| | | }, |
| | | convertTreeListToKeyLeafPairs(treeList, keyLeafPair = []) { |
| | | for(const {key, isLeaf, children} of treeList) { |
| | | keyLeafPair.push({key, isLeaf}) |
| | | if(children && children.length > 0) { |
| | | this.convertTreeListToKeyLeafPairs(children, keyLeafPair) |
| | | } |
| | | } |
| | | return keyLeafPair; |
| | | }, |
| | | emptyCurrForm() { |
| | | this.form.resetFields() |
| | | }, |
| | | loadData(){ |
| | | this.loading = true; |
| | | queryTreeListForRole().then((res) => { |
| | | this.treeData = res.result.treeList |
| | | this.allTreeKeys = res.result.ids |
| | | const keyLeafPairs = this.convertTreeListToKeyLeafPairs(this.treeData) |
| | | queryDepartPermission({departId:this.departId}).then((res)=>{ |
| | | // è¿æ»¤åº leaf node å³å¯ï¼å³éä¸ç |
| | | // Treeç»ä»¶ä¸checkStrictlyé»è®¤ä¸ºfalseçæ¶åï¼éä¸åèç¹ï¼ç¶èç¹ä¼èªå¨è®¾ç½®é䏿åéä¸ |
| | | // ä¿å checkedKeys 以å halfCheckedKeys ä»¥ä¾¿äºæªå任使使¶æäº¤è¡¨åæ°æ® |
| | | const checkedKeys = [...res.result].filter(key => { |
| | | const keyLeafPair = keyLeafPairs.filter(item => item.key === key)[0] |
| | | return keyLeafPair && keyLeafPair.isLeaf |
| | | }) |
| | | const halfCheckedKeys = [...res.result].filter(key => { |
| | | const keyLeafPair = keyLeafPairs.filter(item => item.key === key)[0] |
| | | return keyLeafPair && !keyLeafPair.isLeaf |
| | | }) |
| | | this.checkedKeys = [...checkedKeys]; |
| | | this.halfCheckedKeys = [...halfCheckedKeys] |
| | | this.defaultCheckedKeys = [...halfCheckedKeys, ...checkedKeys]; |
| | | this.expandedKeysss = this.allTreeKeys; |
| | | this.loading = false; |
| | | }) |
| | | }) |
| | | } |
| | | }, |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | |
| | | </style> |