From 0efcc2b62b20361ae1704da82bc47835ddff2cd8 Mon Sep 17 00:00:00 2001 From: zzyuan <781948537@qq.com> Date: Tue, 27 Jan 2026 13:57:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/menu.js | 28 ++++- src/layout/components/Navbar.vue | 192 +++++++++++++++++++++++++++---- 2 files changed, 195 insertions(+), 25 deletions(-) diff --git a/src/api/system/menu.js b/src/api/system/menu.js index 0dff19c6..21d8ec31 100644 --- a/src/api/system/menu.js +++ b/src/api/system/menu.js @@ -57,4 +57,30 @@ export function delMenu(menuId) { url: '/system/menu/delete/' + menuId, method: 'post' }) -} \ No newline at end of file +} + + +// 新增菜单收藏 +export function addMenuCollect(data) { + return request({ + url: '/material-mall/menuCollect/add', + method: 'post', + params: data + }) +} +// 删除菜单收藏 +export function deleteMenuCollect(data) { + return request({ + url: '/material-mall/menuCollect/delete', + method: 'post', + params: data + }) +} +// 查询菜单收藏 +export function getMenuCollectListApi() { + return request({ + url: '/material-mall/menuCollect/listByUser', + method: 'get' + }) +} + diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index 7048d8b0..eee37869 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -52,7 +52,7 @@ /> -
+
收藏
@@ -187,49 +187,54 @@
- + + 手机号 138****8251
- + + 修改密码
- + + 设置默认首页
- + + 操作手册下载
- + + 一键换肤
- + + 清除缓存
- + + 测试网络速度
- + + 意见反馈/闭环
- + + 联系我们
- + 退出
@@ -311,8 +316,8 @@
@@ -321,9 +326,9 @@ @@ -332,7 +337,7 @@ - +
我的收藏
@@ -343,8 +348,8 @@
收藏菜单
-
{{ item.name }}
-
取消
+
{{ item.menuName }}
+
取消
@@ -404,6 +409,8 @@ import { mapGetters } from 'vuex' import Search from '@/components/HeaderSearch' import { getUserProfile } from '@/api/system/user' +import { addMenuCollect,deleteMenuCollect,getMenuCollectListApi } from '@/api/system/menu' + export default { components: { Search }, @@ -479,6 +486,9 @@ export default { }) }, }, + changCollectStatus() { + return + }, }, created() { this.getUser() @@ -503,6 +513,36 @@ export default { goTodo() { // this.$router.push({ path: '/todo' }) // 替换为实际的待办页路由 }, + async getMenuCollectList(){ + try { + const res = await getMenuCollectListApi() + if(res.code==200){ + this.zhinengList = res.data; + }else{ + this.zhinengList = [] + } + console.log(res) + } catch (error) { + console.error(error) + } + }, + goCollection(){ + this.getMenuCollectList() + this.isEdit=false + this.drawerShow=true + }, + gotoPage(item){ + this.drawerShow=false + this.isEdit=false + this.$router.replace({ path: '/'+item.fullRoutePath }) + }, + async delCollect(item){ + let param = { + menuId:item.menuId + } + const res = await deleteMenuCollect(param) + this.getMenuCollectList() + }, goMessageDetail(item) { this.$refs.messagePopover.doClose() // 关闭消息弹窗 // this.$router.push({ path: '/message/detail', query: { id: item.id } }); // 跳消息详情 @@ -619,7 +659,67 @@ export default { handleBoxLeave() { this.showMenuBox = false }, + async handleCollection(route) { + console.log("route2",route) + if(route.isCollect==0){ + try { + let param = { + menuId:route.id + } + const res = await addMenuCollect(param) + if (res.code === 200) { + this.$message.success('菜单收藏成功') + this.$nextTick(()=>{ + this.changCollection(this.menuList,route.id,1) + }) + this.$forceUpdate() + this.showMenuBox = false + } else { + this.$message.error(res.msg || '菜单收藏失败') + this.changCollection(this.menuList,route.id,0) + } + } catch (error) { + this.$message.error('菜单收藏失败:' + (error.message || '未知错误')) + console.error(error) + } + }else if(route.isCollect==1){ + try { + let param = { + menuId:route.id + } + const res = await deleteMenuCollect(param) + if (res.code === 200) { + this.$message.success('取消收藏成功') + this.changCollection(this.menuList,route.id,0) + this.$nextTick(()=>{ + this.changCollection(this.menuList,route.id,0) + }) + this.$forceUpdate() + this.showMenuBox = false + } else { + this.$message.error(res.msg || '取消收藏失败') + this.changCollection(this.menuList,route.id,1) + } + } catch (error) { + this.$message.error('取消收藏失败:' + (error.message || '未知错误')) + console.error(error) + } + } + }, + changCollection(array,targetId,status){ + for (let obj of array) { + if (obj.id === targetId) { + this.$set(obj,"isCollect",status) + obj.isCollect=status; + } + // 如果当前对象有子数组,递归搜索 + if (obj.children && Array.isArray(obj.children)) { + this.changCollection(obj.children, targetId, status); + } + } + }, goRoute(route) { + console.log("route",route) if (route.fullPath) { this.$router.push({ path: route.fullPath, query: route.query }) this.showMenuBox = false @@ -639,6 +739,47 @@ export default { } + +