| | |
| | | import { debounce, decodeFormData } from './util'; |
| | | import { AUTH_URL, MAIN_URL, SECONDARY_URL } from '/@/constants'; |
| | | import { Local, LoginInfo, Session } from '/@/utils/storage'; |
| | | import { isSharePage } from '../stores/chatRoom'; |
| | | import { isSharePage, logoutClick, openLoginDlg } from '../stores/chatRoom'; |
| | | // import JSONbig from 'json-bigint'; |
| | | |
| | | //#region ====================== 后端 res.err_code ====================== |
| | |
| | | //#endregion |
| | | |
| | | const emitNoAuth = () => { |
| | | emitter.emit('logout'); |
| | | emitter.emit('openLoginDlg'); |
| | | logoutClick(); |
| | | openLoginDlg(); |
| | | }; |
| | | |
| | | export const handleNormalAuth = () => { |
| | | const accessSession = Local.get(accessSessionKey); |
| | | if (!accessSession) { |
| | | emitter.emit('logout'); |
| | | emitter.emit('openLoginDlg'); |
| | | logoutClick(); |
| | | openLoginDlg(); |
| | | } |
| | | return !!accessSession; |
| | | }; |
| | | |
| | | export const SESSION_KEY = 'hswatersession'; |
| | | export const handleNoAuth = debounce(() => { |
| | | emitNoAuth(); |
| | | }); |
| | |
| | | const accessSession = Local.get(accessSessionKey); |
| | | if (accessSession) { |
| | | // 将 token 添加到请求报文头中 |
| | | config.headers['hswatersession'] = accessSession; |
| | | config.headers[SESSION_KEY] = accessSession; |
| | | } |
| | | if (!NO_AUTH_API_LIST.includes(config.url) && !isSharePage.value) { |
| | | if (!accessSession && config.url !== LOGIN_URL && config.url !== TEL_LOGIN_URL) { |
| | |
| | | export const userName = 'userName'; |
| | | |
| | | export const getSessionKey = (win: Window) => { |
| | | return sessionName; |
| | | return sessionName; |
| | | }; |
| | | export const getUserNameKey = (win: Window) => { |
| | | return userName; |
| | | return userName; |
| | | }; |
| | | |
| | | export const accessSessionKey = getSessionKey(window); |
| | |
| | | export const refreshAccessTokenKey = `x-${accessSessionKey}`; |
| | | |
| | | // userInfo键定义 |
| | | export const userInfoKey ='userInfo'; |
| | | export const userInfoKey = 'userInfo'; |
| | | // 获取 token |
| | | export const getSession = () => { |
| | | return Local.get(accessSessionKey); |