| | |
| | | import axios, { |
| | | AxiosError, |
| | | AxiosInstance, |
| | | AxiosRequestHeaders, |
| | | AxiosResponse, |
| | | InternalAxiosRequestConfig |
| | | } from 'axios' |
| | | import axios, { AxiosError, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios' |
| | | |
| | | import { ElMessage, ElMessageBox, ElNotification } from 'element-plus' |
| | | import qs from 'qs' |
| | |
| | | const service: AxiosInstance = axios.create({ |
| | | baseURL: base_url, // api 的 base_url |
| | | timeout: request_timeout, // 请求超时时间 |
| | | withCredentials: false // 禁用 Cookie 等信息 |
| | | withCredentials: false, // 禁用 Cookie 等信息 |
| | | // 自定义参数序列化函数 |
| | | paramsSerializer: (params) => { |
| | | return qs.stringify(params, { allowDots: true }) |
| | | } |
| | | }) |
| | | |
| | | // request拦截器 |
| | |
| | | // 是否需要设置 token |
| | | let isToken = (config!.headers || {}).isToken === false |
| | | whiteList.some((v) => { |
| | | if (config.url) { |
| | | config.url.indexOf(v) > -1 |
| | | if (config.url && config.url.indexOf(v) > -1) { |
| | | return (isToken = false) |
| | | } |
| | | }) |
| | | if (getAccessToken() && !isToken) { |
| | | ;(config as Recordable).headers.Authorization = 'Bearer ' + getAccessToken() // 让每个请求携带自定义token |
| | | config.headers.Authorization = 'Bearer ' + getAccessToken() // 让每个请求携带自定义token |
| | | } |
| | | // 设置租户 |
| | | if (tenantEnable && tenantEnable === 'true') { |
| | | const tenantId = getTenantId() |
| | | if (tenantId) (config as Recordable).headers['tenant-id'] = tenantId |
| | | if (tenantId) config.headers['tenant-id'] = tenantId |
| | | } |
| | | const params = config.params || {} |
| | | const data = config.data || false |
| | | if ( |
| | | config.method?.toUpperCase() === 'POST' && |
| | | (config.headers as AxiosRequestHeaders)['Content-Type'] === |
| | | 'application/x-www-form-urlencoded' |
| | | ) { |
| | | config.data = qs.stringify(data) |
| | | const method = config.method?.toUpperCase() |
| | | // 防止 GET 请求缓存 |
| | | if (method === 'GET') { |
| | | config.headers['Cache-Control'] = 'no-cache' |
| | | config.headers['Pragma'] = 'no-cache' |
| | | } |
| | | // get参数编码 |
| | | if (config.method?.toUpperCase() === 'GET' && params) { |
| | | config.params = {} |
| | | const paramsStr = qs.stringify(params, { allowDots: true }) |
| | | if (paramsStr) { |
| | | config.url = config.url + '?' + paramsStr |
| | | // 自定义参数序列化函数 |
| | | else if (method === 'POST') { |
| | | const contentType = config.headers['Content-Type'] || config.headers['content-type'] |
| | | if (contentType === 'application/x-www-form-urlencoded') { |
| | | if (config.data && typeof config.data !== 'string') { |
| | | config.data = qs.stringify(config.data) |
| | | } |
| | | } |
| | | } |
| | | return config |
| | |
| | | t('sys.api.errMsg901') + |
| | | '</div>' + |
| | | '<div> </div>' + |
| | | '<div>参考 https://xxxx/ 教程</div>' + |
| | | '<div>参考 https://doc.iailab.cn/ 教程</div>' + |
| | | '<div> </div>' + |
| | | '<div>5 分钟搭建本地环境</div>' |
| | | }) |
| | |
| | | const handleAuthorized = () => { |
| | | const { t } = useI18n() |
| | | if (!isRelogin.show) { |
| | | // 如果已经到重新登录页面则不进行弹窗提示 |
| | | if (window.location.href.includes('login?redirect=')) { |
| | | return |
| | | } |
| | | isRelogin.show = true |
| | | ElMessageBox.confirm(t('sys.api.timeoutMessage'), t('common.confirmTitle'), { |
| | | showCancelButton: false, |
| | | closeOnClickModal: false, |
| | | showClose: false, |
| | | closeOnPressEscape: false, |
| | | confirmButtonText: t('login.relogin'), |
| | | type: 'warning' |
| | | }).then(() => { |