rw941123 2023-03-28 19:52 采纳率: 80%
浏览 13
已结题

不同用户看见加载不同菜单

我的菜单有两个数据库表,主菜单和子菜单关联了,我想让对应的用户登录之后加载对应的主菜单,请问应该在哪里修改呢,要怎么修改呢,谢谢各位
主菜单如下:

img

前端取菜单的代码如下:

<el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.title}}</span>
            </template>
            
            <el-menu-item :index="it.path" v-for="it in item.sList" :key="it.id" @click="savePath(it.path)">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{it.title}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
 

后端菜单相关代码如下:

 
public class MainMenu {
    private int id;
    private String title;
    private String path;
    private List<SubMenu> sList;
}
 
public class SubMenu {
    private int id;
    private String  title;
    private String path;
}
 
public List<MainMenu> getMenus();
 
 <resultMap id="menuMap" type="com.bishe.springboot.bean.MainMenu">
        <id column="id" property="id"/>
        <result column="title" property="title"/>
        <result column="path" property="path"/>
        <collection  property="sList" ofType="com.bishe.springboot.bean.SubMenu" javaType="java.util.List">
            <result column="sid" property="id"/>
            <result column="stitle" property="title"/>
            <result column="spath" property="path"/>
        </collection>
    </resultMap>
 
    <select id="getMenus" resultMap="menuMap">
        SELECT mm.*,sm.id as sid ,sm.title as stitle,sm.path as spath FROM
        mainmenu mm ,submenu sm WHERE mm.id = sm.mid;
    </select>
 
@RequestMapping("/menus")
    public String getAllMenus(){
        HashMap<String,Object> data = new HashMap<>();
        List<MainMenu> menus = menuDao.getMenus();
        if (menus!=null){
            data.put("menus",menus);
            data.put("flag",200);
        }else {
            data.put("flag",404);
        }
        String s = JSON.toJSONString(data);
        return s;
    }
 

前端router index.js代码如下:

import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import login from '../views/login.vue'
import welcome from '../views/welcome.vue'
import user_manage from '../views/admin/user_manage.vue'
import worker_manage from "../views/admin/worker_manage.vue"
import info_manage from "../views/admin/info_manage.vue"
import apply_manage from "../views/admin/apply_manage.vue"
import donate_manage from "../views/admin/donate_manage.vue"
import in_manage from "../views/admin/in_manage.vue"
import out_manage from "../views/admin/out_manage.vue";
import stock_manage from "../views/admin/stock_manage.vue";
import instock from "../views/employee/instock.vue"
import outstock from "../views/employee/outstock.vue";
import stockflow from "../views/employee/stockflow.vue";
import iteminfo from "../views/user/iteminfo.vue";
import apply from "../views/user/apply.vue";
import donate from "../views/user/donate.vue"
import message from "../views/user/message.vue";
import message_worker from "../views/employee/message_worker.vue";
import message_admin from "../views/admin/message_admin.vue";
 
Vue.use(VueRouter)
 
const routes = [
  {
    path:"/",
    redirect:"/login"
  },
  {
    path: "/login",
    component: login
  },
  {
    path: '/Home',
    component: Home,
    redirect: "/welcome",
    children:[
      {path:'/welcome',component: welcome,},
      {path:'/userhome',component: welcome,},
      {path:'/workerhome',component: welcome,},
      {path:'/usermanage',component: user_manage,},
      {path:'/workermanage',component: worker_manage,},
      {path:'/infomanage',component: info_manage,},
      {path:'/applymanage',component: apply_manage,},
      {path:'/donatemanage',component: donate_manage,},
      {path:'/inmanage',component: in_manage,},
      {path:'/outmanage',component: out_manage,},
      {path:'/stockmanage',component: stock_manage,},
      {path:'/instock',component: instock,},
      {path:'/outstock',component: outstock,},
      {path:'/itemflow',component: stockflow,},
      {path:'/stock',component: stock_manage,},
      {path:'/iteminfo',component: iteminfo,},
      {path:'/apply',component: apply,},
      {path:'/donate',component: donate,},
      {path:'/message',component: message,},
      {path:'/messagemanage',component: message_admin,},
      {path:'/comment',component: message_worker,},
    ]
  },
 
]
 
const router = new VueRouter({
  routes
})
 
//路由导航守卫
router.beforeEach((to,from,next)=>{
  //to 将要访问
  //from 从哪访问
  //next 接着做
  if(to.path=='/login')return next();
  //获取user
  const userFlag = window.sessionStorage.getItem("user");
  if (!userFlag)return  next('/login');
  next();
})
 
export default router
 
 

  • 写回答

2条回答 默认 最新

  • sshdsjidlsan 2023-03-29 13:49
    关注

    1.登录之后,获取user的信息 (权限信息)
    2.在进入主页面的时候,在mount()的时候 向后端请求菜单列表 传用户的权限参数到后台

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月8日
  • 已采纳回答 3月31日
  • 创建了问题 3月28日

悬赏问题

  • ¥100 代写个MATLAB代码,有偿
  • ¥15 ansys electronics 2021 R1安装报错,错误代码2,如图
  • ¥30 搭建面包板由NE555N和SN74LS90N组成的计时电路时出了问题
  • ¥15 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误