32 lines
1021 B
TypeScript
32 lines
1021 B
TypeScript
import { TERMINAL_CONFIG } from '@/config/terminal'
|
|
import { completeMockBinding, getMockBinding, mockPlaylist } from '@/mock/terminal'
|
|
import type { Playlist, TerminalBinding } from '@/types/terminal'
|
|
|
|
const wait = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))
|
|
|
|
/** 正式接口接入点:切换 useMock 后在此替换为 uni.request。 */
|
|
export const fetchTerminalBinding = async (_sn: string): Promise<TerminalBinding> => {
|
|
if (!TERMINAL_CONFIG.useMock) {
|
|
throw new Error('尚未配置广告机绑定接口')
|
|
}
|
|
|
|
await wait(350)
|
|
return getMockBinding()
|
|
}
|
|
|
|
/** 正式接口接入点:按 sn 请求后台下发的图片/视频节目单。 */
|
|
export const fetchTerminalPlaylist = async (_sn: string): Promise<Playlist> => {
|
|
if (!TERMINAL_CONFIG.useMock) {
|
|
throw new Error('尚未配置广告机节目单接口')
|
|
}
|
|
|
|
await wait(350)
|
|
return mockPlaylist
|
|
}
|
|
|
|
export const bindMockTerminal = async () => {
|
|
if (!TERMINAL_CONFIG.useMock) return
|
|
completeMockBinding()
|
|
await wait(150)
|
|
}
|