109 lines
3.5 KiB
Python
109 lines
3.5 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""测试路由生成"""
|
||
|
|
|
||
|
|
import asyncio
|
||
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
||
|
|
from sqlalchemy import text
|
||
|
|
|
||
|
|
DB_CONFIG = {
|
||
|
|
'host': '123.57.81.127',
|
||
|
|
'port': 3306,
|
||
|
|
'user': 'cpy_admin',
|
||
|
|
'password': 'Tgzz2025+',
|
||
|
|
'database': 'ruoyi-fastapi'
|
||
|
|
}
|
||
|
|
|
||
|
|
DATABASE_URL = (
|
||
|
|
f"mysql+asyncmy://{DB_CONFIG['user']}:{DB_CONFIG['password']}@"
|
||
|
|
f"{DB_CONFIG['host']}:{DB_CONFIG['port']}/{DB_CONFIG['database']}"
|
||
|
|
)
|
||
|
|
|
||
|
|
async def test_router():
|
||
|
|
engine = create_async_engine(DATABASE_URL, echo=False)
|
||
|
|
|
||
|
|
async with engine.connect() as conn:
|
||
|
|
# 模拟后端路由生成逻辑
|
||
|
|
print("=" * 80)
|
||
|
|
print("Router Generation Test")
|
||
|
|
print("=" * 80)
|
||
|
|
|
||
|
|
# 获取工单管理目录
|
||
|
|
result = await conn.execute(text("""
|
||
|
|
SELECT menu_id, menu_name, path, component, menu_type, parent_id, is_frame, visible
|
||
|
|
FROM sys_menu
|
||
|
|
WHERE menu_id = 2112
|
||
|
|
"""))
|
||
|
|
parent = result.fetchone()
|
||
|
|
|
||
|
|
# 获取工单领取菜单
|
||
|
|
result = await conn.execute(text("""
|
||
|
|
SELECT menu_id, menu_name, path, component, menu_type, parent_id, is_frame, visible
|
||
|
|
FROM sys_menu
|
||
|
|
WHERE menu_id = 2113
|
||
|
|
"""))
|
||
|
|
child = result.fetchone()
|
||
|
|
|
||
|
|
print("\n[Parent Menu - Work Order Management]")
|
||
|
|
print(f" ID: {parent[0]}")
|
||
|
|
print(f" Name: {parent[1]}")
|
||
|
|
print(f" Path: {parent[2]}")
|
||
|
|
print(f" Component: {parent[3]}")
|
||
|
|
print(f" Type: {parent[4]} (M=Directory)")
|
||
|
|
print(f" Parent: {parent[5]}")
|
||
|
|
print(f" IsFrame: {parent[6]}")
|
||
|
|
print(f" Visible: {parent[7]}")
|
||
|
|
|
||
|
|
print("\n[Child Menu - Work Order Claim]")
|
||
|
|
print(f" ID: {child[0]}")
|
||
|
|
print(f" Name: {child[1]}")
|
||
|
|
print(f" Path: {child[2]}")
|
||
|
|
print(f" Component: {child[3]}")
|
||
|
|
print(f" Type: {child[4]} (C=Menu)")
|
||
|
|
print(f" Parent: {child[5]}")
|
||
|
|
print(f" IsFrame: {child[6]}")
|
||
|
|
print(f" Visible: {child[7]}")
|
||
|
|
|
||
|
|
# 模拟路由生成
|
||
|
|
print("\n[Generated Router Structure]")
|
||
|
|
|
||
|
|
# 父级目录
|
||
|
|
parent_router = {
|
||
|
|
"path": f"/{parent[2]}",
|
||
|
|
"component": "Layout",
|
||
|
|
"hidden": parent[7] == '1',
|
||
|
|
"children": [
|
||
|
|
{
|
||
|
|
"path": child[2].replace(parent[2] + '/', ''),
|
||
|
|
"component": child[3],
|
||
|
|
"name": "WorkOrderClaim",
|
||
|
|
"hidden": child[7] == '1',
|
||
|
|
"meta": {
|
||
|
|
"title": child[1],
|
||
|
|
"icon": ""
|
||
|
|
}
|
||
|
|
}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
print(f" Parent Path: {parent_router['path']}")
|
||
|
|
print(f" Parent Component: {parent_router['component']}")
|
||
|
|
print(f" Child Path: {parent_router['children'][0]['path']}")
|
||
|
|
print(f" Child Component: {parent_router['children'][0]['component']}")
|
||
|
|
|
||
|
|
# 前端最终路径
|
||
|
|
final_path = parent_router['path'] + '/' + parent_router['children'][0]['path']
|
||
|
|
print(f"\n Final URL Path: {final_path}")
|
||
|
|
print(f" Expected: /workorder/claim")
|
||
|
|
|
||
|
|
# 前端组件路径
|
||
|
|
component_path = parent_router['children'][0]['component']
|
||
|
|
print(f"\n Component Path: {component_path}")
|
||
|
|
print(f" Expected: workorder/claim/index")
|
||
|
|
|
||
|
|
print("\n" + "=" * 80)
|
||
|
|
|
||
|
|
await engine.dispose()
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
asyncio.run(test_router())
|