fix: 请求超时时间配置

This commit is contained in:
TsMask
2023-09-22 11:14:40 +08:00
parent 2b5aecc570
commit 021446b04b
3 changed files with 14 additions and 25 deletions

View File

@@ -7,7 +7,7 @@ import { parseObjLineToHump } from '@/utils/parse-utils';
* @param query 查询参数
* @returns object
*/
export async function list5gBase(query: Record<string, any>) {
export async function listBase5G(query: Record<string, any>) {
query.nbId = query.id;
const result = await request({
url: '/ueManagement/v1/elementType/amf/objectType/nbInfo',

View File

@@ -41,6 +41,10 @@ type RepeatSubmitType = {
/**请求参数类型 */
type OptionsType = {
/**请求的根域名地址-不带/后缀 */
baseUrl?: string;
/**超时时间,毫秒 */
timeout?: number;
/**请求地址 */
url: string;
/**请求方法 */
@@ -67,22 +71,10 @@ type OptionsType = {
whithToken?: boolean;
};
/**全局配置类型 */
type ConfigType = {
/**请求的根域名地址-不带/后缀 */
baseUrl: string;
/**超时时间,毫秒 */
timeout: number;
};
/**默认配置 */
const FATCH_CONFIG: ConfigType = {
baseUrl: import.meta.env.VITE_API_BASE_URL,
timeout: 10 * 1000,
};
/**默认请求参数 */
const FATCH_OPTIONS: OptionsType = {
baseUrl: import.meta.env.VITE_API_BASE_URL,
timeout: 30 * 1000,
url: '',
method: 'get',
headers: {
@@ -211,12 +203,13 @@ export async function request(options: OptionsType): Promise<ResultType> {
// 请求超时控制请求终止
const controller = new AbortController();
const { signal } = controller;
const timeoutId = setTimeout(() => {
controller.abort(); // 终止请求
}, FATCH_CONFIG.timeout);
options = Object.assign({ signal }, FATCH_OPTIONS, options);
const timeoutId = setTimeout(() => {
controller.abort(); // 终止请求
}, options.timeout);
// 检查请求拦截
const beforeReq = beforeRequest(options);
if (beforeReq instanceof Promise) {
@@ -227,7 +220,7 @@ export async function request(options: OptionsType): Promise<ResultType> {
// 判断用户传递的URL是否http或/开头
if (!options.url.startsWith('http')) {
const uri = options.url.startsWith('/') ? options.url : `/${options.url}`;
options.url = FATCH_CONFIG.baseUrl + uri;
options.url = options.baseUrl + uri;
}
try {

View File

@@ -6,7 +6,7 @@ import { message } from 'ant-design-vue/lib';
import { SizeType } from 'ant-design-vue/lib/config-provider';
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
import { ColumnsType } from 'ant-design-vue/lib/table';
import { list5gBase } from '@/api/neUser/base5G';
import { listBase5G } from '@/api/neUser/base5G';
import useNeInfoStore from '@/store/modules/neinfo';
import useI18n from '@/hooks/useI18n';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
@@ -127,8 +127,7 @@ function fnTableSize({ key }: MenuInfo) {
function fnGetList() {
if (tableState.loading) return;
tableState.loading = true;
list5gBase(toRaw(queryParams)).then(res => {
console.log(res);
listBase5G(toRaw(queryParams)).then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
// 取消勾选
if (tableState.selectedRowKeys.length > 0) {
@@ -136,9 +135,6 @@ function fnGetList() {
}
tablePagination.total = res.total;
tableState.data = res.rows;
} else {
tablePagination.total = 0;
tableState.data = [];
}
tableState.loading = false;
});