feat: 左侧菜单新增「授权应用」分组,收纳全部受控工具
This commit is contained in:
1 parent
23944ced8c
commit
10b9df668b
1 file changed
+29
-4
@@ -4,6 +4,7 @@ import { useThemeVars } from 'naive-ui';
|
||||
import { RouterLink, useRoute } from 'vue-router';
|
||||
import MenuIconItem from './MenuIconItem.vue';
|
||||
import type { Tool, ToolCategory } from '@/tools/tools.types';
|
||||
import { PROTECTED_TOOLS } from '@/tools/license/license';
|
||||
|
||||
const props = withDefaults(defineProps<{ toolsByCategory?: ToolCategory[] }>(), { toolsByCategory: () => [] });
|
||||
const { toolsByCategory } = toRefs(props);
|
||||
@@ -45,8 +46,25 @@ function collapseAll() {
|
||||
collapsedCategories.value = m;
|
||||
}
|
||||
|
||||
const menuOptions = computed(() =>
|
||||
toolsByCategory.value.map(({ name, components }) => ({
|
||||
const PAID_GROUP_NAME = '授权应用';
|
||||
|
||||
const menuOptions = computed(() => {
|
||||
// pull licensed tools out of their original categories
|
||||
const paidTools: Tool[] = [];
|
||||
const remaining = toolsByCategory.value
|
||||
.map(({ name, components }) => ({
|
||||
name,
|
||||
components: components.filter((tool) => {
|
||||
if (tool.path in PROTECTED_TOOLS) {
|
||||
paidTools.push(tool);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
}))
|
||||
.filter(({ components }) => components.length > 0);
|
||||
|
||||
const toOption = (name: string, components: Tool[]) => ({
|
||||
name,
|
||||
isCollapsed: collapsedCategories.value[name],
|
||||
tools: components.map(tool => ({
|
||||
@@ -54,8 +72,15 @@ const menuOptions = computed(() =>
|
||||
icon: makeIcon(tool),
|
||||
key: tool.path,
|
||||
})),
|
||||
})),
|
||||
);
|
||||
});
|
||||
|
||||
const options = [];
|
||||
if (paidTools.length > 0) {
|
||||
options.push(toOption(PAID_GROUP_NAME, paidTools));
|
||||
}
|
||||
options.push(...remaining.map(({ name, components }) => toOption(name, components)));
|
||||
return options;
|
||||
});
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user