首页 > 其他分享 >若依框架 -------- vue3+element-plus(三)

若依框架 -------- vue3+element-plus(三)

时间:2023-02-20 14:06:01浏览次数:32  
标签:-------- const menu value element item plus router path


后端管理系统,前后端分离的框架若依管理后台,来看下vue3+element-plus版本。

静态文本 assets

assets 静态img、svg、style

main.js ​​import '@/assets/styles/index.scss' // global css​​ 引入了全局样式

 组件 components

breadcrumb 面包屑

从路由中获取面包屑路径

<template>
<el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group name="breadcrumb">
<el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path">
<span v-if="item.redirect === 'noRedirect' || index == levelList.length - 1" class="no-redirect">{{ item.meta.title }}</span>
<a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
</el-breadcrumb-item>
</transition-group>
</el-breadcrumb>
</template>

<script setup>
const route = useRoute();
const router = useRouter();
const levelList = ref([])

function getBreadcrumb() {
// only show routes with meta.title
let matched = route.matched.filter(item => item.meta && item.meta.title);
const first = matched[0]
// 判断是否为首页
if (!isDashboard(first)) {
matched = [{ path: '/index', meta: { title: '首页' } }].concat(matched)
}

levelList.value = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
}
function isDashboard(route) {
const name = route && route.name
if (!name) {
return false
}
return name.trim() === 'Index'
}
function handleLink(item) {
const { redirect, path } = item
if (redirect) {
router.push(redirect)
return
}
router.push(path)
}

watchEffect(() => {
// if you go to the redirect page, do not update the breadcrumbs
if (route.path.startsWith('/redirect/')) {
return
}
getBreadcrumb()
})
getBreadcrumb();
</script>

<style lang='scss' scoped>
.app-breadcrumb.el-breadcrumb {
display: inline-block;
font-size: 14px;
line-height: 50px;
margin-left: 8px;

.no-redirect {
color: #97a8be;
cursor: text;
}
}
</style>

hamburger

展示按钮svg图标

headerSearch 搜索框

Fuse.js——用于JavaScript中数据的模糊搜索

pagination 分页

treeSelect 树选取器

topNav 顶部导航

<template>
<el-menu
:default-active="activeMenu"
mode="horizontal"
@select="handleSelect"
>
<template v-for="(item, index) in topMenus">
<el-menu-item :style="{'--theme': theme}" :index="item.path" :key="index" v-if="index < visibleNumber"
><svg-icon :icon-class="item.meta.icon" />
{{ item.meta.title }}</el-menu-item
>
</template>

<!-- 顶部菜单超出数量折叠 -->
<el-sub-menu :style="{'--theme': theme}" index="more" v-if="topMenus.length > visibleNumber">
<template #title>更多菜单</template>
<template v-for="(item, index) in topMenus">
<el-menu-item
:index="item.path"
:key="index"
v-if="index >= visibleNumber"
><svg-icon :icon-class="item.meta.icon" />
{{ item.meta.title }}</el-menu-item
>
</template>
</el-sub-menu>
</el-menu>
</template>

<script setup>
import { constantRoutes } from "@/router"
import { isHttp } from '@/utils/validate'

// 顶部栏初始数
const visibleNumber = ref(null);
// 是否为首次加载
const isFrist = ref(null);
// 当前激活菜单的 index
const currentIndex = ref(null);

const store = useStore();
const route = useRoute();

// 主题颜色
const theme = computed(() => store.state.settings.theme);
// 所有的路由信息
const routers = computed(() => store.state.permission.topbarRouters);

// 顶部显示菜单
const topMenus = computed(() => {
let topMenus = [];
routers.value.map((menu) => {
if (menu.hidden !== true) {
// 兼容顶部栏一级菜单内部跳转
if (menu.path === "/") {
topMenus.push(menu.children[0]);
} else {
topMenus.push(menu);
}
}
})
return topMenus;
})

// 设置子路由
const childrenMenus = computed(() => {
let childrenMenus = [];
routers.value.map((router) => {
for (let item in router.children) {
if (router.children[item].parentPath === undefined) {
if(router.path === "/") {
router.children[item].path = "/redirect/" + router.children[item].path;
} else {
if(!isHttp(router.children[item].path)) {
router.children[item].path = router.path + "/" + router.children[item].path;
}
}
router.children[item].parentPath = router.path;
}
childrenMenus.push(router.children[item]);
}
})
return constantRoutes.concat(childrenMenus);
})

// 默认激活的菜单
const activeMenu = computed(() => {
const path = route.path;
let activePath = defaultRouter.value;
if (path !== undefined && path.lastIndexOf("/") > 0) {
const tmpPath = path.substring(1, path.length);
activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
} else if ("/index" == path || "" == path) {
if (!isFrist.value) {
isFrist.value = true;
} else {
activePath = "index";
}
}
let routes = activeRoutes(activePath);
if (routes.length === 0) {
activePath = currentIndex.value || defaultRouter.value
activeRoutes(activePath);
}
return activePath;
})
// 默认激活的路由
const defaultRouter = computed(() => {
let router;
Object.keys(routers.value).some((key) => {
if (!routers.value[key].hidden) {
router = routers.value[key].path;
return true;
}
});
return router;
})
function setVisibleNumber() {
const width = document.body.getBoundingClientRect().width / 3;
visibleNumber.value = parseInt(width / 85);
}
function handleSelect(key, keyPath) {
currentIndex.value = key;
if (isHttp(key)) {
// http(s):// 路径新窗口打开
window.open(key, "_blank");
} else if (key.indexOf("/redirect") !== -1) {
// /redirect 路径内部打开
router.push({ path: key.replace("/redirect", "") });
} else {
// 显示左侧联动菜单
activeRoutes(key);
}
}
function activeRoutes(key) {
let routes = [];
if (childrenMenus.value && childrenMenus.value.length > 0) {
childrenMenus.value.map((item) => {
if (key == item.parentPath || (key == "index" && "" == item.path)) {
routes.push(item);
}
});
}
if(routes.length > 0) {
store.commit("SET_SIDEBAR_ROUTERS", routes);
}
return routes;
}

onMounted(() => {
window.addEventListener('resize', setVisibleNumber)
})
onBeforeUnmount(() => {
window.removeEventListener('resize', setVisibleNumber)
})

onMounted(() => {
setVisibleNumber()
})
</script>

<style lang="scss">
.topmenu-container.el-menu--horizontal > .el-menu-item {
float: left;
height: 50px !important;
line-height: 50px !important;
color: #999093 !important;
padding: 0 5px !important;
margin: 0 10px !important;
}

.topmenu-container.el-menu--horizontal > .el-menu-item.is-active, .el-menu--horizontal > .el-sub-menu.is-active .el-submenu__title {
border-bottom: 2px solid #{'var(--theme)'} !important;
color: #303133;
}

/* sub-menu item */
.topmenu-container.el-menu--horizontal > .el-sub-menu .el-submenu__title {
float: left;
height: 50px !important;
line-height: 50px !important;
color: #999093 !important;
padding: 0 5px !important;
margin: 0 10px !important;
}
</style>

router.js中指定了布局

import Layout from '@/layout'

{
path: '/user',
// 页面布局
component: Layout,
hidden: true,
redirect: 'noredirect',
children: [
{
path: 'profile',
component: () => import('@/views/system/user/profile/index'),
name: 'Profile',
meta: { title: '个人中心', icon: 'user' }
}
]
},

layout/index.vue 实现了页面的布局

<template>
<div :class="classObj" class="app-wrapper" :style="{ '--current-color': theme }">
<div v-if="device === 'mobile' && sidebar.opened" class="drawer-bg" @click="handleClickOutside"/>
<!-- 菜单栏 -->
<sidebar class="sidebar-container" />
<!-- 标签 -->
<div :class="{ hasTagsView: needTagsView }" class="main-container">
<div :class="{ 'fixed-header': fixedHeader }">
<navbar @setLayout="setLayout" />
<tags-view v-if="needTagsView" />
</div>
<!-- 主视图 -->
<app-main />
<settings ref="settingRef" />
</div>
</div>
</template>

前端框架的 组件及页面布局完成。

标签:--------,const,menu,value,element,item,plus,router,path
From: https://blog.51cto.com/u_15949848/6068469

相关文章

  • 若依框架 -------- vue3+element-plus(二)
    后端管理系统,前后端分离的框架若依管理后台,来看下vue3+element-plus版本。API后台接口请求user.js//查询用户列表exportfunctionlistUser(query){returnrequest({......
  • Docker-全面详解(学习总结---从入门到深化)
    一、什么是Docker Docker是一个开源的应用容器引擎,基于Go语言并遵从Apache2.0协议开源。 什么是"集装箱技术"我们都知道码头里的集装箱是运载货物用的,它是一种按规......
  • HTML5+CSS3(十)-全面详解(学习总结---从入门到深化)
    ​​Display​​​​编辑 元素隐藏属性对比​​​​学习效果反馈 ​​​​文档流 ​​​​文档流产生的问题 ​​​​空格折叠​​​​元素无空隙​​​​脱离文档流​......
  • 若依框架---PageHelper分页(四)
    我们通过下载并查看​​PageHelper-Spring-Boot-Starter​​​源码,了解到​​PageHelper​​​是通过实现​​MyBatis​​​拦截器接口​​org.apache.ibatis.plugin.Interc......
  • 若依框架---PageHelper分页(三)
    在上一篇文章“​​若依系统分页工具学习-PageHelper篇二​​”中,我们阐述了PageHelper使用ThreadLocal来将分页参数保存在当前线程中。那么我们为什么却找不到若依项目中后......
  • 若依框架---PageHelper分页(十三)
      我们介绍了PageHelper中的cache包以及简单介绍了包中各个类的属性与方法;还介绍了Java中一种加载类的方式:​​Class.forName​​​,并且通过查看​​com.mysql.jdbc.Drive......
  • 若依框架---PageHelper分页(十四)
     在前几篇文章中,我们查看了PageHeler中的包 ​​com.github.pagehelper​​​以及子包​​com.github.pagehelper.cache​​​中的类与结构,并且借着​​cache​​​包......
  • 对JS代码中的每个函数单独进行混淆加密
    自动化脚本:单独对JS代码中的每个函数进行混淆加密用自动化脚本工具,对JS代码中的每个函数分别进行单独混淆加密。这样加密得到的JS代码,比直接对整个JS代码进行混淆加密,效果要......
  • linux利用source命令导入sql文件
    1.创建数据库2.设置编码3.进入sql文件目录,使用msyql的source命令如下:source文件路径mysql>useg6monitor;mysql>source/app/t_sta_high_emission_vehicle.sql; ......
  • Win10应用商店提示“重试该操作 无法加载页面”
    试了好几种方法都没有效果,大家可以都试一下:方法1.按住Windows键+R键,输入“wsreset”,按下回车键重置应用商店 等待一段时间,会自动重置打开商店方法2.在Windows键+X键,点......