diff --git a/src/hooks/system/useListPage.ts b/src/hooks/system/useListPage.ts index b2d8036..a6d5bf3 100644 --- a/src/hooks/system/useListPage.ts +++ b/src/hooks/system/useListPage.ts @@ -9,6 +9,7 @@ import { useMethods } from '/@/hooks/system/useMethods'; import { useDesign } from '/@/hooks/web/useDesign'; import { filterObj } from '/@/utils/common/compUtils'; import { isFunction } from '@/utils/is'; +import type { VAxios } from '/@/utils/http/axios/Axios'; const { handleExportXls, handleImportXls } = useMethods(); // 定义 useListPage 方法所需参数 @@ -26,6 +27,8 @@ interface ListPageOptions { name?: string | (() => string); //导出参数 params?: object | (() => object); + // 自定义 HTTP 客户端,用于微服务场景 + http?: VAxios; }; // 导入配置 importConfig?: { @@ -34,6 +37,8 @@ interface ListPageOptions { //update-end-author:taoyan date:20220507 for: erp代码生成 子表 导入地址是动态的 // 导出成功后的回调 success?: (fileInfo?: any) => void; + // 自定义 HTTP 客户端,用于微服务场景 + http?: VAxios; }; } @@ -65,7 +70,7 @@ export function useListPage(options: ListPageOptions) { // 导出 excel async function onExportXls() { //update-begin---author:wangshuai ---date:20220411 for:导出新增自定义参数------------ - let { url, name, params } = options?.exportConfig ?? {}; + let { url, name, params, http } = options?.exportConfig ?? {}; let realUrl = typeof url === 'function' ? url() : url; if (realUrl) { let title = typeof name === 'function' ? name() : name; @@ -108,7 +113,7 @@ export function useListPage(options: ListPageOptions) { paramsForm['selections'] = selectedRowKeys.value.join(','); } console.log() - return handleExportXls(title as string, realUrl, filterObj(paramsForm)); + return handleExportXls(title as string, realUrl, filterObj(paramsForm), http); //update-end---author:wangshuai ---date:20220411 for:导出新增自定义参数-------------- } else { $message.createMessage.warn('没有传递 exportConfig.url 参数'); @@ -118,11 +123,11 @@ export function useListPage(options: ListPageOptions) { // 导入 excel function onImportXls(file) { - let { url, success } = options?.importConfig ?? {}; + let { url, success, http } = options?.importConfig ?? {}; //update-begin-author:taoyan date:20220507 for: erp代码生成 子表 导入地址是动态的 let realUrl = typeof url === 'function' ? url() : url; if (realUrl) { - return handleImportXls(file, realUrl, success || reload); + return handleImportXls(file, realUrl, success || reload, http); //update-end-author:taoyan date:20220507 for: erp代码生成 子表 导入地址是动态的 } else { $message.createMessage.warn('没有传递 importConfig.url 参数'); diff --git a/src/hooks/system/useMethods.ts b/src/hooks/system/useMethods.ts index f52c228..bdd4f43 100644 --- a/src/hooks/system/useMethods.ts +++ b/src/hooks/system/useMethods.ts @@ -1,6 +1,7 @@ import { defHttp } from '/@/utils/http/axios'; import { useMessage } from '/@/hooks/web/useMessage'; import { useGlobSetting } from '/@/hooks/setting'; +import type { VAxios } from '/@/utils/http/axios/Axios'; const { createMessage, createWarningModal } = useMessage(); const glob = useGlobSetting(); @@ -19,11 +20,13 @@ export function useMethods() { * 导出xls * @param name * @param url + * @param http 自定义的 HTTP 客户端,用于微服务场景 */ - async function exportXls(name, url, params, isXlsx = false) { + async function exportXls(name, url, params, isXlsx = false, http?: VAxios) { + const httpClient = http || defHttp; //update-begin---author:wangshuai---date:2024-01-25---for:【QQYUN-8118】导出超时时间设置长点--- // 修改为返回原生 response,便于获取 headers - const response = await defHttp.get( + const response = await httpClient.get( { url: url, params: params, responseType: 'blob', timeout: 60000 }, { isTransformResponse: false, isReturnNativeResponse: true } ); @@ -70,8 +73,10 @@ export function useMethods() { * @param data 导入的数据 * @param url * @param success 成功后的回调 + * @param http 自定义的 HTTP 客户端,用于微服务场景 */ - async function importXls(data, url, success) { + async function importXls(data, url, success, http?: VAxios) { + const httpClient = http || defHttp; const isReturn = (fileInfo) => { try { if (fileInfo.code === 201) { @@ -101,13 +106,13 @@ export function useMethods() { typeof success === 'function' ? success(fileInfo) : ''; } }; - await defHttp.uploadFile({ url }, { file: data.file }, { success: isReturn }); + await httpClient.uploadFile({ url }, { file: data.file }, { success: isReturn }); } return { - handleExportXls: (name: string, url: string, params?: object) => exportXls(name, url, params), - handleImportXls: (data, url, success) => importXls(data, url, success), - handleExportXlsx: (name: string, url: string, params?: object) => exportXls(name, url, params, true), + handleExportXls: (name: string, url: string, params?: object, http?: VAxios) => exportXls(name, url, params, false, http), + handleImportXls: (data, url, success, http?: VAxios) => importXls(data, url, success, http), + handleExportXlsx: (name: string, url: string, params?: object, http?: VAxios) => exportXls(name, url, params, true, http), }; /** diff --git a/src/utils/http/axios/Axios.ts b/src/utils/http/axios/Axios.ts index 4d7c296..a9500f2 100644 --- a/src/utils/http/axios/Axios.ts +++ b/src/utils/http/axios/Axios.ts @@ -125,7 +125,8 @@ export class VAxios { formData.append(customFilename, params.file); } const glob = useGlobSetting(); - config.baseURL = glob.uploadUrl; + const { requestOptions } = this.options; + config.baseURL = requestOptions?.apiUrl || glob.uploadUrl; if (params.data) { Object.keys(params.data).forEach((key) => { const value = params.data![key]; diff --git a/src/views/base/area/AreaList.vue b/src/views/base/area/AreaList.vue index 251e8d4..6705da7 100644 --- a/src/views/base/area/AreaList.vue +++ b/src/views/base/area/AreaList.vue @@ -94,6 +94,7 @@ import AreaModal from './components/AreaModal.vue'; import SwitchStatus from '/@/views/base/SwitchStatus.vue'; import { JDictSelectTag } from '@/components/Form'; + import { basicHttp } from '/@/utils/http/axios'; const fieldPickers = reactive({}); const formRef = ref(); @@ -172,10 +173,12 @@ name: '库区', url: getExportUrl, params: queryParam, + http: basicHttp, }, importConfig: { url: getImportUrl, success: handleSuccess, + http: basicHttp, }, }); const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = diff --git a/src/views/base/item/ItemList.vue b/src/views/base/item/ItemList.vue index 39808b8..746e4a6 100644 --- a/src/views/base/item/ItemList.vue +++ b/src/views/base/item/ItemList.vue @@ -84,6 +84,7 @@ import ItemModal from './components/ItemModal.vue'; import SwitchStatus from '/@/views/base/SwitchStatus.vue'; import { JDictSelectTag } from '@/components/Form'; + import { basicHttp } from '/@/utils/http/axios'; const fieldPickers = reactive({}); @@ -143,10 +144,12 @@ name: '物料', url: getExportUrl, params: queryParam, + http: basicHttp, }, importConfig: { url: getImportUrl, success: handleSuccess, + http: basicHttp, }, }); const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = diff --git a/src/views/base/point/PointList.vue b/src/views/base/point/PointList.vue index fe089ac..6cf5759 100644 --- a/src/views/base/point/PointList.vue +++ b/src/views/base/point/PointList.vue @@ -104,6 +104,7 @@ import SwitchStatus from '/@/views/base/SwitchStatus.vue'; import { JDictSelectTag, JSearchSelect } from '@/components/Form'; import AreaSelect from '@/views/base/area/components/AreaSelect.vue'; + import { basicHttp } from '/@/utils/http/axios'; const fieldPickers = reactive({}); @@ -166,10 +167,12 @@ name: '库位', url: getExportUrl, params: queryParam, + http: basicHttp, }, importConfig: { url: getImportUrl, success: handleSuccess, + http: basicHttp, }, }); const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext; diff --git a/src/views/base/stock/StockList.vue b/src/views/base/stock/StockList.vue index 5370544..6942cc3 100644 --- a/src/views/base/stock/StockList.vue +++ b/src/views/base/stock/StockList.vue @@ -86,6 +86,7 @@ import { JDictSelectTag, JSearchSelect } from '@/components/Form'; import { JInputTypeEnum } from '@/enums/cpteEnum'; import JInput from '../../../components/Form/src/jeecg/components/JInput.vue'; + import { basicHttp } from '/@/utils/http/axios'; const fieldPickers = reactive({}); const formRef = ref(); @@ -147,10 +148,12 @@ name: '容器', url: getExportUrl, params: queryParam, + http: basicHttp, }, importConfig: { url: getImportUrl, success: handleSuccess, + http: basicHttp, }, }); const [registerTable, { reload }, { rowSelection, selectedRowKeys }] =