新增:历史数据接口对接,资产变化

This commit is contained in:
ivan 2026-03-15 21:02:38 +08:00
parent 947ba83b2d
commit d44e7157e8

View File

@ -735,7 +735,8 @@ import { useUserStore } from '../stores/user'
import { useLocaleStore } from '../stores/locale'
import { useAuthError } from '../composables/useAuthError'
import { cancelOrder as apiCancelOrder } from '../api/order'
import { getOrderList, mapOrderToHistoryItem, mapOrderToOpenOrderItem, OrderStatus } from '../api/order'
import { getOrderList, mapOrderToOpenOrderItem, OrderStatus } from '../api/order'
import { getHistoryRecordListClient, getHistoryRecordList } from '../api/historyRecord'
import { getPositionList, mapPositionToDisplayItem, claimPosition } from '../api/position'
import {
getSettlementRequestsListClient,
@ -780,7 +781,7 @@ const withdrawStatusOptions = computed(() => [
const currentPositionList = computed(() =>
USE_MOCK_WALLET ? positions.value : positionList.value,
)
/** 未结算项:从持仓列表中筛出可领取的(有 marketID+tokenID;若后端有 needClaim 则仅 needClaim 为 true */
/** 未结算项:从持仓列表中筛出可领取的(有 marketID+tokenID,且所属市场已关闭 market.closed=true */
const unsettledItems = computed(() => {
const list = currentPositionList.value
return list
@ -788,7 +789,7 @@ const unsettledItems = computed(() => {
(p) =>
p.marketID &&
p.tokenID &&
(p.needClaim === undefined || p.needClaim === true),
p.marketClosed === true,
)
.map((p) => {
const amount = parseFloat(String(p.value).replace(/[^0-9.-]/g, '')) || 0
@ -872,8 +873,8 @@ interface Position {
marketID?: string
/** Token ID从持仓列表来用于领取结算 */
tokenID?: string
/** 是否待领取/未结算(后端可选,无则按有 marketID+tokenID 视为可领取) */
needClaim?: boolean
/** 所属市场是否已关闭marketClosed=true 表示可结算/可领取 */
marketClosed?: boolean
}
/** 从 avgNow "72¢ → 0.5¢" 解析出 [avg, now] */
@ -1030,6 +1031,7 @@ const historyList = ref<HistoryItem[]>([])
const historyTotal = ref(0)
const historyLoading = ref(false)
/** 历史记录来自 GET /hr/getHistoryRecordListClient需鉴权按当前用户分页 */
async function loadHistoryOrders() {
if (USE_MOCK_WALLET) return
const headers = userStore.getAuthHeaders()
@ -1047,18 +1049,18 @@ async function loadHistoryOrders() {
}
historyLoading.value = true
try {
const res = await getOrderList(
const res = await getHistoryRecordListClient(
{
page: page.value,
pageSize: itemsPerPage.value,
userID,
userId: userID,
},
{ headers },
)
if (res.code === 0 || res.code === 200) {
const list = res.data?.list ?? []
historyList.value = list.map(mapOrderToHistoryItem)
historyTotal.value = res.data?.total ?? 0
const { list, total } = getHistoryRecordList(res.data)
historyList.value = list
historyTotal.value = total
} else {
historyList.value = []
historyTotal.value = 0
@ -1346,8 +1348,11 @@ function shareHistory(id: string) {
const plChartRef = ref<HTMLElement | null>(null)
let plChartInstance: ECharts | null = null
/** 根据时间范围生成盈亏折线数据 [timestamp, pnl] */
function generatePlData(range: string): [number, number][] {
/**
* 资产变化折线图数据 [timestamp_ms, pnl]
* 暂无接口时返回真实格式的时间序列数值均为 0有接口后改为从 API 拉取并在此处做分时过滤
*/
function getPlChartData(range: string): [number, number][] {
const now = Date.now()
let stepMs: number
let count: number
@ -1371,11 +1376,9 @@ function generatePlData(range: string): [number, number][] {
break
}
const data: [number, number][] = []
let pnl = 0
for (let i = count; i >= 0; i--) {
const t = now - i * stepMs
pnl += (Math.random() - 0.48) * 20
data.push([t, Math.round(pnl * 100) / 100])
data.push([t, 0])
}
return data
}
@ -1437,18 +1440,18 @@ function buildPlChartOption(chartData: [number, number][]) {
const plChartData = ref<[number, number][]>([])
function updatePlChart() {
plChartData.value = generatePlData(plRange.value)
plChartData.value = getPlChartData(plRange.value)
const last = plChartData.value[plChartData.value.length - 1]
if (last) profitLoss.value = last[1].toFixed(2)
if (last != null) profitLoss.value = last[1].toFixed(2)
if (plChartInstance)
plChartInstance.setOption(buildPlChartOption(plChartData.value), { replaceMerge: ['series'] })
}
function initPlChart() {
if (!plChartRef.value) return
plChartData.value = generatePlData(plRange.value)
plChartData.value = getPlChartData(plRange.value)
const last = plChartData.value[plChartData.value.length - 1]
if (last) profitLoss.value = last[1].toFixed(2)
if (last != null) profitLoss.value = last[1].toFixed(2)
plChartInstance = echarts.init(plChartRef.value)
plChartInstance.setOption(buildPlChartOption(plChartData.value))
}