修改请求逻辑处理

v1.1.0
于肖磊 2024-12-02 16:42:55 +08:00
parent d9462a946d
commit 9126b65e28
3 changed files with 40 additions and 2 deletions

View File

@ -2,7 +2,7 @@
<div :class="props.direction == 'vertical' ? 'flex-col gap-x-18' : 'flex-row gap-y-20 jc-e'">
<div v-for="(item, index) in props.filterData" :key="index" class="filter-style flex-row gap-12">
<div v-if="!isEmpty(item.title)" :class="['title text-line-1', props.direction == 'vertical' ? '' : 'horizontal-title']" :style="`width: ${ Number(props.titleWidth) > 0 ? props.titleWidth + 'px;' : '100%' }`">{{ item.title }}</div>
<div class="w h flex-1">
<div class="w h flex-1 vertical-style">
<template v-if="item.type == 'select'">
<template v-if="item.config.is_level.toString() == '1'">
<div class="flex-row gap-10">
@ -164,6 +164,22 @@ const contains_value = (list: any[], config: any, result: any[], children?: stri
min-height: 3.2rem;
min-width: 20rem;
}
.vertical-style {
min-width: 20rem;
}
//
:deep(.el-cascader) {
height: 3.2rem;
.el-input {
height: 3.2rem;
}
.el-cascader__tags {
flex-wrap: nowrap !important;
}
.el-tag {
max-width: 10rem;
}
}
.horizontal-title {
flex-basis: max-content;
}

View File

@ -188,8 +188,10 @@ const default_data = () => {
form.value.data_source_carousel_col = show_number[0];
}
// ,
if (!isEmpty(data_type) && isEmpty(data_source_content.data_type) && !data_type.includes(data_source_content.data_type)) {
if (!isEmpty(data_type) && isEmpty(data_source_content.data_type) && !data_type.includes(Number(data_source_content.data_type))) {
form.value.data_source_content.data_type = data_type[0];
} else if (!isEmpty(data_source_content.data_type) && typeof data_source_content.data_type == 'string') { // 使
form.value.data_source_content.data_type = Number(form.value.data_source_content.data_type);
}
}
//

View File

@ -20,6 +20,9 @@ const message_error = (info: string) => {
// 创建一个状态变量来跟踪是否已经弹出了退出登录的弹窗
const isLogoutModalShown = ref(true);
// 用于存储每个请求的CancelToken
const pendingRequests = new Map();
// 创建 axios 实例
const index = window.location.href.lastIndexOf('?s=');
const pro_url = window.location.href.substring(0, index);
@ -43,6 +46,17 @@ service.interceptors.request.use(
config.url = config.url + '&token=' + (JSON.parse(cookie) !== 'null' ? JSON.parse(cookie)?.token : '');
}
}
// 检查是否有相同请求正在进行,如果有则取消, 防止重复请求导致返回数据有误
if (pendingRequests.has(config.url)) {
const cancelToken = pendingRequests.get(config.url);
cancelToken.cancel('canceled');
pendingRequests.delete(config.url);
}
// 创建一个新的 CancelToken
const source = axios.CancelToken.source();
config.cancelToken = source.token;
pendingRequests.set(config.url, source);
return config;
},
(error: any) => {
@ -52,6 +66,9 @@ service.interceptors.request.use(
// 响应拦截器
service.interceptors.response.use(
(response: AxiosResponse) => {
// 请求完成后从pendingRequests中移除
pendingRequests.delete(response.config.url);
const { code, msg, message, data } = response.data;
if (code == 0) {
return response.data;
@ -74,9 +91,12 @@ service.interceptors.response.use(
}
},
(error: any) => {
console.log(error);
if (error.response && error.response.data) {
const { msg, message } = error.response.data;
message_error(msg || message || '系统出错');
} else if (error.message == 'canceled') {
console.log('请求已取消');
} else {
message_error(error.message);
}