fix: 修复菜单配置无法调整顺序的问题

This commit is contained in:
xieyonghong 2023-04-28 17:20:18 +08:00
parent 7ae187ba63
commit 3fb2b4b956
2 changed files with 39 additions and 22 deletions

View File

@ -10,6 +10,7 @@
<div class="content"> <div class="content">
<j-card title="菜单配置" style="width: 80%"> <j-card title="菜单配置" style="width: 80%">
<div class="tree"> <div class="tree">
<j-scrollbar>
<j-tree <j-tree
v-if="treeData.length !== 0" v-if="treeData.length !== 0"
show-line show-line
@ -17,7 +18,6 @@
multiple multiple
draggable draggable
:tree-data="treeData" :tree-data="treeData"
:height="520"
@select="onSelect" @select="onSelect"
:selectedKeys="selectedKeys" :selectedKeys="selectedKeys"
@drop="onDrop" @drop="onDrop"
@ -34,6 +34,7 @@
</div> </div>
</template> </template>
</j-tree> </j-tree>
</j-scrollbar>
</div> </div>
</j-card> </j-card>
</div> </div>
@ -70,6 +71,7 @@ import {
getMaxDepth, getMaxDepth,
mergeArr, mergeArr,
findAllParentsAndChildren, findAllParentsAndChildren,
handleSorts
} from './utils'; } from './utils';
import BaseMenu from '@/views/init-home/data/baseMenu'; import BaseMenu from '@/views/init-home/data/baseMenu';
import type { AntTreeNodeDropEvent } from 'ant-design-vue/es/tree'; import type { AntTreeNodeDropEvent } from 'ant-design-vue/es/tree';
@ -134,9 +136,9 @@ function filterTree(nodes: Array<any>, selectedKeys: Array<any>) {
const handleOk = async () => { const handleOk = async () => {
const _dataArr = filterTree(cloneDeep(treeData.value), selectedKeys.value); const _dataArr = filterTree(cloneDeep(treeData.value), selectedKeys.value);
const _dataSorts = handleSorts(_dataArr)
loading.value = true; loading.value = true;
const res = await updateMenus(_dataArr).catch(() => {}); const res = await updateMenus(_dataSorts).catch(() => {});
if (res?.status === 200) { if (res?.status === 200) {
onlyMessage('操作成功', 'success'); onlyMessage('操作成功', 'success');
} }
@ -260,6 +262,7 @@ onMounted(() => {
border-radius: 4px; border-radius: 4px;
overflow: hidden; overflow: hidden;
width: 100%; width: 100%;
height: 540px;
&-content { &-content {
display: flex; display: flex;

View File

@ -304,3 +304,17 @@ export const getNodeDepth = (node: any) => {
} }
return depth; return depth;
}; };
export const handleSorts = (node: any[]) => {
if (!node) return []
return node.map((item, index) => {
if (item.index !== index) {
item.sortIndex = index
if (item.children) {
item.children = handleSorts(item.children)
}
}
return item
})
}