¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <BasicDrawer |
| | | title="é¨é¨è§è²æéé
ç½®" |
| | | :width="650" |
| | | :loading="loading" |
| | | showFooter |
| | | okText="ä¿åå¹¶å
³é" |
| | | @ok="onSubmit(true)" |
| | | @close="onClose" |
| | | @register="registerDrawer" |
| | | > |
| | | <div> |
| | | <a-spin :spinning="loading"> |
| | | <template v-if="treeData.length > 0"> |
| | | <BasicTree |
| | | title="ææ¥æçé¨é¨æé" |
| | | toolbar |
| | | checkable |
| | | :treeData="treeData" |
| | | :checkedKeys="checkedKeys" |
| | | :selectedKeys="selectedKeys" |
| | | :expandedKeys="expandedKeys" |
| | | :checkStrictly="checkStrictly" |
| | | :clickRowToExpand="false" |
| | | @check="onCheck" |
| | | @expand="onExpand" |
| | | @select="onSelect" |
| | | > |
| | | <template #title="{ slotTitle, ruleFlag }"> |
| | | <span>{{ slotTitle }}</span> |
| | | <Icon v-if="ruleFlag" icon="ant-design:align-left-outlined" style="margin-left: 5px; color: red" /> |
| | | </template> |
| | | </BasicTree> |
| | | </template> |
| | | <a-empty v-else description="æ å¯é
ç½®é¨é¨æé" /> |
| | | </a-spin> |
| | | </div> |
| | | |
| | | <template #centerFooter> |
| | | <a-button type="primary" :loading="loading" ghost @click="onSubmit(false)">ä»
ä¿å</a-button> |
| | | </template> |
| | | </BasicDrawer> |
| | | <DepartRoleDataRuleDrawer @register="registerDataRuleDrawer" /> |
| | | </template> |
| | | |
| | | <script lang="ts" setup> |
| | | import { ref } from 'vue' |
| | | |
| | | import { BasicDrawer, useDrawer, useDrawerInner } from '/@/components/Drawer' |
| | | import { BasicTree } from '/@/components/Tree/index' |
| | | import { useMessage } from '/@/hooks/web/useMessage' |
| | | |
| | | import { queryDeptRolePermission, queryTreeListForDeptRole, saveDeptRolePermission } from '../depart.user.api' |
| | | import DepartRoleDataRuleDrawer from './DepartRoleDataRuleDrawer.vue' |
| | | |
| | | defineEmits(['register']) |
| | | const { createMessage } = useMessage() |
| | | const loading = ref(false) |
| | | const departId = ref('') |
| | | const roleId = ref('') |
| | | const treeData = ref<Array<any>>([]) |
| | | const checkedKeys = ref<Array<any>>([]) |
| | | const lastCheckedKeys = ref<Array<any>>([]) |
| | | const expandedKeys = ref<Array<any>>([]) |
| | | const selectedKeys = ref<Array<any>>([]) |
| | | const allTreeKeys = ref<Array<any>>([]) |
| | | const checkStrictly = ref(true) |
| | | |
| | | // æ³¨åæ½å±ç»ä»¶ |
| | | const [registerDrawer, { closeDrawer }] = useDrawerInner((data) => { |
| | | roleId.value = data.record.id |
| | | departId.value = data.record.departId |
| | | loadData() |
| | | }) |
| | | // æ³¨åæ°æ®è§åææå¼¹çªæ½å± |
| | | const [registerDataRuleDrawer, dataRuleDrawer] = useDrawer() |
| | | |
| | | async function loadData() { |
| | | try { |
| | | loading.value = true |
| | | // ç¨æ·è§è²ææåè½ï¼æ¥è¯¢èåæéæ |
| | | const { ids, treeList } = await queryTreeListForDeptRole({ departId: departId.value }) |
| | | if (ids.length > 0) { |
| | | allTreeKeys.value = ids |
| | | expandedKeys.value = ids |
| | | treeData.value = treeList |
| | | // æ¥è¯¢è§è²ææ |
| | | checkedKeys.value = await queryDeptRolePermission({ roleId: roleId.value }) |
| | | lastCheckedKeys.value = [checkedKeys.value] |
| | | } else { |
| | | reset() |
| | | } |
| | | } finally { |
| | | loading.value = false |
| | | } |
| | | } |
| | | |
| | | // éç½®é¡µé¢ |
| | | function reset() { |
| | | treeData.value = [] |
| | | expandedKeys.value = [] |
| | | checkedKeys.value = [] |
| | | lastCheckedKeys.value = [] |
| | | loading.value = false |
| | | } |
| | | |
| | | // treeå¾éå¤éæ¡äºä»¶ |
| | | function onCheck(event) { |
| | | if (checkStrictly.value) { |
| | | checkedKeys.value = event.checked |
| | | } else { |
| | | checkedKeys.value = event |
| | | } |
| | | } |
| | | |
| | | // treeå±å¼äºä»¶ |
| | | function onExpand($expandedKeys) { |
| | | expandedKeys.value = $expandedKeys |
| | | } |
| | | |
| | | // treeéä¸äºä»¶ |
| | | function onSelect($selectedKeys, { selectedNodes }) { |
| | | if (selectedNodes[0]?.ruleFlag) { |
| | | let functionId = $selectedKeys[0] |
| | | dataRuleDrawer.openDrawer(true, { roleId, departId, functionId }) |
| | | } |
| | | selectedKeys.value = [] |
| | | } |
| | | |
| | | function doClose() { |
| | | reset() |
| | | closeDrawer() |
| | | } |
| | | |
| | | function onClose() { |
| | | reset() |
| | | } |
| | | |
| | | async function onSubmit(exit) { |
| | | try { |
| | | loading.value = true |
| | | let params = { |
| | | roleId: roleId.value, |
| | | permissionIds: checkedKeys.value.join(','), |
| | | lastpermissionIds: lastCheckedKeys.value.join(','), |
| | | } |
| | | await saveDeptRolePermission(params) |
| | | if (exit) { |
| | | doClose() |
| | | } |
| | | } finally { |
| | | loading.value = false |
| | | if (!exit) { |
| | | loadData() |
| | | } |
| | | } |
| | | } |
| | | </script> |