wangting
2024-05-14 51636e9cd814bddba7a9b4ff21b5bc94e95fb6cb
Source/ProjectWeb/src/router/avue-router.js
@@ -1,3 +1,5 @@
import {validatenull} from "@/util/validate";
let RouterPlugin = function () {
  this.$router = null;
  this.$store = null;
@@ -90,7 +92,6 @@
     * first: 为了区分外界 调用formatRoutes 和 当前文件调用 formatRoutes
     */
    formatRoutes: function (aMenu = [], first) {
      // debugger;
      const aRouter = []
      // 获取到全局配置中的 props
      const propsConfig = this.$website.menu.props;
@@ -98,7 +99,8 @@
      const propsDefault = {
        label: propsConfig.label || 'name',
        path: 'code',
        pathValue:propsConfig.path || 'path',
        code: 'code',
        pathValue: 'pathValue',
        icon: propsConfig.icon || 'icon',
        children: propsConfig.children || 'children',
        meta: propsConfig.meta || 'meta',
@@ -119,20 +121,32 @@
          }
        })();
        let code = (() => {
            return oMenu[propsDefault.path]
          return oMenu[propsDefault.code]
        })();
        // 将字符串分割成数组,以'?'作为分隔符
        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";
        let component = '';
        let parts = '';
        // 如果路径中存在 '?',则取问号前面部分给 parts
        if (path.includes('?')) {
          parts = path.split("?")[0];
        } else {
          parts = path; // 不存在 '?' 整条路径就是 parts
        }
        if(validatenull(parts)){
          parts='UI';
        }
        // 如果问号前面部分不在 ['ui', 'UI', 'base'] 中,则是自定义组件
        if (!['ui', 'UI', 'base','bs'].includes(parts) && parts.indexOf('views/')==-1) {
          component = `views/custom-ui/${parts}`;
        }else if (['UI', 'ui', 'base','bs'].includes(parts)) {
          // 如果问号前面等于 UI、ui 则为UI引擎
          component = 'views/base/UIContentViewer';
        }else{
          component = `${parts}`;
        }
        //特殊处理组件 执行完这个 component 也就是精确到具体的文件了  views文件夹下面就是具体的页面代码
        let component = bsValue === 'UI' ? 'views/base/UIContentViewer' : `views/custom-ui/${bsValue}`,
          name = oMenu[propsDefault.label],
        let name = oMenu[propsDefault.label],
          icon = oMenu[propsDefault.icon],
          children = oMenu[propsDefault.children],
          meta = oMenu[propsDefault.meta] || {};
@@ -147,7 +161,7 @@
        //是否有子路由
        const isChild = children.length !== 0;
        const oRouter = {
          path: code,
          path: '/' + code,
          component(resolve) {
            // 判断是否为首路由
            if (first) {
@@ -175,7 +189,7 @@
          children: !isChild ? (() => {
            if (first) {
              // 这里的isURL判断,因为这个网站有使用 iframe。所以需要判断是否为网页链接
              if (!isURL(path)) oMenu[propsDefault.path] = `${path}/index`;
              if (!isURL(path)) oMenu[propsDefault.pathValue] = `${path}/index`;
              return [{
                component(resolve) {
                  require([`../${component}.vue`], resolve)