Skip to content

Commit

Permalink
feat: adjust some pages
Browse files Browse the repository at this point in the history
  • Loading branch information
yuler committed Jan 2, 2024
1 parent 2143db9 commit bb4b2bc
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 149 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"@vueuse/core": "^10.7.1",
"@vueuse/head": "^2.0.0",
"element-plus": "^2.4.4",
"nprogress": "^0.2.0",
"pinia": "^2.1.7",
Expand Down
70 changes: 0 additions & 70 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<script setup lang="ts">
useHead({
title: 'Element Plus Admin',
meta: [{name: 'description', content: 'Element Plus Admin'}],
link: [],
})
</script>
<script setup lang="ts"></script>

<template>
<RouterView />
Expand Down
75 changes: 52 additions & 23 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type {RouteRecordRaw} from 'vue-router'
import { routes as _routes } from 'vue-router/auto/routes'

export const MENUS: RouteRecordRaw[] = []
;(function generateMenus() {
if (MENUS.length) return

;(function generateMenus(){
if (MENUS.length) return
const routes = _routes
// Simple clone
.map(route => {
Expand All @@ -18,31 +18,60 @@ export const MENUS: RouteRecordRaw[] = []
return sortA - sortB
})

const map = new Map<string, RouteRecordRaw>()

for (let index = 0; index < routes.length; index++) {
const route = routes[index]
map.set(route.name as string, route)
}

for (let index = 0; index < routes.length; index++) {
const route = routes[index]
const {path} = route

console.log(routes)
for (const route of routes) {
// Skip `hideInMenu`
if (route.meta?.hideInMenu) {
continue
}

const segments = path.split('/').filter(Boolean)
if (segments.length === 1) {
MENUS.push(route)
} else {
for (let index = 1; index < segments.length; index++) {
const segment = segments[index - 1] // parent segment
const parent = map.get(segment)!
parent.children = (parent.children || []).concat(route)
}
}
MENUS.push(route)
}
})()

// export const MENUS: RouteRecordRaw[] = []
// ;(function generateMenus() {
// if (MENUS.length) return

// const routes = _routes
// // Simple clone
// .map(route => {
// return {
// ...route,
// }
// })
// .sort((a, b) => {
// let sortA = a.meta!.sortInMenu as number
// let sortB = b.meta!.sortInMenu as number
// return sortA - sortB
// })

// const map = new Map<string, RouteRecordRaw>()

// for (let index = 0; index < routes.length; index++) {
// const route = routes[index]
// map.set(route.path as string, route)
// }

// for (let index = 0; index < routes.length; index++) {
// const route = routes[index]
// const {path} = route

// // Skip `hideInMenu`
// if (route.meta?.hideInMenu) {
// continue
// }

// const segments = path.split('/').filter(Boolean)
// if (segments.length === 1) {
// MENUS.push(route)
// } else {
// for (let index = 1; index < segments.length; index++) {
// const segment = segments[index - 1] // parent segment
// const parent = map.get(segment)!
// if (parent)
// parent.children = (parent.children || []).concat(route)
// }
// }
// }
// })()
3 changes: 1 addition & 2 deletions src/layouts/components/AsideMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const props = defineProps<{
}>()
const formatTitle = computed(() => {
const {title, name} = props.item.meta ?? ({} as any)
const {title = '', name = ''} = props.item.meta ?? ({} as any)
return title || capitalize(name)
})
</script>
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import './main.css'
const app = createApp(App)

// Setup routes
// TODO:
const routes = setupLayouts(_routes)
const router = createRouter({
extendRoutes(routes) {
Expand All @@ -23,7 +24,7 @@ const router = createRouter({
route.meta.sortInMenu = 1000
}
}
return routes
return setupLayouts(routes)
},
history: createWebHistory()
})
Expand Down
8 changes: 0 additions & 8 deletions src/modules/head.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/dashboard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<route lang="yaml">
meta:
title: 控制面板
icon: odometer
</route>
2 changes: 1 addition & 1 deletion src/pages/dashboard/console.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<route lang="yaml">
meta:
title: Console
title: 控制面板
icon: user
</route>

Expand Down
7 changes: 0 additions & 7 deletions src/pages/dashboard/index.vue

This file was deleted.

8 changes: 0 additions & 8 deletions src/pages/dashboard/monitor.vue

This file was deleted.

8 changes: 0 additions & 8 deletions src/pages/dashboard/workspace.vue

This file was deleted.

12 changes: 0 additions & 12 deletions src/pages/hi.vue

This file was deleted.

3 changes: 2 additions & 1 deletion src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<route lang="yaml">
meta:
title: Welcome
hideInMenu: true
</route>

<script lang="ts" setup></script>

<template>
<p>xxx</p>
<h1>Welcome</h1>
</template>

0 comments on commit bb4b2bc

Please sign in to comment.