@@ -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 {
}
+
+