角色授权操作不方便

pull/1207/merge
JEECG 2024-04-26 18:31:09 +08:00
parent 4aa4f702ba
commit 24df8d2356
2 changed files with 95 additions and 30 deletions

View File

@ -19,6 +19,7 @@
toRaw,
watch,
onMounted,
nextTick,
} from 'vue';
import TreeHeader from './components/TreeHeader.vue';
import { Tree, Spin, Empty } from 'ant-design-vue';
@ -68,6 +69,7 @@
...fieldNames,
};
});
const treeRef = ref<any>(null);
const getBindValues = computed(() => {
let propsData = {
@ -88,28 +90,35 @@
emit('update:selectedKeys', v);
},
onCheck: (v: CheckKeys, e) => {
let currentValue = toRaw(state.checkedKeys) as KeyType[];
if (isArray(currentValue) && searchState.startSearch) {
//update-begin-author:liusq---date:20230404--for: [issue/429]---
const value = e.node.eventKey;
currentValue = difference(currentValue, getChildrenKeys(value));
if (e.checked) {
currentValue.push(value);
}
//update-begin-author:liusq---date:20230404--for: [issue/429]---
state.checkedKeys = currentValue;
} else {
state.checkedKeys = v;
}
const rawVal = toRaw(state.checkedKeys);
emit('update:value', rawVal);
emit('check', rawVal, e);
handleCheck(v, e);
},
onRightClick: handleRightClick,
};
return omit(propsData, 'treeData', 'class');
});
/**
* 2024-04-26
* liaozhiyang
* issues/1151层级独立时勾选了父级然后点击层级关联子级视觉上勾选了但是保存子级没存上(把函数独立出来复用)
* */
const handleCheck = (v: CheckKeys, e?) => {
let currentValue = toRaw(state.checkedKeys) as KeyType[];
if (isArray(currentValue) && searchState.startSearch && e) {
// update-begin-author:liusq---date:20230404--for: [issue/429]---
const value = e.node.eventKey;
currentValue = difference(currentValue, getChildrenKeys(value));
if (e.checked) {
currentValue.push(value);
}
// update-begin-author:liusq---date:20230404--for: [issue/429]---
state.checkedKeys = currentValue;
} else {
state.checkedKeys = v;
}
const rawVal = toRaw(state.checkedKeys);
emit('update:value', rawVal);
emit('check', rawVal, e);
};
const getTreeData = computed((): TreeItem[] =>
searchState.startSearch ? searchState.searchData : unref(treeDataRef),
@ -317,10 +326,18 @@
emit('change', v);
},
);
watchEffect(() => {
state.checkStrictly = props.checkStrictly;
});
// update-begin--author:liaozhiyang---date:20240426---forissues/1151
watch(
() => props.checkStrictly,
() => {
state.checkStrictly = props.checkStrictly;
nextTick(() => {
const value = treeRef.value?.checkedKeys;
handleCheck([...value]);
});
}
);
// update-end--author:liaozhiyang---date:20240426---forissues/1151
const instance: TreeActionType = {
setExpandedKeys,
@ -444,7 +461,7 @@
)}
<Spin spinning={unref(props.loading)} tip="加载中...">
<ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}>
<Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value} />
<Tree ref={treeRef} {...unref(getBindValues)} showIcon={false} treeData={treeData.value} />
</ScrollContainer>
<Empty
v-show={unref(getNotFound)}

View File

@ -25,8 +25,8 @@
:checkedKeys="checkedKeys"
:expandedKeys="expandedKeys"
:selectedKeys="selectedKeys"
:checkStrictly="checkStrictly"
:clickRowToExpand="false"
:checkStrictly="true"
title="所拥有的的权限"
@check="onCheck"
@select="onTreeNodeSelect"
@ -48,8 +48,8 @@
</template>
<script lang="ts" setup>
import { ref, computed, unref, onMounted } from 'vue';
import { BasicDrawer, useDrawer, useDrawerInner } from '/src/components/Drawer';
import { BasicTree, TreeItem } from '/src/components/Tree';
import { BasicDrawer, useDrawer, useDrawerInner } from '/@/components/Drawer';
import { BasicTree, TreeItem } from '/@/components/Tree';
import { PopConfirmButton } from '/@/components/Button';
import RoleDataRuleDrawer from './RoleDataRuleDrawer.vue';
import { queryTreeListForRole, queryRolePermission, saveRolePermission } from '../role.api';
@ -60,7 +60,7 @@
//
const allTreeKeys = ref([]);
//
const checkedKeys = ref([]);
const checkedKeys = ref<any>([]);
const defaultCheckedKeys = ref([]);
//
const selectedKeys = ref([]);
@ -71,8 +71,8 @@
//key
const expandedKeys = ref<any>([]);
//
const checkStrictly = ref<boolean>(true);
// truefalse
const checkStrictly = ref<boolean>(false);
const [registerDrawer1, { openDrawer: openDataRuleDrawer }] = useDrawer();
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
await reset();
@ -114,10 +114,58 @@
}
/**
* 点击选中
* 2024-04-26
* liaozhiyang
*/
function onCheck(o) {
checkedKeys.value = o.checked ? o.checked : o;
function onCheck(o, e) {
// checkStrictly: true=>false=>.
if (checkStrictly.value) {
checkedKeys.value = o.checked ? o.checked : o;
} else {
const keys = getNodeAllKey(e.node, 'children', 'key');
if (e.checked) {
// keysnew Set
checkedKeys.value = [...new Set([...checkedKeys.value, ...keys])];
} else {
const result = removeMatchingItems(checkedKeys.value, keys);
checkedKeys.value = result;
}
}
}
/**
* 2024-04-26
* liaozhiyang
* 删除相匹配数组的项
*/
function removeMatchingItems(arr1, arr2) {
// 使 arr2
const hashTable = {};
for (const item of arr2) {
hashTable[item] = true;
}
// 使 filter
return arr1.filter((item) => !hashTable[item]);
}
/**
* 2024-04-26
* liaozhiyang
* 获取当前节点及以下所有子孙级的key
*/
function getNodeAllKey(node: any, children: any, key: string) {
const result: any = [];
result.push(node[key]);
const recursion = (data) => {
data.forEach((item: any) => {
result.push(item[key]);
if (item[children]?.length) {
recursion(item[children]);
}
});
};
node[children]?.length && recursion(node[children]);
return result;
}
/**
* 选中节点打开数据权限抽屉
*/