使用AI一步一步实现若依前端(11)

news/2025/3/13 11:48:24/

功能11:实现面包屑功能

功能10:添加首页菜单项
功能9:退出登录功能
功能8:页面权限控制
功能7:路由全局前置守卫
功能6:动态添加路由记录
功能5:侧边栏菜单动态显示
功能4:首页使用Layout布局
功能3:点击登录按钮实现页面跳转
功能2:静态登录界面
功能1:创建前端项目

前言

在导航栏上显示当前页面路径的就是面包屑。它可以侧边栏菜单联动。
在这里插入图片描述

一.操作步骤

1.先问问AI,提供一些思路

AI思考了107秒
在这里插入图片描述
AI会给出一些可能要修改的问题点,根据AI给出的方向适当修改代码。

2.修改Sidebar.vue

给el-menu设置default-active和default-openeds属性。

<template><el-menu router :default-active="activeMenu" :default-openeds="openedMenus" class="el-menu-vertical" unique-opened><template v-for="item in menuData" :key="item.path"><MenuItem :item="item" :level="0" /></template></el-menu>
</template><script setup>
import { defineProps, computed } from 'vue';
import MenuItem from './MenuItem.vue';
import { useRoute } from 'vue-router';const route = useRoute()
defineProps({menuData: {type: Array,required: true}
});const activeMenu = computed(() => {return route.path
})const openedMenus = computed(() => {return route.matched.map(item => item.path).filter(path => path !== '/')
})
</script>

3.修改Navbar.vue

style部分没有改变,不贴代码了。

<template><el-header class="navbar"><el-breadcrumb separator="/"><el-breadcrumb-item v-for="(item, index) in breadcrumbItems" :key="item.path"><router-link v-if="index === 0" :to="item.path">{{ item.meta.title }}</router-link><span v-else>{{ item.meta.title }}</span></el-breadcrumb-item></el-breadcrumb><div class="user-menu"><el-dropdown trigger="hover"><div class="avatar-container"><img :src="avatarUrl" alt="用户头像" class="avatar-image" /></div><template #dropdown><el-dropdown-menu class="dropdown-menu"><el-dropdown-item @click="handleSettings" class="menu-item"><span>个人设置</span></el-dropdown-item><el-dropdown-item divided @click="handleLogout" class="menu-item"><span>退出登录</span></el-dropdown-item></el-dropdown-menu></template></el-dropdown></div></el-header>
</template><script setup>
import { ElMessageBox } from 'element-plus'
import { computed } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()const breadcrumbItems = computed(() => {// 获取当前路由的匹配数组,过滤无meta的路由const matched = route.matched.filter(item => item.meta?.title);// 确保首页始终在首位(如果当前路由不是首页)if (route.path !== '/' && matched[0]?.path !== '/') {matched.unshift({ path: '/index', meta: { title: '首页' } });}if (route.path === '/' || route.path === '/index') {matched.splice(0, matched.length - 1)}return matched;
})// 请确保在 assets 目录下存在 user-avatar.png 图片文件
const avatarUrl = new URL('@/assets/images/profile.jpg', import.meta.url).hrefimport useUserStore from '@/stores/user'
const userStore = useUserStore()const handleLogout = () => {// 处理退出登录逻辑ElMessageBox.confirm('确定注销并退出系统吗?', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'}).then(() => {userStore.logout().then(() => {location.href = '/index';})}).catch(() => { });
}const handleSettings = () => {// 处理设置逻辑console.log('打开设置页面')
}
</script>

4.修改MenuItem.vue

优先处理跟目录,返回/index,跟menu里的一致,组件才能正常联动。

const resolvePath = (routePath) => {if (routePath === '/') {return '/index'}if (props.basePath.length === 0) {return routePath}return getNormalPath(props.basePath + '/' + routePath)
}

后端返回的路由数据里的图标,有些是ElemetPlus里没有的,导致不显示,暂时先全部显示成主页图标House,方便观察菜单的层级关系。

                    <el-icon v-if="item.meta?.icon"><component is="House" /></el-icon>

二.功能验证

运行项目,浏览器访问http://localhost:5173/index
在这里插入图片描述

三.知识点拓展

四.思考

遗留一个Bug,在点击系统管理--日志管理--操作日志菜单时,在面包屑上只显示了首页/系统管理/操作日志


http://www.ppmy.cn/news/1578786.html

相关文章

bug修改模板(日志)

第一段&#xff1a;前端报错&#xff1a;Uncaught (in promise) TypeError: Cannot read properties of undefined (reading bookDetailList) 第二段&#xff1a;后端报错&#xff1a;Failed to convert value of type ‘java.lang.String‘ to required type ‘java.lang.Lon…

idea超级AI插件,让 AI 为 Java 工程师

引言​ 用户可在界面中直接通过输入自然语言的形式描述接口的需求&#xff0c;系统通过输入的需求自动分析关键的功能点有哪些&#xff0c;并对不确定方案的需求提供多种选择&#xff0c;以及对需求上下文进行补充&#xff0c;用户修改确定需求后&#xff0c;系统会根据需求设…

【Java】——数据类型和变量

个人主页&#xff1a;User_芊芊君子 &#x1f389;欢迎大家点赞&#x1f44d;评论&#x1f4dd;收藏⭐文章 文章目录&#xff1a; 1.Java中的注释1.1.基本规则1.2.注释规范 2.标识符3.关键字4.字面常量5.数据类型6.变量6.1变量的概念6.2语法6.3整型变量6.3.1整型变量6.3.2长整…

PC端QT实现mqtt客户端发布和订阅

在Windows11-64位系统下使用QT开发桌面应用程序&#xff0c;实现mqtt客户端的发布和订阅功能。 需求&#xff1a; mqtt代理服务器 --mosquitto&#xff1b; mqtt客户端工具 -- mqtt.fx&#xff1b; qtcreator开发工具 -- qtcreator6.8.2版本&#xff1b; 过程&#xff1a;…

Java开发者如何接入并使用DeepSeek

目录 一、准备工作 二、添加DeepSeek SDK依赖 三、初始化DeepSeek客户端 四、数据上传与查询 五、数据处理与分析 六、实际应用案例 七、总结 【博主推荐】&#xff1a;最近发现了一个超棒的人工智能学习网站&#xff0c;内容通俗易懂&#xff0c;风格风趣幽默&#xff…

深度学习基础:线性代数本质3——矩阵与线性变换

你对线性代数的一切困惑&#xff0c;根源就在于没有真正理解矩阵到底是什么。 1. 线性变换 变换本质上就是函数。例如&#xff0c;你输入一个向量 &#xff0c;经过某个变换&#xff08;即函数&#xff09;的作用之后&#xff0c;输出另一个向量。 ​ 既然&#xff0c;变换本…

歌词相关实现

歌词相关 歌词数据模型&#xff1a; // Lyric.swift class Lyric: BaseModel {/// 是否是精确到字的歌词var isAccurate:Bool false/// 所有的歌词var datum:Array<LyricLine>! }// LyricLine.swift class LyricLine: BaseModel {/// 整行歌词var data:String!/// 开始…

centos8.0系统部署zabbix6.0监控

centos8.0系统部署zabbix6.0监控 一、部署过程1、确认系统版本2、主机基础环境设置3、安装MySQL 8.0数据库3.1 安装MySQL 8.0仓库3.2 安装软件3.3 设置root用户密码3.4 创建zabbix数据库&#xff0c;授权用户 4、配置zabbix6.0仓库5、安装zabbix服务端软件6、导入zabbix数据表7…