|
|
@@ -1,7 +1,7 @@
|
|
|
import { getAssetUrl } from '@/api/asset'
|
|
|
import { getProgram as programApi } from '@/api/program'
|
|
|
import { getSchedule as scheduleApi } from '@/api/calendar'
|
|
|
-import { ScheduleType } from '@/constant'
|
|
|
+import { EventTarget } from '@/constant'
|
|
|
|
|
|
const cacheMap = {}
|
|
|
|
|
|
@@ -13,16 +13,12 @@ function getScheduleInst (id) {
|
|
|
return scheduleApi(id, { custom: true, background: true })
|
|
|
}
|
|
|
|
|
|
-function getInstName ({ name }) {
|
|
|
- return name
|
|
|
-}
|
|
|
-
|
|
|
function getProgramImage ({ img }) {
|
|
|
return getAssetUrl(img)
|
|
|
}
|
|
|
|
|
|
function getScheduleImage ({ events }) {
|
|
|
- return getImage(ScheduleType.CALENDAR, events[0].programId)
|
|
|
+ return getImage(EventTarget.PROGRAM, events[0].programId)
|
|
|
}
|
|
|
|
|
|
function getCache (type) {
|
|
|
@@ -33,21 +29,18 @@ function getCache (type) {
|
|
|
}
|
|
|
|
|
|
function getPromise (type, id) {
|
|
|
+ const key = `${type}__${id}`
|
|
|
const cache = getCache()
|
|
|
- if (!cache[id]) {
|
|
|
- const promise = (type === ScheduleType.CALENDAR ? getProgramInst : getScheduleInst)(id)
|
|
|
+ if (!cache[key]) {
|
|
|
+ const promise = (type === EventTarget.PROGRAM ? getProgramInst : getScheduleInst)(id)
|
|
|
promise.catch(() => {
|
|
|
- cache[id] = null
|
|
|
+ cache[key] = null
|
|
|
})
|
|
|
- cache[id] = promise
|
|
|
+ cache[key] = promise
|
|
|
}
|
|
|
- return cache[id]
|
|
|
-}
|
|
|
-
|
|
|
-export function getName (type, id) {
|
|
|
- return getPromise(type, id).then(getInstName)
|
|
|
+ return cache[key]
|
|
|
}
|
|
|
|
|
|
export function getImage (type, id) {
|
|
|
- return getPromise(type, id).then(type === ScheduleType.CALENDAR ? getProgramImage : getScheduleImage)
|
|
|
+ return getPromise(type, id).then(type === EventTarget.PROGRAM ? getProgramImage : getScheduleImage)
|
|
|
}
|