路由优化

main
向文可 2 years ago
parent c3c98de87f
commit 2752f7f731

@ -57,7 +57,7 @@
border-radius: @layout-border-radius; border-radius: @layout-border-radius;
width: @layout-aside-item-size; width: @layout-aside-item-size;
.x-icon { .x-icon {
margin-bottom: 10px; margin-bottom: @layout-space;
} }
P { P {
line-height: 1; line-height: 1;
@ -67,7 +67,7 @@
color: @layout-aside-fc; color: @layout-aside-fc;
} }
+ .el-menu-item { + .el-menu-item {
margin-top: 10px; margin-top: @layout-space;
} }
} }
} }

@ -1,12 +1,18 @@
<template> <template>
<el-breadcrumb separator="/"> <el-breadcrumb separator="/">
<el-breadcrumb-item :to="{ path: '/' }">课程管理</el-breadcrumb-item> <template v-for="(item, index) in breakcrumbList" :key="index">
<el-breadcrumb-item><a href="/">课程列表</a></el-breadcrumb-item> <el-breadcrumb-item v-if="index === breakcrumbList.length - 1">{{ item.meta.title }}</el-breadcrumb-item>
<el-breadcrumb-item>添加课程</el-breadcrumb-item> <el-breadcrumb-item v-else :to="{ name: item.name }">
{{ item.meta.title }}
</el-breadcrumb-item>
</template>
</el-breadcrumb> </el-breadcrumb>
</template> </template>
<script setup></script> <script setup>
const store = useStore();
const breakcrumbList = computed(() => store.state.layout.breakcrumbList);
</script>
<style lang="less" scoped> <style lang="less" scoped>
.el-breadcrumb { .el-breadcrumb {

@ -38,7 +38,7 @@
color: @layout-menu-active-fc; color: @layout-menu-active-fc;
} }
+ .el-menu-item { + .el-menu-item {
margin-top: 5px; margin-top: @layout-space-small;
} }
} }
.el-sub-menu { .el-sub-menu {
@ -51,10 +51,10 @@
} }
:deep(.el-sub-menu__title) { :deep(.el-sub-menu__title) {
border-radius: @layout-border-radius; border-radius: @layout-border-radius;
margin-bottom: 5px; margin-bottom: @layout-space-small;
} }
+ .el-menu-item { + .el-menu-item {
margin-top: 5px; margin-top: @layout-space-small;
} }
:deep(.el-menu) { :deep(.el-menu) {
padding: 0 !important; padding: 0 !important;

@ -2,7 +2,7 @@
<el-scrollbar class="layout-menu" :class="{ collapse: collapseAside }"> <el-scrollbar class="layout-menu" :class="{ collapse: collapseAside }">
<div class="title">马士兵严选后台管理平台</div> <div class="title">马士兵严选后台管理平台</div>
<el-divider>{{ activeAsideName }}</el-divider> <el-divider>{{ activeAsideName }}</el-divider>
<el-menu unique-opened router :default-active="activeMenu"> <el-menu unique-opened :default-active="activeMenu" @select="handleSelect">
<MenuItem v-for="(item, index) in menuList" :key="index" :menu-item="item" /> <MenuItem v-for="(item, index) in menuList" :key="index" :menu-item="item" />
</el-menu> </el-menu>
</el-scrollbar> </el-scrollbar>
@ -10,11 +10,16 @@
<script setup> <script setup>
import MenuItem from './menu-item.vue'; import MenuItem from './menu-item.vue';
const router = useRouter();
const store = useStore(); const store = useStore();
const activeAsideName = computed(() => store.getters['layout/activeAsideName']); const activeAsideName = computed(() => store.getters['layout/activeAsideName']);
const menuList = computed(() => store.state.layout.menuList); const menuList = computed(() => store.state.layout.menuList);
const activeMenu = computed(() => store.state.layout.activeMenu); const activeMenu = computed(() => store.state.layout.activeMenu);
const collapseAside = computed(() => store.getters['layout/collapseAside']); const collapseAside = computed(() => store.getters['layout/collapseAside']);
const handleSelect = (index) => {
// TODO
router.push({ name: index });
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

@ -81,9 +81,6 @@ router.beforeEach(async (to, from, next) => {
// await store.dispatch('auth/getPermission'); // await store.dispatch('auth/getPermission');
// } // }
if (to.matched.length) { if (to.matched.length) {
store.commit('layout/setActiveAside', to.matched.find((item) => !item.meta?.layout).name);
store.commit('layout/setActiveMenu', to.name);
store.commit('layout/setActiveTab', to.name);
console.info(`[router] from ${from.name} to ${to.name}`); console.info(`[router] from ${from.name} to ${to.name}`);
if (to.meta.global) { if (to.meta.global) {
next(); next();
@ -97,6 +94,10 @@ router.beforeEach(async (to, from, next) => {
next({ name: childName }); next({ name: childName });
} else { } else {
next(); next();
store.commit('layout/setActiveAside', to.matched.find((item) => !item.meta?.layout).name);
store.commit('layout/setActiveMenu', to.name);
store.commit('layout/setActiveTab', to.name);
store.commit('layout/setBreakcrumbList', to.matched);
store.commit('layout/addTab', to); store.commit('layout/addTab', to);
} }
} }

@ -6,6 +6,7 @@ const state = () => ({
menuList: [], menuList: [],
tabList: [], tabList: [],
activeTab: null, activeTab: null,
breakcrumbList: [],
}); });
const getters = { const getters = {
asideList: () => { asideList: () => {
@ -46,6 +47,7 @@ const mutations = {
} }
}, },
setActiveTab: (state, data) => (state.activeTab = data), setActiveTab: (state, data) => (state.activeTab = data),
setBreakcrumbList: (state, data) => (state.breakcrumbList = data),
}; };
const actions = {}; const actions = {};
export default { export default {

@ -82,10 +82,10 @@
width: 420px; width: 420px;
padding: 30px; padding: 30px;
background: #1a2229; background: #1a2229;
border-radius: 10px; border-radius: @layout-border-radius;
.title { .title {
margin-bottom: 20px; margin-bottom: @layout-space-super;
font-size: 20px; font-size: @layout-h1;
text-align: center; text-align: center;
} }
.content { .content {
@ -93,11 +93,11 @@
width: 100%; width: 100%;
display: flex; display: flex;
+ .flex { + .flex {
margin-top: 10px; margin-top: @layout-space;
} }
.el-button { .el-button {
width: 30%; width: 30%;
margin-left: 10px; margin-left: @layout-space;
color: #fff; color: #fff;
} }
} }

Loading…
Cancel
Save