fix(components): 修复菜单选择标签渲染问题

This commit is contained in:
xlsea
2025-06-18 23:48:49 +08:00
parent 8c84063ad1
commit 6e6cc4d91f
4 changed files with 33 additions and 8 deletions

View File

@ -1,18 +1,22 @@
<script setup lang="tsx">
import { useAttrs } from 'vue';
import { onMounted, useAttrs } from 'vue';
import type { TreeOption, TreeSelectProps } from 'naive-ui';
import { useLoading } from '@sa/hooks';
import { fetchGetMenuList } from '@/service/api/system';
import { handleTree } from '@/utils/common';
import SvgIcon from '@/components/custom/svg-icon.vue';
import { $t } from '@/locales';
defineOptions({ name: 'MenuTreeSelect' });
interface Props {
immediate?: boolean;
[key: string]: any;
}
defineProps<Props>();
const props = withDefaults(defineProps<Props>(), {
immediate: true
});
const value = defineModel<CommonType.IdType | null>('value', { required: false });
const options = defineModel<Api.System.MenuList>('options', { required: false, default: [] });
@ -35,7 +39,19 @@ async function getMenuList() {
endLoading();
}
getMenuList();
onMounted(() => {
if (props.immediate) {
getMenuList();
}
});
function renderLabel({ option }: { option: TreeOption }) {
let label = String(option.menuName);
if (label?.startsWith('route.') || label?.startsWith('menu.')) {
label = $t(label as App.I18n.I18nKey);
}
return <div>{label}</div>;
}
function renderPrefix({ option }: { option: TreeOption }) {
const renderLocalIcon = String(option.icon).startsWith('local-icon-');
@ -55,6 +71,8 @@ function renderPrefix({ option }: { option: TreeOption }) {
label-field="menuName"
:options="options"
:default-expanded-keys="[0]"
:render-tag="renderLabel"
:render-label="renderLabel"
:render-prefix="renderPrefix"
v-bind="attrs"
/>