| | |
| | | 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 JSONbig from 'json-bigint'; |
| | | |
| | | //#region ====================== 后端 res.err_code ====================== |
| | |
| | | // 将 token 添加到请求报文头中 |
| | | config.headers['hswatersession'] = accessSession; |
| | | } |
| | | if (!NO_AUTH_API_LIST.includes(config.url)) { |
| | | if (!NO_AUTH_API_LIST.includes(config.url) && !isSharePage.value) { |
| | | if (!accessSession && config.url !== LOGIN_URL && config.url !== TEL_LOGIN_URL) { |
| | | handleNoAuth(config.url); |
| | | throw '权限验证失败'; |
| | |
| | | if (!serveData.json_ok) { |
| | | switch (serveData?.err_code) { |
| | | case ErrorCode.Auth: |
| | | if (res.config.url !== LOGIN_URL && res.config.url !== TEL_LOGIN_URL) { |
| | | if (res.config.url !== LOGIN_URL && res.config.url !== TEL_LOGIN_URL && !isSharePage.value) { |
| | | handleNoAuth(); |
| | | throw '权限验证失败'; |
| | | } |
| | |
| | | const createAxiosInstance = (option: Partial<CreateAxiosDefaults<any>> = {}) => { |
| | | return axios.create({ |
| | | baseURL: MAIN_URL, |
| | | timeout: 120000, |
| | | headers: { 'Content-Type': 'application/json;charset=utf-8 ' }, |
| | | timeout: 1200000, |
| | | headers: { |
| | | 'Content-Type': 'application/x-www-form-urlencoded', |
| | | }, |
| | | ...option, |
| | | }); |
| | | }; |
| | | |
| | | const service = createAxiosInstance(); |
| | | |
| | | export const mainRequest = service; |
| | | |
| | | //#region ====================== 流响应数据 ====================== |
| | |
| | | responseType: 'stream', |
| | | }); |
| | | const decoder = new TextDecoder(); |
| | | const encoder = new TextEncoder(); |
| | | const readStream = async (stream: ReadableStream, cb: (value) => void): Promise<any> => { |
| | | const reader = stream.getReader(); |
| | | let lastValue = ''; |
| | |
| | | // const txt = decoder.decode(Uint8Array.from([...lastValue, ...value])); |
| | | const txt = decoder.decode(value); |
| | | const txtArr = txt.split('\n'); |
| | | txtArr[0] =lastValue+ txtArr[0] |
| | | txtArr[0] = lastValue + txtArr[0]; |
| | | txtArr.forEach((value, index, array) => { |
| | | // 一般不会出现连续换行,只可能最后一个是换行 |
| | | if (index === array.length - 1) { |
| | | lastValue =value; |
| | | |
| | | lastValue = value; |
| | | } else { |
| | | const decodeValue = decodeURIComponent(value); |
| | | fullValue += decodeValue; |
| | |
| | | |
| | | // userInfo键定义 |
| | | export const userInfoKey = getDomainPrefix(window) + 'userInfo'; |
| | | |
| | | // 获取 token |
| | | export const getSession = () => { |
| | | return Local.get(accessSessionKey); |