feat: add setup primary menu support (#684)

#### What type of PR is this?

/kind feature
/milestone 2.0

#### What this PR does / why we need it:

支持设置主菜单。 适配 https://github.com/halo-dev/halo/pull/2667

#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/2533

#### Screenshots:

<img width="503" alt="image" src="https://user-images.githubusercontent.com/21301288/200283150-1292821e-ad4b-4909-865b-fcdba94ae4c2.png">

#### Special notes for your reviewer:

/cc @halo-dev/sig-halo-console 

测试方式:

1. Halo 需要使用 https://github.com/halo-dev/halo/pull/2667 分支。
2. 在 Console 的菜单管理新建若干个菜单。
3. 选择一个菜单点击更多按钮,再点击设置为主菜单按钮,检查是否生效。

#### Does this PR introduce a user-facing change?

```release-note
菜单管理支持设置主菜单。 
```
pull/687/head
Ryan Wang 2 years ago committed by GitHub
parent e0ca6186ab
commit e93a6fbb4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@ import {
VStatusDot,
VEntity,
VEntityField,
VTag,
} from "@halo-dev/components";
import MenuEditingModal from "./MenuEditingModal.vue";
import { onMounted, onUnmounted, ref } from "vue";
@ -142,6 +143,44 @@ onMounted(async () => {
defineExpose({
handleFetchMenus,
});
// primary menu
const primaryMenuName = ref<string>();
const handleFetchPrimaryMenuName = async () => {
const { data } = await apiClient.extension.configMap.getv1alpha1ConfigMap({
name: "system",
});
if (!data.data?.menu) {
return;
}
const menuConfig = JSON.parse(data.data.menu);
primaryMenuName.value = menuConfig.primary;
};
const handleSetPrimaryMenu = async (menu: Menu) => {
const { data: systemConfigMap } =
await apiClient.extension.configMap.getv1alpha1ConfigMap({
name: "system",
});
if (systemConfigMap.data) {
const menuConfigToUpdate = JSON.parse(systemConfigMap.data?.menu || "{}");
menuConfigToUpdate.primary = menu.metadata.name;
systemConfigMap.data["menu"] = JSON.stringify(menuConfigToUpdate);
await apiClient.extension.configMap.updatev1alpha1ConfigMap({
name: "system",
configMap: systemConfigMap,
});
}
await handleFetchPrimaryMenuName();
};
onMounted(handleFetchPrimaryMenuName);
</script>
<template>
<MenuEditingModal
@ -175,7 +214,11 @@ defineExpose({
<VEntityField
:title="menu.spec?.displayName"
:description="`${menu.spec.menuItems?.length || 0} 个菜单项`"
></VEntityField>
>
<template v-if="menu.metadata.name === primaryMenuName" #extra>
<VTag>主菜单</VTag>
</template>
</VEntityField>
</template>
<template #end>
<VEntityField v-if="menu.metadata.deletionTimestamp">
@ -192,6 +235,14 @@ defineExpose({
v-close-popper
block
type="secondary"
@click="handleSetPrimaryMenu(menu)"
>
设置为主菜单
</VButton>
<VButton
v-close-popper
block
type="default"
@click="handleOpenEditingModal(menu)"
>
修改

@ -10,5 +10,5 @@
},
"apiVersion": "v1alpha1",
"kind": "Menu",
"metadata": { "name": "2f0ef354-6f8f-40b9-b41d-2163f3e51b4f" }
"metadata": { "name": "primary" }
}

Loading…
Cancel
Save