| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { timerTask } from '@/utils/timer'
- import { enumStore, errorInfoStore, loginStore, userStore, futuresStore, menuStore, accountStore } from '@/stores'
- import { tokenCheck } from '@/services/api/account'
- import eventBus from '@/services/bus'
- /**
- * 初始化业务数据(暂无用,后期优化废除)
- */
- export async function initBaseData() {
- await enumStore.actions.getAllEnumList()
- await errorInfoStore.actions.getErrorInfoList()
- if (loginStore.getters.token) {
- await Promise.all([
- userStore.actions.getUserData(),
- menuStore.actions.getUserMenuList(),
- futuresStore.actions.getGoodsList(),
- ])
- accountStore.actions.getAccountList()
- }
- }
- /**
- * 令牌效验
- */
- export function checkToken() {
- const { loginId, token } = loginStore.$mapGetters()
- return tokenCheck({
- data: {
- LoginID: loginId.value,
- Token: token.value,
- },
- fail: () => eventBus.$emit('LogoutNotify')
- })
- }
- /**
- * 轮询效验令牌
- */
- export function checkTokenLoop() {
- const delay = 1 * 60 * 1000 // 每1分钟效验一次令牌
- timerTask.setTimeout(() => {
- checkToken().then(() => checkTokenLoop())
- }, delay, 'checkToken')
- }
- /**
- * 停止令牌效验
- */
- export function stopCheckToken() {
- timerTask.clearTimeout('checkToken')
- }
|