python跳转界面到 前端项目的router文件,给出route json配置供复制 代码放在项目根目录

该文章展示了一个Python脚本,它用于处理从后端到前端项目的router配置。脚本包含了获取相对路径、Windows到Linux路径转换的功能,并生成特定格式的routeJSON配置。主要操作包括对文件路径的处理,以构建前端页面路由。
摘要由CSDN通过智能技术生成

python跳转界面到 前端项目的router文件,给出route json配置供复制
代码放在项目根目录
D:\proj\brain\admin-antd-react\go_router.py
文档:python跳转界面到 前端项目的router文?..
链接:http://note.youdao.com/noteshare?id=27e06dc9ba08ac62074e4aa44115186b&sub=A32DCD33B5F045E1AEA4EF0023182AEC
添加链接描述

# D:\proj\brain\chat-brain\src\layouts\UniversalLayout\routes.ts

import os 


tpl="""
{
        path: '{path}',
        meta: {
          icon: 'control',
          title: '{pages_name}',
        },
        component: lazy(() => import('@/pages/{pages_name}')),
      },"""

import os


def parent_directory(file_path):
        # 获取父路径
    parent_directory = os.path.dirname(file_path)

    # print(parent_directory)  # 输出父路径
    return parent_directory

def get_relative_path(filePath = rf"D:\proj\brain\chat-brain\src\pages\Ta\index.tsx"):
    """
    Ta\index.tsx
    """
    
    # filePath = rf"D:\proj\brain\chat-brain\src\pages\Ta\index.tsx"

    # 获取父路径
    parent_directory = os.path.dirname(os.path.dirname(filePath))

    # 去掉前面的绝对路径
    relative_path = filePath.replace(parent_directory, "", 1).lstrip("\\/")

    print("relative_path")  # 输出相对路径
    print(relative_path)

    linux_path=win_path_to_linux_path(relative_path)
    return linux_path

def win_path_to_linux_path(win_path = r"D:\proj\brain\chat-brain\src\pages\Ta\index.tsx"):
    # win_path = r"D:\proj\brain\chat-brain\src\pages\Ta\index.tsx"

    linux_path = win_path.replace("\\", "/")

    # print(linux_path)  # 输出Linux路径
    return linux_path


filePath = rf"""
D:\proj\brain\admin-antd-react\src\pages\ParentComponent
"""
# 获取 pages 后面的 名字
filePath=filePath.strip() 
filePath=filePath.replace(".tsx","")

parts=filePath.split("pages\\")
relative_path=parts[1]
pages_name=relative_path.replace("\\index.tsx","")
# python 获取文件名字 到他的上一级目录为止
# 获取pages名称
dirName=os.path.dirname(filePath)
print("dirName",dirName)

path=filePath.replace("\\", "/")
code=tpl.replace("{path}",pages_name).replace("{pages_name}",pages_name)

print(code)
print("\n\n")



cmd=rf'code src/layouts/UniversalLayout/routes.ts'
print(cmd)
os.system(cmd)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值