feat: 全局获取userinfo、数据持久化、store处理

This commit is contained in:
renxiaodong
2025-06-23 22:03:57 -04:00
parent 55198613a8
commit 59dac3bb13
10 changed files with 104 additions and 75 deletions

View File

@ -77,30 +77,33 @@ export default defineComponent({
if (appStore.device === 'desktop') appStore.updateSettings({ menuCollapse: val });
};
const renderSubMenu = () => {
function travel(_route: RouteRecordRaw[], nodes = []) {
if (Array.isArray(_route)) {
_route.forEach((element) => {
// This is demo, modify nodes as needed
const icon = element?.meta?.icon ? () => h(element?.meta?.icon as object) : null;
const node =
element?.children && element?.children.length !== 0 ? (
<a-sub-menu
key={element?.name}
v-slots={{
icon,
title: () => element?.meta?.locale || '',
}}
>
{travel(element?.children)}
</a-sub-menu>
) : (
<a-menu-item key={element?.name} v-slots={{ icon }} onClick={() => goto(element)}>
{element?.meta?.locale || ''}
</a-menu-item>
);
nodes.push(node as never);
});
}
function travel(_route: RouteRecordRaw[] = [], nodes: any[] = []) {
if (!Array.isArray(_route)) return nodes;
_route.forEach((element) => {
// 跳过没有 name 的菜单项,防止 key 报错
if (!element?.name) return;
const icon = element?.meta?.icon ? () => h(element.meta.icon as object) : null;
if (element.children && element.children.length > 0) {
nodes.push(
<a-sub-menu
key={String(element.name)}
v-slots={{
icon,
title: () => element.meta?.locale || '',
}}
>
{travel(element.children)}
</a-sub-menu>,
);
} else {
nodes.push(
<a-menu-item key={String(element.name)} v-slots={{ icon }} onClick={() => goto(element)}>
{element.meta?.locale || ''}
</a-menu-item>,
);
}
});
return nodes;
}
return travel(menuTree.value ?? []);