11<script lang="ts">
2- import { h } from ' vue'
2+ import { h , defineComponent } from ' vue'
33import { ElMenuItem , ElSubMenu , ElIcon } from ' element-plus-secondary'
44
55import model from ' @/assets/svg/icon_dataset_filled.svg'
66import ds from ' @/assets/svg/ds.svg'
7-
7+ import dashboard from ' @/assets/svg/dashboard.svg'
8+ import chat from ' @/assets/svg/chat.svg'
9+ import icon_user from ' @/assets/svg/icon_user.svg'
10+ import { useRouter } from ' vue-router'
811const iconMap = {
912 icon_ai: model ,
1013 ds ,
14+ dashboard ,
15+ chat ,
16+ icon_user: icon_user ,
1117} as { [key : string ]: any }
1218
1319const titleWithIcon = (props : any ) => {
@@ -17,16 +23,64 @@ const titleWithIcon = (props: any) => {
1723 h (' span' , null , { default : () => title }),
1824 ]
1925}
26+ const MenuItem = defineComponent ({
27+ name: ' MenuItem' ,
28+ props: {
29+ menu: {
30+ type: Object ,
31+ required: true ,
32+ },
33+ },
34+ setup(props ) {
35+ const router = useRouter ()
36+
37+ const handleMenuClick = (e : any ) => {
38+ router .push (e .index )
39+ }
40+
41+ return () => {
42+ const { children, hidden, path } = props .menu
43+ if (hidden ) {
44+ return null
45+ }
2046
21- const MenuItem = (props : any ) => {
47+ if (children ?.length ) {
48+ return h (
49+ ElSubMenu ,
50+ { index: path , onClick : (e : any ) => handleMenuClick (e ) },
51+ {
52+ title : () => titleWithIcon (props ),
53+ default : () => children .map ((ele : any ) => h (MenuItem , { menu: ele })),
54+ }
55+ )
56+ }
57+
58+ const { title, icon } = props .menu ?.meta || {}
59+ const iconCom: any = iconMap [icon ] ? ElIcon : null
60+ return h (
61+ ElMenuItem ,
62+ { index: path , onClick : (e : any ) => handleMenuClick (e ) },
63+ {
64+ default : () => [
65+ h (iconCom , null , {
66+ default : () => h (iconMap [icon ]),
67+ }),
68+ h (' span' , null , { default : () => title }),
69+ ],
70+ }
71+ )
72+ }
73+ },
74+ })
75+ /* const MenuItem = (props: any) => {
2276 const { children, hidden, path } = props.menu
2377 if (hidden) {
2478 return null
2579 }
2680 if (children?.length) {
2781 return h(
2882 ElSubMenu,
29- { index: path },
83+ { index: path, onClick: (e: any) => handleMenuClick(e) },
3084 {
3185 title: () => titleWithIcon(props),
3286 default: () => children.map((ele: any) => h(MenuItem, { menu: ele })),
@@ -37,14 +91,14 @@ const MenuItem = (props: any) => {
3791 const iconCom: any = iconMap[icon] ? ElIcon : null
3892 return h(
3993 ElMenuItem,
40- { index: path },
94+ { index: path, onClick: (e: any) => handleMenuClick(e) },
4195 {
4296 title: h('span', null, { default: () => title }),
4397 default: h(iconCom, null, {
4498 default: () => h(iconMap[icon]),
4599 }),
46100 }
47101 )
48- }
102+ } */
49103export default MenuItem
50104 </script >
0 commit comments