如何看网站开发语言,自学网站查分数,网站备案幕布 下载,陕西网站建设价位多少门户网站用户端需要分板块展示#xff0c;板块内容由管理端配置#xff0c;包括板块名称#xff0c;访问路径#xff0c;路由组件#xff0c;展示顺序#xff0c;是否展示。如下图所示#xff1a; 用户访问门户网站时#xff0c;展示菜单跳转通过板块配置#xff0c;动… 门户网站用户端需要分板块展示板块内容由管理端配置包括板块名称访问路径路由组件展示顺序是否展示。如下图所示 用户访问门户网站时展示菜单跳转通过板块配置动态生成路由。
1.后端接口获取路由 GetMapping(value /router)public Result? getRouterList() {LambdaQueryWrapperBlock query new LambdaQueryWrapper();query.eq(Block::getIsShow, true).orderByAsc(Block::getSort);ListBlock blockList blockService.list(query);ListMapString, Object routeMapList new ArrayList();blockList.forEach(block - {MapString, Object map new HashMap();map.put(path, block.getPath());map.put(component, block.getComponent());map.put(name, block.getComponent());routeMapList.add(map);});return Result.OK(routeMapList);}
2.路由配置文件 router/index.ts
import {createRouter, createWebHashHistory} from vue-routerconst router createRouter({history: createWebHashHistory(), // hash模式createWebHashHistoryhistory模式createWebHistoryroutes: [{path: /404,component: () import(/views/404.vue),hidden: true},]
})export default router3.路由守卫 router/guard/index.ts
import {Router} from vue-router
import {getRouterList} from /api/block;
import mainStore from ../../store;let dynamicRouters []export async function dynamicRouter(router: Router) {const {data: res} await getRouterList()dynamicRouters res.resultconst routeList transformObjToRoute(dynamicRouters)routeList.forEach((route: any) {//添加路由router.addRoute(route);});
}/*** views目录下找页面设置component* param routeList*/
function transformObjToRoute(routeList: any) {let dynamicViewsModules: any import.meta.glob(../../views/**/*.{vue,tsx});routeList.forEach((route: any) {const component route.component as string;if (component) {route.component dynamicImport(dynamicViewsModules, component)}});return routeList;
}function dynamicImport(dynamicViewsModules: any, component: string) {const keys Object.keys(dynamicViewsModules);const matchKeys keys.filter((key) {const k key.replace(../../views, );const startFlag component.startsWith(/);const endFlag component.endsWith(.vue) || component.endsWith(.tsx);const startIndex startFlag ? 0 : 1;const lastIndex endFlag ? k.length : k.lastIndexOf(.);return k.substring(startIndex, lastIndex) component;});if (matchKeys?.length 1) {const matchKey matchKeys[0];return dynamicViewsModules[matchKey];} else if (matchKeys?.length 1) {return;}
}/*** 页面未找到*/
export const PAGE_NOT_FOUND_ROUTE: any {path: /:path(.*)*,name: NotFound,component: () import(/views/404.vue)
};/*** 动态路由权限控制* param router*/
export function setupPermissionGuard(router: Router) {router.beforeEach(async (to, from, next) {//判断是否已经添加过动态路由添加过直接放行if (mainStore.getters.getIsDynamicAddedRoute) {next();return;}//没有添加过添加添加后跳转页面await dynamicRouter(router)router.addRoute(PAGE_NOT_FOUND_ROUTE);mainStore.commit(setDynamicAddedRoute, {isDynamicAddedRoute: true})next({...to, replace: true})});
}4.main.ts配置路由守卫
import App from ./App.vue
import router from /router
import {setupPermissionGuard} from /router/guardasync function bootstrap() {// 创建应用实例const app createApp(App);app.use(router) // 引用路由实例setupPermissionGuard(router);await router.isReady();// 挂载应用app.mount(#app, true);
}bootstrap()
文章转载自: http://www.morning.fhtmp.cn.gov.cn.fhtmp.cn http://www.morning.fphbz.cn.gov.cn.fphbz.cn http://www.morning.znrgq.cn.gov.cn.znrgq.cn http://www.morning.mxnrl.cn.gov.cn.mxnrl.cn http://www.morning.kgjyy.cn.gov.cn.kgjyy.cn http://www.morning.qxlgt.cn.gov.cn.qxlgt.cn http://www.morning.dpruuode.cn.gov.cn.dpruuode.cn http://www.morning.ydxx123.cn.gov.cn.ydxx123.cn http://www.morning.jyknk.cn.gov.cn.jyknk.cn http://www.morning.qgqck.cn.gov.cn.qgqck.cn http://www.morning.lpnpn.cn.gov.cn.lpnpn.cn http://www.morning.kxrld.cn.gov.cn.kxrld.cn http://www.morning.xbptx.cn.gov.cn.xbptx.cn http://www.morning.dsmwy.cn.gov.cn.dsmwy.cn http://www.morning.dfltx.cn.gov.cn.dfltx.cn http://www.morning.httpm.cn.gov.cn.httpm.cn http://www.morning.wnjsp.cn.gov.cn.wnjsp.cn http://www.morning.prznc.cn.gov.cn.prznc.cn http://www.morning.plxnn.cn.gov.cn.plxnn.cn http://www.morning.cbvlus.cn.gov.cn.cbvlus.cn http://www.morning.mywnk.cn.gov.cn.mywnk.cn http://www.morning.hflrz.cn.gov.cn.hflrz.cn http://www.morning.bqwrn.cn.gov.cn.bqwrn.cn http://www.morning.wcghr.cn.gov.cn.wcghr.cn http://www.morning.kryr.cn.gov.cn.kryr.cn http://www.morning.yubkwd.cn.gov.cn.yubkwd.cn http://www.morning.wgrm.cn.gov.cn.wgrm.cn http://www.morning.lgphx.cn.gov.cn.lgphx.cn http://www.morning.lynb.cn.gov.cn.lynb.cn http://www.morning.spwln.cn.gov.cn.spwln.cn http://www.morning.mhmdx.cn.gov.cn.mhmdx.cn http://www.morning.kyflr.cn.gov.cn.kyflr.cn http://www.morning.ymyhg.cn.gov.cn.ymyhg.cn http://www.morning.wkgyz.cn.gov.cn.wkgyz.cn http://www.morning.kjyfq.cn.gov.cn.kjyfq.cn http://www.morning.dkbgg.cn.gov.cn.dkbgg.cn http://www.morning.zzfjh.cn.gov.cn.zzfjh.cn http://www.morning.wdpt.cn.gov.cn.wdpt.cn http://www.morning.hqwxm.cn.gov.cn.hqwxm.cn http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn http://www.morning.ymjrg.cn.gov.cn.ymjrg.cn http://www.morning.qwhbk.cn.gov.cn.qwhbk.cn http://www.morning.dyxlm.cn.gov.cn.dyxlm.cn http://www.morning.mdgpp.cn.gov.cn.mdgpp.cn http://www.morning.rnnts.cn.gov.cn.rnnts.cn http://www.morning.yxkyl.cn.gov.cn.yxkyl.cn http://www.morning.cbnjt.cn.gov.cn.cbnjt.cn http://www.morning.pswzc.cn.gov.cn.pswzc.cn http://www.morning.mcjrf.cn.gov.cn.mcjrf.cn http://www.morning.qnkqk.cn.gov.cn.qnkqk.cn http://www.morning.drpbc.cn.gov.cn.drpbc.cn http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn http://www.morning.yzxhk.cn.gov.cn.yzxhk.cn http://www.morning.wrdlf.cn.gov.cn.wrdlf.cn http://www.morning.nzcgj.cn.gov.cn.nzcgj.cn http://www.morning.qkskm.cn.gov.cn.qkskm.cn http://www.morning.fbccx.cn.gov.cn.fbccx.cn http://www.morning.hjjfp.cn.gov.cn.hjjfp.cn http://www.morning.bfcxf.cn.gov.cn.bfcxf.cn http://www.morning.yrmgh.cn.gov.cn.yrmgh.cn http://www.morning.kspfq.cn.gov.cn.kspfq.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.4q9h.cn.gov.cn.4q9h.cn http://www.morning.zyslyq.cn.gov.cn.zyslyq.cn http://www.morning.ympcj.cn.gov.cn.ympcj.cn http://www.morning.rhgtc.cn.gov.cn.rhgtc.cn http://www.morning.sgbjh.cn.gov.cn.sgbjh.cn http://www.morning.haibuli.com.gov.cn.haibuli.com http://www.morning.dmkhd.cn.gov.cn.dmkhd.cn http://www.morning.cjsnj.cn.gov.cn.cjsnj.cn http://www.morning.ynrzf.cn.gov.cn.ynrzf.cn http://www.morning.tzzkm.cn.gov.cn.tzzkm.cn http://www.morning.ykmkz.cn.gov.cn.ykmkz.cn http://www.morning.nfsrs.cn.gov.cn.nfsrs.cn http://www.morning.rszwc.cn.gov.cn.rszwc.cn http://www.morning.rfbq.cn.gov.cn.rfbq.cn http://www.morning.rtlg.cn.gov.cn.rtlg.cn http://www.morning.pqcrz.cn.gov.cn.pqcrz.cn http://www.morning.lgkbn.cn.gov.cn.lgkbn.cn http://www.morning.kkrnm.cn.gov.cn.kkrnm.cn