| | |
| | | } |
| | | //#endregion |
| | | |
| | | const openLoginDlg = debounce(() => { |
| | | const handleNoAuth = debounce(() => { |
| | | emitter.emit('logout'); |
| | | emitter.emit('openLoginDlg'); |
| | | }); |
| | | |
| | | const loginUrl = '/login'; |
| | | const initRequestInterceptor = (request: AxiosInstance) => { |
| | | // 添加请求拦截器 |
| | | request.interceptors.request.use( |
| | |
| | | // 将 token 添加到请求报文头中 |
| | | config.headers['hswatersession'] = accessSession; |
| | | } else { |
| | | openLoginDlg(); |
| | | if (config.url !== loginUrl) { |
| | | handleNoAuth(config.url); |
| | | throw '权限验证失败'; |
| | | } |
| | | } |
| | | return config; |
| | | }, |
| | |
| | | if (!serveData.json_ok) { |
| | | switch (serveData?.err_code) { |
| | | case ErrorCode.Auth: |
| | | openLoginDlg(); |
| | | throw '权限验证失败'; |
| | | if (res.config.url !== loginUrl) { |
| | | handleNoAuth(); |
| | | throw '权限验证失败'; |
| | | } |
| | | } |
| | | const msg = serveData.json_msg ?? ''; |
| | | |