From 021446b04b0261a41c3ce4bf1903bbf2188ebf03 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Fri, 22 Sep 2023 11:14:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=B7=E6=B1=82=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/neUser/base5G.ts | 2 +- src/plugins/http-fetch.ts | 29 +++++++++++------------------ src/views/neUser/base5G/index.vue | 8 ++------ 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/api/neUser/base5G.ts b/src/api/neUser/base5G.ts index c1157436..326bd7a9 100644 --- a/src/api/neUser/base5G.ts +++ b/src/api/neUser/base5G.ts @@ -7,7 +7,7 @@ import { parseObjLineToHump } from '@/utils/parse-utils'; * @param query 查询参数 * @returns object */ -export async function list5gBase(query: Record) { +export async function listBase5G(query: Record) { query.nbId = query.id; const result = await request({ url: '/ueManagement/v1/elementType/amf/objectType/nbInfo', diff --git a/src/plugins/http-fetch.ts b/src/plugins/http-fetch.ts index a0f961fd..2e020398 100644 --- a/src/plugins/http-fetch.ts +++ b/src/plugins/http-fetch.ts @@ -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 { // 请求超时控制请求终止 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 { // 判断用户传递的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 { diff --git a/src/views/neUser/base5G/index.vue b/src/views/neUser/base5G/index.vue index c5301507..6c6cc5f6 100644 --- a/src/views/neUser/base5G/index.vue +++ b/src/views/neUser/base5G/index.vue @@ -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; });