@moluoxixi/ajax-package 0.0.12 → 0.0.14-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/index.mjs CHANGED
@@ -2,9 +2,9 @@
2
2
  "use strict";
3
3
  try {
4
4
  if (typeof document !== "undefined") {
5
- if (!document.getElementById("c6a35fc5-e19d-40c8-8129-fe6481835a30")) {
5
+ if (!document.getElementById("ffe3dd99-bf7e-4730-8936-fd7b509c3c02")) {
6
6
  var elementStyle = document.createElement("style");
7
- elementStyle.id = "c6a35fc5-e19d-40c8-8129-fe6481835a30";
7
+ elementStyle.id = "ffe3dd99-bf7e-4730-8936-fd7b509c3c02";
8
8
  elementStyle.appendChild(document.createTextNode("._root_11p33_1 .el-dialog__header {\n padding: 0 12px 12px;\n}\n\n._root_11p33_1 .el-dialog__body {\n border-top: 1px solid #e5e7eb;\n border-bottom: 1px solid #e5e7eb;\n padding: 0 12px;\n}\n\n._root_11p33_1 .el-dialog__footer {\n padding: 0 12px;\n}"));
9
9
  document.head.appendChild(elementStyle);
10
10
  }
@@ -12170,7 +12170,11 @@ function extractSystemErrorInfo(response, code, message2) {
12170
12170
  errorMessage: message2
12171
12171
  };
12172
12172
  }
12173
- function defaultOnLoginRequired() {
12173
+ function defaultOnLoginRequired(messageInstance) {
12174
+ messageInstance == null ? void 0 : messageInstance.error({
12175
+ message: "登录已过期,请重新登录",
12176
+ duration: 5 * 1e3
12177
+ });
12174
12178
  if (typeof window !== "undefined") {
12175
12179
  window.location.href = `/login?redirect=${encodeURIComponent(window.location.href)}`;
12176
12180
  }
@@ -12179,6 +12183,10 @@ function defaultGetToken() {
12179
12183
  return typeof localStorage !== "undefined" ? localStorage.getItem("token") || "" : "";
12180
12184
  }
12181
12185
  class BaseHttpClient {
12186
+ /**
12187
+ * 创建 BaseHttpClient 实例
12188
+ * @param config - HTTP 客户端配置对象
12189
+ */
12182
12190
  constructor(config) {
12183
12191
  __publicField(this, "baseURL", "");
12184
12192
  __publicField(this, "timeout", 5e3);
@@ -12208,18 +12216,101 @@ class BaseHttpClient {
12208
12216
  baseURL: this.baseURL,
12209
12217
  timeout: this.timeout,
12210
12218
  ...axiosConfig
12219
+ // 将所有剩余参数传给axios.create
12211
12220
  });
12212
12221
  this.setupInterceptors();
12213
12222
  }
12223
+ /**
12224
+ * 处理请求配置,子类可重写此方法自定义请求配置
12225
+ * @param config - 请求配置对象
12226
+ * @returns 处理后的请求配置
12227
+ */
12214
12228
  processRequestConfig(config) {
12215
12229
  return config;
12216
12230
  }
12231
+ /**
12232
+ * 处理响应配置,子类可重写此方法自定义响应处理
12233
+ * 按照标准 HTTP 结构处理响应
12234
+ * @param response - Axios 响应对象
12235
+ * @returns 解析后的响应数据
12236
+ */
12217
12237
  processResponseConfig(response) {
12238
+ this.handleHttpStatus(response);
12239
+ return this.handleSuccessResponse(response);
12240
+ }
12241
+ /**
12242
+ * 处理 HTTP 状态码
12243
+ * 子类可重写此方法来自定义 HTTP 状态码处理逻辑
12244
+ * @param response - Axios 响应对象
12245
+ */
12246
+ handleHttpStatus(response) {
12247
+ var _a2;
12248
+ if (response.status !== 200) {
12249
+ throw new Error(((_a2 = response.data) == null ? void 0 : _a2.message) || `HTTP Error: ${response.status}`);
12250
+ }
12251
+ }
12252
+ /**
12253
+ * 处理成功响应
12254
+ * 子类可重写此方法来自定义成功响应的处理逻辑
12255
+ * @param response - Axios 响应对象
12256
+ * @returns 解析后的响应数据
12257
+ */
12258
+ handleSuccessResponse(response) {
12218
12259
  return response.data;
12219
12260
  }
12261
+ /**
12262
+ * 处理响应错误,子类可重写此方法自定义错误处理
12263
+ * 按照标准 HTTP 错误结构处理错误
12264
+ * @param error - Axios 错误对象
12265
+ * @returns 处理后的错误对象
12266
+ */
12220
12267
  async processResponseError(error) {
12268
+ this.handleAuthenticationError(error);
12269
+ this.handleTimeoutError(error);
12270
+ this.handleNetworkError(error);
12221
12271
  return error;
12222
12272
  }
12273
+ /**
12274
+ * 处理认证错误(401 - 未授权/登录失效)
12275
+ * 子类可重写此方法来自定义认证错误处理逻辑
12276
+ * @param error - Axios 错误对象
12277
+ */
12278
+ handleAuthenticationError(error) {
12279
+ var _a2, _b;
12280
+ if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
12281
+ (_b = this.onLoginRequired) == null ? void 0 : _b.call(this, this.messageInstance);
12282
+ }
12283
+ }
12284
+ /**
12285
+ * 处理超时错误
12286
+ * 子类可重写此方法来自定义超时错误处理逻辑
12287
+ * @param error - Axios 错误对象
12288
+ */
12289
+ handleTimeoutError(error) {
12290
+ if (error.code === "ECONNABORTED" && error.message.includes("timeout")) {
12291
+ this.onTimeout(this.messageInstance);
12292
+ }
12293
+ }
12294
+ /**
12295
+ * 处理网络错误(其他错误)
12296
+ * 子类可重写此方法来自定义网络错误处理逻辑
12297
+ * @param error - Axios 错误对象
12298
+ */
12299
+ handleNetworkError(error) {
12300
+ var _a2, _b, _c;
12301
+ if (((_a2 = error.response) == null ? void 0 : _a2.status) !== 401 && error.code !== "ECONNABORTED") {
12302
+ const fallbackError = error;
12303
+ (_c = this.messageInstance) == null ? void 0 : _c.error({
12304
+ message: ((_b = fallbackError.response) == null ? void 0 : _b.data) || fallbackError.message || "网络错误",
12305
+ duration: 5 * 1e3
12306
+ });
12307
+ }
12308
+ }
12309
+ /**
12310
+ * 设置请求和响应拦截器
12311
+ * 请求拦截器:自动添加 Token
12312
+ * 响应拦截器:处理成功响应和错误响应(401、超时等)
12313
+ */
12223
12314
  setupInterceptors() {
12224
12315
  this.instance.interceptors.request.use(
12225
12316
  (config) => {
@@ -12238,53 +12329,67 @@ class BaseHttpClient {
12238
12329
  );
12239
12330
  this.instance.interceptors.response.use(
12240
12331
  (res) => {
12241
- var _a2;
12242
- if (res.status !== 200) {
12243
- return Promise.reject(new Error(((_a2 = res.data) == null ? void 0 : _a2.message) || "Error"));
12244
- }
12245
12332
  return this.processResponseConfig(res);
12246
12333
  },
12247
12334
  async (error) => {
12248
- var _a2, _b, _c, _d, _e, _f;
12249
12335
  await this.processResponseError(error);
12250
- if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
12251
- (_b = this.onLoginRequired) == null ? void 0 : _b.call(this);
12252
- (_c = this.messageInstance) == null ? void 0 : _c.error({
12253
- message: "登录已过期,请重新登录",
12254
- duration: 5 * 1e3
12255
- });
12256
- } else if (error.code === "ECONNABORTED" && error.message.includes("timeout")) {
12257
- this.onTimeout();
12258
- (_d = this.messageInstance) == null ? void 0 : _d.error({
12259
- message: "请求超时,请检查网络连接或稍后重试",
12260
- duration: 5 * 1e3
12261
- });
12262
- } else {
12263
- const fallbackError = error;
12264
- (_f = this.messageInstance) == null ? void 0 : _f.error({
12265
- message: ((_e = fallbackError.response) == null ? void 0 : _e.data) || fallbackError.message || "网络错误",
12266
- duration: 5 * 1e3
12267
- });
12268
- }
12269
12336
  return Promise.reject(error);
12270
12337
  }
12271
12338
  );
12272
12339
  }
12340
+ /**
12341
+ * 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
12342
+ * @param config - Axios 请求配置对象
12343
+ * @returns 解析后的响应数据
12344
+ */
12273
12345
  async request(config) {
12274
12346
  return this.instance.request(config);
12275
12347
  }
12348
+ /**
12349
+ * 发送 GET 请求
12350
+ * @param url - 请求 URL 路径
12351
+ * @param params - 查询参数对象
12352
+ * @param config - 额外的请求配置
12353
+ * @returns 解析后的响应数据
12354
+ */
12276
12355
  async get(url, params, config) {
12277
12356
  return this.request({ ...config, url, method: "get", params });
12278
12357
  }
12358
+ /**
12359
+ * 发送 POST 请求
12360
+ * @param url - 请求 URL 路径
12361
+ * @param data - 请求体数据
12362
+ * @param config - 额外的请求配置
12363
+ * @returns 解析后的响应数据
12364
+ */
12279
12365
  async post(url, data, config) {
12280
12366
  return this.request({ ...config, url, method: "post", data });
12281
12367
  }
12368
+ /**
12369
+ * 发送 DELETE 请求
12370
+ * @param url - 请求 URL 路径
12371
+ * @param params - 查询参数对象
12372
+ * @param config - 额外的请求配置
12373
+ * @returns 解析后的响应数据
12374
+ */
12282
12375
  async delete(url, params, config) {
12283
12376
  return this.request({ ...config, url, method: "delete", params });
12284
12377
  }
12378
+ /**
12379
+ * 发送 PUT 请求
12380
+ * @param url - 请求 URL 路径
12381
+ * @param data - 请求体数据
12382
+ * @param config - 额外的请求配置
12383
+ * @returns 解析后的响应数据
12384
+ */
12285
12385
  async put(url, data, config) {
12286
12386
  return this.request({ ...config, url, method: "put", data });
12287
12387
  }
12388
+ /**
12389
+ * 批量请求,并发发送多个请求
12390
+ * @param requests - 请求配置数组或已发起的请求 Promise 数组
12391
+ * @returns 所有请求的响应数据数组
12392
+ */
12288
12393
  async all(requests) {
12289
12394
  if (!requests.length)
12290
12395
  return [];
@@ -12297,6 +12402,13 @@ class BaseHttpClient {
12297
12402
  const promises = requests.map((config) => this.request(config));
12298
12403
  return await Promise.all(promises);
12299
12404
  }
12405
+ /**
12406
+ * 文件上传,将文件包装为 FormData 发送
12407
+ * @param url - 上传地址
12408
+ * @param file - 文件对象
12409
+ * @param config - 额外的请求配置
12410
+ * @returns 解析后的响应数据
12411
+ */
12300
12412
  async uploadFile(url, file, config) {
12301
12413
  const formData = new FormData();
12302
12414
  formData.append("file", file);
@@ -12308,6 +12420,25 @@ class BaseHttpClient {
12308
12420
  }
12309
12421
  });
12310
12422
  }
12423
+ /**
12424
+ * 下载文件,将 Blob 对象下载到本地
12425
+ * @param blob - Blob 对象
12426
+ * @param filename - 文件名,如果不提供则使用时间戳
12427
+ */
12428
+ downloadFile(blob, filename) {
12429
+ if (typeof window === "undefined") {
12430
+ console.warn("downloadFile: 非浏览器环境,无法下载文件");
12431
+ return;
12432
+ }
12433
+ const url = window.URL.createObjectURL(blob);
12434
+ const link = document.createElement("a");
12435
+ link.href = url;
12436
+ link.download = filename || `download-${Date.now()}`;
12437
+ document.body.appendChild(link);
12438
+ link.click();
12439
+ link.remove();
12440
+ window.URL.revokeObjectURL(url);
12441
+ }
12311
12442
  }
12312
12443
  async function dynamicImports(modulePromise, exportNames) {
12313
12444
  const module = await modulePromise;
@@ -12409,10 +12540,12 @@ function createApiDialog(DialogComponent) {
12409
12540
  cleanup();
12410
12541
  }
12411
12542
  },
12543
+ // 监听关闭事件
12412
12544
  onClose: () => {
12413
12545
  reject(new Error("对话框已关闭"));
12414
12546
  cleanup();
12415
12547
  },
12548
+ // 监听确认事件(如有)
12416
12549
  onConfirm: (data) => {
12417
12550
  resolve(data);
12418
12551
  cleanup();
@@ -12463,6 +12596,10 @@ function createApiDialog(DialogComponent) {
12463
12596
  const hasDocument = typeof document !== "undefined";
12464
12597
  let systemErrorDialogInstance = null;
12465
12598
  class BaseApi extends BaseHttpClient {
12599
+ /**
12600
+ * 创建 BaseApi 实例
12601
+ * @param config - API 配置对象
12602
+ */
12466
12603
  constructor(config) {
12467
12604
  const {
12468
12605
  responseFields,
@@ -12482,20 +12619,90 @@ class BaseApi extends BaseHttpClient {
12482
12619
  };
12483
12620
  this.enableSystemErrorDialog = enableSystemErrorDialog;
12484
12621
  }
12622
+ /**
12623
+ * 处理请求配置,子类可重写此方法自定义请求配置
12624
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
12625
+ * @param config - 请求配置对象
12626
+ * @returns 处理后的请求配置
12627
+ */
12485
12628
  processRequestConfig(config) {
12486
12629
  return super.processRequestConfig(config);
12487
12630
  }
12631
+ /**
12632
+ * 处理响应配置,子类可重写此方法自定义响应处理
12633
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
12634
+ * @param response - Axios 响应对象
12635
+ * @returns 解析后的响应数据
12636
+ */
12637
+ processResponseConfig(response) {
12638
+ return super.processResponseConfig(response);
12639
+ }
12640
+ /**
12641
+ * 处理响应错误,子类可重写此方法自定义错误处理
12642
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
12643
+ * @param error - Axios 错误对象
12644
+ * @returns 处理后的错误对象
12645
+ */
12488
12646
  async processResponseError(error) {
12489
12647
  return super.processResponseError(error);
12490
12648
  }
12491
- processResponseConfig(response) {
12492
- const data = response.data;
12493
- const { code, message: message2, responseData } = this.parseResponseFields(data);
12494
- this.handleErrorCode(response, code, message2, responseData);
12495
- this.handleErrors(responseData);
12649
+ /**
12650
+ * 处理 HTTP 状态码
12651
+ * 重写父类方法,确保子类可以重写此方法
12652
+ * @param response - Axios 响应对象
12653
+ */
12654
+ handleHttpStatus(response) {
12655
+ return super.handleHttpStatus(response);
12656
+ }
12657
+ /**
12658
+ * 处理认证错误(401 - 未授权/登录失效)
12659
+ * 重写父类方法,处理 HTTP 401 错误
12660
+ * 子类可重写此方法来自定义 HTTP 认证错误处理逻辑
12661
+ * @param error - Axios 错误对象
12662
+ */
12663
+ handleAuthenticationError(error) {
12664
+ super.handleAuthenticationError(error);
12665
+ }
12666
+ /**
12667
+ * 处理超时错误
12668
+ * 重写父类方法,确保子类可以重写此方法
12669
+ * @param error - Axios 错误对象
12670
+ */
12671
+ handleTimeoutError(error) {
12672
+ return super.handleTimeoutError(error);
12673
+ }
12674
+ /**
12675
+ * 处理网络错误(其他错误)
12676
+ * 重写父类方法,确保子类可以重写此方法
12677
+ * @param error - Axios 错误对象
12678
+ */
12679
+ handleNetworkError(error) {
12680
+ return super.handleNetworkError(error);
12681
+ }
12682
+ /**
12683
+ * 处理成功响应
12684
+ * 重写父类方法,在标准 HTTP 成功响应基础上,处理业务特定的响应结构
12685
+ * 支持嵌套路径解析,自动处理业务层的登录失效、系统异常等错误
12686
+ * 注意:HTTP 层的错误(如 HTTP 401、超时等)由父类 BaseHttpClient 处理
12687
+ * @param response - Axios 响应对象
12688
+ * @returns 解析后的响应数据
12689
+ */
12690
+ handleSuccessResponse(response) {
12691
+ const httpData = super.handleSuccessResponse(response);
12692
+ const parsedFields = this.parseResponseFields(httpData);
12693
+ const { code, message: message2, responseData } = parsedFields;
12694
+ this.handleSystemError(response, code, message2, responseData);
12695
+ this.handleBusinessError(code, message2);
12696
+ this.handleErrorArray(responseData);
12496
12697
  this.handleTips(responseData);
12497
12698
  return responseData;
12498
12699
  }
12700
+ /**
12701
+ * 解析响应字段,支持嵌套路径解析
12702
+ * 子类可重写此方法来自定义字段解析逻辑
12703
+ * @param data - 响应数据对象
12704
+ * @returns 解析后的字段值对象
12705
+ */
12499
12706
  parseResponseFields(data) {
12500
12707
  var _a2, _b, _c;
12501
12708
  const getValueByPath = (obj, path) => {
@@ -12517,11 +12724,15 @@ class BaseApi extends BaseHttpClient {
12517
12724
  const responseData = getValueByPath(data, (_c = this.responseFields) == null ? void 0 : _c.data);
12518
12725
  return { code, message: message2, responseData };
12519
12726
  }
12520
- handleErrorCode(response, code, message2, responseData) {
12521
- var _a2;
12522
- if (code === 401) {
12523
- throw new Error("登录失效,请重新登录");
12524
- }
12727
+ /**
12728
+ * 处理系统异常错误(-1 - 系统异常)
12729
+ * 子类可重写此方法来自定义系统异常处理逻辑
12730
+ * @param response - Axios 响应对象
12731
+ * @param code - 响应状态码
12732
+ * @param message - 错误消息
12733
+ * @param responseData - 响应数据
12734
+ */
12735
+ handleSystemError(response, code, message2, responseData) {
12525
12736
  if (code === -1) {
12526
12737
  if (this.enableSystemErrorDialog) {
12527
12738
  this.showSystemExceptionDialog(response, responseData, code, message2).catch((error) => {
@@ -12530,6 +12741,15 @@ class BaseApi extends BaseHttpClient {
12530
12741
  }
12531
12742
  throw new Error(message2 || "系统异常");
12532
12743
  }
12744
+ }
12745
+ /**
12746
+ * 处理业务错误(其他非200错误码)
12747
+ * 子类可重写此方法来自定义业务错误处理逻辑
12748
+ * @param code - 响应状态码
12749
+ * @param message - 错误消息
12750
+ */
12751
+ handleBusinessError(code, message2) {
12752
+ var _a2;
12533
12753
  if (code && code !== 200) {
12534
12754
  (_a2 = this.messageInstance) == null ? void 0 : _a2.error({
12535
12755
  message: message2 || "请求失败",
@@ -12538,55 +12758,90 @@ class BaseApi extends BaseHttpClient {
12538
12758
  throw new Error(message2 || "请求失败");
12539
12759
  }
12540
12760
  }
12541
- handleErrors(responseData) {
12542
- var _a2, _b, _c;
12761
+ /**
12762
+ * 处理错误数组 errors(如果有配置)
12763
+ * 子类可重写此方法来自定义错误数组处理逻辑
12764
+ * @param responseData - 响应数据
12765
+ */
12766
+ handleErrorArray(responseData) {
12767
+ var _a2;
12543
12768
  const errorsField = (_a2 = this.responseFields) == null ? void 0 : _a2.errors;
12544
12769
  if (errorsField) {
12545
12770
  const errors = responseData == null ? void 0 : responseData[errorsField];
12546
12771
  if (Array.isArray(errors) && errors.length) {
12547
- const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
12548
- if (hasDocument) {
12549
- (_b = this.notificationInstance) == null ? void 0 : _b.call(this, {
12550
- title: "提示",
12551
- message: html,
12552
- type: "error"
12553
- });
12554
- } else {
12555
- const errorMessages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
12556
- (_c = this.notificationInstance) == null ? void 0 : _c.call(this, {
12557
- title: "提示",
12558
- message: errorMessages,
12559
- type: "error"
12560
- });
12561
- }
12772
+ this.showErrorArrayNotification(errors);
12562
12773
  throw new Error("请求错误");
12563
12774
  }
12564
12775
  }
12565
12776
  }
12777
+ /**
12778
+ * 显示错误数组通知
12779
+ * 子类可重写此方法来自定义错误数组通知显示方式
12780
+ * @param errors - 错误数组
12781
+ */
12782
+ showErrorArrayNotification(errors) {
12783
+ var _a2, _b;
12784
+ const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
12785
+ if (hasDocument) {
12786
+ (_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, {
12787
+ title: "提示",
12788
+ message: html,
12789
+ type: "error"
12790
+ });
12791
+ } else {
12792
+ const errorMessages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
12793
+ (_b = this.notificationInstance) == null ? void 0 : _b.call(this, {
12794
+ title: "提示",
12795
+ message: errorMessages,
12796
+ type: "error"
12797
+ });
12798
+ }
12799
+ }
12800
+ /**
12801
+ * 处理提示信息 tips(如果有配置)
12802
+ * 子类可重写此方法来自定义提示信息处理逻辑
12803
+ * @param responseData - 响应数据
12804
+ */
12566
12805
  handleTips(responseData) {
12567
- var _a2, _b, _c;
12806
+ var _a2;
12568
12807
  const tipsField = (_a2 = this.responseFields) == null ? void 0 : _a2.tips;
12569
12808
  if (tipsField) {
12570
12809
  const tips = responseData == null ? void 0 : responseData[tipsField];
12571
12810
  if (Array.isArray(tips) && tips.length) {
12572
- const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
12573
- if (hasDocument) {
12574
- (_b = this.notificationInstance) == null ? void 0 : _b.call(this, {
12575
- title: "提示",
12576
- message: html,
12577
- type: "warning"
12578
- });
12579
- } else {
12580
- const tipMessages = tips.map((item) => `${item.code}:${item.message}`).join("\n");
12581
- (_c = this.notificationInstance) == null ? void 0 : _c.call(this, {
12582
- title: "提示",
12583
- message: tipMessages,
12584
- type: "warning"
12585
- });
12586
- }
12811
+ this.showTipsNotification(tips);
12587
12812
  }
12588
12813
  }
12589
12814
  }
12815
+ /**
12816
+ * 显示提示信息通知
12817
+ * 子类可重写此方法来自定义提示信息通知显示方式
12818
+ * @param tips - 提示信息数组
12819
+ */
12820
+ showTipsNotification(tips) {
12821
+ var _a2, _b;
12822
+ const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
12823
+ if (hasDocument) {
12824
+ (_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, {
12825
+ title: "提示",
12826
+ message: html,
12827
+ type: "warning"
12828
+ });
12829
+ } else {
12830
+ const tipMessages = tips.map((item) => `${item.code}:${item.message}`).join("\n");
12831
+ (_b = this.notificationInstance) == null ? void 0 : _b.call(this, {
12832
+ title: "提示",
12833
+ message: tipMessages,
12834
+ type: "warning"
12835
+ });
12836
+ }
12837
+ }
12838
+ /**
12839
+ * 显示系统异常对话框,当响应状态码为 -1 时调用
12840
+ * @param response - Axios 响应对象
12841
+ * @param responseData - 响应数据
12842
+ * @param code - 错误状态码
12843
+ * @param message - 错误消息
12844
+ */
12590
12845
  async showSystemExceptionDialog(response, responseData, code, message2) {
12591
12846
  if (!hasDocument) {
12592
12847
  console.error("系统异常信息:", responseData);
@@ -12625,6 +12880,10 @@ class BaseApi extends BaseHttpClient {
12625
12880
  console.error("系统异常信息:", responseData);
12626
12881
  }
12627
12882
  }
12883
+ /**
12884
+ * 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
12885
+ * @param errorInfo - 错误信息对象
12886
+ */
12628
12887
  async reportError(errorInfo) {
12629
12888
  var _a2, _b;
12630
12889
  try {
@@ -12642,11 +12901,98 @@ class BaseApi extends BaseHttpClient {
12642
12901
  });
12643
12902
  }
12644
12903
  }
12904
+ /**
12905
+ * 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
12906
+ * 显式声明以确保类型一致性,子类可重写此方法
12907
+ * @param config - Axios 请求配置对象
12908
+ * @returns 解析后的响应数据
12909
+ */
12910
+ async request(config) {
12911
+ return super.request(config);
12912
+ }
12913
+ /**
12914
+ * 发送 GET 请求
12915
+ * 显式声明以确保类型一致性,子类可重写此方法
12916
+ * @param url - 请求 URL 路径
12917
+ * @param params - 查询参数对象
12918
+ * @param config - 额外的请求配置
12919
+ * @returns 解析后的响应数据
12920
+ */
12921
+ async get(url, params, config) {
12922
+ return super.get(url, params, config);
12923
+ }
12924
+ /**
12925
+ * 发送 POST 请求
12926
+ * 显式声明以确保类型一致性,子类可重写此方法
12927
+ * @param url - 请求 URL 路径
12928
+ * @param data - 请求体数据
12929
+ * @param config - 额外的请求配置
12930
+ * @returns 解析后的响应数据
12931
+ */
12932
+ async post(url, data, config) {
12933
+ return super.post(url, data, config);
12934
+ }
12935
+ /**
12936
+ * 发送 DELETE 请求
12937
+ * 显式声明以确保类型一致性,子类可重写此方法
12938
+ * @param url - 请求 URL 路径
12939
+ * @param params - 查询参数对象
12940
+ * @param config - 额外的请求配置
12941
+ * @returns 解析后的响应数据
12942
+ */
12943
+ async delete(url, params, config) {
12944
+ return super.delete(url, params, config);
12945
+ }
12946
+ /**
12947
+ * 发送 PUT 请求
12948
+ * 显式声明以确保类型一致性,子类可重写此方法
12949
+ * @param url - 请求 URL 路径
12950
+ * @param data - 请求体数据
12951
+ * @param config - 额外的请求配置
12952
+ * @returns 解析后的响应数据
12953
+ */
12954
+ async put(url, data, config) {
12955
+ return super.put(url, data, config);
12956
+ }
12957
+ /**
12958
+ * 批量请求,并发发送多个请求
12959
+ * 显式声明以确保类型一致性,子类可重写此方法
12960
+ * @param requests - 请求配置数组或已发起的请求 Promise 数组
12961
+ * @returns 所有请求的响应数据数组
12962
+ */
12963
+ async all(requests) {
12964
+ return super.all(requests);
12965
+ }
12966
+ /**
12967
+ * 文件上传,将文件包装为 FormData 发送
12968
+ * 显式声明以确保类型一致性,子类可重写此方法
12969
+ * @param url - 上传地址
12970
+ * @param file - 文件对象
12971
+ * @param config - 额外的请求配置
12972
+ * @returns 解析后的响应数据
12973
+ */
12974
+ async uploadFile(url, file, config) {
12975
+ return super.uploadFile(url, file, config);
12976
+ }
12977
+ /**
12978
+ * 下载文件,将 Blob 对象下载到本地
12979
+ * 显式声明以确保类型一致性,子类可重写此方法
12980
+ * @param blob - Blob 对象
12981
+ * @param filename - 文件名,如果不提供则使用时间戳
12982
+ */
12983
+ downloadFile(blob, filename) {
12984
+ return super.downloadFile(blob, filename);
12985
+ }
12645
12986
  }
12646
12987
  function createHttpService(options = {}) {
12647
12988
  return new BaseApi(options);
12648
12989
  }
12649
12990
  const VueAxiosPlugin = {
12991
+ /**
12992
+ * 安装插件
12993
+ * @param app - Vue 应用实例
12994
+ * @param options - 插件配置选项
12995
+ */
12650
12996
  install(app, options = {}) {
12651
12997
  const httpService = createHttpService(options.default ?? {});
12652
12998
  app.config.globalProperties.$http = httpService;
@@ -12827,10 +13173,12 @@ const SystemErrorDialog = defineComponent({
12827
13173
  h("span", { style: { fontWeight: "bold", fontSize: "16px" } }, props.title || "系统异常信息")
12828
13174
  ]),
12829
13175
  default: () => h("div", { style: { padding: 0, maxHeight: "500px", overflowY: "auto" } }, [
13176
+ // 第一块:无法完成您的请求
12830
13177
  h("div", { style: { padding: "20px", borderBottom: "1px solid #ebeef5" } }, [
12831
13178
  h("h3", { style: { margin: "0 0 12px 0", fontSize: "16px", fontWeight: "bold", color: "#303133" } }, "无法完成您的请求"),
12832
13179
  h("p", { style: { margin: 0, color: "#606266", lineHeight: 1.5 } }, "系统在处理您的请求时遇到了问题,可能是由于服务暂时不可用。")
12833
13180
  ]),
13181
+ // 第二块:技术摘要(可展开)
12834
13182
  h("div", { style: { borderBottom: "1px solid #ebeef5" } }, [
12835
13183
  h(
12836
13184
  "div",
@@ -12892,6 +13240,7 @@ const SystemErrorDialog = defineComponent({
12892
13240
  )
12893
13241
  ) : null
12894
13242
  ]),
13243
+ // SkyWalking 按钮
12895
13244
  h("div", { style: { padding: "16px 20px", borderBottom: "1px solid #ebeef5" } }, [
12896
13245
  h(
12897
13246
  ElButton,
@@ -12903,6 +13252,7 @@ const SystemErrorDialog = defineComponent({
12903
13252
  { default: () => "📊 在SkyWalking中查看详情" }
12904
13253
  )
12905
13254
  ]),
13255
+ // 黑色错误信息区域
12906
13256
  h("div", { style: { backgroundColor: "#2c3e50", color: "#fff", padding: "16px 20px", fontFamily: 'Monaco, Consolas, "Courier New", monospace', fontSize: "12px", lineHeight: 1.5, maxHeight: "200px", overflowY: "auto" } }, [
12907
13257
  h("div", { style: { marginBottom: "8px", color: "#ecf0f1" } }, `Trace ID: ${props.traceId || "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"}`),
12908
13258
  h("div", { style: { color: "#e74c3c", fontWeight: "bold" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)