87 lines
2.9 KiB
Python
87 lines
2.9 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 add_menu():
|
||
|
|
engine = create_async_engine(DATABASE_URL, echo=False)
|
||
|
|
|
||
|
|
async with engine.connect() as conn:
|
||
|
|
print("=" * 80)
|
||
|
|
print("Adding Test Form Menu")
|
||
|
|
print("=" * 80)
|
||
|
|
|
||
|
|
# 找到测试配置管理目录ID (ID:2059)
|
||
|
|
parent_id = 2059
|
||
|
|
|
||
|
|
if not parent_id:
|
||
|
|
print("[ERROR] Test Config directory not found")
|
||
|
|
return
|
||
|
|
|
||
|
|
print(f"[1] Found Test Config directory: {parent_id}")
|
||
|
|
|
||
|
|
# 检查是否已存在
|
||
|
|
result = await conn.execute(text("""
|
||
|
|
SELECT COUNT(*) FROM sys_menu WHERE path = 'test_form'
|
||
|
|
"""))
|
||
|
|
if result.scalar() > 0:
|
||
|
|
print("[INFO] Test Form menu already exists")
|
||
|
|
return
|
||
|
|
|
||
|
|
# 添加测试表单管理菜单
|
||
|
|
print("[2] Adding Test Form menu...")
|
||
|
|
await conn.execute(text(f"""
|
||
|
|
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component,
|
||
|
|
is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time)
|
||
|
|
VALUES ('表单管理', {parent_id}, 6, 'test_form', 'system/test_form/index',
|
||
|
|
0, 0, 'C', '0', '0', 'system:test_form:list', 'el-icon-document', 'admin', NOW())
|
||
|
|
"""))
|
||
|
|
await conn.commit()
|
||
|
|
|
||
|
|
# 获取新菜单ID
|
||
|
|
result = await conn.execute(text("""
|
||
|
|
SELECT menu_id FROM sys_menu WHERE path = 'test_form'
|
||
|
|
"""))
|
||
|
|
menu_id = result.scalar()
|
||
|
|
|
||
|
|
# 添加按钮权限
|
||
|
|
buttons = [
|
||
|
|
('表单查询', 'system:test_form:query'),
|
||
|
|
('表单新增', 'system:test_form:add'),
|
||
|
|
('表单修改', 'system:test_form:edit'),
|
||
|
|
('表单删除', 'system:test_form:remove'),
|
||
|
|
]
|
||
|
|
|
||
|
|
for btn_name, btn_perm in buttons:
|
||
|
|
await conn.execute(text(f"""
|
||
|
|
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component,
|
||
|
|
is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time)
|
||
|
|
VALUES ('{btn_name}', {menu_id}, 1, '#', NULL,
|
||
|
|
0, 0, 'F', '0', '0', '{btn_perm}', NULL, 'admin', NOW())
|
||
|
|
"""))
|
||
|
|
await conn.commit()
|
||
|
|
|
||
|
|
print(f"[OK] Test Form menu added (ID: {menu_id})")
|
||
|
|
|
||
|
|
print("\n" + "=" * 80)
|
||
|
|
|
||
|
|
await engine.dispose()
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
asyncio.run(add_menu())
|