pullNotice.js 900 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { getCache } from "./cache";
  2. import {pullNotice} from '@/api/collect.js'
  3. // #ifdef APP
  4. const notify = uni.requireNativePlugin('Ba-Notify')
  5. // #endif
  6. let pullNoticeExecutor = null
  7. export const startPullNotice = () => {
  8. console.log('开始执行轮询');
  9. if(pullNoticeExecutor) {
  10. clearImmediate(pullNoticeExecutor)
  11. }
  12. pullNoticeExecutor = setInterval(() => {
  13. getCache('token').then(res => {
  14. console.log('token is', res);
  15. pullNotice().then(resp => {
  16. console.log('pull', resp);
  17. if(resp.msg) {
  18. // #ifdef APP
  19. notify.show({
  20. 'channelID': '0',
  21. 'channelName': '普通通知',
  22. 'ID': 0,
  23. 'notifyType': 0,
  24. 'ticker': 'Ticker',
  25. 'title': '提醒',
  26. 'content': resp.msg,
  27. },
  28. (res) => {
  29. console.log(res)
  30. });
  31. // #endif
  32. }
  33. })
  34. }).catch(err => {
  35. console.log('token not found', err);
  36. })
  37. }, 5 * 60_000)
  38. }