新增:历史数据接口对接,资产变化
This commit is contained in:
parent
947ba83b2d
commit
d44e7157e8
@ -735,7 +735,8 @@ import { useUserStore } from '../stores/user'
|
|||||||
import { useLocaleStore } from '../stores/locale'
|
import { useLocaleStore } from '../stores/locale'
|
||||||
import { useAuthError } from '../composables/useAuthError'
|
import { useAuthError } from '../composables/useAuthError'
|
||||||
import { cancelOrder as apiCancelOrder } from '../api/order'
|
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 { getPositionList, mapPositionToDisplayItem, claimPosition } from '../api/position'
|
||||||
import {
|
import {
|
||||||
getSettlementRequestsListClient,
|
getSettlementRequestsListClient,
|
||||||
@ -780,7 +781,7 @@ const withdrawStatusOptions = computed(() => [
|
|||||||
const currentPositionList = computed(() =>
|
const currentPositionList = computed(() =>
|
||||||
USE_MOCK_WALLET ? positions.value : positionList.value,
|
USE_MOCK_WALLET ? positions.value : positionList.value,
|
||||||
)
|
)
|
||||||
/** 未结算项:从持仓列表中筛出可领取的(有 marketID+tokenID;若后端有 needClaim 则仅 needClaim 为 true) */
|
/** 未结算项:从持仓列表中筛出可领取的(有 marketID+tokenID,且所属市场已关闭 market.closed=true) */
|
||||||
const unsettledItems = computed(() => {
|
const unsettledItems = computed(() => {
|
||||||
const list = currentPositionList.value
|
const list = currentPositionList.value
|
||||||
return list
|
return list
|
||||||
@ -788,7 +789,7 @@ const unsettledItems = computed(() => {
|
|||||||
(p) =>
|
(p) =>
|
||||||
p.marketID &&
|
p.marketID &&
|
||||||
p.tokenID &&
|
p.tokenID &&
|
||||||
(p.needClaim === undefined || p.needClaim === true),
|
p.marketClosed === true,
|
||||||
)
|
)
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
const amount = parseFloat(String(p.value).replace(/[^0-9.-]/g, '')) || 0
|
const amount = parseFloat(String(p.value).replace(/[^0-9.-]/g, '')) || 0
|
||||||
@ -872,8 +873,8 @@ interface Position {
|
|||||||
marketID?: string
|
marketID?: string
|
||||||
/** Token ID(从持仓列表来,用于领取结算) */
|
/** Token ID(从持仓列表来,用于领取结算) */
|
||||||
tokenID?: string
|
tokenID?: string
|
||||||
/** 是否待领取/未结算(后端可选,无则按有 marketID+tokenID 视为可领取) */
|
/** 所属市场是否已关闭,marketClosed=true 表示可结算/可领取 */
|
||||||
needClaim?: boolean
|
marketClosed?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 从 avgNow "72¢ → 0.5¢" 解析出 [avg, now] */
|
/** 从 avgNow "72¢ → 0.5¢" 解析出 [avg, now] */
|
||||||
@ -1030,6 +1031,7 @@ const historyList = ref<HistoryItem[]>([])
|
|||||||
const historyTotal = ref(0)
|
const historyTotal = ref(0)
|
||||||
const historyLoading = ref(false)
|
const historyLoading = ref(false)
|
||||||
|
|
||||||
|
/** 历史记录来自 GET /hr/getHistoryRecordListClient(需鉴权,按当前用户分页) */
|
||||||
async function loadHistoryOrders() {
|
async function loadHistoryOrders() {
|
||||||
if (USE_MOCK_WALLET) return
|
if (USE_MOCK_WALLET) return
|
||||||
const headers = userStore.getAuthHeaders()
|
const headers = userStore.getAuthHeaders()
|
||||||
@ -1047,18 +1049,18 @@ async function loadHistoryOrders() {
|
|||||||
}
|
}
|
||||||
historyLoading.value = true
|
historyLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await getOrderList(
|
const res = await getHistoryRecordListClient(
|
||||||
{
|
{
|
||||||
page: page.value,
|
page: page.value,
|
||||||
pageSize: itemsPerPage.value,
|
pageSize: itemsPerPage.value,
|
||||||
userID,
|
userId: userID,
|
||||||
},
|
},
|
||||||
{ headers },
|
{ headers },
|
||||||
)
|
)
|
||||||
if (res.code === 0 || res.code === 200) {
|
if (res.code === 0 || res.code === 200) {
|
||||||
const list = res.data?.list ?? []
|
const { list, total } = getHistoryRecordList(res.data)
|
||||||
historyList.value = list.map(mapOrderToHistoryItem)
|
historyList.value = list
|
||||||
historyTotal.value = res.data?.total ?? 0
|
historyTotal.value = total
|
||||||
} else {
|
} else {
|
||||||
historyList.value = []
|
historyList.value = []
|
||||||
historyTotal.value = 0
|
historyTotal.value = 0
|
||||||
@ -1346,8 +1348,11 @@ function shareHistory(id: string) {
|
|||||||
const plChartRef = ref<HTMLElement | null>(null)
|
const plChartRef = ref<HTMLElement | null>(null)
|
||||||
let plChartInstance: ECharts | 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()
|
const now = Date.now()
|
||||||
let stepMs: number
|
let stepMs: number
|
||||||
let count: number
|
let count: number
|
||||||
@ -1371,11 +1376,9 @@ function generatePlData(range: string): [number, number][] {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
const data: [number, number][] = []
|
const data: [number, number][] = []
|
||||||
let pnl = 0
|
|
||||||
for (let i = count; i >= 0; i--) {
|
for (let i = count; i >= 0; i--) {
|
||||||
const t = now - i * stepMs
|
const t = now - i * stepMs
|
||||||
pnl += (Math.random() - 0.48) * 20
|
data.push([t, 0])
|
||||||
data.push([t, Math.round(pnl * 100) / 100])
|
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
@ -1437,18 +1440,18 @@ function buildPlChartOption(chartData: [number, number][]) {
|
|||||||
const plChartData = ref<[number, number][]>([])
|
const plChartData = ref<[number, number][]>([])
|
||||||
|
|
||||||
function updatePlChart() {
|
function updatePlChart() {
|
||||||
plChartData.value = generatePlData(plRange.value)
|
plChartData.value = getPlChartData(plRange.value)
|
||||||
const last = plChartData.value[plChartData.value.length - 1]
|
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)
|
if (plChartInstance)
|
||||||
plChartInstance.setOption(buildPlChartOption(plChartData.value), { replaceMerge: ['series'] })
|
plChartInstance.setOption(buildPlChartOption(plChartData.value), { replaceMerge: ['series'] })
|
||||||
}
|
}
|
||||||
|
|
||||||
function initPlChart() {
|
function initPlChart() {
|
||||||
if (!plChartRef.value) return
|
if (!plChartRef.value) return
|
||||||
plChartData.value = generatePlData(plRange.value)
|
plChartData.value = getPlChartData(plRange.value)
|
||||||
const last = plChartData.value[plChartData.value.length - 1]
|
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 = echarts.init(plChartRef.value)
|
||||||
plChartInstance.setOption(buildPlChartOption(plChartData.value))
|
plChartInstance.setOption(buildPlChartOption(plChartData.value))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user