import UserCache from '@caches/UserCache'; import {message} from 'antd'; import {jumpLogin, checkUserInQb} from './index'; export const onEffect = async (action: any, res: any, effects: any, history: any) => { const tmp = {...action}; try { const body = await res.json(); tmp.status = body.status; tmp.loading = false; if (body.status === 401) { jumpLogin(history); tmp.message = body.message; tmp.status = 401; tmp.success = false; tmp.result = body.content; tmp.type = 'app.auth'; return tmp; } if (tmp.url.startsWith('/api/')) { tmp.message = body.message; tmp.success = body.status === 200; tmp.result = body.content; return tmp; } } catch (err) { message.error(err.message); tmp.success = false; tmp.error = '服务端异常'; } return tmp; }; export const onFetchOption = (option: any, item: any) => { const opt = option; if (item.key !== 'user.login') { if (UserCache.user) { opt.headers = option.headers || {}; opt.headers.userId = UserCache.user.userId; } checkUserInQb(); } return opt; };