田源
2024-04-07 0ba9e571a77dab21c749461c298af1bca69b6b98
路由整合代码
已修改3个文件
262 ■■■■■ 文件已修改
Source/ProjectWeb/src/router/avue-router.js 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/router/page/index.js 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/store/modules/user.js 215 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/router/avue-router.js
@@ -97,7 +97,8 @@
      // 设置 props默认值 作用就是将字段设置成配置的
      const propsDefault = {
        label: propsConfig.label || 'name',
        path: propsConfig.path || 'path',
        path: 'code',
        pathValue:propsConfig.path || 'path',
        icon: propsConfig.icon || 'icon',
        children: propsConfig.children || 'children',
        meta: propsConfig.meta || 'meta',
@@ -110,15 +111,27 @@
        const oMenu = aMenu[i];
        // 这一块的赋值 也就是取到返回的值
        let path = (() => {
            if (first) {
              // 将 '/index' 替换为 ''
              return oMenu[propsDefault.path].replace('/index', '')
            } else {
              return oMenu[propsDefault.path]
            }
          })(),
          //特殊处理组件 执行完这个 component 也就是精确到具体的文件了  views文件夹下面就是具体的页面代码
          component = 'views' + path,
          if (first) {
            // 将 '/index' 替换为 ''
            return oMenu[propsDefault.pathValue].replace('/index', '')
          } else {
            return oMenu[propsDefault.pathValue]
          }
        })();
        let code = (() => {
            return oMenu[propsDefault.path]
        })();
        // 将字符串分割成数组,以'?'作为分隔符
        let parts = path.split("?");
        // 如果数组的长度大于1,表示有'?',则取第一个元素的第一个部分,否则直接取整个字符串
        let bsValue = parts.length > 1 ? parts[0].split("=")[1] : path.split("=")[1];
        if (bsValue ===''  || bsValue === undefined || bsValue === null ) {
          bsValue = "UI";
        }
        //特殊处理组件 执行完这个 component 也就是精确到具体的文件了  views文件夹下面就是具体的页面代码
        let component = bsValue === 'UI' ? 'views/base/UIContentViewer' : `views/custom-ui/${bsValue}`,
          name = oMenu[propsDefault.label],
          icon = oMenu[propsDefault.icon],
          children = oMenu[propsDefault.children],
@@ -134,7 +147,7 @@
        //是否有子路由
        const isChild = children.length !== 0;
        const oRouter = {
          path: path,
          path: code,
          component(resolve) {
            // 判断是否为首路由
            if (first) {
Source/ProjectWeb/src/router/page/index.js
@@ -90,6 +90,18 @@
    ]
  },
  {
    path: '/UIContentViewer',
    name: '动态表格页面',
    component: Layout,
    children: [
      {
        path: '', // 空路径表示访问 '/dynamic-form' 时加载 Layout 组件
        component: () => import('@/views/base/UIContentViewer'),
        props: true
      }
    ]
  },
  {
    path: '/referIndex',
    name: '动态表格页面',
    component: Layout,
Source/ProjectWeb/src/store/modules/user.js
@@ -14,7 +14,7 @@
  const propsConfig = menu.props;
  const propsDefault = {
    label: propsConfig.label || 'name',
    path: propsConfig.path || 'path',
    path: 'code',
    icon: propsConfig.icon || 'icon',
    children: propsConfig.children || 'children'
  }
@@ -31,6 +31,8 @@
  }
}
const user = {
  state: {
@@ -204,14 +206,221 @@
    GetMenu({commit, dispatch}, topMenuId) {
      return new Promise(resolve => {
        getRoutes('modelManagmentNode').then((res) => {
          const list =[
            {
              "action": null,
              "actionName": null,
              "alias": "资源库",
              "category": null,
              "categoryName": null,
              "children": [
                {
                  "action": null,
                  "actionName": null,
                  "alias": "知识库",
                  "category": null,
                  "categoryName": null,
                  "children": [
                    {
                      "action": null,
                      "actionName": null,
                      "alias": "resourcelib",
                      "category": null,
                      "categoryName": null,
                      "children": [],
                      "code": "resourcelib",
                      "hasChildren": false,
                      "id": "2C5FABD2-535F-8568-8E61-C643BA7D77A1",
                      "isOpen": null,
                      "isOpenName": null,
                      "meta": {
                        "keepAlive": false
                      },
                      "name": "设备资源库",
                      "parentId": "9B00AD2C-A407-7F71-B35C-58E466E53A33",
                      "parentName": null,
                      "path": "bs=test?image=resource&type=folder&context=resourcemanager&querytype=0&querytemplate=resourcelibroot",
                      "remark": null,
                      "sort": 1,
                      "source": ""
                    },
                    {
                      "action": null,
                      "actionName": null,
                      "alias": "工艺知识库",
                      "category": null,
                      "categoryName": null,
                      "children": [],
                      "code": "gongyi",
                      "hasChildren": false,
                      "id": "AC04E222-F14B-F4FF-11BB-DFE8917A2756",
                      "isOpen": null,
                      "isOpenName": null,
                      "meta": {
                        "keepAlive": false
                      },
                      "name": "工艺知识库",
                      "parentId": "9B00AD2C-A407-7F71-B35C-58E466E53A33",
                      "parentName": null,
                      "path": "bs=UI?image=report&type=folder&context=knowledgemanager&querytype=0&querytemplate=knowledgelibroot",
                      "remark": null,
                      "sort": 2,
                      "source": ""
                    }
                  ],
                  "code": "zhishiku",
                  "hasChildren": true,
                  "id": "9B00AD2C-A407-7F71-B35C-58E466E53A33",
                  "isOpen": null,
                  "isOpenName": null,
                  "meta": {
                    "keepAlive": false
                  },
                  "name": "知识库",
                  "parentId": "4EDC91B8-E3B2-D126-E75C-D2CEC59F53CE",
                  "parentName": null,
                  "path": "bs=/base",
                  "remark": null,
                  "sort": 1,
                  "source": ""
                },
                {
                  "action": null,
                  "actionName": null,
                  "alias": "TemplateLib",
                  "category": null,
                  "categoryName": null,
                  "children": [
                    {
                      "action": null,
                      "actionName": null,
                      "alias": "CardTemplateLib",
                      "category": null,
                      "categoryName": null,
                      "children": [],
                      "code": "CardTemplateLib",
                      "hasChildren": false,
                      "id": "E6E963E7-2DF6-80EE-2A61-FA86E0F3D5F2",
                      "isOpen": null,
                      "isOpenName": null,
                      "meta": {
                        "keepAlive": false
                      },
                      "name": "卡片模板",
                      "parentId": "8493A92A-13DA-8800-140D-9C0C4A722665",
                      "parentName": null,
                      "path": "bs=?image=card&type=folder&context=cardtemplatemanager&querytype=0&querytemplate=cardtemplateroot",
                      "remark": null,
                      "sort": 1,
                      "source": ""
                    }
                  ],
                  "code": "TemplateLib",
                  "hasChildren": true,
                  "id": "8493A92A-13DA-8800-140D-9C0C4A722665",
                  "isOpen": null,
                  "isOpenName": null,
                  "meta": {
                    "keepAlive": false
                  },
                  "name": "模板库",
                  "parentId": "4EDC91B8-E3B2-D126-E75C-D2CEC59F53CE",
                  "parentName": null,
                  "path": "bs=mb",
                  "remark": null,
                  "sort": 2,
                  "source": ""
                },
                {
                  "action": null,
                  "actionName": null,
                  "alias": "典型数据库",
                  "category": null,
                  "categoryName": null,
                  "children": [
                    {
                      "action": null,
                      "actionName": null,
                      "alias": "典型规程",
                      "category": null,
                      "categoryName": null,
                      "children": [],
                      "code": "guicheng",
                      "hasChildren": false,
                      "id": "B3EC1413-1A33-61E3-DDD1-CB4D0CFD0C6E",
                      "isOpen": null,
                      "isOpenName": null,
                      "meta": {
                        "keepAlive": false
                      },
                      "name": "典型规程",
                      "parentId": "BDBD6CFA-2F4C-EEF7-C380-5E9BBF6A37B3",
                      "parentName": null,
                      "path": "bs=?image=typical&type=workorder&context=TypicalProcessLib",
                      "remark": null,
                      "sort": 1,
                      "source": ""
                    }
                  ],
                  "code": "dianxing",
                  "hasChildren": true,
                  "id": "BDBD6CFA-2F4C-EEF7-C380-5E9BBF6A37B3",
                  "isOpen": null,
                  "isOpenName": null,
                  "meta": {
                    "keepAlive": false
                  },
                  "name": "典型数据库",
                  "parentId": "4EDC91B8-E3B2-D126-E75C-D2CEC59F53CE",
                  "parentName": null,
                  "path": "bs=dx",
                  "remark": null,
                  "sort": 3,
                  "source": ""
                }
              ],
              "code": "ziyuanku",
              "hasChildren": true,
              "id": "4EDC91B8-E3B2-D126-E75C-D2CEC59F53CE",
              "isOpen": null,
              "isOpenName": null,
              "meta": {
                "keepAlive": false
              },
              "name": "资源库",
              "parentId": "modelManagmentNode",
              "parentName": null,
              "path": "bs=zy",
              "remark": null,
              "sort": 913,
              "source": ""
            }
          ];
          const data = res.data.obj;
          let menu = deepClone(data);
          let menu = deepClone(list);
          menu.forEach(ele => {
            addPath(ele, true);
          });
          updateCode(menu)
          function updateCode(items) {
            items.forEach(item => {
              // 将字符串分割成数组,以'?'作为分隔符
              let parts = item.path.split("?");
              // 如果数组的长度大于1,表示有'?',则取第一个元素的第一个部分,否则直接取整个字符串
              let bsValue = parts.length > 1 ? parts[0].split("=")[1] : item.path.split("=")[1];
              if (bsValue ===''  || bsValue === undefined || bsValue === null) {
                bsValue = "UI";
              }
              item.path = bsValue === 'UI' ? '/base/UIContentViewer' :  `/custom-ui/${bsValue}`;
              // 如果children不为空,递归调用这个函数
              if (item.children && item.children.length > 0) {
                updateCode(item.children);
              }
            });
          }
          commit('SET_MENU_ALL', menu)
          commit('SET_MENU', menu)
          //dispatch('GetButtons');
          //dispatch('GetButtons');s
          resolve(menu)
        })
      })