refactor: 统一API路径和字段命名,优化数据请求逻辑
- 将API路径从'/api/user/info'改为'api/v1/user/info'以统一版本前缀 - 将数据字段从大驼峰改为小驼峰命名规范 - 使用onShow替代onMounted并添加防重复请求机制 - 移除策略编辑页面的导航栏,简化页面结构 - 优化交易记录页面按钮样式和文案
This commit is contained in:
parent
291024f9e7
commit
43280fa447
@ -116,18 +116,18 @@
|
||||
<view class="timeline-box">
|
||||
<view class="timeline-item" v-for="(log, k) in logs" :key="k">
|
||||
<view class="tl-left">
|
||||
<text class="tl-date">{{ log.Date }}</text>
|
||||
<text class="tl-time">{{ log.Time }}</text>
|
||||
<text class="tl-date">{{ log.date }}</text>
|
||||
<text class="tl-time">{{ log.time }}</text>
|
||||
</view>
|
||||
|
||||
<view class="tl-line">
|
||||
<view class="tl-dot" :class="log.Type === 'buy' ? 'bg-red' : 'bg-green'"></view>
|
||||
<view class="tl-dot" :class="log.type === 'buy' ? 'bg-red' : 'bg-green'"></view>
|
||||
<view class="tl-dash" v-if="k !== logs.length - 1"></view>
|
||||
</view>
|
||||
|
||||
<view class="tl-right">
|
||||
<text class="tl-title">{{ log.Title }}</text>
|
||||
<text class="tl-desc">{{ log.Type === 'buy' ? '录入增加' : '结出减少' }} {{ log.Amount }}</text>
|
||||
<text class="tl-title">{{ log.title }}</text>
|
||||
<text class="tl-desc">{{ log.type === 'buy' ? '增加' : '减少' }} {{ log.amount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -136,11 +136,11 @@
|
||||
<view class="action-section fixed-bottom">
|
||||
<button class="action-btn btn-buy" @click="handleBuy">
|
||||
<uni-icons type="download" size="20" color="#FFFFFF"></uni-icons>
|
||||
<text class="btn-text">录入增加 / 比例校准</text>
|
||||
<text class="btn-text">增加</text>
|
||||
</button>
|
||||
<button class="action-btn btn-sell" @click="handleSell">
|
||||
<uni-icons type="upload" size="20" color="#064E3B"></uni-icons>
|
||||
<text class="btn-text">结出减少 / 调减</text>
|
||||
<text class="btn-text">减少</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
@ -148,7 +148,7 @@
|
||||
<view v-if="showTransactionForm" class="transaction-modal">
|
||||
<view class="modal-content">
|
||||
<view class="modal-header">
|
||||
<text class="modal-title">{{ transactionType === 'buy' ? '录入增加' : '结出减少' }}</text>
|
||||
<text class="modal-title">{{ transactionType === 'buy' ? '增加' : '减少' }}</text>
|
||||
<view class="close-btn" @click="showTransactionForm = false">
|
||||
<uni-icons type="close" size="20" color="#6B7280"></uni-icons>
|
||||
</view>
|
||||
@ -302,8 +302,8 @@ onMounted(async () => {
|
||||
});
|
||||
|
||||
const goStrategyConfig = () => {
|
||||
if (portfolioData.value.strategy?.Id) {
|
||||
uni.navigateTo({ url: `/pages/strategies/edit/edit?id=${portfolioData.value.strategy.Id}` });
|
||||
if (portfolioData.value.strategy?.id) {
|
||||
uni.navigateTo({ url: `/pages/strategies/edit/edit?id=${portfolioData.value.strategy.id}` });
|
||||
}
|
||||
};
|
||||
|
||||
@ -538,6 +538,16 @@ const submitTransaction = async () => {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
border: none;
|
||||
flex-direction: row;
|
||||
padding: 0 16rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.btn-text {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
line-height: 1.3;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.btn-buy { background-color: #064E3B; color: #FFFFFF; box-shadow: 0 8rpx 20rpx rgba(6, 78, 59, 0.2); }
|
||||
.btn-buy:active { background-color: #047857; }
|
||||
|
||||
@ -91,7 +91,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { ref, onShow } from 'vue';
|
||||
import { api } from '../../utils/api';
|
||||
|
||||
// 资产数据
|
||||
@ -104,8 +104,12 @@ const assetData = ref({
|
||||
// 持仓组合数据
|
||||
const holdings = ref([]);
|
||||
|
||||
// 防止重复请求的标志
|
||||
let isFetching = false;
|
||||
|
||||
// 从后端API获取资产数据的函数
|
||||
const fetchAssetData = async () => {
|
||||
if (isFetching) return;
|
||||
try {
|
||||
console.log('开始获取资产数据...');
|
||||
const response = await api.assets.getAssetData();
|
||||
@ -113,11 +117,11 @@ const fetchAssetData = async () => {
|
||||
// 映射资产数据字段
|
||||
const data = response.data;
|
||||
assetData.value = {
|
||||
totalValue: data.TotalValue,
|
||||
currency: data.Currency,
|
||||
todayProfit: data.TodayProfit,
|
||||
todayProfitCurrency: data.TodayProfitCurrency,
|
||||
totalReturnRate: data.TotalReturnRate
|
||||
totalValue: data.totalValue,
|
||||
currency: data.currency,
|
||||
todayProfit: data.todayProfit,
|
||||
todayProfitCurrency: data.todayProfitCurrency,
|
||||
totalReturnRate: data.totalReturnRate
|
||||
};
|
||||
console.log('资产数据获取成功');
|
||||
}
|
||||
@ -128,6 +132,7 @@ const fetchAssetData = async () => {
|
||||
|
||||
// 从后端API获取持仓组合数据的函数
|
||||
const fetchHoldingsData = async () => {
|
||||
if (isFetching) return;
|
||||
try {
|
||||
console.log('开始获取持仓数据...');
|
||||
const response = await api.assets.getHoldings();
|
||||
@ -135,18 +140,18 @@ const fetchHoldingsData = async () => {
|
||||
// 处理响应数据结构,获取 items 数组并映射字段
|
||||
const items = response.data.items || [];
|
||||
holdings.value = items.map(item => ({
|
||||
id: item.Id,
|
||||
name: item.Name,
|
||||
tags: item.Tags,
|
||||
status: item.Status,
|
||||
statusType: item.StatusType,
|
||||
iconChar: item.IconChar,
|
||||
iconBgClass: item.IconBgClass,
|
||||
iconTextClass: item.IconTextClass,
|
||||
value: item.Value,
|
||||
currency: item.Currency,
|
||||
returnRate: item.ReturnRate,
|
||||
returnType: item.ReturnType
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
tags: item.tags,
|
||||
status: item.status,
|
||||
statusType: item.statusType,
|
||||
iconChar: item.iconChar,
|
||||
iconBgClass: item.iconBgClass,
|
||||
iconTextClass: item.iconTextClass,
|
||||
value: item.value,
|
||||
currency: item.currency,
|
||||
returnRate: item.returnRate,
|
||||
returnType: item.returnType
|
||||
}));
|
||||
console.log('持仓数据获取成功,items数量:', holdings.value.length);
|
||||
console.log('持仓数据:', holdings.value);
|
||||
@ -156,14 +161,17 @@ const fetchHoldingsData = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 页面加载时检查登录状态
|
||||
onMounted(async () => {
|
||||
console.log('首页加载,开始加载数据...');
|
||||
// 页面显示时刷新数据
|
||||
onShow(async () => {
|
||||
console.log('首页显示,刷新数据...');
|
||||
isFetching = true;
|
||||
|
||||
await Promise.all([
|
||||
fetchAssetData(),
|
||||
fetchHoldingsData()
|
||||
]);
|
||||
|
||||
isFetching = false;
|
||||
});
|
||||
|
||||
const goConfig = () => {
|
||||
|
||||
@ -1,13 +1,5 @@
|
||||
<template>
|
||||
<view class="page-container">
|
||||
|
||||
<view class="nav-bar">
|
||||
<view class="back-btn" @click="uni.navigateBack()">
|
||||
<uni-icons type="left" size="20" color="#374151"></uni-icons>
|
||||
</view>
|
||||
<text class="nav-title">{{ isEditMode ? '编辑策略' : '创建策略' }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section-title">选择逻辑模型</view>
|
||||
<scroll-view scroll-x class="strategy-scroll" :show-scrollbar="false">
|
||||
<view class="strategy-row">
|
||||
|
||||
@ -61,14 +61,18 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, getCurrentInstance } from 'vue';
|
||||
import { ref, onShow, getCurrentInstance } from 'vue';
|
||||
|
||||
const { proxy } = getCurrentInstance();
|
||||
const api = proxy.$api;
|
||||
|
||||
const strategies = ref([]);
|
||||
|
||||
// 防止重复请求的标志
|
||||
let isFetching = false;
|
||||
|
||||
const fetchStrategies = async () => {
|
||||
if (isFetching) return;
|
||||
try {
|
||||
const response = await api.strategies.getStrategies();
|
||||
if (response.code === 200) {
|
||||
@ -91,8 +95,11 @@ const fetchStrategies = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
// 页面显示时刷新数据
|
||||
onShow(async () => {
|
||||
isFetching = true;
|
||||
await fetchStrategies();
|
||||
isFetching = false;
|
||||
});
|
||||
|
||||
const goToAdd = () => {
|
||||
|
||||
@ -391,7 +391,7 @@ export const api = {
|
||||
*/
|
||||
getUserInfo: () => {
|
||||
console.log('📤 发起 getUserInfo 请求');
|
||||
return get('/api/user/info');
|
||||
return get('api/v1/user/info');
|
||||
},
|
||||
/**
|
||||
* 获取用户统计数据
|
||||
@ -399,7 +399,7 @@ export const api = {
|
||||
*/
|
||||
getUserStats: () => {
|
||||
console.log('📤 发起 getUserStats 请求');
|
||||
return get('/api/user/stats');
|
||||
return get('api/v1/user/stats');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user