1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<script>
import { Menu, Icon, Spin } from "ant-design-vue";
import { mapGetters } from "vuex";
// Conversion router to menu.
export default {
props: {
collapsed: { default: false, type: Boolean },
theme: { default: "dark", type: String },
layout: { type: String },
mode: { default: "inline", type: String },
menuData: { default: () => [], type: Array },
styles: { type: String },
},
computed: {
...mapGetters({
loading: "global/nav/loading",
}),
},
components: {
AMenu: Menu,
AMenuItem: Menu.Item,
ASubMenu: Menu.SubMenu,
AMenuDivider: Menu.Divider,
AMenuItemGroup: Menu.ItemGroup,
AIcon: Icon,
},
methods: {
getIcon(icon) {
if (typeof icon === "string" && icon.indexOf("http") === 0) {
return <img src={icon} alt="icon" class="icon" />;
}
if (typeof icon === "string") {
return <a-icon type={icon} />;
}
// if(!icon){
// return <a-icon type='profile' />;
// }
return icon;
},
getNavMenuItems(menusData, parent) {
// console.log(menusData)
if (!menusData) {
return [];
}
return menusData.map((item) => {
if (item.name) {
return this.getSubMenuOrItem(item, parent);
}
if (item.menus) {
return this.getNavMenuItems(item.menus, parent);
}
});
},
getSubMenuOrItem(item) {
// doc: add hideChildrenInMenu 隐藏菜单
if (item.menus && item.menus.some((menu) => menu.name)) {
const name = this.$t(item.locale);
return (
<a-sub-menu
title={
item.icon ? (
<span>
{this.getIcon(item.icon)}
<span>{name}</span>
</span>
) : (
name
)
}
key={item.path}
>
{this.getNavMenuItems(item.menus)}
</a-sub-menu>
);
}
return (
<a-menu-item key={item.path}>{this.getMenuItemPath(item)}</a-menu-item>
);
},
getMenuItemPath(item) {
const name = this.$t(item.locale);
const itemPath = this.conversionPath(item.path);
const icon = this.getIcon(item.icon);
// // Is it a http link
if (/^https?:\/\//.test(itemPath)) {
return (
<a href={itemPath}>
{icon}
<span>{name}</span>
</a>
);
}
return (
<router-link to={itemPath}>
{icon}
<span>{name}</span>
</router-link>
);
},
conversionPath(path) {
if (path && path.indexOf("http") === 0) {
return path;
}
return `/${path || ""}`.replace(/\/+/g, "/");
},
urlToList(url) {
const urllist = url.split("/").filter((i) => i);
return urllist.map(
(urlItem, index) => `/${urllist.slice(0, index + 1).join("/")}`
);
},
getOpenKeys(path) {
const openKeys = this.urlToList(path);
if (this.layout === "topmenu") {
return null;
}
return openKeys.filter((item) => item !== path);
},
},
render() {
const { path } = this.$route;
const openKeys = this.getOpenKeys(path);
return (
<Spin spinning={this.loading} class="baseMenuLoadding">
<a-menu
defaultOpenKeys={openKeys}
selectedKeys={[path]}
key="Menu"
mode={this.mode}
theme={this.theme}
collapsed={this.collapsed}
style={this.styles}
>
{this.getNavMenuItems(this.menuData)}
</a-menu>
</Spin>
);
},
};
</script>