登录失效
This commit is contained in:
@@ -10,9 +10,9 @@ export const checkStatus = (status: number) => {
|
|||||||
case 400:
|
case 400:
|
||||||
ElMessage.error("请求失败!请您稍后重试");
|
ElMessage.error("请求失败!请您稍后重试");
|
||||||
break;
|
break;
|
||||||
case 401:
|
// case 401:
|
||||||
ElMessage.error("登录失效!请您重新登录");
|
// ElMessage.error("登录失效!请您重新登录");
|
||||||
break;
|
// break;
|
||||||
case 403:
|
case 403:
|
||||||
ElMessage.error("当前账号无权限访问!");
|
ElMessage.error("当前账号无权限访问!");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ResultEnum } from '@/enums/httpEnum'
|
|||||||
import { checkStatus } from './helper/checkStatus'
|
import { checkStatus } from './helper/checkStatus'
|
||||||
import { useUserStore } from '@/stores/modules/user'
|
import { useUserStore } from '@/stores/modules/user'
|
||||||
import router from '@/routers'
|
import router from '@/routers'
|
||||||
|
import {refreshToken} from '@/api/user/login'
|
||||||
|
|
||||||
export interface CustomAxiosRequestConfig extends InternalAxiosRequestConfig {
|
export interface CustomAxiosRequestConfig extends InternalAxiosRequestConfig {
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
@@ -53,22 +54,44 @@ class RequestHttp {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let isFirst = true
|
||||||
/**
|
/**
|
||||||
* @description 响应拦截器
|
* @description 响应拦截器
|
||||||
* 服务器换返回信息 -> [拦截统一处理] -> 客户端JS获取到信息
|
* 服务器换返回信息 -> [拦截统一处理] -> 客户端JS获取到信息
|
||||||
*/
|
*/
|
||||||
this.service.interceptors.response.use(
|
this.service.interceptors.response.use(
|
||||||
(response: AxiosResponse) => {
|
async (response: AxiosResponse) => {
|
||||||
const { data } = response
|
const { data } = response
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
tryHideFullScreenLoading()
|
tryHideFullScreenLoading()
|
||||||
|
|
||||||
|
if(data.code === ResultEnum.ACCESSTOKEN_EXPIRED){
|
||||||
|
// 用长token去换短token
|
||||||
|
const result = await refreshToken()
|
||||||
|
if (result) { //获取新token成功的话
|
||||||
|
// 有新的token后,重新请求
|
||||||
|
userStore.setAccessToken(result.data.accessToken)
|
||||||
|
userStore.setRefreshToken(result.data.refreshToken)
|
||||||
|
response.config.headers.Authorization = `Bearer ${result.data.accessToken}`//重新请求前需要将更新后的新token更换掉之前无效的token,不然会死循环
|
||||||
|
const resp = await this.service.request(response.config)
|
||||||
|
return resp
|
||||||
|
} else {
|
||||||
|
// 刷新失效,跳转登录页
|
||||||
|
}
|
||||||
|
}
|
||||||
// 登陆失效
|
// 登陆失效
|
||||||
if (data.code == ResultEnum.OVERDUE) {
|
if (data.code == ResultEnum.OVERDUE) {
|
||||||
|
console.log("登陆失效")
|
||||||
userStore.setAccessToken('')
|
userStore.setAccessToken('')
|
||||||
userStore.setRefreshToken('')
|
userStore.setRefreshToken('')
|
||||||
userStore.setUserInfo({ name: '' })
|
userStore.setUserInfo({ name: '' })
|
||||||
router.replace(LOGIN_URL)
|
router.replace(LOGIN_URL)
|
||||||
ElMessage.error(data.message)
|
if(data.code != ResultEnum.OVERDUE){//临时处理token失效弹窗多次
|
||||||
|
ElMessage.error(data.message)
|
||||||
|
}else if(isFirst){
|
||||||
|
ElMessage.error(data.message)
|
||||||
|
isFirst = false
|
||||||
|
}
|
||||||
return Promise.reject(data)
|
return Promise.reject(data)
|
||||||
}
|
}
|
||||||
// 全局错误信息拦截(防止下载文件的时候返回数据流,没有 code 直接报错)
|
// 全局错误信息拦截(防止下载文件的时候返回数据流,没有 code 直接报错)
|
||||||
@@ -87,6 +110,7 @@ class RequestHttp {
|
|||||||
async (error: AxiosError) => {
|
async (error: AxiosError) => {
|
||||||
const { response } = error
|
const { response } = error
|
||||||
tryHideFullScreenLoading()
|
tryHideFullScreenLoading()
|
||||||
|
console.log('error', error.message)
|
||||||
// 请求超时 && 网络错误单独判断,没有 response
|
// 请求超时 && 网络错误单独判断,没有 response
|
||||||
if (error.message.indexOf('timeout') !== -1) ElMessage.error('请求超时!请您稍后重试')
|
if (error.message.indexOf('timeout') !== -1) ElMessage.error('请求超时!请您稍后重试')
|
||||||
if (error.message.indexOf('Network Error') !== -1) ElMessage.error('网络错误!请您稍后重试')
|
if (error.message.indexOf('Network Error') !== -1) ElMessage.error('网络错误!请您稍后重试')
|
||||||
|
|||||||
@@ -30,7 +30,11 @@ export const getDictList = () =>{
|
|||||||
return http.get<Dict>('/dictData/dictDataCache')
|
return http.get<Dict>('/dictData/dictDataCache')
|
||||||
}
|
}
|
||||||
|
|
||||||
// token刷新
|
//token刷新
|
||||||
export const refreshToken = () => {
|
export const refreshToken = () => {
|
||||||
return http.post<Login.ResLogin>(`${rePrefix}/refreshToken`, {},{ loading: false })
|
return http.get<Login.ResLogin>(`${rePrefix}/refreshToken`,
|
||||||
|
{},
|
||||||
|
{ loading: false }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
export enum ResultEnum {
|
export enum ResultEnum {
|
||||||
SUCCESS = "A0000",
|
SUCCESS = "A0000",
|
||||||
ERROR = 500,
|
ERROR = 500,
|
||||||
OVERDUE = "401",
|
ACCESSTOKEN_EXPIRED = 401,
|
||||||
|
OVERDUE = 4001,
|
||||||
TIMEOUT = 30000,
|
TIMEOUT = 30000,
|
||||||
TYPE = "success"
|
TYPE = "success"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -891,21 +891,21 @@ const handleTest = async (val: string) => {
|
|||||||
|
|
||||||
|
|
||||||
if (val === '手动检测' || val === '自动检测' || val === '不合格项复检' || val === '全部复检') {
|
if (val === '手动检测' || val === '自动检测' || val === '不合格项复检' || val === '全部复检') {
|
||||||
if (devNum > 6) {
|
// if (devNum > 6) {
|
||||||
|
// ElMessageBox.confirm(
|
||||||
|
// '每次检测最多只能选择6台设备,请重新选择',
|
||||||
|
// '提示',
|
||||||
|
// {
|
||||||
|
// confirmButtonText: '确定',
|
||||||
|
// cancelButtonText: '取消',
|
||||||
|
// type: 'warning',
|
||||||
|
// },
|
||||||
|
// )
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
if (devChannelsNum > 12) {
|
||||||
ElMessageBox.confirm(
|
ElMessageBox.confirm(
|
||||||
'每次检测最多只能选择6台设备,请重新选择',
|
'每次检测最多只能检测12个设备通道,请重新选择',
|
||||||
'提示',
|
|
||||||
{
|
|
||||||
confirmButtonText: '确定',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
type: 'warning',
|
|
||||||
},
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (devChannelsNum > 20) {
|
|
||||||
ElMessageBox.confirm(
|
|
||||||
'每次检测最多只能检测20个设备通道,请重新选择',
|
|
||||||
'提示',
|
'提示',
|
||||||
{
|
{
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<el-button type="primary" :icon="DArrowRight" v-if="stepsActiveIndex < 2 && ActiveStatue != 'success'" :disabled="skipDisabled"
|
<el-button type="primary" :icon="DArrowRight" v-if="stepsActiveIndex < 2 && ActiveStatue != 'success'" :disabled="skipDisabled"
|
||||||
@click="nextStep">跳过
|
@click="nextStep">跳过
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button type="primary" :icon="VideoPlay" v-if="ActiveStatue === 'waiting'" @click="handleSubmit">开始检测</el-button>
|
<el-button type="primary" :icon="VideoPlay" v-if="ActiveStatue === 'waiting'" @click="handleSubmit" :disabled="btnState">开始检测</el-button>
|
||||||
<el-button type="primary" v-if="TestStatus === 'process'" @click="handleSubmit" disabled>
|
<el-button type="primary" v-if="TestStatus === 'process'" @click="handleSubmit" disabled>
|
||||||
<el-icon class="loading-box" style="color: #fff;margin-right: 8px;">
|
<el-icon class="loading-box" style="color: #fff;margin-right: 8px;">
|
||||||
<component :is="Refresh"/>
|
<component :is="Refresh"/>
|
||||||
@@ -114,7 +114,7 @@ import {showFullScreenLoading} from "@/components/Loading/fullScreen";
|
|||||||
// (e: 'update:visible', value: boolean): void;
|
// (e: 'update:visible', value: boolean): void;
|
||||||
// (e: 'submit', data: any): void;
|
// (e: 'submit', data: any): void;
|
||||||
// }>();
|
// }>();
|
||||||
|
const btnState = ref(false)
|
||||||
const checkStore = useCheckStore();
|
const checkStore = useCheckStore();
|
||||||
const skipDisabled = ref(false);
|
const skipDisabled = ref(false);
|
||||||
const nextStepText = ref('下一步');
|
const nextStepText = ref('下一步');
|
||||||
@@ -243,6 +243,7 @@ const open = (selection: Device.ResPqDev[], title: string, time: boolean) => {
|
|||||||
let loading;
|
let loading;
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
skipDisabled.value = true
|
skipDisabled.value = true
|
||||||
|
//btnState.value = true
|
||||||
console.log('=============', stepsActiveIndex.value)
|
console.log('=============', stepsActiveIndex.value)
|
||||||
|
|
||||||
let deviceIds = checkStore.devices.map((item) => item.deviceId)
|
let deviceIds = checkStore.devices.map((item) => item.deviceId)
|
||||||
|
|||||||
Reference in New Issue
Block a user