-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Resource authorization selection directory checkbox Cancel optimization #4253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ | |
| ref="multipleTableRef" | ||
| class="mt-16" | ||
| :data="filteredData" | ||
| @selection-change="handleSelectionChange" | ||
| @select="select" | ||
| :maxTableHeight="260" | ||
| :row-key="(row: any) => row.id" | ||
| :expand-row-keys="defaultExpandKeys" | ||
|
|
@@ -147,6 +147,7 @@ import { hasPermission } from '@/utils/permission/index' | |
| import { ComplexPermission } from '@/utils/permission/type' | ||
| import { getPermissionOptions } from '@/views/system/resource-authorization/constant' | ||
| import useStore from '@/stores' | ||
| import { TreeToFlatten } from '@/utils/array' | ||
|
|
||
| const { model, user } = useStore() | ||
| const route = useRoute() | ||
|
|
@@ -310,11 +311,33 @@ const filteredData = computed(() => { | |
| }) | ||
|
|
||
| const multipleSelection = ref<any[]>([]) | ||
| const selectObj: any = {} | ||
| const select = (val: any[], active: any) => { | ||
| if (active.resource_type === 'folder') { | ||
| if (!val.some((item) => item.id == active.id)) { | ||
| if (selectObj[active.id] === undefined) { | ||
| selectObj[active.id] = 0 | ||
| } | ||
| if (selectObj[active.id] % 2 == 0) { | ||
| console.log(TreeToFlatten([active])) | ||
| TreeToFlatten([active]) | ||
| .filter((item: any) => item.id != active.id) | ||
| .forEach((item: any) => { | ||
| multipleTableRef.value?.toggleRowSelection(item, true) | ||
| }) | ||
|
|
||
| const handleSelectionChange = (val: any[]) => { | ||
| multipleSelection.value = val | ||
| multipleSelection.value = multipleTableRef.value.getSelectionRows() | ||
| } else { | ||
| multipleSelection.value = val | ||
| } | ||
| selectObj[active.id] = selectObj[active.id] + 1 | ||
| } else { | ||
| multipleSelection.value = val | ||
| } | ||
| } else { | ||
| multipleSelection.value = val | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code appears to be mostly well-written, but there are a few areas that could potentially benefit from improvements:
Here's an updated version with some of these suggestions applied: @@ -55,7 +55,7 @@
ref="multipleTableRef"
class="mt-16"
:data="filteredData"
- @selection-change="handleSelectionChange"
+ @select="handleSelect"
:max-table-height="260"
:row-key="(row: any) => row.id"
:expand-row-keys="defaultExpandKeys"
@@ -310,21 +311,35 @@ const filteredData = computed(() => {
})
const multipleSelection = ref([])
+const selectedFoldersWithAllChildrenSelected = new WeakMap(); // Use WeakMap instead of plain object
+function handleSelect(val: any[], active: any) {
if (active.resource_type === 'folder' && active.child_count > 0) {
if (!val.some(item => item.id === active.id)) {
let childIds = getAllChildIds(active.children);
+ if (!selectedFoldersWithAllChildrenSelected.has(active.id)) {
+ selectedFoldersWithAllChildrenSelected.set(active.id, [...childIds]);
+ }
console.log(childIds);
- childIds.forEach(item => {
- multipleTableRef.value.toggleRowSelection(this.$refs.multipleTableRef.rows.find(row => row.id === item), true);
- });
+ val.push(...childIds.map(id => multipleTableRef.value.getRowById(id)));
} else if (selectedFoldersWithAllChildrenSelected.get(active.id).length !== childIds.length) {
selectedFoldersWithAllChildrenSelected.delete(active.id);
val.forEach(item => { multipleTableRef.value.toggleRowSelection(item, false); });
+ val.push(...childIds.map(id => multipleTableRef.value.getRowById(id)));
}
multipleSelection.value = val;
return;
}
}
+ const expandedFolderIds: string[] = [];
+ Object.entries(selectedFoldersWithAllChildrenSelected).forEach(([key, children]) => {
+ const expandedIndex = multipleTableRef.value.expanded.indexOf(Number(key));
+ if (expandedIndex === -1) {
+ multipleTableRef.value.expandRowByKey(Number(key));
+ expandedFolderIds.push(Number(key));
+ }
+ });
multipleSelection.value = val.filter((item) => !children.includes(String(item.id)))
}Explanation Changes:
|
||
| } | ||
|
|
||
| const dialogVisible = ref(false) | ||
| const radioPermission = ref('') | ||
| function openMulConfigureDialog() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code is generally clean and well-structured. Here are some minor improvements and clarifications:
pageSizesin the first line of the<el-pagination>tag. Remove it to ensure proper syntax.Optimizations and Suggestions
handleSizeChangejust to call another function (handleCurrentChange). You can directly pass the event handler without defining an additional function.Here’s the revised version with these adjustments:
These changes make your code slightly more concise and align better with Vue.js conventions.