fix: refine home filters and stock action chart
This commit is contained in:
@ -59,16 +59,59 @@ export function useDashboardData() {
|
||||
.filter((item): item is string => Boolean(item))
|
||||
})
|
||||
|
||||
function inferActionSide(buyAmount: number, sellAmount: number, netAmount: number): ActionItem['action_side'] {
|
||||
if (buyAmount > 0 && sellAmount <= 0) return 'buy'
|
||||
if (sellAmount > 0 && buyAmount <= 0) return 'sell'
|
||||
if (netAmount >= 0) return 'net_buy'
|
||||
return 'net_sell'
|
||||
}
|
||||
|
||||
function matchesActionFilter(item: ActionItem): boolean {
|
||||
const buyAmount = numberFromText(item.buy_amount_wan) ?? 0
|
||||
const sellAmount = numberFromText(item.sell_amount_wan) ?? 0
|
||||
const netAmount = numberFromText(item.net_amount_wan) ?? buyAmount - sellAmount
|
||||
|
||||
if (selectedActionFilter.value === 'buy') return buyAmount > 0
|
||||
if (selectedActionFilter.value === 'sell') return sellAmount > 0
|
||||
if (selectedActionFilter.value === 'net_buy') return netAmount > 0
|
||||
if (selectedActionFilter.value === 'net_sell') return netAmount < 0
|
||||
return true
|
||||
}
|
||||
|
||||
function aggregateCandidateActions(rows: ActionItem[]): ActionItem[] {
|
||||
const groups = new Map<string, ActionItem>()
|
||||
|
||||
for (const item of rows) {
|
||||
const existing = groups.get(item.stock_code)
|
||||
if (!existing) {
|
||||
groups.set(item.stock_code, { ...item })
|
||||
continue
|
||||
}
|
||||
|
||||
const nextBuy = (numberFromText(existing.buy_amount_wan) ?? 0) + (numberFromText(item.buy_amount_wan) ?? 0)
|
||||
const nextSell = (numberFromText(existing.sell_amount_wan) ?? 0) + (numberFromText(item.sell_amount_wan) ?? 0)
|
||||
const nextNet = nextBuy - nextSell
|
||||
const traderNames = new Set([existing.trader_name, item.trader_name].filter(Boolean))
|
||||
const tableTitles = new Set([existing.table_title, item.table_title].filter(Boolean))
|
||||
const seatNames = new Set([existing.seat_name, item.seat_name].filter(Boolean))
|
||||
|
||||
groups.set(item.stock_code, {
|
||||
...existing,
|
||||
trader_name: [...traderNames].join(' / '),
|
||||
table_title: [...tableTitles].join(' / '),
|
||||
seat_name: seatNames.size > 1 ? `${seatNames.size}个席位` : existing.seat_name,
|
||||
buy_amount_wan: nextBuy.toFixed(2),
|
||||
sell_amount_wan: nextSell.toFixed(2),
|
||||
net_amount_wan: nextNet.toFixed(2),
|
||||
action_side: inferActionSide(nextBuy, nextSell, nextNet),
|
||||
})
|
||||
}
|
||||
|
||||
return [...groups.values()]
|
||||
}
|
||||
|
||||
const filteredActions = computed(() => {
|
||||
return actions.value.filter((item) => {
|
||||
if (selectedTraderFilter.value !== 'all' && item.trader_name !== selectedTraderFilter.value) {
|
||||
return false
|
||||
}
|
||||
if (selectedActionFilter.value !== 'all' && item.action_side !== selectedActionFilter.value) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
return actions.value.filter(matchesActionFilter)
|
||||
})
|
||||
|
||||
const watchlistMap = computed(() => {
|
||||
@ -80,14 +123,8 @@ export function useDashboardData() {
|
||||
})
|
||||
|
||||
const candidateActionRows = computed(() => {
|
||||
const unique = new Map<string, ActionItem>()
|
||||
for (const item of filteredActions.value) {
|
||||
if (watchlistMap.value.has(item.stock_code)) continue
|
||||
if (!unique.has(item.stock_code)) {
|
||||
unique.set(item.stock_code, item)
|
||||
}
|
||||
}
|
||||
return [...unique.values()]
|
||||
const rows = actions.value.filter((item) => !watchlistMap.value.has(item.stock_code))
|
||||
return aggregateCandidateActions(rows).filter(matchesActionFilter)
|
||||
})
|
||||
|
||||
const watchlistMetrics = computed(() => {
|
||||
|
||||
Reference in New Issue
Block a user