653472def3
对齐 VeighNa 4.4 原生 Qt UI,新增成交监控、资金监控、网关管理、全局配置等页面与 API,功能对等性 98.5%。 - 新增 API: /api/v1/trades, /api/v1/accounts, /api/v1/settings, 网关扩展 - 新增前端页面: 成交、资金、合约、网关、全局配置、微信通知 - 扩展导航菜单与实时数据推送 - 补充需求分析与实现计划文档
263 lines
8.7 KiB
Python
263 lines
8.7 KiB
Python
"""
|
|
Phase 2 功能静态验证
|
|
验证前端代码是否包含所有 Phase 2 的功能
|
|
"""
|
|
import re
|
|
|
|
|
|
def test_app_js_features():
|
|
"""测试 app.js 是否包含 Phase 2 的功能"""
|
|
print("\n=== 测试 app.js 功能 ===")
|
|
|
|
try:
|
|
with open('sanguo_web/static/js/app.js', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
checks = [
|
|
('导航菜单包含活动委托', "active_orders"),
|
|
('导航菜单包含合约', "'contracts'"),
|
|
('合约状态定义', 'allContracts'),
|
|
('合约搜索功能', 'contractSearch'),
|
|
('合约过滤计算属性', 'filteredContracts'),
|
|
('排序状态管理', 'tableSort'),
|
|
('排序函数', 'sortTable'),
|
|
('排序图标函数', 'getSortIcon'),
|
|
('排序数据函数', 'sortData'),
|
|
('选中合约状态', 'selectedTick'),
|
|
('选择合约函数', 'selectTick'),
|
|
('刷新合约函数', 'refreshContracts'),
|
|
('合约 WebSocket 处理', "wsClient.on('contract'"),
|
|
('选中合约实时更新', 'selectedTick.value = data'),
|
|
('返回新状态和方法', 'allContracts')
|
|
]
|
|
|
|
passed = 0
|
|
failed = 0
|
|
|
|
for check_name, check_string in checks:
|
|
if check_string in content:
|
|
print(f"✓ {check_name}")
|
|
passed += 1
|
|
else:
|
|
print(f"✗ {check_name}")
|
|
failed += 1
|
|
|
|
print(f"\napp.js 检查: {passed}/{passed + failed} 通过")
|
|
return failed == 0
|
|
|
|
except Exception as e:
|
|
print(f"✗ app.js 测试异常: {e}")
|
|
return False
|
|
|
|
|
|
def test_index_html_features():
|
|
"""测试 index.html 是否包含 Phase 2 的功能"""
|
|
print("\n=== 测试 index.html 功能 ===")
|
|
|
|
try:
|
|
with open('sanguo_web/templates/index.html', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
checks = [
|
|
('活动委托页面', "currentPage === 'active_orders'"),
|
|
('活动委托表格排序', "sortData(activeOrders"),
|
|
('活动委托只显示活动订单', '未成交和部分成交的订单'),
|
|
('合约管理页面', "currentPage === 'contracts'"),
|
|
('合约搜索框', 'v-model="contractSearch"'),
|
|
('合约刷新按钮', '@click="refreshContracts"'),
|
|
('合约表格排序', "sortData(filteredContracts"),
|
|
('市场深度盘口', 'order-book'),
|
|
('卖盘五档', 'ask_price_5'),
|
|
('买盘五档', 'bid_price_5'),
|
|
('最新价显示', 'last-price'),
|
|
('涨跌幅显示', 'price-change'),
|
|
('选中合约提示', 'selectedTick'),
|
|
('交易页面委托列表排序', "sortData(allOrders"),
|
|
('行情页面排序', "sortData(filteredTicks"),
|
|
('持仓页面排序', "sortData(positions"),
|
|
('成交页面排序', "sortData(trades"),
|
|
('资金页面排序', "sortData(allAccounts"),
|
|
('策略页面排序', "sortData(strategies, tableSort")
|
|
]
|
|
|
|
passed = 0
|
|
failed = 0
|
|
|
|
for check_name, check_string in checks:
|
|
if check_string in content:
|
|
print(f"✓ {check_name}")
|
|
passed += 1
|
|
else:
|
|
print(f"✗ {check_name}")
|
|
failed += 1
|
|
|
|
print(f"\nindex.html 检查: {passed}/{passed + failed} 通过")
|
|
return failed == 0
|
|
|
|
except Exception as e:
|
|
print(f"✗ index.html 测试异常: {e}")
|
|
return False
|
|
|
|
|
|
def test_css_features():
|
|
"""测试 CSS 是否包含 Phase 2 的功能"""
|
|
print("\n=== 测试 CSS 功能 ===")
|
|
|
|
try:
|
|
with open('sanguo_web/static/css/main.css', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
checks = [
|
|
('市场深度盘口样式', '.order-book'),
|
|
('卖盘样式', '.order-book-row.ask'),
|
|
('买盘样式', '.order-book-row.bid'),
|
|
('卖盘颜色', 'rgb(160, 255, 160)'),
|
|
('买盘颜色', 'rgb(255, 174, 201)'),
|
|
('选中行样式', '.selected-row'),
|
|
('买盘单元格', '.bid-cell'),
|
|
('卖盘单元格', '.ask-cell'),
|
|
('合约信息文本', '.info-text'),
|
|
('选中合约标签', '.selected-tick')
|
|
]
|
|
|
|
passed = 0
|
|
failed = 0
|
|
|
|
for check_name, check_string in checks:
|
|
if check_string in content:
|
|
print(f"✓ {check_name}")
|
|
passed += 1
|
|
else:
|
|
print(f"✗ {check_name}")
|
|
failed += 1
|
|
|
|
print(f"\nCSS 检查: {passed}/{passed + failed} 通过")
|
|
return failed == 0
|
|
|
|
except Exception as e:
|
|
print(f"✗ CSS 测试异常: {e}")
|
|
return False
|
|
|
|
|
|
def test_websocket_events():
|
|
"""测试 WebSocket 事件处理是否支持五档数据"""
|
|
print("\n=== 测试 WebSocket 事件处理 ===")
|
|
|
|
try:
|
|
with open('sanguo_web/websocket/events.py', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
checks = [
|
|
('bid_price_2 字段', 'bid_price_2'),
|
|
('bid_price_3 字段', 'bid_price_3'),
|
|
('bid_price_4 字段', 'bid_price_4'),
|
|
('bid_price_5 字段', 'bid_price_5'),
|
|
('ask_price_2 字段', 'ask_price_2'),
|
|
('ask_price_3 字段', 'ask_price_3'),
|
|
('ask_price_4 字段', 'ask_price_4'),
|
|
('ask_price_5 字段', 'ask_price_5'),
|
|
('bid_volume_2-5 字段', 'bid_volume_5'),
|
|
('ask_volume_2-5 字段', 'ask_volume_5')
|
|
]
|
|
|
|
passed = 0
|
|
failed = 0
|
|
|
|
for check_name, check_string in checks:
|
|
if check_string in content:
|
|
print(f"✓ {check_name}")
|
|
passed += 1
|
|
else:
|
|
print(f"✗ {check_name}")
|
|
failed += 1
|
|
|
|
print(f"\nWebSocket 事件检查: {passed}/{passed + failed} 通过")
|
|
return failed == 0
|
|
|
|
except Exception as e:
|
|
print(f"✗ WebSocket 测试异常: {e}")
|
|
return False
|
|
|
|
|
|
def test_backend_api():
|
|
"""测试后端 API 是否支持 Phase 2 功能"""
|
|
print("\n=== 测试后端 API ===")
|
|
|
|
try:
|
|
# 检查 trading.py 中的活动订单 API
|
|
with open('sanguo_web/api/routes/trading.py', 'r', encoding='utf-8') as f:
|
|
trading_content = f.read()
|
|
|
|
# 检查 market.py 中的合约 API
|
|
with open('sanguo_web/api/routes/market.py', 'r', encoding='utf-8') as f:
|
|
market_content = f.read()
|
|
|
|
checks = [
|
|
('活动订单 API 端点', 'get("/orders/active"', trading_content),
|
|
('获取所有订单 API', 'get("/orders"', trading_content),
|
|
('获取合约 API', 'get("/contracts"', market_content),
|
|
('获取行情 API', 'get("/ticks"', market_content)
|
|
]
|
|
|
|
passed = 0
|
|
failed = 0
|
|
|
|
for check_name, check_string, content in checks:
|
|
if check_string in content:
|
|
print(f"✓ {check_name}")
|
|
passed += 1
|
|
else:
|
|
print(f"✗ {check_name}")
|
|
failed += 1
|
|
|
|
print(f"\n后端 API 检查: {passed}/{passed + failed} 通过")
|
|
return failed == 0
|
|
|
|
except Exception as e:
|
|
print(f"✗ 后端 API 测试异常: {e}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""主测试函数"""
|
|
print("=" * 60)
|
|
print("Phase 2 功能静态验证")
|
|
print("=" * 60)
|
|
|
|
results = []
|
|
|
|
# 测试各个文件
|
|
results.append(("app.js 功能", test_app_js_features()))
|
|
results.append(("index.html 功能", test_index_html_features()))
|
|
results.append(("CSS 功能", test_css_features()))
|
|
results.append(("WebSocket 事件", test_websocket_events()))
|
|
results.append(("后端 API", test_backend_api()))
|
|
|
|
# 汇总结果
|
|
print("\n" + "=" * 60)
|
|
print("静态验证结果汇总")
|
|
print("=" * 60)
|
|
|
|
passed = sum(1 for _, result in results if result)
|
|
total = len(results)
|
|
|
|
for name, result in results:
|
|
status = "✓ 通过" if result else "✗ 失败"
|
|
print(f"{name}: {status}")
|
|
|
|
print(f"\n总计: {passed}/{total} 通过")
|
|
|
|
if passed == total:
|
|
print("\n🎉 静态验证全部通过!Phase 2 功能代码已正确实现。")
|
|
print("\n功能清单:")
|
|
print("1. ✓ 活动委托视图 - 只显示未成交和部分成交的订单")
|
|
print("2. ✓ 市场深度盘口 - 五档盘口显示(买盘/卖盘)")
|
|
print("3. ✓ 合约管理页面 - 合约查询和搜索过滤")
|
|
print("4. ✓ 表格排序功能 - 所有数据表格支持排序")
|
|
else:
|
|
print(f"\n⚠ 有 {total - passed} 个验证失败,请检查相关文件。")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|