diff --git a/src/api/overseasHttp.ts b/src/api/overseasHttp.ts index 3abc261..e567603 100644 --- a/src/api/overseasHttp.ts +++ b/src/api/overseasHttp.ts @@ -65,3 +65,27 @@ export async function overseasApiRequest(config: AxiosRequestConfig) { throw new ApiError(error instanceof Error ? error.message : '海外接口请求失败') } } + +export async function overseasBlobRequest(config: AxiosRequestConfig) { + try { + const response = await transport.request({ ...config, responseType: 'blob' }) + return response.data + } catch (error) { + if (error instanceof ApiError) throw error + if (axios.isAxiosError(error)) { + const body = error.response?.data + if (body instanceof Blob && body.type.includes('json')) { + try { + const parsed: unknown = JSON.parse(await body.text()) + if (isApiEnvelope(parsed) || isApiFailure(parsed)) { + throw new ApiError(parsed.message, parsed.code, error.response?.status, undefined, parsed.traceId, parsed.requestId) + } + } catch (parseError) { + if (parseError instanceof ApiError) throw parseError + } + } + throw new ApiError(error.code === 'ERR_NETWORK' ? '无法连接海外服务' : error.message, error.code || 'OVERSEAS_HTTP_ERROR', error.response?.status) + } + throw new ApiError(error instanceof Error ? error.message : '海外文件下载失败') + } +} diff --git a/src/components.d.ts b/src/components.d.ts index befd71f..f15b3f0 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -33,6 +33,7 @@ declare module 'vue' { ElEmpty: typeof import('element-plus/es')['ElEmpty'] ElForm: typeof import('element-plus/es')['ElForm'] ElFormItem: typeof import('element-plus/es')['ElFormItem'] + ElImage: typeof import('element-plus/es')['ElImage'] ElInput: typeof import('element-plus/es')['ElInput'] ElInputNumber: typeof import('element-plus/es')['ElInputNumber'] ElOption: typeof import('element-plus/es')['ElOption'] diff --git a/src/modules/first-leg/views/businessIdentifiers.test.mjs b/src/modules/first-leg/views/businessIdentifiers.test.mjs index a19916e..9b60b06 100644 --- a/src/modules/first-leg/views/businessIdentifiers.test.mjs +++ b/src/modules/first-leg/views/businessIdentifiers.test.mjs @@ -35,5 +35,5 @@ test('keeps overseas warehouse operations first and renders readable list values assert.match(overseas, /function formatDateTime\(value\?: string \| null\)/) assert.match(overseas, /import SingleLineText from '@\/components\/common\/SingleLineText\.vue'/) assert.match(overseas, /