我的菜单有两个数据库表,主菜单和子菜单关联了,我想让对应的用户登录之后加载对应的主菜单,请问应该在哪里修改呢,要怎么修改呢,谢谢各位
主菜单如下:
前端取菜单的代码如下:
<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