田源
2023-09-18 da6cc144cc4d60805e4693e4adc5ebdf78b5b37d
Source/UBCS-WEB/src/router/avue-router.js
@@ -23,23 +23,18 @@
    return result.join('&');
  }
  let titileName;
  this.$router.$avueRouter = {
    //全局配置
    $website: this.$store.getters.website,
    group: '',
    meta: {},
    safe: this,
    tianyuan:'',
    // 设置标题
    setTitle: (title) => {
      titileName=title
      const defaultTitle = this.$vue.$t('title');
      this.$router.$avueRouter.tianyuan=title
      title = title ? `${title}-${defaultTitle}` : defaultTitle;
      document.title = title;
    },
    closeTag: (value) => {
      let tag = value || this.$store.getters.tag;
      if (typeof value === 'string') {
@@ -90,11 +85,13 @@
    },
    //动态路由
    // 路由是专门的一个接口获取
    /**
     * aMenu: 接受到的动态路由数据 menu的结构外层有父级path 里面有一个childen 记录页面的路由
     * first: 为了区分外界 调用formatRoutes 和 当前文件调用 formatRoutes
     */
      /**
       * aMenu: 接受到的动态路由数据 menu的结构外层有父级path 里面有一个childen 记录页面的路由
       * first: 为了区分外界 调用formatRoutes 和 当前文件调用 formatRoutes
      */
    formatRoutes: function (aMenu = [], first) {
      // window.console.log('aMenu')
      // window.console.log(aMenu)
      const aRouter = []
      // 获取到全局配置中的 props
      const propsConfig = this.$website.menu.props;
@@ -102,6 +99,8 @@
      const propsDefault = {
        label: propsConfig.label || 'name',
        path: propsConfig.path || 'path',
        fullPath: propsConfig.fullPath || 'fullPath',
        query:propsConfig.query || 'query',
        icon: propsConfig.icon || 'icon',
        children: propsConfig.children || 'children',
        meta: propsConfig.meta || 'meta',
@@ -120,14 +119,29 @@
            } else {
              return oMenu[propsDefault.path]
            }
          })(),
          })();
          let fullPath=path;
        let query=oMenu[propsDefault.query] || {};
        if(path.indexOf('?')!=-1){
          let params=path.split('?')[1].split('@');
          path=path.split('?')[0]
          params.forEach(pitem=>{
            try {
              query[pitem.split('=')[0]]=pitem.split('=')[1];
            }catch (e) {
              query[pitem.split('=')[0]]=null;
            }
          })
        }
          //特殊处理组件 执行完这个 component 也就是精确到具体的文件了  views文件夹下面就是具体的页面代码
          component = 'views' + oMenu.path,
         let component = 'views' + path,
          name = oMenu[propsDefault.label],
          icon = oMenu[propsDefault.icon],
          children = oMenu[propsDefault.children],
          meta = oMenu[propsDefault.meta] || {};
        // meta中 keepalive 的处理
          // meta中 keepalive 的处理
        meta = Object.assign(meta, (function () {
          if (option.keepAlive === true) {
            return {
@@ -139,6 +153,9 @@
        const isChild = children.length !== 0;
        const oRouter = {
          path: path,
          fullPath:fullPath,
          query:query,
          params:query,
          component(resolve) {
            // 判断是否为首路由
            if (first) {
@@ -182,12 +199,11 @@
            /**
             * 这里是重点,当有子路由的时候 会再去执行 formatRoutes 方法,然后又会有一个新的 aMenu for循环。
             * 最后返回的是一个数组 aRouter 这个数组就会作为 childen的值被 return
             */
            */
            return this.formatRoutes(children, false)
          })()
        }
        aRouter.push(oRouter)
        // console.log(aRouter)
      }
      // for循环结束
      // 这个first 卡的其实就是首路由