fix: 菜单tree修复
This commit is contained in:
@@ -1 +1 @@
|
||||
DATABASE_URL="postgresql://postgres:ultimate@81.70.149.52:8000/promise?schema=public"
|
||||
DATABASE_URL="postgresql://postgres:ultimate@81.70.149.52:8000/nestjs-admin?schema=public"
|
||||
|
||||
@@ -35,20 +35,15 @@ export class MenuService {
|
||||
});
|
||||
}
|
||||
|
||||
generatorMenu(data, parentId?: string) {
|
||||
generatorMenu(data, parentId = '-') {
|
||||
const menu = [];
|
||||
for (const item of data) {
|
||||
// 不存在父id 代表是顶级菜单
|
||||
if (!parentId) {
|
||||
menu.push(item);
|
||||
} else {
|
||||
if (item.parentId === parentId) {
|
||||
const children = this.generatorMenu(data, item.id);
|
||||
if (children.length) {
|
||||
item.children = children;
|
||||
}
|
||||
menu.push(item);
|
||||
if ((item.parentId || '-') === parentId) {
|
||||
const children = this.generatorMenu(data, item.id);
|
||||
if (children.length) {
|
||||
item.children = children;
|
||||
}
|
||||
menu.push(item);
|
||||
}
|
||||
}
|
||||
return menu;
|
||||
@@ -56,7 +51,7 @@ export class MenuService {
|
||||
|
||||
async getTreeMenu() {
|
||||
const query: Prisma.SysMenuFindManyArgs = {
|
||||
orderBy: [{ sort: 'desc' }, { id: 'asc' }],
|
||||
orderBy: [{ sort: 'desc' }, { createdAt: 'desc' }],
|
||||
};
|
||||
const list = await this.prisma.sysMenu.findMany(query);
|
||||
return this.generatorMenu(list);
|
||||
|
||||
Reference in New Issue
Block a user