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-box">
|
||||||
<view class="timeline-item" v-for="(log, k) in logs" :key="k">
|
<view class="timeline-item" v-for="(log, k) in logs" :key="k">
|
||||||
<view class="tl-left">
|
<view class="tl-left">
|
||||||
<text class="tl-date">{{ log.Date }}</text>
|
<text class="tl-date">{{ log.date }}</text>
|
||||||
<text class="tl-time">{{ log.Time }}</text>
|
<text class="tl-time">{{ log.time }}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="tl-line">
|
<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 class="tl-dash" v-if="k !== logs.length - 1"></view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="tl-right">
|
<view class="tl-right">
|
||||||
<text class="tl-title">{{ log.Title }}</text>
|
<text class="tl-title">{{ log.title }}</text>
|
||||||
<text class="tl-desc">{{ log.Type === 'buy' ? '录入增加' : '结出减少' }} {{ log.Amount }}</text>
|
<text class="tl-desc">{{ log.type === 'buy' ? '增加' : '减少' }} {{ log.amount }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -136,11 +136,11 @@
|
|||||||
<view class="action-section fixed-bottom">
|
<view class="action-section fixed-bottom">
|
||||||
<button class="action-btn btn-buy" @click="handleBuy">
|
<button class="action-btn btn-buy" @click="handleBuy">
|
||||||
<uni-icons type="download" size="20" color="#FFFFFF"></uni-icons>
|
<uni-icons type="download" size="20" color="#FFFFFF"></uni-icons>
|
||||||
<text class="btn-text">录入增加 / 比例校准</text>
|
<text class="btn-text">增加</text>
|
||||||
</button>
|
</button>
|
||||||
<button class="action-btn btn-sell" @click="handleSell">
|
<button class="action-btn btn-sell" @click="handleSell">
|
||||||
<uni-icons type="upload" size="20" color="#064E3B"></uni-icons>
|
<uni-icons type="upload" size="20" color="#064E3B"></uni-icons>
|
||||||
<text class="btn-text">结出减少 / 调减</text>
|
<text class="btn-text">减少</text>
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -148,7 +148,7 @@
|
|||||||
<view v-if="showTransactionForm" class="transaction-modal">
|
<view v-if="showTransactionForm" class="transaction-modal">
|
||||||
<view class="modal-content">
|
<view class="modal-content">
|
||||||
<view class="modal-header">
|
<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">
|
<view class="close-btn" @click="showTransactionForm = false">
|
||||||
<uni-icons type="close" size="20" color="#6B7280"></uni-icons>
|
<uni-icons type="close" size="20" color="#6B7280"></uni-icons>
|
||||||
</view>
|
</view>
|
||||||
@ -302,8 +302,8 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const goStrategyConfig = () => {
|
const goStrategyConfig = () => {
|
||||||
if (portfolioData.value.strategy?.Id) {
|
if (portfolioData.value.strategy?.id) {
|
||||||
uni.navigateTo({ url: `/pages/strategies/edit/edit?id=${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-size: 30rpx;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
border: none;
|
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 { background-color: #064E3B; color: #FFFFFF; box-shadow: 0 8rpx 20rpx rgba(6, 78, 59, 0.2); }
|
||||||
.btn-buy:active { background-color: #047857; }
|
.btn-buy:active { background-color: #047857; }
|
||||||
|
|||||||
@ -91,7 +91,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onShow } from 'vue';
|
||||||
import { api } from '../../utils/api';
|
import { api } from '../../utils/api';
|
||||||
|
|
||||||
// 资产数据
|
// 资产数据
|
||||||
@ -104,8 +104,12 @@ const assetData = ref({
|
|||||||
// 持仓组合数据
|
// 持仓组合数据
|
||||||
const holdings = ref([]);
|
const holdings = ref([]);
|
||||||
|
|
||||||
|
// 防止重复请求的标志
|
||||||
|
let isFetching = false;
|
||||||
|
|
||||||
// 从后端API获取资产数据的函数
|
// 从后端API获取资产数据的函数
|
||||||
const fetchAssetData = async () => {
|
const fetchAssetData = async () => {
|
||||||
|
if (isFetching) return;
|
||||||
try {
|
try {
|
||||||
console.log('开始获取资产数据...');
|
console.log('开始获取资产数据...');
|
||||||
const response = await api.assets.getAssetData();
|
const response = await api.assets.getAssetData();
|
||||||
@ -113,11 +117,11 @@ const fetchAssetData = async () => {
|
|||||||
// 映射资产数据字段
|
// 映射资产数据字段
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
assetData.value = {
|
assetData.value = {
|
||||||
totalValue: data.TotalValue,
|
totalValue: data.totalValue,
|
||||||
currency: data.Currency,
|
currency: data.currency,
|
||||||
todayProfit: data.TodayProfit,
|
todayProfit: data.todayProfit,
|
||||||
todayProfitCurrency: data.TodayProfitCurrency,
|
todayProfitCurrency: data.todayProfitCurrency,
|
||||||
totalReturnRate: data.TotalReturnRate
|
totalReturnRate: data.totalReturnRate
|
||||||
};
|
};
|
||||||
console.log('资产数据获取成功');
|
console.log('资产数据获取成功');
|
||||||
}
|
}
|
||||||
@ -128,6 +132,7 @@ const fetchAssetData = async () => {
|
|||||||
|
|
||||||
// 从后端API获取持仓组合数据的函数
|
// 从后端API获取持仓组合数据的函数
|
||||||
const fetchHoldingsData = async () => {
|
const fetchHoldingsData = async () => {
|
||||||
|
if (isFetching) return;
|
||||||
try {
|
try {
|
||||||
console.log('开始获取持仓数据...');
|
console.log('开始获取持仓数据...');
|
||||||
const response = await api.assets.getHoldings();
|
const response = await api.assets.getHoldings();
|
||||||
@ -135,18 +140,18 @@ const fetchHoldingsData = async () => {
|
|||||||
// 处理响应数据结构,获取 items 数组并映射字段
|
// 处理响应数据结构,获取 items 数组并映射字段
|
||||||
const items = response.data.items || [];
|
const items = response.data.items || [];
|
||||||
holdings.value = items.map(item => ({
|
holdings.value = items.map(item => ({
|
||||||
id: item.Id,
|
id: item.id,
|
||||||
name: item.Name,
|
name: item.name,
|
||||||
tags: item.Tags,
|
tags: item.tags,
|
||||||
status: item.Status,
|
status: item.status,
|
||||||
statusType: item.StatusType,
|
statusType: item.statusType,
|
||||||
iconChar: item.IconChar,
|
iconChar: item.iconChar,
|
||||||
iconBgClass: item.IconBgClass,
|
iconBgClass: item.iconBgClass,
|
||||||
iconTextClass: item.IconTextClass,
|
iconTextClass: item.iconTextClass,
|
||||||
value: item.Value,
|
value: item.value,
|
||||||
currency: item.Currency,
|
currency: item.currency,
|
||||||
returnRate: item.ReturnRate,
|
returnRate: item.returnRate,
|
||||||
returnType: item.ReturnType
|
returnType: item.returnType
|
||||||
}));
|
}));
|
||||||
console.log('持仓数据获取成功,items数量:', holdings.value.length);
|
console.log('持仓数据获取成功,items数量:', holdings.value.length);
|
||||||
console.log('持仓数据:', holdings.value);
|
console.log('持仓数据:', holdings.value);
|
||||||
@ -156,14 +161,17 @@ const fetchHoldingsData = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 页面加载时检查登录状态
|
// 页面显示时刷新数据
|
||||||
onMounted(async () => {
|
onShow(async () => {
|
||||||
console.log('首页加载,开始加载数据...');
|
console.log('首页显示,刷新数据...');
|
||||||
|
isFetching = true;
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
fetchAssetData(),
|
fetchAssetData(),
|
||||||
fetchHoldingsData()
|
fetchHoldingsData()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
isFetching = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
const goConfig = () => {
|
const goConfig = () => {
|
||||||
|
|||||||
@ -1,13 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="page-container">
|
<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>
|
<view class="section-title">选择逻辑模型</view>
|
||||||
<scroll-view scroll-x class="strategy-scroll" :show-scrollbar="false">
|
<scroll-view scroll-x class="strategy-scroll" :show-scrollbar="false">
|
||||||
<view class="strategy-row">
|
<view class="strategy-row">
|
||||||
|
|||||||
@ -61,14 +61,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, getCurrentInstance } from 'vue';
|
import { ref, onShow, getCurrentInstance } from 'vue';
|
||||||
|
|
||||||
const { proxy } = getCurrentInstance();
|
const { proxy } = getCurrentInstance();
|
||||||
const api = proxy.$api;
|
const api = proxy.$api;
|
||||||
|
|
||||||
const strategies = ref([]);
|
const strategies = ref([]);
|
||||||
|
|
||||||
|
// 防止重复请求的标志
|
||||||
|
let isFetching = false;
|
||||||
|
|
||||||
const fetchStrategies = async () => {
|
const fetchStrategies = async () => {
|
||||||
|
if (isFetching) return;
|
||||||
try {
|
try {
|
||||||
const response = await api.strategies.getStrategies();
|
const response = await api.strategies.getStrategies();
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
@ -91,8 +95,11 @@ const fetchStrategies = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
// 页面显示时刷新数据
|
||||||
|
onShow(async () => {
|
||||||
|
isFetching = true;
|
||||||
await fetchStrategies();
|
await fetchStrategies();
|
||||||
|
isFetching = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
const goToAdd = () => {
|
const goToAdd = () => {
|
||||||
|
|||||||
@ -391,7 +391,7 @@ export const api = {
|
|||||||
*/
|
*/
|
||||||
getUserInfo: () => {
|
getUserInfo: () => {
|
||||||
console.log('📤 发起 getUserInfo 请求');
|
console.log('📤 发起 getUserInfo 请求');
|
||||||
return get('/api/user/info');
|
return get('api/v1/user/info');
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 获取用户统计数据
|
* 获取用户统计数据
|
||||||
@ -399,7 +399,7 @@ export const api = {
|
|||||||
*/
|
*/
|
||||||
getUserStats: () => {
|
getUserStats: () => {
|
||||||
console.log('📤 发起 getUserStats 请求');
|
console.log('📤 发起 getUserStats 请求');
|
||||||
return get('/api/user/stats');
|
return get('api/v1/user/stats');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user