新增连板页面
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { getTradeCalendar } from '@/api/common'
|
||||
|
||||
let tradeCalendarPromise = null
|
||||
let tradeCalendarCache = null
|
||||
|
||||
const normalizeTradeCalendar = (data = {}) => ({
|
||||
open_dates: Array.isArray(data.open_dates) ? data.open_dates : [],
|
||||
max_date: data.max_date || ''
|
||||
})
|
||||
|
||||
export async function fetchTradeCalendar(force = false) {
|
||||
if (tradeCalendarCache && !force) return tradeCalendarCache
|
||||
|
||||
if (!tradeCalendarPromise || force) {
|
||||
tradeCalendarPromise = getTradeCalendar()
|
||||
.then((data) => {
|
||||
tradeCalendarCache = normalizeTradeCalendar(data)
|
||||
return tradeCalendarCache
|
||||
})
|
||||
.finally(() => {
|
||||
tradeCalendarPromise = null
|
||||
})
|
||||
}
|
||||
|
||||
return tradeCalendarPromise
|
||||
}
|
||||
|
||||
export function getCachedTradeCalendar() {
|
||||
return tradeCalendarCache
|
||||
}
|
||||
Reference in New Issue
Block a user