fix: type error

This commit is contained in:
chansee97 2024-03-29 23:22:59 +08:00
parent 2e4f691058
commit 0a0c0e25ee
9 changed files with 45 additions and 37 deletions

17
netlify.toml Normal file
View File

@ -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"

View File

@ -57,6 +57,7 @@
"echarts": "^5.5.0", "echarts": "^5.5.0",
"md-editor-v3": "^4.11.3", "md-editor-v3": "^4.11.3",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",
"performant-array-to-tree": "^1.11.0",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"pinia-plugin-persist": "^1.0.0", "pinia-plugin-persist": "^1.0.0",
"qs": "^6.12.0", "qs": "^6.12.0",

View File

@ -18,7 +18,7 @@ const appStore = useAppStore()
const data = useVModel(props, 'modelValue', emit) const data = useVModel(props, 'modelValue', emit)
const theme = computed(() => { const theme = computed(() => {
return appStore.darkMode ? 'dark' : 'light' return appStore.colorMode ? 'dark' : 'light'
}) })
const toolbarsExclude: ToolbarNames[] = [ const toolbarsExclude: ToolbarNames[] = [

View File

@ -87,7 +87,7 @@ export function useEcharts(options: Ref<ECOption>) {
return Boolean(domRef.value && chart) return Boolean(domRef.value && chart)
} }
async function render() { async function render() {
const chartTheme = appStore.darkMode ? 'dark' : 'light' const chartTheme = appStore.colorMode ? 'dark' : 'light'
await nextTick() await nextTick()
if (domRef.value) { if (domRef.value) {
chart = echarts.init(domRef.value, chartTheme) chart = echarts.init(domRef.value, chartTheme)

View File

@ -13,7 +13,7 @@ import { useAuthStore } from '@/store/auth'
interface RoutesStatus { interface RoutesStatus {
isInitAuthRoute: boolean isInitAuthRoute: boolean
menus: any menus: AppRoute.Route[]
rowRoutes: AppRoute.RowRoute[] rowRoutes: AppRoute.RowRoute[]
activeMenu: string | null activeMenu: string | null
cacheRoutes: string[] cacheRoutes: string[]
@ -44,6 +44,7 @@ export const useRouteStore = defineStore('route-store', {
/* 生成侧边菜单的数据 */ /* 生成侧边菜单的数据 */
createMenus(userRoutes: AppRoute.RowRoute[]) { createMenus(userRoutes: AppRoute.RowRoute[]) {
const resultMenus = clone(userRoutes).map(i => construct(i)) as AppRoute.Route[] const resultMenus = clone(userRoutes).map(i => construct(i)) as AppRoute.Route[]
// arrayToTree2()
/** 过滤不需要显示的菜单 */ /** 过滤不需要显示的菜单 */
const visibleMenus = resultMenus.filter(route => !route.meta.hide) const visibleMenus = resultMenus.filter(route => !route.meta.hide)
// 生成侧边菜单 // 生成侧边菜单
@ -84,15 +85,7 @@ export const useRouteStore = defineStore('route-store', {
) )
: item.meta.title, : item.meta.title,
key: item.path, key: item.path,
icon: renderIcon(item.meta.icon), icon: item.meta.icon ? renderIcon(item.meta.icon) : undefined,
}
/** 判断子元素 */
if (item.children) {
const children = this.transformAuthRoutesToMenus(item.children)
// 只有子元素有且不为空时才添加
if (children.length !== 0)
target.children = children
else target.children = undefined
} }
return target return target
}) })

20
src/utils/array.ts Normal file
View File

@ -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)
}

View File

@ -1,25 +1,3 @@
export * from './icon' export * from './icon'
export * from './storage' export * from './storage'
export * from './array'
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
}

View File

@ -1,6 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import type { FormInst } from 'naive-ui' import type { FormInst } from 'naive-ui'
import { useRequest } from 'alova'
import { local } from '@/utils' import { local } from '@/utils'
import { useAuthStore } from '@/store' import { useAuthStore } from '@/store'

View File

@ -4,7 +4,7 @@ import { usePermission } from '@/hooks'
const authStore = useAuthStore() const authStore = useAuthStore()
const { hasPermission } = usePermission() const { hasPermission } = usePermission()
const { role } = authStore.userInfo const { role } = authStore.userInfo!
const roleList: Auth.RoleType[] = ['super', 'admin', 'user'] const roleList: Auth.RoleType[] = ['super', 'admin', 'user']