request
This commit is contained in:
parent
d25abf3b18
commit
e1bb664c53
@ -1,18 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Do not edit
|
* @Author: Do not edit
|
||||||
* @Date: 2023-11-20 11:02:29
|
* @Date: 2023-11-20 11:02:29
|
||||||
* @LastEditTime: 2024-01-10 17:31:37
|
* @LastEditTime: 2024-01-11 10:34:34
|
||||||
* @LastEditors: DY
|
* @LastEditors: DY
|
||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { getTenantId, getAccessToken, getRefreshToken, setToken } from '@/utils/auth'
|
import { getTenantId, getAccessToken, getRefreshToken, setToken } from '@/utils/auth'
|
||||||
import { refreshToken } from '@/api/login'
|
import { refreshToken } from '@/api/login'
|
||||||
|
import { MessageBox } from 'element-ui'
|
||||||
|
|
||||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
||||||
|
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
// baseURL: 'http://192.168.0.33:48082/admin-api',
|
// baseURL: 'http://192.168.1.78:48082/admin-api',
|
||||||
baseURL: 'http://192.168.0.33:48082/admin-api',
|
baseURL: 'http://192.168.0.33:48082/admin-api',
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
withCredentials: false
|
withCredentials: false
|
||||||
@ -53,13 +54,13 @@ service.interceptors.response.use(async res => {
|
|||||||
try {
|
try {
|
||||||
const refreshTokenRes = await refreshToken()
|
const refreshTokenRes = await refreshToken()
|
||||||
// 2.1 刷新成功,则回放队列的请求 + 当前请求
|
// 2.1 刷新成功,则回放队列的请求 + 当前请求
|
||||||
if (refreshTokenRes.data.code === 0) {
|
// if (refreshTokenRes.data.code === 0) {
|
||||||
setToken(refreshTokenRes.data.data)
|
setToken(refreshTokenRes.data.data)
|
||||||
requestList.forEach(cb => cb())
|
requestList.forEach(cb => cb())
|
||||||
return service(res.config)
|
return service(res.config)
|
||||||
} else {
|
// } else {
|
||||||
return handleAuthorized()
|
// return handleAuthorized()
|
||||||
}
|
// }
|
||||||
} catch (e) { // 为什么需要 catch 异常呢?刷新失败时,请求因为 Promise.reject 触发异常。
|
} catch (e) { // 为什么需要 catch 异常呢?刷新失败时,请求因为 Promise.reject 触发异常。
|
||||||
// 2.2 刷新失败,只回放队列的请求
|
// 2.2 刷新失败,只回放队列的请求
|
||||||
requestList.forEach(cb => cb())
|
requestList.forEach(cb => cb())
|
||||||
@ -87,22 +88,19 @@ service.interceptors.response.use(async res => {
|
|||||||
function handleAuthorized () {
|
function handleAuthorized () {
|
||||||
if (!isRelogin.show) {
|
if (!isRelogin.show) {
|
||||||
isRelogin.show = true
|
isRelogin.show = true
|
||||||
this.$message.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
||||||
confirmButtonText: '重新登录',
|
confirmButtonText: '重新登录',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}
|
}
|
||||||
).then(() => {
|
).then(() => {
|
||||||
isRelogin.show = false
|
isRelogin.show = false
|
||||||
this.$router.push({ path: '/' })
|
location.href = ''
|
||||||
// store.dispatch('LogOut').then(() => {
|
|
||||||
// location.href = getPath('/index');
|
|
||||||
// })
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
isRelogin.show = false
|
isRelogin.show = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return Promise.reject(new Error('无效的会话,或者会话已过期,请重新登录。'))
|
// return Promise.reject(new Error('无效的会话,或者会话已过期,请重新登录。'))
|
||||||
}
|
}
|
||||||
|
|
||||||
export default service
|
export default service
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<!--
|
<!--
|
||||||
* @Author: Do not edit
|
* @Author: Do not edit
|
||||||
* @Date: 2024-01-09 13:48:42
|
* @Date: 2024-01-09 13:48:42
|
||||||
* @LastEditTime: 2024-01-10 17:56:00
|
* @LastEditTime: 2024-01-11 09:26:12
|
||||||
* @LastEditors: DY
|
* @LastEditors: DY
|
||||||
* @Description:
|
* @Description:
|
||||||
-->
|
-->
|
||||||
@ -112,12 +112,16 @@ export default {
|
|||||||
},
|
},
|
||||||
getLine () {
|
getLine () {
|
||||||
lineList().then(res => {
|
lineList().then(res => {
|
||||||
|
if (res && res.data.data.length > 0) {
|
||||||
this.lineArray = res.data.data.map(item => {
|
this.lineArray = res.data.data.map(item => {
|
||||||
return {
|
return {
|
||||||
text: item.name,
|
text: item.name,
|
||||||
value: item.id
|
value: item.id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
this.lineArray = []
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getSection () {
|
getSection () {
|
||||||
|
Loading…
Reference in New Issue
Block a user