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

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)

你可能感兴趣的:(python,前端,json)