feat: add types

This commit is contained in:
Fine 2023-07-08 14:34:49 +08:00
parent 2549bdff37
commit e99adebc03
2 changed files with 21 additions and 7 deletions

13
src/types/app.d.ts vendored
View File

@ -46,3 +46,16 @@ export type EventParams = {
color: string; color: string;
event: any; event: any;
}; };
export interface MenuOptions {
layer: string;
icon: string;
title: string;
activate: boolean;
subItems: {
layer: string;
icon: string;
title: string;
activate: boolean;
}[];
}

View File

@ -33,12 +33,13 @@ limitations under the License. -->
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { MenuOptions } from "@/types/app";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const { t } = useI18n(); const { t } = useI18n();
const treeRef = ref<InstanceType<any>>(); const treeRef = ref<InstanceType<any>>();
const activateMenus = ref<any[]>([]); const activateMenus = ref<MenuOptions[]>([]);
const checkedKeys = ref<string[]>([]); const checkedKeys = ref<string[]>([]);
const defaultProps = { const defaultProps = {
children: "subItems", children: "subItems",
@ -56,10 +57,10 @@ limitations under the License. -->
async function getActivateMenus() { async function getActivateMenus() {
const resp = (await appStore.queryMenuItems()) || {}; const resp = (await appStore.queryMenuItems()) || {};
const menus = (resp.getMenuItems || []).map((d: any, index: number) => { const menus = (resp.getMenuItems || []).map((d: MenuOptions, index: number) => {
d.id = String(index); d.id = String(index);
if (d.subItems) { if (d.subItems) {
d.subItems = d.subItems.map((item: any, subIndex: number) => { d.subItems = d.subItems.map((item: MenuOptions, subIndex: number) => {
item.id = `${index}-${subIndex}`; item.id = `${index}-${subIndex}`;
return item; return item;
}); });
@ -69,9 +70,9 @@ limitations under the License. -->
return d; return d;
}); });
activateMenus.value = menus.filter((d: any) => { activateMenus.value = menus.filter((d: MenuOptions) => {
if (d.activate) { if (d.activate) {
d.subItems = d.subItems.filter((item: any) => { d.subItems = d.subItems.filter((item: MenuOptions) => {
if (item.activate) { if (item.activate) {
return item; return item;
} }
@ -95,9 +96,9 @@ limitations under the License. -->
} }
function setCurrentMenus() { function setCurrentMenus() {
const current = activateMenus.value.filter((d: any) => { const current = activateMenus.value.filter((d: MenuOptions) => {
if (checkedKeys.value.includes(d.id)) { if (checkedKeys.value.includes(d.id)) {
d.subItems = d.subItems.filter((item: any) => { d.subItems = d.subItems.filter((item: MenuOptions) => {
if (checkedKeys.value.includes(item.id)) { if (checkedKeys.value.includes(item.id)) {
return item; return item;
} }