Files
monisuo/test_flutter_asset.sh
sion f0af05e366 fix: 修复资金账户余额显示0.00的问题
主要修改:
1. asset_page.dart - _FundAccountCard组件
   - 添加fallback逻辑:优先使用fund.balance,如果为null则使用overview.fundBalance
   - 确保即使fund数据未加载也能显示余额

2. asset_page.dart - initState方法
   - 强制刷新数据(force: true),不使用缓存
   - 确保每次进入页面都加载最新数据

3. 添加账户体系设计文档
   - ACCOUNT_SYSTEM_DESIGN.md - 完整的账户体系设计
   - check_flutter_data.md - 问题诊断步骤

修复后效果:
-  资金账户余额正确显示 (15500 USDT)
-  数据加载更可靠
-  页面刷新时强制更新数据

问题原因:
- fund数据可能未加载或为null
- 添加fallback到overview.fundBalance
- 强制刷新确保数据最新
2026-03-24 16:58:31 +08:00

90 lines
2.8 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
BASE_URL="http://localhost:5010"
echo "================================"
echo "测试Flutter资产页面API调用"
echo "================================"
# 1. 用户登录
echo -e "\n步骤1: 用户登录..."
LOGIN_RESPONSE=$(curl -s -X POST "$BASE_URL/api/user/login" \
-H "Content-Type: application/json" \
-d '{"username":"abcd","password":"abcd123"}')
TOKEN=$(echo $LOGIN_RESPONSE | python3 -c "
import sys, json
data = json.load(sys.stdin)
if data.get('success'):
print(data['data']['token'])
" 2>/dev/null)
if [ -z "$TOKEN" ]; then
echo "❌ 登录失败"
exit 1
fi
echo "✅ 登录成功"
# 2. 测试资产总览Flutter首页调用
echo -e "\n================================"
echo "测试1: /api/asset/overview (资产总览)"
echo "================================"
OVERVIEW=$(curl -s "$BASE_URL/api/asset/overview" \
-H "Authorization: Bearer $TOKEN")
echo "$OVERVIEW" | python3 -m json.tool
# 3. 测试资金账户Flutter资金账户Tab调用
echo -e "\n================================"
echo "测试2: /api/asset/fund (资金账户)"
echo "================================"
FUND=$(curl -s "$BASE_URL/api/asset/fund" \
-H "Authorization: Bearer $TOKEN")
echo "$FUND" | python3 -m json.tool
# 4. 测试交易账户Flutter交易账户Tab调用
echo -e "\n================================"
echo "测试3: /api/asset/trade (交易账户)"
echo "================================"
TRADE=$(curl -s "$BASE_URL/api/asset/trade" \
-H "Authorization: Bearer $TOKEN")
echo "$TRADE" | python3 -m json.tool
# 5. 分析数据结构
echo -e "\n================================"
echo "数据分析"
echo "================================"
echo "$FUND" | python3 -c "
import sys, json
data = json.load(sys.stdin)
if data.get('success') and data.get('data'):
fund = data['data'].get('fund', {})
print('资金账户数据:')
print(f' - balance: {fund.get(\"balance\")}')
print(f' - frozen: {fund.get(\"frozen\")}')
print(f' - total_deposit: {fund.get(\"totalDeposit\")}')
print(f' - total_withdraw: {fund.get(\"totalWithdraw\")}')
if fund.get('balance') == 0:
print('\n⚠ 余额为0但数据库中应该有15500')
else:
print(f'\n✅ 余额正确: {fund.get(\"balance\")}')
"
echo "$TRADE" | python3 -c "
import sys, json
data = json.load(sys.stdin)
if data.get('success') and data.get('data'):
positions = data['data'].get('positions', [])
print(f'\n交易账户持仓数: {len(positions)}')
if positions:
for pos in positions:
print(f' - {pos.get(\"coinCode\")}: {pos.get(\"quantity\")} (价值: {pos.get(\"value\")} USDT)')
else:
print(' 暂无持仓')
"
echo -e "\n================================"
echo "测试完成"
echo "================================"