index.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { timerTask } from '@/utils/timer'
  2. import { enumStore, errorInfoStore, loginStore, userStore, futuresStore, menuStore, accountStore } from '@/stores'
  3. import { tokenCheck } from '@/services/api/account'
  4. import eventBus from '@/services/bus'
  5. /**
  6. * 初始化业务数据(暂无用,后期优化废除)
  7. */
  8. export async function initBaseData() {
  9. await enumStore.actions.getAllEnumList()
  10. await errorInfoStore.actions.getErrorInfoList()
  11. if (loginStore.getters.token) {
  12. await Promise.all([
  13. userStore.actions.getUserData(),
  14. menuStore.actions.getUserMenuList(),
  15. futuresStore.actions.getGoodsList(),
  16. ])
  17. accountStore.actions.getAccountList()
  18. }
  19. }
  20. /**
  21. * 令牌效验
  22. */
  23. export function checkToken() {
  24. const { loginId, token } = loginStore.$mapGetters()
  25. return tokenCheck({
  26. data: {
  27. LoginID: loginId.value,
  28. Token: token.value,
  29. },
  30. fail: () => eventBus.$emit('LogoutNotify')
  31. })
  32. }
  33. /**
  34. * 轮询效验令牌
  35. */
  36. export function checkTokenLoop() {
  37. const delay = 1 * 60 * 1000 // 每1分钟效验一次令牌
  38. timerTask.setTimeout(() => {
  39. checkToken().then(() => checkTokenLoop())
  40. }, delay, 'checkToken')
  41. }
  42. /**
  43. * 停止令牌效验
  44. */
  45. export function stopCheckToken() {
  46. timerTask.clearTimeout('checkToken')
  47. }