1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { getCache } from "./cache";
- import {pullNotice} from '@/api/collect.js'
- // #ifdef APP
- const notify = uni.requireNativePlugin('Ba-Notify')
- // #endif
- let pullNoticeExecutor = null
- export const startPullNotice = () => {
- console.log('开始执行轮询');
- if(pullNoticeExecutor) {
- clearImmediate(pullNoticeExecutor)
- }
- pullNoticeExecutor = setInterval(() => {
- getCache('token').then(res => {
- console.log('token is', res);
- pullNotice().then(resp => {
- console.log('pull', resp);
- if(resp.msg) {
- // #ifdef APP
- notify.show({
- 'channelID': '0',
- 'channelName': '普通通知',
- 'ID': 0,
- 'notifyType': 0,
- 'ticker': 'Ticker',
- 'title': '提醒',
- 'content': resp.msg,
- },
- (res) => {
- console.log(res)
- });
- // #endif
- }
- })
- }).catch(err => {
- console.log('token not found', err);
- })
- }, 5 * 60_000)
- }
|