ruoyi 替换默认首页 替换redirect 使用后台查询的菜单数据替换首页

ruoyi 替换默认首页 替换redirect 使用后台查询的菜单数据替换首页

本人使用的ruoyi 版本 为 4.8.2

接触ruoyi的过程中发现他有一个默认的首页,然而在使用的过程中,每个用户权限不一致。就会产生每个用户需要访问不同首页的需求。 下面咱们实现一下这个需求

  1. 编写一个获取首页路径的函数

function checkFirstCharacter(str, char) { //检查首位字节
  return str.charAt(0) === char;
}

export function getMainPath(list , path) {
  if (list?.length){
    if (list[0].children){
      return getMainPath(list[0].children , checkFirstCharacter(list[0].path , '/') ? list[0].path : '/'+ list[0].path );
    }else {
      console.log('===',path);
      console.log('===',path? path +'/' + list[0].path : list[0].path);
      return path? path +'/' + list[0].path : list[0].path
    }
  }
}

该函数的规则是 获取路由的最上方的第一个路由 如下方数据 会最终生成的路径为 /tool/build

[
    {
        "name": "Tool",
        "path": "/tool",
        "children": [
            {
                "name": "Build",
                "path": "build",
                "hidden": false,
                "meta": {
                    "title": "表单构建",
                    "icon": "build",
                    "noCache": false,
                    "link": null
                }
            },
            {
                "name": "Gen",
                "path": "gen",
                "hidden": false,
                "meta": {
                    "title": "代码生成",
                    "icon": "code",
                    "noCache": false,
                    "link": null
                }
            }
        ]
    },
    {
        "name": "System",
        "path": "/system",
        "children": [
            {
                "name": "User",
                "path": "user",
                "hidden": false,
                "meta": {
                    "title": "用户管理",
                    "icon": "user",
                    "noCache": false,
                    "link": null
                }
            }
        ]
    }
]
  1. 第二步 删除原有首页
    在这里插入图片描述
  2. 更改 src\permission.js 文件

在这里插入图片描述
代码如下

store.dispatch('GetInfo').then(() => {
          isRelogin.show = false
          store.dispatch('GenerateRoutes').then(accessRoutes => {
            let path =  getMainPath(accessRoutes) ; //首页 
            router.addRoutes([{ //更改路由
                path: '/',
                redirect: path
              },
              {
                path: '/index',
                redirect: path
              }
            ])

            router.addRoutes(accessRoutes) // 动态添加可访问路由表
            
            next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
            
          })
        }).catch(err => {
            store.dispatch('LogOut').then(() => {
              Message.error(err)
              next({ path: '/' })
            })
          })
在Roayi框架进行二次开发时,如果需要批量替换特定字符串,通常涉及到文件内容的修改。以下是一个简单的步骤指南: 1. **定位目标文件**:首先找到Roayi项目中的所有可能包含待替换字符串的源代码文件,这可能包括但不限于控制器、服务类、配置文件等。 2. **编写脚本**:可以使用文本编辑器(如Notepad++或Sublime Text),或者通过编程语言(例如Python、批处理命令行、shell script)创建一个脚本来进行遍历和替换操作。比如在Python中,你可以使用`re.sub()`函数来替换字符串。 ```python import os import re # 替换规则 search_string = "ruoyi" # 要查找并替换的原始字符串 replacement_string = "your_new_string" # 新的字符串 # 遍历指定目录及其子目录下的所有.txt文件 for root, dirs, files in os.walk('path/to/your/project'): for file in files: if file.endswith('.txt'): # 只处理.txt类型的文件 with open(os.path.join(root, file), 'r', encoding='utf-8') as f: content = f.read() new_content = re.sub(search_string, replacement_string, content) with open(os.path.join(root, file), 'w', encoding='utf-8') as f: f.write(new_content) ``` 3. **执行脚本**:运行上述脚本,它会递归地查找指定目录下所有的.txt文件,并将找到的"ruoyi"替换为你想要的新字符串。 4. **检查结果**:替换完成后,记得检查每个文件是否按预期进行了修改,以防有遗漏或意外的替换
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值