关于MAP文件的使用(转贴)

 在看《深入理解计算机系统》的时候总会看到MAP文件,一直不懂,今天看到一片相关的文章,收录下来,大家一起看看吧。毕竟有些时候我们的IDE提示的信息不够明白,使用MAP文件是一个调试的好帮手。

仅通过崩溃地址找出源代码的出错行

作为程序员,我们平时最担心见到的事情是什么?是内存泄漏?是界面不好看?……错啦!我相信我的看法是不会有人反对的——那就是,程序发生了崩溃!

“该程序执行了非法操作,即将关闭。请与你的软件供应商联系。”,呵呵,这句 M$ 的“名言”,恐怕就是程序员最担心见到的东西了。有的时候,自己的程序在自己的机器上运行得好好的,但是到了别人的机器上就崩溃了;有时自己在编写和测试的过程中就莫名其妙地遇到了非法操作,但是却无法确定到底是源代码中的哪行引起的……是不是很痛苦呢?不要紧,本文可以帮助你走出这种困境,甚至你从此之后可以自豪地要求用户把崩溃地址告诉你,然后你就可以精确地定位到源代码中出错的那行了。(很神奇吧?呵呵。)

首先我必须强调的是,本方法可以在目前市面上任意一款编译器上面使用。但是我只熟悉 M$ 的 VC 和 MASM ,因此后面的部分只介绍如何在这两个编译器中实现,请读者自行融会贯通,掌握在别的编译器上使用的方法。

Well,废话说完了,让我们开始! :)

首先必须生成程序的 MAP 文件。什么是 MAP 文件?简单地讲, MAP 文件是程序的全局符号、源文件和代码行号信息的唯一的文本表示方法,它可以在任何地方、任何时候使用,不需要有额外的程序进行支持。而且,这是唯一能找出程序崩溃的地方的救星。

好吧,既然 MAP 文件如此神奇,那么我们应该如何生成它呢?在 VC 中,我们可以按下 Alt+F7 ,打开“Project Settings”选项页,选择 C/C++ 选项卡,并在最下面的 Project Options 里面输入:/Zd ,然后要选择 Link 选项卡,在最下面的  Project Options 里面输入: /mapinfo:lines 和 /map:PROJECT_NAME.map 。最后按下 F7 来编译生成 EXE 可执行文件和 MAP 文件。

在 MASM 中,我们要设置编译和连接参数,我通常是这样做的:

rc %1.rc
ml /c /coff /Zd %1.asm
link /subsystem:windows /mapinfo:exports /mapinfo:lines /map:%1.map %1.obj %1.res 

把它保存成 makem.bat ,就可以在命令行输入 makem filename 来编译生成 EXE 可执行文件和 MAP 文件了。

在此我先解释一下加入的参数的含义:

/Zd              表示在编译的时候生成行信息
/map[:filename]  表示生成 MAP 文件的路径和文件名
/mapinfo:lines   表示生成 MAP 文件时,加入行信息
/mapinfo:exports 表示生成 MAP 文件时,加入 exported functions (如果生成的是 DLL 文件,这个选项就要加上) 

OK,通过上面的步骤,我们已经得到了 MAP 文件,那么我们该如何利用它呢?

让我们从简单的实例入手,请打开你的 VC ,新建这样一个文件:

01  //****************************************************************
02  //程序名称:演示如何通过崩溃地址找出源代码的出错行
03  //作者:罗聪
04  //日期:2003-2-7
05  //出处:http://www.luocong.com(老罗的缤纷天地)
06  //本程序会产生“除0错误”,以至于会弹出“非法操作”对话框。
07  //“除0错误”只会在 Debug 版本下产生,本程序为了演示而尽量简化。
08  //注意事项:如欲转载,请保持本程序的完整,并注明:
09  //转载自“老罗的缤纷天地”(http://www.luocong.com
10  //****************************************************************
11  
12  void Crash(void)
13  {
14      int i = 1;
15      int j = 0;
16      i /= j;
17  }
18  
19  void main(void)
20  {
21      Crash();
22  } 

很显然本程序有“除0错误”,在 Debug 方式下编译的话,运行时肯定会产生“非法操作”。好,让我们运行它,果然,“非法操作”对话框出现了,这时我们点击“详细信息”按钮,记录下产生崩溃的地址——在我的机器上是 0x0040104a 。

再看看它的 MAP 文件:(由于文件内容太长,中间没用的部分我进行了省略)

CrashDemo

Timestamp is 3e430a76 (Fri Feb 07 09:23:02 2003)

Preferred load address is 00400000

Start         Length     Name                   Class
0001:00000000 0000de04H .text                   CODE
0001:0000de04 0001000cH .textbss                CODE
0002:00000000 00001346H .rdata                  DATA
0002:00001346 00000000H .edata                  DATA
0003:00000000 00000104H .CRT$XCA                DATA
0003:00000104 00000104H .CRT$XCZ                DATA
0003:00000208 00000104H .CRT$XIA                DATA
0003:0000030c 00000109H .CRT$XIC                DATA
0003:00000418 00000104H .CRT$XIZ                DATA
0003:0000051c 00000104H .CRT$XPA                DATA
0003:00000620 00000104H .CRT$XPX                DATA
0003:00000724 00000104H .CRT$XPZ                DATA
0003:00000828 00000104H .CRT$XTA                DATA
0003:0000092c 00000104H .CRT$XTZ                DATA
0003:00000a30 00000b93H .data                   DATA
0003:000015c4 00001974H .bss                    DATA
0004:00000000 00000014H .idata$2                DATA
0004:00000014 00000014H .idata$3                DATA
0004:00000028 00000110H .idata$4                DATA
0004:00000138 00000110H .idata$5                DATA
0004:00000248 000004afH .idata$6                DATA

  Address         Publics by Value              Rva+Base     Lib:Object

0001:00000020       ?Crash@@YAXXZ              00401020 f   CrashDemo.obj
0001:00000070       _main                      00401070 f   CrashDemo.obj
0004:00000000       __IMPORT_DESCRIPTOR_KERNEL32 00424000     kernel32:KERNEL32.dll
0004:00000014       __NULL_IMPORT_DESCRIPTOR   00424014     kernel32:KERNEL32.dll
0004:00000138       __imp__GetCommandLineA@0   00424138     kernel32:KERNEL32.dll
0004:0000013c       __imp__GetVersion@0        0042413c     kernel32:KERNEL32.dll
0004:00000140       __imp__ExitProcess@4       00424140     kernel32:KERNEL32.dll
0004:00000144       __imp__DebugBreak@0        00424144     kernel32:KERNEL32.dll
0004:00000148       __imp__GetStdHandle@4      00424148     kernel32:KERNEL32.dll
0004:0000014c       __imp__WriteFile@20        0042414c     kernel32:KERNEL32.dll
0004:00000150       __imp__InterlockedDecrement@4 00424150     kernel32:KERNEL32.dll
0004:00000154       __imp__OutputDebugStringA@4 00424154     kernel32:KERNEL32.dll
0004:00000158       __imp__GetProcAddress@8    00424158     kernel32:KERNEL32.dll
0004:0000015c       __imp__LoadLibraryA@4      0042415c     kernel32:KERNEL32.dll
0004:00000160       __imp__InterlockedIncrement@4 00424160     kernel32:KERNEL32.dll
0004:00000164       __imp__GetModuleFileNameA@12 00424164     kernel32:KERNEL32.dll
0004:00000168       __imp__TerminateProcess@8  00424168     kernel32:KERNEL32.dll
0004:0000016c       __imp__GetCurrentProcess@0 0042416c     kernel32:KERNEL32.dll
0004:00000170       __imp__UnhandledExceptionFilter@4 00424170     kernel32:KERNEL32.dll
0004:00000174       __imp__FreeEnvironmentStringsA@4 00424174     kernel32:KERNEL32.dll
0004:00000178       __imp__FreeEnvironmentStringsW@4 00424178     kernel32:KERNEL32.dll
0004:0000017c       __imp__WideCharToMultiByte@32 0042417c     kernel32:KERNEL32.dll
0004:00000180       __imp__GetEnvironmentStrings@0 00424180     kernel32:KERNEL32.dll
0004:00000184       __imp__GetEnvironmentStringsW@0 00424184     kernel32:KERNEL32.dll
0004:00000188       __imp__SetHandleCount@4    00424188     kernel32:KERNEL32.dll
0004:0000018c       __imp__GetFileType@4       0042418c     kernel32:KERNEL32.dll
0004:00000190       __imp__GetStartupInfoA@4   00424190     kernel32:KERNEL32.dll
0004:00000194       __imp__HeapDestroy@4       00424194     kernel32:KERNEL32.dll
0004:00000198       __imp__HeapCreate@12       00424198     kernel32:KERNEL32.dll
0004:0000019c       __imp__HeapFree@12         0042419c     kernel32:KERNEL32.dll
0004:000001a0       __imp__VirtualFree@12      004241a0     kernel32:KERNEL32.dll
0004:000001a4       __imp__RtlUnwind@16        004241a4     kernel32:KERNEL32.dll
0004:000001a8       __imp__GetLastError@0      004241a8     kernel32:KERNEL32.dll
0004:000001ac       __imp__SetConsoleCtrlHandler@8 004241ac     kernel32:KERNEL32.dll
0004:000001b0       __imp__IsBadWritePtr@8     004241b0     kernel32:KERNEL32.dll
0004:000001b4       __imp__IsBadReadPtr@8      004241b4     kernel32:KERNEL32.dll
0004:000001b8       __imp__HeapValidate@12     004241b8     kernel32:KERNEL32.dll
0004:000001bc       __imp__GetCPInfo@8         004241bc     kernel32:KERNEL32.dll
0004:000001c0       __imp__GetACP@0            004241c0     kernel32:KERNEL32.dll
0004:000001c4       __imp__GetOEMCP@0          004241c4     kernel32:KERNEL32.dll
0004:000001c8       __imp__HeapAlloc@12        004241c8     kernel32:KERNEL32.dll
0004:000001cc       __imp__VirtualAlloc@16     004241cc     kernel32:KERNEL32.dll
0004:000001d0       __imp__HeapReAlloc@16      004241d0     kernel32:KERNEL32.dll
0004:000001d4       __imp__MultiByteToWideChar@24 004241d4     kernel32:KERNEL32.dll
0004:000001d8       __imp__LCMapStringA@24     004241d8     kernel32:KERNEL32.dll
0004:000001dc       __imp__LCMapStringW@24     004241dc     kernel32:KERNEL32.dll
0004:000001e0       __imp__GetStringTypeA@20   004241e0     kernel32:KERNEL32.dll
0004:000001e4       __imp__GetStringTypeW@16   004241e4     kernel32:KERNEL32.dll
0004:000001e8       __imp__SetFilePointer@16   004241e8     kernel32:KERNEL32.dll
0004:000001ec       __imp__SetStdHandle@8      004241ec     kernel32:KERNEL32.dll
0004:000001f0       __imp__FlushFileBuffers@4  004241f0     kernel32:KERNEL32.dll
0004:000001f4       __imp__CloseHandle@4       004241f4     kernel32:KERNEL32.dll
0004:000001f8       /177KERNEL32_NULL_THUNK_DATA 004241f8     kernel32:KERNEL32.dll

entry point at        0001:000000f0


Line numbers for ./Debug/CrashDemo.obj(d:/msdev/myprojects/crashdemo/crashdemo.cpp) segment .text

    13 0001:00000020    14 0001:00000038    15 0001:0000003f    16 0001:00000046
    17 0001:00000050    20 0001:00000070    21 0001:00000088    22 0001:0000008d 

如果仔细浏览 Rva+Base 这栏,你会发现第一个比崩溃地址 0x0040104a 大的函数地址是 0x00401070 ,所以在 0x00401070 这个地址之前的那个入口就是产生崩溃的函数,也就是这行:

0001:00000020       ?Crash@@YAXXZ              00401020 f   CrashDemo.obj 

因此,发生崩溃的函数就是 ?Crash@@YAXXZ ,所有以问号开头的函数名称都是 C++ 修饰的名称。在我们的源程序中,也就是 Crash() 这个子函数。

OK,现在我们轻而易举地便知道了发生崩溃的函数名称,你是不是很兴奋呢?呵呵,先别忙,接下来,更厉害的招数要出场了。

请注意 MAP 文件的最后部分——代码行信息(Line numbers information),它是以这样的形式显示的:

13 0001:00000020 

第一个数字代表在源代码中的代码行号,第二个数是该代码行在所属的代码段中的偏移量。

如果要查找代码行号,需要使用下面的公式做一些十六进制的减法运算:

崩溃行偏移 = 崩溃地址(Crash Address) - 基地址(ImageBase Address) - 0x1000 

为什么要这样做呢?细心的朋友可能会留意到 Rva+Base 这栏了,我们得到的崩溃地址都是由 偏移地址(Rva)+ 基地址(Base) 得来的,所以在计算行号的时候要把基地址减去,一般情况下,基地址的值是 0x00400000 。另外,由于一般的 PE 文件的代码段都是从 0x1000 偏移开始的,所以也必须减去 0x1000 。

好了,明白了这点,我们就可以来进行小学减法计算了:

崩溃行偏移 = 0x0040104a - 0x00400000 - 0x1000 = 0x4a 

如果浏览 MAP 文件的代码行信息,会看到不超过计算结果,但却最接近的数是 CrashDemo.cpp 文件中的:

16 0001:00000046 

也就是在源代码中的第 16 行,让我们来看看源代码:

16      i /= j; 

哈!!!果然就是第 16 行啊!

兴奋吗?我也一样! :)

方法已经介绍完了,从今以后,我们就可以精确地定位到源代码中的崩溃行,而且只要编译器可以生成 MAP 文件(包括 VC、MASM、VB、BCB、 Delphi……),本方法都是适用的。我们时常抱怨 M$ 的产品如何如何差,但其实 M$ 还是有意无意间提供了很多有价值的信息给我们的,只是我们往往不懂得怎么利用而已……相信这样一来,你就可以更为从容地面对“非法操作”提示了。你甚至可以要求用户提供崩溃的地址,然后就可以坐在家中舒舒服服地找到出错的那行,并进行修正。

转载:http://blog.youkuaiyun.com/xiaoweiboy/article/details/6309870

/** * 判断是否有路由的权限 * @param authority 路由权限配置 * @param permissions 用户权限集合 * @returns {boolean|*} */ function hasPermission(authority, permissions) { let required = '*' if (typeof authority === 'string') { required = authority } else if (typeof authority === 'object') { required = authority.permission } return required === '*' || (permissions && permissions.findIndex(item => item === required || item.id === required) !== -1) } /** * 判断是否有路由需要的角色 * @param authority 路由权限配置 * @param roles 用户角色集合 */ function hasRole(authority, roles) { let required if (typeof authority === 'object') { required = authority.role } return authority === '*' || hasAnyRole(required, roles) } /** * 判断是否有需要的任意一个角色 * @param required {String | Array[String]} 需要的角色,可以是单个角色或者一个角色数组 * @param roles 拥有的角色 * @returns {boolean} */ function hasAnyRole(required, roles) { if (!required) { return false } else if (Array.isArray(required)) { return roles.findIndex(role => { return required.findIndex(item => item === role || item === role.id) !== -1 }) !== -1 } else { return roles.findIndex(role => role === required || role.id === required) !== -1 } } /** * 路由权限校验 * @param route 路由 * @param permissions 用户权限集合 * @param roles 用户角色集合 * @returns {boolean} */ function hasAuthority(route, permissions, roles) { const authority = route.meta?.authority; if (!authority) return true; // 检查 role 或 permission return ( (authority.role && hasRole(authority, roles)) || (authority.permission && hasPermission(authority, permissions)) ); } /** * 根据权限配置过滤菜单数据 * @param menuData * @param permissions * @param roles */ function filterMenu(menuData, permissions, roles) { return menuData.filter(menu => { if (menu.meta && menu.meta.invisible === undefined) { if (!hasAuthority(menu, permissions, roles)) { return false } } if (menu.children && menu.children.length > 0) { menu.children = filterMenu(menu.children, permissions, roles) } return true }) } export { filterMenu, hasAuthority } import routerMap from '@/router/async/router.map' import { mergeI18nFromRoutes } from '@/utils/i18n' import Router from 'vue-router' import deepMerge from 'deepmerge' import basicOptions from '@/router/async/config.async' // 应用配置 const appOptions = { router: undefined, i18n: undefined, store: undefined } /** * 设置应用配置 * @param options */ function setAppOptions(options) { const { router, store, i18n } = options appOptions.router = router appOptions.store = store appOptions.i18n = i18n } /** * 根据 路由配置 和 路由组件注册 解析路由 * @param routesConfig 路由配置 * @param routerMap 本地路由组件注册配置 */ function parseRoutes(routesConfig, routerMap) { const routes = [] routesConfig.forEach(item => { // 获取注册在 routerMap 中的 router,初始化 routeCfg let router; let routeCfg = {} if (typeof item === 'string') { router = routerMap[item] routeCfg = { path: (router && router.path) || item, router: item } } else if (typeof item === 'object') { router = routerMap[item.router] routeCfg = item } if (!router) { console.warn(`can't find register for router ${routeCfg.router}, please register it in advance.`) router = typeof item === 'string' ? { path: item, name: item } : item } // 从 router 和 routeCfg 解析路由 const meta = { authority: router.authority, icon: router.icon, page: router.page, link: router.link, params: router.params, query: router.query, ...router.meta } const cfgMeta = { authority: routeCfg.authority, icon: routeCfg.icon, page: routeCfg.page, link: routeCfg.link, params: routeCfg.params, query: routeCfg.query, ...routeCfg.meta } Object.keys(cfgMeta).forEach(key => { if (cfgMeta[key] === undefined || cfgMeta[key] === null || cfgMeta[key] === '') { delete cfgMeta[key] } }) Object.assign(meta, cfgMeta) const route = { path: routeCfg.path || router.path || routeCfg.router, name: routeCfg.name || router.name, component: router.component, redirect: routeCfg.redirect || router.redirect, meta: { ...meta, authority: meta.authority || '*' } } if (routeCfg.invisible || router.invisible) { route.meta.invisible = true } if (routeCfg.children && routeCfg.children.length > 0) { route.children = parseRoutes(routeCfg.children, routerMap) } routes.push(route) }) return routes } /** * 加载路由 * @param routesConfig {RouteConfig[]} 路由配置 */ // function loadRoutes(routesConfig) { // //兼容 0.6.1 以下版本 // /*************** 兼容 version < v0.6.1 *****************/ // if (arguments.length > 0) { // const arg0 = arguments[0] // if (arg0.router || arg0.i18n || arg0.store) { // routesConfig = arguments[1] // console.error('the usage of signature loadRoutes({router, store, i18n}, routesConfig) is out of date, please use the new signature: loadRoutes(routesConfig).') // console.error('方法签名 loadRoutes({router, store, i18n}, routesConfig) 的用法已过时, 请使用新的方法签名 loadRoutes(routesConfig)。') // } // } // /*************** 兼容 version < v0.6.1 *****************/ // // 应用配置 // // const {router, store, i18n} = appOptions // // 如果 routesConfig 有值,则更新到本地,否则从本地获取 // if (routesConfig) { // store.commit('account/setRoutesConfig', routesConfig) // } else { // routesConfig = store.getters['account/routesConfig'] // } // // 如果开启了异步路由,则加载异步路由配置 // const asyncRoutes = store.state.setting.asyncRoutes // if (asyncRoutes) { // if (routesConfig && routesConfig.length > 0) { // const routes = parseRoutes(routesConfig, routerMap) // const finalRoutes = mergeRoutes(basicOptions.routes, routes) // formatRoutes(finalRoutes) // router.options = {...router.options, routes: finalRoutes} // router.matcher = new Router({...router.options, routes:[]}).matcher // router.addRoutes(finalRoutes) // } // } // // 提取路由国际化数据 // mergeI18nFromRoutes(i18n, router.options.routes) // // 初始化Admin后台菜单数据 // const rootRoute = router.options.routes.find(item => item.path === '/') // const menuRoutes = rootRoute && rootRoute.children // if (menuRoutes) { // store.commit('setting/setMenuData', menuRoutes) // } // } function loadRoutes(routesConfig) { const { router, store, i18n } = appOptions if (routesConfig) { store.commit('account/setRoutesConfig', routesConfig) } else { routesConfig = store.getters['account/routesConfig'] } // 如果开启了异步路由,则加载异步路由配置 const asyncRoutes = store.state.setting.asyncRoutes if (asyncRoutes) { if (routesConfig && routesConfig.length > 0) { const routes = parseRoutes(routesConfig, routerMap) formatAuthority(routes) const finalRoutes = mergeRoutes(router.options.routes, routes) router.options = { ...router.options, routes: finalRoutes } router.matcher = new Router({ ...router.options, routes: [] }).matcher router.addRoutes(finalRoutes) } } // 初始化Admin后台菜单数据 const rootRoute = router.options.routes.find(item => item.path === '/') const menuRoutes = rootRoute && rootRoute.children if (menuRoutes) { // 提取路由国际化数据 mergeI18nFromRoutes(i18n, menuRoutes) store.commit('setting/setMenuData', menuRoutes) } } /** * 合并路由 * @param target {Route[]} * @param source {Route[]} * @returns {Route[]} */ function mergeRoutes(target, source) { const routesMap = {} target.forEach(item => routesMap[item.path] = item) source.forEach(item => routesMap[item.path] = item) return Object.values(routesMap) } /** * 深度合并路由 * @param target {Route[]} * @param source {Route[]} * @returns {Route[]} */ function deepMergeRoutes(target, source) { // 映射路由数组 const mapRoutes = routes => { const routesMap = {} routes.forEach(item => { routesMap[item.path] = { ...item, children: item.children ? mapRoutes(item.children) : undefined } }) return routesMap } const tarMap = mapRoutes(target) const srcMap = mapRoutes(source) // 合并路由 const merge = deepMerge(tarMap, srcMap) // 转换为 routes 数组 const parseRoutesMap = routesMap => { return Object.values(routesMap).map(item => { if (item.children) { item.children = parseRoutesMap(item.children) } else { delete item.children } return item }) } return parseRoutesMap(merge) } /** * 格式化路由 * @param routes 路由配置 */ function formatRoutes(routes) { routes.forEach(route => { const { path } = route if (!path.startsWith('/') && path !== '*') { route.path = '/' + path } }) formatAuthority(routes) } /** * 格式化路由的权限配置 * @param routes 路由 * @param pAuthorities 父级路由权限配置集合 */ function formatAuthority(routes, pAuthorities = []) { routes.forEach(route => { const meta = route.meta const defaultAuthority = pAuthorities[pAuthorities.length - 1] || { permission: '*' } if (meta) { let authority = {} if (!meta.authority) { authority = defaultAuthority } else if (typeof meta.authority === 'string') { authority.permission = meta.authority } else if (typeof meta.authority === 'object') { authority = meta.authority const { role } = authority if (typeof role === 'string') { authority.role = [role] } if (!authority.permission && !authority.role) { authority = defaultAuthority } } meta.authority = authority } else { const authority = defaultAuthority route.meta = { authority } } route.meta.pAuthorities = pAuthorities if (route.children) { formatAuthority(route.children, [...pAuthorities, route.meta.authority]) } }) } /** * 从路由 path 解析 i18n key * @param path * @returns {*} */ function getI18nKey(path) { const keys = path.split('/').filter(item => !item.startsWith(':') && item != '') keys.push('name') return keys.join('.') } /** * 加载导航守卫 * @param guards * @param options */ function loadGuards(guards, options) { const { beforeEach, afterEach } = guards const { router } = options beforeEach.forEach(guard => { if (guard && typeof guard === 'function') { router.beforeEach((to, from, next) => guard(to, from, next, options)) } }) afterEach.forEach(guard => { if (guard && typeof guard === 'function') { router.afterEach((to, from) => guard(to, from, options)) } }) } export { parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes, setAppOptions } import Vue from 'vue' import App from './App.vue' import {initRouter} from './router' import './theme/index.less' import Antd from 'ant-design-vue' import Viser from 'viser-vue' // import '@/mock'//注释掉这句话,就会使用服务端API import store from './store' import 'animate.css/source/animate.css' import Plugins from '@/plugins' import {initI18n} from '@/utils/i18n' import bootstrap from '@/bootstrap' import 'moment/locale/zh-cn' const router = initRouter(store.state.setting.asyncRoutes) const i18n = initI18n('CN', 'US') // var sso = window.g.ssoUrlPc // console.log(sso,'-----------------') Vue.use(Antd) Vue.config.productionTip = false Vue.use(Viser) Vue.use(Plugins) bootstrap({router, store, i18n, message: Vue.prototype.$message}) new Vue({ router, store, i18n, render: h => h(App), }).$mount('#app') import { loadRoutes, loadGuards, setAppOptions } from '@/utils/routerUtil' import { loadInterceptors } from '@/utils/request' import guards from '@/router/guards' import interceptors from '@/utils/axios-interceptors' /** * 启动引导方法 * 应用启动时需要执行的操作放在这里 * @param router 应用的路由实例 * @param store 应用的 vuex.store 实例 * @param i18n 应用的 vue-i18n 实例 * @param i18n 应用的 message 实例 */ function bootstrap({ router, store, i18n, message }) { // 设置应用配置 setAppOptions({ router, store, i18n }) // 加载 axios 拦截器 loadInterceptors(interceptors, { router, store, i18n, message }) // 加载路由 loadRoutes() // 加载路由守卫 loadGuards(guards, { router, store, i18n, message }) } export default bootstrap import TabsView from '@/layouts/tabs/TabsView' import BlankView from '@/layouts/BlankView' // import PageView from '@/layouts/PageView' console.log(process.env.NODE_ENV, '----') //const groupLink = process.env.NODE_ENV === 'production' ? window.g.groupLink : 'http://10.105.191.35:12024//#/App' //console.log('groupLink', groupLink) // 路由配置 const options = { routes: [ { path: '/login', name: '登录页', component: () => import('@/pages/login') }, { path: '*', name: '404', component: () => import('@/pages/exception/404') }, { path: '/403', name: '403', component: () => import('@/pages/exception/403') }, { path: '/', name: '首页', component: TabsView, redirect: '/login', children: [ { path: 'dashboard', name: '首页', component: () => import('@/pages/dashboard/index'), }, { path: 'WoManage', name: '工单管理', meta: { authority: { role: 'WoAdmin' } }, component: BlankView, children: [ { path: 'search', name: 'Search', meta: { authority: { permission: 'ViewSearch' } }, component: () => import('@/pages/workorderManage/Search') }, { path: 'woList', name: '工单处理', meta: { authority: { permission: 'ViewWorkOrderList' } }, component: () => import('@/pages/workorderManage/WorkOrderList') }, { path: 'woDetail', name: '工单详情', meta: { invisible: true // 不渲染到菜单栏 }, component: () => import('@/pages/workorderManage/WorkOrderDetail') } ] }, { path: 'SysManage', name: '系统管理', component: BlankView, meta: { authority: { role: 'SysAdmin' } }, children: [ { path: 'product', name: '非转贴Product维护', meta: { authority: { permission: 'ViewProduct' } }, component: () => import('@/pages/sysManage/Product') }, { path: 'markRule', name: 'ShenNongMark取值规则维护', meta: { authority: { permission: 'ViewMarkRules' } }, component: () => import('@/pages/sysManage/MarkRules') }, { path: 'sjWoVersionConfig', name: 'AB2升版卡控维护', meta: { authority: { permission: 'ViewSjWoVersionConfig' } }, component: () => import('@/pages/sysManage/SjWoVersionConfig') } ] }, { path: 'DieManage', name: '配DIE工单管理', meta: { authority: { role: 'DieAdmin' } }, component: BlankView, children: [ { path: 'productBom', name: '产品型号BOM', meta: { authority: { permission: 'ViewProductBom' } }, component: () => import('@/pages/dieManage/ProductBom') }, { path: 'woInventory', name: '主料待工单库存', meta: { authority: { permission: 'ViewWoInventory' } }, component: () => import('@/pages/dieManage/WoInventory') }, { path: 'topDieInventory', name: 'TOP DIE库存', meta: { authority: { permission: 'ViewTopDieInventory' } }, component: () => import('@/pages/dieManage/TopDieInventory') }, { path: 'dieConfig', name: 'AB1开单管理', meta: { authority: { permission: 'ViewDieConfig' } }, component: () => import('@/pages/dieManage/DieConfig') }, { path: 'createdWoManage', name: '已创建工单管理', meta: { authority: { permission: 'ViewCreatedWoManage' } }, component: () => import('@/pages/dieManage/CreatedWoManage') }, { path: 'assistMaintainInterface', name: '产品物料维护', meta: { invisible: true // 不渲染到菜单栏 }, component: () => import('@/pages/dieManage/AssistMaintainInterface') }, { path: 'ingredientBinding', name: '配料绑定界面', meta: { invisible: true // 不渲染到菜单栏 }, component: () => import('@/pages/dieManage/IngredientBinding') }, { path: 'woDetails', name: '工单详情', meta: { invisible: true // 不渲染到菜单栏 }, component: () => import('@/pages/dieManage/WoDetails') } ] }, ] } ] } export default options import routerMap from './router.map' import { parseRoutes } from '@/utils/routerUtil' // 异步路由配置 const routesConfig = [ 'login', 'root', { router: 'exp404', path: '*', name: '404' }, { router: 'exp403', path: '/403', name: '403' }, { router: 'homes', path: '/homes', name: 'homes' } // { // router:'toDo1', // path: '/cp/toDo', // name: 'toDo1', // }, // { // router:'toDo2', // path: '/ft/toDo', // name: 'toDo2', // }, ] const options = { routes: parseRoutes(routesConfig, routerMap) } export default options 基于现在这些文件,我还是固定的的路由,我该如何改成动态路由?
最新发布
09-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值