import { TypeDate } from '../types'; import { CountDownMonitor } from './CountDownMonitor'; export interface TypeCountDownOptions { base?: TypeDate; target?: TypeDate; interval?: number; onChange?: (delta: number) => void; onStop?: (delta: number) => void; } export interface TypeAllMonitors { [key: string]: CountDownMonitor; } export declare const allMonitors: TypeAllMonitors; export declare const localBaseTime: number; /** * 提供倒计时器统一封装 * @class CountDown * @param {Object} spec 选项 * @param {Date} [spec.base] 矫正时间(ms),如果需要用服务端时间矫正倒计时,使用此参数 * @param {Date} [spec.target=Date.now() + 3000] 目标时间(ms) * @param {Number} [spec.interval=1000] 倒计时触发间隔(ms) * @param {Function} [spec.onChange] 倒计时触发变更的事件回调 * @param {Function} [spec.onStop] 倒计时结束的回调 * @example * import { CountDown } from '@spore-ui/tskit'; * const target = Date.now() + 5000; * * const cd1 = new CountDown({ * target, * onChange(delta) { * console.info('cd1 change', delta); * }, * onStop(delta) { * console.info('cd1 stop', delta); * } * }); * * setTimeout(() => { * //trigger stop * cd1.stop(); * }, 2000); * * const cd2 = new CountDown({ * target, * interval: 2000, * onChange(delta) { * console.info('cd2 change', delta); * }, * onStop(delta) { * console.info('cd2 stop', delta); * } * }); */ export declare class CountDown { conf: TypeCountDownOptions; timeDiff: number; target: number; interval: number; timeInterval: number; monitor: CountDownMonitor; delta: number; curUnit: number; boundCheck: (localDelta: number) => void; constructor(spec: TypeCountDownOptions); start(): void; inspect(): void; update(now: number): void; /** * 重设目标时间 * @method CountDown#setTarget * @memberof CountDown * @example * const cd = new CountDown(); * const localTime = '2019/01/01'; * cd.setTarget(serverTime); */ setTarget(time: TypeDate): void; /** * 纠正时间差 * @method CountDown#correct * @memberof CountDown * @example * const cd = new CountDown(); * const serverTime = '2019/01/01'; * const localTime = '2020/01/01'; * cd.correct(serverTime); * cd.correct(serverTime, localTime); */ correct(serverTime: TypeDate, localTime?: TypeDate): void; check(localDelta: number): void; /** * 停止倒计时 * @method CountDown#stop * @memberof CountDown * @example * const cd = new CountDown(); * cd.stop(); */ stop(): void; /** * 销毁倒计时 * @method CountDown#destroy * @memberof CountDown * @example * const cd = CountDown(); * cd.destroy(); */ destroy(): void; } export default CountDown;