赞
踩
- const router = createRouter({
- history: createWebHistory(import.meta.env.BASE_URL),
- routes: [
- {
- path: "/project",
- name: "projectGroup",
- meta: {
- requiresAuth: true,
- title: "项目列表",
- navBreadcrumb: [
- { label: "项目列表", name: "projectSample", link: true },
- ],
- },
- component: () => import("../views/project/Index.vue"),
- children: [
- {
- path: "sample/:id",
- name: "projectGroup:sample",
- meta: {
- requiresAuth: true,
- title: "项目列表",
- navBreadcrumb: [
- { label: "项目列表", name: "projectSample", link: true },
- ],
- },
- component: () => import("../views/project/Sample.vue"),
- },
- {
- path: "alg/:id",
- name: "projectGroup:alg",
- meta: {
- requiresAuth: true,
- title: "项目列表",
- navBreadcrumb: [
- { label: "项目列表", name: "projectSample", link: true },
- ],
- },
- component: () => import("../views/project/Alg.vue"),
- },
- ],
- },
- ],
- });
1. 我选择使用自定义组件BaseLayout.vue文件来设置header和aside样式显示
- <template>
- <el-config-provider namespace="ep" :locale="zhCn">
- //BaseHeader是我自己的定义的组件,为当前页面的头部
- <div class="top-header">
- <BaseHeader />
- <div>
- <user-avatar />
- </div>
- </div>
- <div class="app-main" v-if="userInfo !== null">
- //BaseSide 自定义组件,为当前页面的侧边栏
- <div class="base-side-main" v-if="props.hasBaseSide"><BaseSide /></div>
- <div
- :class="['content-main', mainClass]"
- :style="{ left: props.hasBaseSide ? '64px' : '0' }"
- >
- <slot></slot>
- </div>
- </div>
- </el-config-provider>
- </template>
也可以使用element plus中的Container 布局容器
2. BaseHeader.vue文件里面为页面头部样式,头部样式相对简单
- <template>
- <div class="top-nav-bar">
- <div class="app-title">
- <router-link :to="{ name: 'home' }"> 病理图像AI自训练中台 </router-link
- ><el-tag
- effect="dark"
- type="danger"
- style="margin-left: 10px"
- v-if="envMode === 'test'"
- >
- 测试版
- </el-tag>
- </div>
- <el-menu
- class="el-menu-bar"
- mode="horizontal"
- :ellipsis="false"
- :defaultActive="menuActive"
- >
- <el-menu-item index="3" @click="goPage('/dashboard')"
- >控制台</el-menu-item
- >
- <el-menu-item index="1" @click="goPage('/alg')">我的算法</el-menu-item>
- <el-menu-item index="2" @click="goPage('/market')">应用市场</el-menu-item>
- <el-menu-item index="4" @click="goPage('/project')"
- >项目列表</el-menu-item
- >
- </el-menu>
- </div>
- </template>
3. BaseSide.vue文件里面是侧边栏样式,这里是重点!!!这里进行页面路由跳转设置
- <template>
- <el-menu
- class="el-menu-vertical-demo"
- @open="handleOpen"
- @close="handleClose"
- >
- <div v-for="i in listProject?.ListProjectByTenant" :key="i.id">
- //因为我的侧边栏数据是需要动态获取的,所以这里的index不能相同,否则几个侧边栏会同时展开时
- <el-sub-menu :index="i">
- <template #title>{{ i.name }}</template>
- <el-menu-item index="alg">
- //这里使用<router-link>,通过属性to来进行跳转,里面的name就是刚才在router.js文件中设置的,params这里包含的是路由跳转时传递的参数
- <router-link
- :to="{
- name: 'projectGroup:alg',
- params: { id: i.id, name: i.name },
- }"
- >算法</router-link
- >
- </el-menu-item>
- <el-menu-item index="sample"
- ><router-link
- :to="{
- name: 'projectGroup:sample',
- params: { id: i.id, name: i.name },
- }"
- >样本</router-link
- ></el-menu-item
- >
- </el-sub-menu>
- </div>
- </el-menu>
- </template>
- <template>
- //因为我的数据是动态获取,所以要先判断一下是否有数据,有数据再显示侧边栏
- <BaseLayout :hasBaseSide="isProjectLoaded && projectListData.length">
- <PaddingLayout>
- <el-card class="table-card" shadow="never">
- <router-view></router-view>
- </el-card>
- </PaddingLayout>
- </AlgProjectLayout>
- </template>
样式如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。