-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
270 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,102 @@ | ||
<script setup lang="ts"> | ||
import { ElIcon, ElMenuItem, ElSubMenu } from 'element-plus'; | ||
import { ElIcon, ElMenuItem, ElSubMenu } from "element-plus"; | ||
import { h, ref } from "vue"; | ||
import { Icon } from "@iconify/vue"; | ||
import { Document, Folder } from '@element-plus/icons-vue'; | ||
import { Document, Folder } from "@element-plus/icons-vue"; | ||
import { useSettingStore } from "@/stores/setting"; | ||
import { useUserStore } from "@/stores/user"; | ||
const userStore = useUserStore(); | ||
const settingStore = useSettingStore(); | ||
export interface MenuItem { | ||
name: string, | ||
route_path: string, | ||
icon: string, | ||
[props: string]: any | ||
name: string; | ||
route_path: string; | ||
icon: string; | ||
[props: string]: any; | ||
} | ||
const model = defineModel<Array<MenuItem>>({ required: true }) | ||
const model = defineModel<Array<MenuItem>>({ required: true }); | ||
interface Props { | ||
option: any[] | ||
option: any[]; | ||
} | ||
const collapse = ref<boolean>(false); | ||
const activeMenu = ref<string>("/console") | ||
const TreeMenu = (props: Props, ctx?: any) => { | ||
return props.option.map((item) => { | ||
if (item.children?.length) { | ||
return h(ElSubMenu, { | ||
index: item.route_path || item.id.toString() | ||
}, { | ||
default: () => { | ||
const childNode = TreeMenu({ option: item.children }); | ||
return childNode; | ||
}, | ||
title: () => [h(ElIcon, null, () => { | ||
if (item.icon) { | ||
return h(Icon, { icon: item.icon }); | ||
} else { | ||
return h(Folder) | ||
} | ||
}), h("span", item.name)] | ||
}) | ||
} | ||
return h(ElMenuItem, { | ||
index: item.route_path | ||
}, () => [h(ElIcon, null, () => { | ||
if (item.icon) { | ||
return props.option.map((item) => { | ||
if (item.children?.length) { | ||
return h( | ||
ElSubMenu, | ||
{ | ||
index: item.route_path || item.id.toString(), | ||
}, | ||
{ | ||
default: () => { | ||
const childNode = TreeMenu({ option: item.children }); | ||
return childNode; | ||
}, | ||
title: () => [ | ||
h(ElIcon, null, () => { | ||
if (item.icon) { | ||
return h(Icon, { icon: item.icon }); | ||
} else { | ||
return h(Document) | ||
} | ||
}), h("span", null, item.name)]); | ||
}) | ||
} | ||
} else { | ||
return h(Folder); | ||
} | ||
}), | ||
h("span", item.name), | ||
], | ||
} | ||
); | ||
} | ||
return h( | ||
ElMenuItem, | ||
{ | ||
index: item.route_path, | ||
}, | ||
() => [ | ||
h(ElIcon, null, () => { | ||
if (item.icon) { | ||
return h(Icon, { icon: item.icon }); | ||
} else { | ||
return h(Document); | ||
} | ||
}), | ||
h("span", null, item.name), | ||
] | ||
); | ||
}); | ||
}; | ||
const handleOpen = (param) => { | ||
console.log(param); | ||
}; | ||
const handleSelect = (index, path, item) => { | ||
const navIndex = userStore.navigator.findIndex( | ||
(item) => item.route_path == index | ||
); | ||
userStore.navigator[navIndex]["active"] = true; | ||
console.log(userStore.navigator); | ||
}; | ||
</script> | ||
<template> | ||
<ElMenu active-text-color="#ffd04b" background-color="#00000" :collapse="collapse" | ||
:class="collapse ? 'collapse' : 'layout-menu'" class="layout-menu" :default-active="activeMenu" | ||
text-color="#fff" unique-opened router> | ||
<TreeMenu :option="model"></TreeMenu> | ||
</ElMenu> | ||
<ElMenu | ||
active-text-color="#ffd04b" | ||
background-color="#00000" | ||
:collapse="collapse" | ||
:class="collapse ? 'collapse' : 'layout-menu'" | ||
@open="handleOpen" | ||
@select="handleSelect" | ||
class="layout-menu" | ||
:default-active="settingStore.activeURL" | ||
text-color="#fff" | ||
unique-opened | ||
router | ||
> | ||
<TreeMenu :option="model"></TreeMenu> | ||
</ElMenu> | ||
</template> | ||
<style lang="scss" scoped> | ||
.el-menu { | ||
border: none; | ||
border: none; | ||
} | ||
.layout-menu { | ||
width: 220px; | ||
width: 220px; | ||
} | ||
</style> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.