From 0a0c0e25ee599b5d3844516de96df2f10b33e84f Mon Sep 17 00:00:00 2001 From: chansee97 Date: Fri, 29 Mar 2024 23:22:59 +0800 Subject: [PATCH] fix: type error --- netlify.toml | 17 +++++++++++++ package.json | 1 + .../custom/Editor/MarkDownEditor/index.vue | 2 +- src/hooks/useEcharts.ts | 2 +- src/store/route.ts | 13 +++------- src/utils/array.ts | 20 ++++++++++++++++ src/utils/index.ts | 24 +------------------ src/views/login/components/Login/index.vue | 1 - src/views/permission/permission/index.vue | 2 +- 9 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 netlify.toml create mode 100644 src/utils/array.ts diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..cd6cd12 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,17 @@ +[build] +publish = "dist" +command = "pnpm run build" + +[build.environment] +NODE_VERSION = "20" + +[[redirects]] +from = "/*" +to = "/index.html" +status = 200 + +[[headers]] +for = "/manifest.webmanifest" + +[headers.values] +Content-Type = "application/manifest+json" diff --git a/package.json b/package.json index 6cf365e..3126e06 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "echarts": "^5.5.0", "md-editor-v3": "^4.11.3", "nprogress": "^0.2.0", + "performant-array-to-tree": "^1.11.0", "pinia": "^2.1.7", "pinia-plugin-persist": "^1.0.0", "qs": "^6.12.0", diff --git a/src/components/custom/Editor/MarkDownEditor/index.vue b/src/components/custom/Editor/MarkDownEditor/index.vue index 5667afa..245f958 100644 --- a/src/components/custom/Editor/MarkDownEditor/index.vue +++ b/src/components/custom/Editor/MarkDownEditor/index.vue @@ -18,7 +18,7 @@ const appStore = useAppStore() const data = useVModel(props, 'modelValue', emit) const theme = computed(() => { - return appStore.darkMode ? 'dark' : 'light' + return appStore.colorMode ? 'dark' : 'light' }) const toolbarsExclude: ToolbarNames[] = [ diff --git a/src/hooks/useEcharts.ts b/src/hooks/useEcharts.ts index a7e723c..715fb24 100644 --- a/src/hooks/useEcharts.ts +++ b/src/hooks/useEcharts.ts @@ -87,7 +87,7 @@ export function useEcharts(options: Ref) { return Boolean(domRef.value && chart) } async function render() { - const chartTheme = appStore.darkMode ? 'dark' : 'light' + const chartTheme = appStore.colorMode ? 'dark' : 'light' await nextTick() if (domRef.value) { chart = echarts.init(domRef.value, chartTheme) diff --git a/src/store/route.ts b/src/store/route.ts index c433320..8c61da6 100644 --- a/src/store/route.ts +++ b/src/store/route.ts @@ -13,7 +13,7 @@ import { useAuthStore } from '@/store/auth' interface RoutesStatus { isInitAuthRoute: boolean - menus: any + menus: AppRoute.Route[] rowRoutes: AppRoute.RowRoute[] activeMenu: string | null cacheRoutes: string[] @@ -44,6 +44,7 @@ export const useRouteStore = defineStore('route-store', { /* 生成侧边菜单的数据 */ createMenus(userRoutes: AppRoute.RowRoute[]) { const resultMenus = clone(userRoutes).map(i => construct(i)) as AppRoute.Route[] + // arrayToTree2() /** 过滤不需要显示的菜单 */ const visibleMenus = resultMenus.filter(route => !route.meta.hide) // 生成侧边菜单 @@ -84,15 +85,7 @@ export const useRouteStore = defineStore('route-store', { ) : item.meta.title, key: item.path, - icon: renderIcon(item.meta.icon), - } - /** 判断子元素 */ - if (item.children) { - const children = this.transformAuthRoutesToMenus(item.children) - // 只有子元素有且不为空时才添加 - if (children.length !== 0) - target.children = children - else target.children = undefined + icon: item.meta.icon ? renderIcon(item.meta.icon) : undefined, } return target }) diff --git a/src/utils/array.ts b/src/utils/array.ts new file mode 100644 index 0000000..0d3a17a --- /dev/null +++ b/src/utils/array.ts @@ -0,0 +1,20 @@ +import { arrayToTree as _arrayToTree } from 'performant-array-to-tree' +import { omit } from 'radash' + +export function arrayToTree(data: any) { + const rowTree = _arrayToTree(data, { + parentId: 'pid', + dataField: null, + }) + + const transform = (node: any) => { + if (node.children.length > 0) { + return ({ + ...node, + children: node.children.map(transform), + }) + } + return omit(node, ['children']) + } + return rowTree.map(transform) +} diff --git a/src/utils/index.ts b/src/utils/index.ts index 27ea28c..c8551d7 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,25 +1,3 @@ export * from './icon' export * from './storage' - -export function arrayToTree(arr) { - const map = {} - - arr.forEach((item) => { - map[item.id] = { ...item } - }) - - arr.forEach((item) => { - if (item.pid !== 0) { - const parent = map[item.pid] - if (parent) { - parent.children = parent.children || [] - parent.children.push(map[item.id]) - } - } - }) - - // 找出根节点 - const tree = Object.values(map).filter(item => item.pid === 0) - - return tree -} +export * from './array' diff --git a/src/views/login/components/Login/index.vue b/src/views/login/components/Login/index.vue index b4277f6..86a7f84 100644 --- a/src/views/login/components/Login/index.vue +++ b/src/views/login/components/Login/index.vue @@ -1,6 +1,5 @@