| 1234567891011121314151617181920212223242526272829303132 |
- /** 首页「实时」时段对应 range 参数 */
- export const HOME_REALTIME_RANGE = 'TODAY'
- const POLL_MS = 10000
- /**
- * 实时时段下每 10s 拉数;非实时或离开页面前需 clearHomeRealtimePoll
- * @param {object} vm 面板组件实例(挂 _homePollTimer)
- * @param {() => void} onTick 定时回调(建议静默刷新)
- */
- export function syncHomeRealtimePoll(vm, onTick) {
- clearHomeRealtimePoll(vm)
- if (vm.activeRange !== HOME_REALTIME_RANGE) {
- return
- }
- vm._homePollTimer = setInterval(() => {
- if (vm.activeRange !== HOME_REALTIME_RANGE) {
- clearHomeRealtimePoll(vm)
- return
- }
- onTick()
- }, POLL_MS)
- }
- /** 停止轮询(切换时段、离开 Tab、组件销毁时调用) */
- export function clearHomeRealtimePoll(vm) {
- if (vm._homePollTimer) {
- clearInterval(vm._homePollTimer)
- vm._homePollTimer = null
- }
- }
|