fix: 请求超时时间配置
This commit is contained in:
@@ -7,7 +7,7 @@ import { parseObjLineToHump } from '@/utils/parse-utils';
|
|||||||
* @param query 查询参数
|
* @param query 查询参数
|
||||||
* @returns object
|
* @returns object
|
||||||
*/
|
*/
|
||||||
export async function list5gBase(query: Record<string, any>) {
|
export async function listBase5G(query: Record<string, any>) {
|
||||||
query.nbId = query.id;
|
query.nbId = query.id;
|
||||||
const result = await request({
|
const result = await request({
|
||||||
url: '/ueManagement/v1/elementType/amf/objectType/nbInfo',
|
url: '/ueManagement/v1/elementType/amf/objectType/nbInfo',
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ type RepeatSubmitType = {
|
|||||||
|
|
||||||
/**请求参数类型 */
|
/**请求参数类型 */
|
||||||
type OptionsType = {
|
type OptionsType = {
|
||||||
|
/**请求的根域名地址-不带/后缀 */
|
||||||
|
baseUrl?: string;
|
||||||
|
/**超时时间,毫秒 */
|
||||||
|
timeout?: number;
|
||||||
/**请求地址 */
|
/**请求地址 */
|
||||||
url: string;
|
url: string;
|
||||||
/**请求方法 */
|
/**请求方法 */
|
||||||
@@ -67,22 +71,10 @@ type OptionsType = {
|
|||||||
whithToken?: boolean;
|
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 = {
|
const FATCH_OPTIONS: OptionsType = {
|
||||||
|
baseUrl: import.meta.env.VITE_API_BASE_URL,
|
||||||
|
timeout: 30 * 1000,
|
||||||
url: '',
|
url: '',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -211,12 +203,13 @@ export async function request(options: OptionsType): Promise<ResultType> {
|
|||||||
// 请求超时控制请求终止
|
// 请求超时控制请求终止
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const { signal } = controller;
|
const { signal } = controller;
|
||||||
const timeoutId = setTimeout(() => {
|
|
||||||
controller.abort(); // 终止请求
|
|
||||||
}, FATCH_CONFIG.timeout);
|
|
||||||
|
|
||||||
options = Object.assign({ signal }, FATCH_OPTIONS, options);
|
options = Object.assign({ signal }, FATCH_OPTIONS, options);
|
||||||
|
|
||||||
|
const timeoutId = setTimeout(() => {
|
||||||
|
controller.abort(); // 终止请求
|
||||||
|
}, options.timeout);
|
||||||
|
|
||||||
// 检查请求拦截
|
// 检查请求拦截
|
||||||
const beforeReq = beforeRequest(options);
|
const beforeReq = beforeRequest(options);
|
||||||
if (beforeReq instanceof Promise) {
|
if (beforeReq instanceof Promise) {
|
||||||
@@ -227,7 +220,7 @@ export async function request(options: OptionsType): Promise<ResultType> {
|
|||||||
// 判断用户传递的URL是否http或/开头
|
// 判断用户传递的URL是否http或/开头
|
||||||
if (!options.url.startsWith('http')) {
|
if (!options.url.startsWith('http')) {
|
||||||
const uri = options.url.startsWith('/') ? options.url : `/${options.url}`;
|
const uri = options.url.startsWith('/') ? options.url : `/${options.url}`;
|
||||||
options.url = FATCH_CONFIG.baseUrl + uri;
|
options.url = options.baseUrl + uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { message } from 'ant-design-vue/lib';
|
|||||||
import { SizeType } from 'ant-design-vue/lib/config-provider';
|
import { SizeType } from 'ant-design-vue/lib/config-provider';
|
||||||
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
|
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
|
||||||
import { ColumnsType } from 'ant-design-vue/lib/table';
|
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 useNeInfoStore from '@/store/modules/neinfo';
|
||||||
import useI18n from '@/hooks/useI18n';
|
import useI18n from '@/hooks/useI18n';
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
@@ -127,8 +127,7 @@ function fnTableSize({ key }: MenuInfo) {
|
|||||||
function fnGetList() {
|
function fnGetList() {
|
||||||
if (tableState.loading) return;
|
if (tableState.loading) return;
|
||||||
tableState.loading = true;
|
tableState.loading = true;
|
||||||
list5gBase(toRaw(queryParams)).then(res => {
|
listBase5G(toRaw(queryParams)).then(res => {
|
||||||
console.log(res);
|
|
||||||
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
|
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
|
||||||
// 取消勾选
|
// 取消勾选
|
||||||
if (tableState.selectedRowKeys.length > 0) {
|
if (tableState.selectedRowKeys.length > 0) {
|
||||||
@@ -136,9 +135,6 @@ function fnGetList() {
|
|||||||
}
|
}
|
||||||
tablePagination.total = res.total;
|
tablePagination.total = res.total;
|
||||||
tableState.data = res.rows;
|
tableState.data = res.rows;
|
||||||
} else {
|
|
||||||
tablePagination.total = 0;
|
|
||||||
tableState.data = [];
|
|
||||||
}
|
}
|
||||||
tableState.loading = false;
|
tableState.loading = false;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user