编写路由代码。

This commit is contained in:
2025-10-23 17:52:01 +08:00
parent fd4275c3a5
commit 7ea8e7ab4d
24 changed files with 1606 additions and 150 deletions

View File

@@ -0,0 +1,86 @@
<!--
* @Author: Kane
* @Date: 2023-03-23 15:07:31
* @LastEditors: Kane
* @FilePath: /task_schedule/src/layout/Index.vue
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
-->
<template>
<el-container class="layout-container">
<el-header class="layout-header">
<LayoutHeader />
</el-header>
<el-container class="layout-container-down">
<el-aside class="layout-aside">
<LayoutAside />
</el-aside>
<el-main class="layout-main">
<LayoutMain />
</el-main>
</el-container>
</el-container>
</template>
<script lang="ts">
// 组件
import LayoutHeader from "./components/Header.vue";
import LayoutAside from "./components/Aside.vue";
import LayoutMain from "./components/Main.vue";
export default {
name: "MainFrame",
components: {
LayoutHeader,
LayoutAside,
LayoutMain,
},
setup()
{
return {};
},
};
</script>
<style lang="scss" scoped>
@media screen {
.layout-container {
height: 100vh;
width: 100vw;
max-height: 100vh;
max-width: 100vw;
.layout-header {
height: 50px;
width: 100vw;
max-height: 50px;
max-width: 100vw;
padding: 0px;
}
.layout-container-down {
height: calc(100vh - 50px);
max-height: calc(100vh - 50px);
width: 100vw;
max-width: 100vw;
.layout-aside {
height: calc(100vh - 50px);
max-height: calc(100vh - 50px);
min-height: calc(100vh - 50px);
width: 200px;
overflow-x: hidden;
background-color: #2f4156;
}
.layout-main {
padding: 0px;
height: calc(100vh - 50px);
width: calc(100vw - 200px);
}
}
}
}
</style>

View File

@@ -0,0 +1,155 @@
<!--
author: Kane Wang <wangkane@qq.com>
date: 2025-10-23 15:32:30
component: Aside
Copyright © CPIC All rights reserved
-->
<template>
<el-scrollbar class="sidebar-wrapper">
<el-menu
class="side-bar"
router
:default-active="currentPath"
background-color="#2f4156"
text-color="#fff"
active-text-color="#ffd04b"
>
<template v-for="route in routes">
<template v-if="!route.hidden">
<template v-if="hasOnlyChild(route.children)">
<!-- 当只有一个子路由时将这个子路由作为顶级菜单项 -->
<el-menu-item
:key="route.children[0].path"
:index="route.children[0].path"
class="sidebar-submenu"
>
<component
:is="route.children[0] && route.children[0].meta.icon"
class="icons"
/>
<template #title>
{{ route.children[0].meta && route.children[0].meta.title }}
</template>
</el-menu-item>
</template>
<template v-else>
<!-- 不止一个子路由可能是咩有子s路由或者有多个子路由 -->
<!-- 如果没有子路由就不渲染 -->
<el-sub-menu
v-if="route.children && route.children.length"
:key="route.path"
:index="route.path"
class="sidebar-submenu"
>
<template #title>
<component
:is="route.meta && route.meta.icon"
class="icons"
/>
<span>{{ route.meta && route.meta.title }}</span>
</template>
<template v-for="child in route.children">
<el-menu-item
v-if="!child.hidden"
:key="child.path"
:index="child.path"
class="sidebar-item"
>
<component
:is="child.meta && child.meta.icon"
class="icons"
/>
<template #title>
{{ child.meta && child.meta.title }}
</template>
</el-menu-item>
</template>
</el-sub-menu>
</template>
</template>
</template>
</el-menu>
</el-scrollbar>
</template>
<script lang="js">
// @ts-expect-error 之后再补充类型文件
import { hasOnlyChild } from "../../../router/index";
import { useRoute, useRouter } from "vue-router";
import { computed } from "vue";
export default {
name: "LayoutAside",
setup()
{
const userRout = useRoute();
const router = useRouter();
const routes = router.getRoutes();// as SideBarRouteRecordNormalized[];
const currentPath = computed(() =>
{
return userRout.path;
});
return { userRout, routes, currentPath, hasOnlyChild, };
},
};
</script>
<style lang="scss" scoped>
.sidebar-wrapper {
// @include no-select;
-webkit-touch-callout: none;
-moz-user-select: none;
/*火狐*/
-webkit-user-select: none;
/*webkit浏览器*/
-ms-user-select: none;
/*IE10*/
-khtml-user-select: none;
/*早期浏览器*/
user-select: none;
height: 100%;
width: 100%;
}
:deep(.el-menu) {
border-right: none;
/* border-left: 5px solid #1d74b2; */
overflow: auto;
.el-menu-item {
font-weight: normal;
}
.el-sub-menu {
font-weight: normal;
}
.el-menu-item.is-active {
// background-color: #ffffff1f !important;
font-weight: 1000;
font-size: 15px;
color: #ffd04b;
}
}
.sidebar-submenu {
background-color: #2f4156 !important;
}
.sidebar-item {
background-color: #223142 !important;
}
/* .is-opened {
border-left: 5px solid #1d74b2;
} */
.icons {
width: 1em;
height: 1em;
margin-right: 8px;
}
</style>

View File

@@ -0,0 +1,118 @@
<!--
author: Kane Wang <wangkane@qq.com>
date: 2025-10-23 15:32:30
component: Header
Copyright © CPIC All rights reserved
-->
<template>
<div class="header-wrapper">
<span class="company-name">CPIC</span>
<div class="version-wrapper">
<span>制度库后台管理</span>
<span>Build-20251021</span>
</div>
<div class="buttons-wrapper">
<component
:is="'SwitchButton'"
class="icons"
@click="Logout"
/>
</div>
</div>
</template>
<script lang="ts">
import { ElMessageBox } from "element-plus";
// import { logout } from "@/utils/account.js";
export default {
name: "LayoutHeader",
setup()
{
/**
* 退出登录
*/
const Logout = (): void =>
{
ElMessageBox.confirm(
"是否要退出系统?",
"",
{
confirmButtonText: "是",
cancelButtonText: "否",
type: "warning",
}
)
.then((): void =>
{
// debugger;
console.log( "退出" );
// logout();
})
.catch((): void => {});
};
return { Logout, };
},
};
</script>
<style lang="scss" scoped>
.header-wrapper {
// @include no-select;
height: 50px;
max-height: 50px;
padding: 0px 15px;
// position: relative;
display: flex;
justify-content: start;
align-items: center;
background-color: #1d74b2;
color: #fff;
// background-color: $banner-background-color;
span {
text-align: left;
}
>*+* {
margin-left: 10px;
}
.version-wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: start;
font: {
size: 0.75rem;
}
>*+* {
margin-top: 1px;
}
}
.company-name {
font-size: 2rem;
}
.buttons-wrapper {
margin-left: auto;
padding-top: 5px;
// border: 1px solid salmon;
}
.icons {
width: 25px;
height: 25px;
// margin-right: 8px;
cursor: pointer;
}
}
</style>

View File

@@ -0,0 +1,42 @@
<!--
* @Author: Kane
* @Date: 2023-03-23 15:44:52
* @LastEditors: Kane
* @FilePath: /task_schedule/src/layout/components/Main.vue
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
-->
<!--
* @Author: Kane
* @Date: 2023-01-04 11:40:03
* @LastEditors: Kane
* @LastEditTime: 2023-09-27 11:19:05
* @FilePath: /it-console/src/layout/components/Main.vue
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
-->
<template>
<el-scrollbar>
<router-view />
</el-scrollbar>
</template>
<script lang="ts">
export default {
name: "LayoutMain",
setup()
{
return {};
},
};
</script>
<style scoped>
.el-scrollbar {
height: 100%;
width: 100%;
/* background-color: #ecf2f9; */
}
</style>