@moluoxixi/ajax-package 0.0.34 → 0.0.36

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.
@@ -16,10 +16,41 @@ export default class BaseHttpClient {
16
16
  protected onTimeout: (messageInstance: MessageInstance) => void;
17
17
  protected getToken?: () => string | null;
18
18
  protected onLoginRequired?: (messageInstance: MessageInstance) => void;
19
+ protected appendTo?: HTMLElement | string | null;
19
20
  instance: ReturnType<typeof axios.create>;
20
21
  protected messageInstance: MessageInstance;
21
22
  protected notificationInstance: NotificationInstance;
22
23
  protected addSign?: (config: AxiosRequestConfig) => void;
24
+ /**
25
+ * 检查是否在浏览器环境(在类初始化时判断)
26
+ * 注意:这是静态属性,所有实例共享
27
+ */
28
+ protected static readonly hasDocument: boolean;
29
+ /**
30
+ * 获取是否在浏览器环境(实例 getter)
31
+ * @returns 是否在浏览器环境
32
+ */
33
+ protected get hasDocument(): boolean;
34
+ /**
35
+ * 解析 appendTo 配置,返回目标 HTMLElement
36
+ * @returns 目标元素,默认为 document.body
37
+ */
38
+ protected resolveAppendToTarget(): HTMLElement;
39
+ /**
40
+ * 获取或创建 ajaxPackage-container 容器元素
41
+ * @returns 容器元素,如果不是浏览器环境则返回 null
42
+ */
43
+ protected getContainer(): HTMLElement | null;
44
+ /**
45
+ * 获取或创建 ajaxPackage-popover 容器元素(用于 Dialog)
46
+ * @returns 容器元素,如果不是浏览器环境则返回 null
47
+ */
48
+ protected getPopoverContainer(): HTMLElement | null;
49
+ /**
50
+ * 获取或创建 ajaxPackage-message 容器元素(用于 Message 和 Notification)
51
+ * @returns 容器元素,如果不是浏览器环境则返回 null
52
+ */
53
+ protected getMessageContainer(): HTMLElement | null;
23
54
  /**
24
55
  * 创建 BaseHttpClient 实例
25
56
  * @param config - HTTP 客户端配置对象
@@ -16,6 +16,8 @@ export interface BaseHttpClientConfig {
16
16
  getToken?: () => string | null;
17
17
  /** 登录失效回调函数,当检测到 401 错误时调用,接收 messageInstance 用于显示消息提示 */
18
18
  onLoginRequired?: (messageInstance: MessageInstance) => void;
19
+ /** container 插入的目标元素,可以是 HTMLElement 或选择器字符串,默认为 document.body */
20
+ appendTo?: HTMLElement | string | null;
19
21
  /** 允许其他任意配置项,会直接传递给 axios.create */
20
22
  [key: string]: any;
21
23
  }
@@ -1,39 +1,12 @@
1
1
  /**
2
2
  * 创建消息实例的包装函数
3
- * @returns 消息实例,支持 success、error、warning、info 方法
3
+ * @param hasDocument - 是否在浏览器环境
4
+ * @param container - 容器元素,如果提供则消息将挂载到该容器中
5
+ * @returns 消息函数实例,直接调用即可,支持传入 type: 'success' | 'error' | 'warning' | 'info'
4
6
  */
5
- export declare function createMessageWrapper(): (import('element-plus').MessageFn & {
6
- primary: import('element-plus').MessageTypedFn;
7
- success: import('element-plus').MessageTypedFn;
8
- warning: import('element-plus').MessageTypedFn;
9
- info: import('element-plus').MessageTypedFn;
10
- error: import('element-plus').MessageTypedFn;
11
- } & import('vue').ObjectPlugin<any[]> & {
12
- _context: import('vue').AppContext | null;
13
- }) | (import('element-plus').MessageFn & {
14
- primary: import('element-plus').MessageTypedFn;
15
- success: import('element-plus').MessageTypedFn;
16
- warning: import('element-plus').MessageTypedFn;
17
- info: import('element-plus').MessageTypedFn;
18
- error: import('element-plus').MessageTypedFn;
19
- } & ((app: import('vue').App, ...options: any[]) => any) & Partial<import('vue').ObjectPlugin<any[]>> & {
20
- _context: import('vue').AppContext | null;
21
- }) | {
22
- success: (options: string | {
23
- message?: string;
24
- [key: string]: any;
25
- }) => void;
26
- error: (options: string | {
27
- message?: string;
28
- [key: string]: any;
29
- }) => void;
30
- warning: (options: string | {
31
- message?: string;
32
- [key: string]: any;
33
- }) => void;
34
- info: (options: string | {
35
- message?: string;
36
- [key: string]: any;
37
- }) => void;
38
- };
7
+ export declare function createMessageWrapper(hasDocument: boolean, container?: HTMLElement | null): (options: string | {
8
+ message?: string;
9
+ type?: "success" | "error" | "warning" | "info";
10
+ [key: string]: any;
11
+ }) => void;
39
12
  export type MessageInstance = ReturnType<typeof createMessageWrapper>;
@@ -1,10 +1,15 @@
1
1
  /**
2
2
  * 创建通知实例的包装函数(用于 errors / tips 展示)
3
- * @returns 通知实例,支持 success、error、warning、info 方法
3
+ * @param hasDocument - 是否在浏览器环境
4
+ * @param container - 容器元素,如果提供则通知将挂载到该容器中
5
+ * @returns 通知函数实例,直接调用即可,支持传入 type: 'success' | 'error' | 'warning' | 'info'
4
6
  */
5
- export declare function createNotificationWrapper(): ((import('element-plus').Notify & import('vue').Plugin) & {
6
- _context: import('vue').AppContext | null;
7
- }) | ((options: string | {
7
+ export declare function createNotificationWrapper(hasDocument: boolean, container?: HTMLElement | null): ((options: string | {
8
+ message?: string;
9
+ title?: string;
10
+ type?: "success" | "error" | "warning" | "info";
11
+ [key: string]: any;
12
+ }) => import('element-plus').NotificationHandle) | ((options: string | {
8
13
  message?: string;
9
14
  title?: string;
10
15
  type?: "success" | "error" | "warning" | "info";
package/es/class.d.ts CHANGED
@@ -10,11 +10,6 @@ export default class BaseApi extends BaseHttpClient {
10
10
  protected responseFields: Required<BaseApiConfig['responseFields']>;
11
11
  protected enableSystemErrorDialog: boolean;
12
12
  protected systemErrorMessage: string;
13
- /**
14
- * 检查是否在浏览器环境(在类初始化时判断)
15
- * 注意:这是静态属性,所有实例共享
16
- */
17
- private static readonly hasDocument;
18
13
  /**
19
14
  * SystemErrorDialog 实例
20
15
  * 注意:这是实例属性,每个实例有自己的对话框实例
@@ -32,11 +27,6 @@ export default class BaseApi extends BaseHttpClient {
32
27
  * 注意:这是静态属性,所有实例共享同一个错误信息存储
33
28
  */
34
29
  private static systemErrorInfoMap;
35
- /**
36
- * 获取是否在浏览器环境(实例 getter)
37
- * @returns 是否在浏览器环境
38
- */
39
- protected get hasDocument(): boolean;
40
30
  /**
41
31
  * 获取系统错误信息存储(实例 getter)
42
32
  * @returns 系统错误信息存储 Map
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("b2882460-4b80-4dc1-b28b-fc865ae04458")) {
5
+ if (!document.getElementById("55abf58f-b1b4-4e82-ab0d-ee119c15bd62")) {
6
6
  var elementStyle = document.createElement("style");
7
- elementStyle.id = "b2882460-4b80-4dc1-b28b-fc865ae04458";
7
+ elementStyle.id = "55abf58f-b1b4-4e82-ab0d-ee119c15bd62";
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
  }
@@ -12049,32 +12049,38 @@ notify.closeAll = closeAll;
12049
12049
  notify.updateOffsets = updateOffsets;
12050
12050
  notify._context = null;
12051
12051
  const ElNotification = withInstallFunction(notify, "$notify");
12052
- const hasDocument$1 = typeof document !== "undefined";
12053
- function createMessageWrapper() {
12054
- if (hasDocument$1) {
12055
- return ElMessage;
12052
+ function createMessageWrapper(hasDocument, container) {
12053
+ if (hasDocument) {
12054
+ return (options) => {
12055
+ const opts = typeof options === "string" ? { message: options } : options;
12056
+ const finalOptions = container ? { ...opts, appendTo: container } : opts;
12057
+ return ElMessage(finalOptions);
12058
+ };
12056
12059
  }
12057
- return {
12058
- success: (options) => {
12059
- typeof options === "string" ? options : (options == null ? void 0 : options.message) || "";
12060
- },
12061
- error: (options) => {
12062
- const message2 = typeof options === "string" ? options : (options == null ? void 0 : options.message) || "";
12063
- console.error(`[Message Error] ${message2}`);
12064
- },
12065
- warning: (options) => {
12066
- const message2 = typeof options === "string" ? options : (options == null ? void 0 : options.message) || "";
12067
- console.warn(`[Message Warning] ${message2}`);
12068
- },
12069
- info: (options) => {
12070
- typeof options === "string" ? options : (options == null ? void 0 : options.message) || "";
12060
+ return (options) => {
12061
+ const opts = typeof options === "string" ? { message: options } : options;
12062
+ const message2 = (opts == null ? void 0 : opts.message) || "";
12063
+ const type = (opts == null ? void 0 : opts.type) || "info";
12064
+ const logMessage = `[Message ${type}] ${message2}`;
12065
+ switch (type) {
12066
+ case "success":
12067
+ break;
12068
+ case "error":
12069
+ console.error(logMessage);
12070
+ break;
12071
+ case "warning":
12072
+ console.warn(logMessage);
12073
+ break;
12071
12074
  }
12072
12075
  };
12073
12076
  }
12074
- const hasDocument = typeof document !== "undefined";
12075
- function createNotificationWrapper() {
12077
+ function createNotificationWrapper(hasDocument, container) {
12076
12078
  if (hasDocument) {
12077
- return ElNotification;
12079
+ return (options) => {
12080
+ const opts = typeof options === "string" ? { message: options } : options;
12081
+ const finalOptions = container ? { ...opts, appendTo: container } : opts;
12082
+ return ElNotification(finalOptions);
12083
+ };
12078
12084
  }
12079
12085
  const consoleNotification = (options, level = "info") => {
12080
12086
  const opts = typeof options === "string" ? { message: options } : options;
@@ -12188,7 +12194,8 @@ function extractSystemErrorInfo(response, code, message2) {
12188
12194
  };
12189
12195
  }
12190
12196
  function defaultOnLoginRequired(messageInstance) {
12191
- messageInstance == null ? void 0 : messageInstance.error({
12197
+ messageInstance == null ? void 0 : messageInstance({
12198
+ type: "error",
12192
12199
  message: "登录已过期,请重新登录",
12193
12200
  duration: 5 * 1e3
12194
12201
  });
@@ -12199,7 +12206,7 @@ function defaultOnLoginRequired(messageInstance) {
12199
12206
  function defaultGetToken() {
12200
12207
  return typeof localStorage !== "undefined" ? localStorage.getItem("token") || "" : "";
12201
12208
  }
12202
- class BaseHttpClient {
12209
+ const _BaseHttpClient = class _BaseHttpClient {
12203
12210
  /**
12204
12211
  * 创建 BaseHttpClient 实例
12205
12212
  * @param config - HTTP 客户端配置对象
@@ -12210,6 +12217,7 @@ class BaseHttpClient {
12210
12217
  __publicField(this, "onTimeout");
12211
12218
  __publicField(this, "getToken");
12212
12219
  __publicField(this, "onLoginRequired");
12220
+ __publicField(this, "appendTo");
12213
12221
  __publicField(this, "instance");
12214
12222
  __publicField(this, "messageInstance");
12215
12223
  __publicField(this, "notificationInstance");
@@ -12221,13 +12229,17 @@ class BaseHttpClient {
12221
12229
  },
12222
12230
  getToken = defaultGetToken,
12223
12231
  onLoginRequired = defaultOnLoginRequired,
12232
+ appendTo,
12224
12233
  addSign,
12225
12234
  ...axiosConfig
12226
12235
  } = config;
12227
12236
  this.baseURL = baseURL;
12228
12237
  this.timeout = timeout;
12229
- this.messageInstance = createMessageWrapper();
12230
- this.notificationInstance = createNotificationWrapper();
12238
+ this.appendTo = appendTo;
12239
+ this.getContainer();
12240
+ const messageContainer = this.getMessageContainer();
12241
+ this.messageInstance = createMessageWrapper(this.hasDocument, messageContainer);
12242
+ this.notificationInstance = createNotificationWrapper(this.hasDocument, messageContainer);
12231
12243
  this.onTimeout = onTimeout;
12232
12244
  this.getToken = getToken;
12233
12245
  this.onLoginRequired = onLoginRequired;
@@ -12240,6 +12252,83 @@ class BaseHttpClient {
12240
12252
  });
12241
12253
  this.setupInterceptors();
12242
12254
  }
12255
+ /**
12256
+ * 获取是否在浏览器环境(实例 getter)
12257
+ * @returns 是否在浏览器环境
12258
+ */
12259
+ get hasDocument() {
12260
+ return _BaseHttpClient.hasDocument;
12261
+ }
12262
+ /**
12263
+ * 解析 appendTo 配置,返回目标 HTMLElement
12264
+ * @returns 目标元素,默认为 document.body
12265
+ */
12266
+ resolveAppendToTarget() {
12267
+ if (!this.hasDocument) {
12268
+ return document.body;
12269
+ }
12270
+ if (!this.appendTo) {
12271
+ return document.body;
12272
+ }
12273
+ if (this.appendTo instanceof HTMLElement) {
12274
+ return this.appendTo;
12275
+ }
12276
+ if (typeof this.appendTo === "string") {
12277
+ const element = document.querySelector(this.appendTo);
12278
+ if (element) {
12279
+ return element;
12280
+ }
12281
+ console.warn(`appendTo 选择器 "${this.appendTo}" 未找到元素,将使用默认的 document.body`);
12282
+ return document.body;
12283
+ }
12284
+ return document.body;
12285
+ }
12286
+ /**
12287
+ * 获取或创建 ajaxPackage-container 容器元素
12288
+ * @returns 容器元素,如果不是浏览器环境则返回 null
12289
+ */
12290
+ getContainer() {
12291
+ if (!this.hasDocument) {
12292
+ return null;
12293
+ }
12294
+ let container = document.getElementById("ajaxPackage-container");
12295
+ if (!container) {
12296
+ container = document.createElement("div");
12297
+ container.id = "ajaxPackage-container";
12298
+ const targetElement = this.resolveAppendToTarget();
12299
+ targetElement.appendChild(container);
12300
+ const popoverContainer = document.createElement("div");
12301
+ popoverContainer.id = "ajaxPackage-popover";
12302
+ container.appendChild(popoverContainer);
12303
+ const messageContainer = document.createElement("div");
12304
+ messageContainer.id = "ajaxPackage-message";
12305
+ messageContainer.style.zIndex = "99999999";
12306
+ container.appendChild(messageContainer);
12307
+ }
12308
+ return container;
12309
+ }
12310
+ /**
12311
+ * 获取或创建 ajaxPackage-popover 容器元素(用于 Dialog)
12312
+ * @returns 容器元素,如果不是浏览器环境则返回 null
12313
+ */
12314
+ getPopoverContainer() {
12315
+ if (!this.hasDocument) {
12316
+ return null;
12317
+ }
12318
+ this.getContainer();
12319
+ return document.getElementById("ajaxPackage-popover");
12320
+ }
12321
+ /**
12322
+ * 获取或创建 ajaxPackage-message 容器元素(用于 Message 和 Notification)
12323
+ * @returns 容器元素,如果不是浏览器环境则返回 null
12324
+ */
12325
+ getMessageContainer() {
12326
+ if (!this.hasDocument) {
12327
+ return null;
12328
+ }
12329
+ this.getContainer();
12330
+ return document.getElementById("ajaxPackage-message");
12331
+ }
12243
12332
  /**
12244
12333
  * 处理请求配置,子类可重写此方法自定义请求配置
12245
12334
  * @param config - 请求配置对象
@@ -12323,7 +12412,8 @@ class BaseHttpClient {
12323
12412
  var _a2, _b, _c;
12324
12413
  if (((_a2 = error.response) == null ? void 0 : _a2.status) !== 401 && error.code !== "ECONNABORTED") {
12325
12414
  const fallbackError = error;
12326
- (_c = this.messageInstance) == null ? void 0 : _c.error({
12415
+ (_c = this.messageInstance) == null ? void 0 : _c.call(this, {
12416
+ type: "error",
12327
12417
  message: ((_b = fallbackError.response) == null ? void 0 : _b.data) || fallbackError.message || "网络错误",
12328
12418
  duration: 5 * 1e3
12329
12419
  });
@@ -12462,6 +12552,42 @@ class BaseHttpClient {
12462
12552
  link.remove();
12463
12553
  window.URL.revokeObjectURL(url);
12464
12554
  }
12555
+ };
12556
+ /**
12557
+ * 检查是否在浏览器环境(在类初始化时判断)
12558
+ * 注意:这是静态属性,所有实例共享
12559
+ */
12560
+ __publicField(_BaseHttpClient, "hasDocument", typeof document !== "undefined");
12561
+ let BaseHttpClient = _BaseHttpClient;
12562
+ async function copyToClipboard(text) {
12563
+ if (!text) {
12564
+ console.warn("复制文本为空");
12565
+ return false;
12566
+ }
12567
+ try {
12568
+ if (navigator.clipboard && navigator.clipboard.writeText) {
12569
+ await navigator.clipboard.writeText(text);
12570
+ return true;
12571
+ } else {
12572
+ const textArea = document.createElement("textarea");
12573
+ textArea.value = text;
12574
+ textArea.style.position = "fixed";
12575
+ textArea.style.left = "-999999px";
12576
+ textArea.style.top = "-999999px";
12577
+ document.body.appendChild(textArea);
12578
+ textArea.select();
12579
+ if (document.execCommand("copy")) {
12580
+ document.body.removeChild(textArea);
12581
+ return true;
12582
+ } else {
12583
+ document.body.removeChild(textArea);
12584
+ return false;
12585
+ }
12586
+ }
12587
+ } catch (error) {
12588
+ console.error("复制到剪贴板失败:", error);
12589
+ return false;
12590
+ }
12465
12591
  }
12466
12592
  async function dynamicImport(modulePromise, exportName = "default") {
12467
12593
  const module = await modulePromise;
@@ -12483,7 +12609,7 @@ async function dynamicImports(modulePromise, exportNames) {
12483
12609
  }
12484
12610
  return result;
12485
12611
  }
12486
- function createApiDialog(DialogComponent) {
12612
+ function createApiDialog(DialogComponent, parentContainer) {
12487
12613
  let container = null;
12488
12614
  let vnode = null;
12489
12615
  let isOpen = false;
@@ -12518,6 +12644,8 @@ function createApiDialog(DialogComponent) {
12518
12644
  "modelValue": props.modelValue,
12519
12645
  "title": props.title,
12520
12646
  "width": props.width,
12647
+ // 如果提供了父容器,则挂载到父容器中
12648
+ "appendTo": parentContainer || void 0,
12521
12649
  "onUpdate:modelValue": (val) => {
12522
12650
  emit("update:modelValue", val);
12523
12651
  if (!val) {
@@ -12545,7 +12673,8 @@ function createApiDialog(DialogComponent) {
12545
12673
  const FinalDialogComponent = DialogComponent || DefaultDialog;
12546
12674
  function createContainer() {
12547
12675
  const el = document.createElement("div");
12548
- document.body.appendChild(el);
12676
+ const mountTarget = parentContainer || document.body;
12677
+ mountTarget.appendChild(el);
12549
12678
  return el;
12550
12679
  }
12551
12680
  function show(options = {}) {
@@ -12629,7 +12758,7 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
12629
12758
  const {
12630
12759
  responseFields,
12631
12760
  enableSystemErrorDialog = true,
12632
- systemErrorMessage = "系统异常",
12761
+ systemErrorMessage = "系统异常,点击看详情",
12633
12762
  ...baseConfig
12634
12763
  } = config;
12635
12764
  super(baseConfig);
@@ -12661,13 +12790,6 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
12661
12790
  this.systemErrorDialogInitPromise = this.initSystemErrorDialog();
12662
12791
  }
12663
12792
  }
12664
- /**
12665
- * 获取是否在浏览器环境(实例 getter)
12666
- * @returns 是否在浏览器环境
12667
- */
12668
- get hasDocument() {
12669
- return _BaseApi.hasDocument;
12670
- }
12671
12793
  /**
12672
12794
  * 获取系统错误信息存储(实例 getter)
12673
12795
  * @returns 系统错误信息存储 Map
@@ -12748,7 +12870,8 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
12748
12870
  async initSystemErrorDialog() {
12749
12871
  try {
12750
12872
  const { default: SystemErrorDialog2 } = await dynamicImports(Promise.resolve().then(() => SystemErrorDialog$1), ["default"]);
12751
- this.systemErrorDialogInstance = createApiDialog(SystemErrorDialog2);
12873
+ const popoverContainer = this.getPopoverContainer();
12874
+ this.systemErrorDialogInstance = createApiDialog(SystemErrorDialog2, popoverContainer);
12752
12875
  } catch (error) {
12753
12876
  console.warn("Failed to load SystemErrorDialog:", error);
12754
12877
  throw error;
@@ -12888,25 +13011,13 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
12888
13011
  })
12889
13012
  ])
12890
13013
  ]);
12891
- (_a2 = this.messageInstance) == null ? void 0 : _a2.error({
13014
+ (_a2 = this.messageInstance) == null ? void 0 : _a2.call(this, {
13015
+ type: "error",
12892
13016
  message: messageVNode,
12893
13017
  duration: 5 * 1e3,
12894
13018
  customClass: "system-error-message"
12895
13019
  // 添加自定义类名
12896
13020
  });
12897
- if (typeof document !== "undefined") {
12898
- let styleElement = document.getElementById("system-error-message-style");
12899
- if (!styleElement) {
12900
- styleElement = document.createElement("style");
12901
- styleElement.id = "system-error-message-style";
12902
- document.head.appendChild(styleElement);
12903
- }
12904
- styleElement.textContent = `
12905
- .system-error-message {
12906
- z-index: 99999998 !important;
12907
- }
12908
- `;
12909
- }
12910
13021
  }
12911
13022
  /**
12912
13023
  * 处理业务错误(其他非200错误码)
@@ -12917,7 +13028,8 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
12917
13028
  handleBusinessError(code, message2) {
12918
13029
  var _a2;
12919
13030
  if (code && code !== 200) {
12920
- (_a2 = this.messageInstance) == null ? void 0 : _a2.error({
13031
+ (_a2 = this.messageInstance) == null ? void 0 : _a2.call(this, {
13032
+ type: "error",
12921
13033
  message: message2 || "请求失败",
12922
13034
  duration: 5 * 1e3
12923
13035
  });
@@ -13013,24 +13125,10 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
13013
13125
  ...messageOptions,
13014
13126
  message: (messageOptions == null ? void 0 : messageOptions.message) ?? tipsMessage
13015
13127
  };
13016
- const messageType = finalOptions.type || "success";
13017
13128
  const messageInstance = this.messageInstance;
13018
13129
  if (!messageInstance)
13019
13130
  return;
13020
- switch (messageType) {
13021
- case "success":
13022
- messageInstance.success(finalOptions);
13023
- break;
13024
- case "error":
13025
- messageInstance.error(finalOptions);
13026
- break;
13027
- case "warning":
13028
- messageInstance.warning(finalOptions);
13029
- break;
13030
- case "info":
13031
- messageInstance.info(finalOptions);
13032
- break;
13033
- }
13131
+ messageInstance(finalOptions);
13034
13132
  }
13035
13133
  /**
13036
13134
  * 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
@@ -13115,11 +13213,6 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
13115
13213
  return super.downloadFile(blob, filename);
13116
13214
  }
13117
13215
  };
13118
- /**
13119
- * 检查是否在浏览器环境(在类初始化时判断)
13120
- * 注意:这是静态属性,所有实例共享
13121
- */
13122
- __publicField(_BaseApi, "hasDocument", typeof document !== "undefined");
13123
13216
  /**
13124
13217
  * 系统错误信息存储,用于在点击 icon 时打开详细错误弹窗
13125
13218
  * key: 错误ID,value: 错误信息对象
@@ -13262,6 +13355,22 @@ const SystemErrorDialog = defineComponent({
13262
13355
  function handleModelValueChange(val) {
13263
13356
  emit("update:modelValue", val);
13264
13357
  }
13358
+ function getAjaxPackageMessageContainer() {
13359
+ if (typeof document === "undefined")
13360
+ return null;
13361
+ return document.getElementById("ajaxPackage-message");
13362
+ }
13363
+ function getAjaxPackagePopoverContainer() {
13364
+ if (typeof document === "undefined")
13365
+ return null;
13366
+ return document.getElementById("ajaxPackage-popover");
13367
+ }
13368
+ function showMessage(options) {
13369
+ const container = getAjaxPackageMessageContainer();
13370
+ const { type = "info", message: message2 } = options;
13371
+ const finalOptions = container ? { type, message: message2, appendTo: container } : { type, message: message2 };
13372
+ ElMessage(finalOptions);
13373
+ }
13265
13374
  async function handleReport() {
13266
13375
  await baseApi.post("/upgGlobalExceptionReports", {
13267
13376
  username: userInfo.value.userName,
@@ -13275,7 +13384,7 @@ const SystemErrorDialog = defineComponent({
13275
13384
  menuUrl: currentUrl,
13276
13385
  errorMessage: props.errorMessage
13277
13386
  });
13278
- ElMessage.success("上报成功");
13387
+ showMessage({ type: "success", message: "上报成功" });
13279
13388
  handleClose();
13280
13389
  }
13281
13390
  function toggleTechSummary() {
@@ -13294,6 +13403,19 @@ const SystemErrorDialog = defineComponent({
13294
13403
  const skyWalkingUrl = `${origin2}/middle/skywalking/trace/Trace?traceId=${encodeURIComponent(props.traceId)}`;
13295
13404
  window.open(skyWalkingUrl, "_blank");
13296
13405
  }
13406
+ async function handleCopyTraceId() {
13407
+ const traceId = props.traceId;
13408
+ if (!traceId) {
13409
+ showMessage({ type: "warning", message: "TraceId 不存在" });
13410
+ return;
13411
+ }
13412
+ const success = await copyToClipboard(traceId);
13413
+ if (success) {
13414
+ showMessage({ type: "success", message: "复制 traceId 成功" });
13415
+ } else {
13416
+ showMessage({ type: "error", message: "复制 traceId 失败" });
13417
+ }
13418
+ }
13297
13419
  function close2() {
13298
13420
  handleClose();
13299
13421
  }
@@ -13304,6 +13426,7 @@ const SystemErrorDialog = defineComponent({
13304
13426
  return typeof props.width === "number" ? `${props.width}px` : props.width;
13305
13427
  });
13306
13428
  return () => {
13429
+ const popoverContainer = getAjaxPackagePopoverContainer();
13307
13430
  return h(
13308
13431
  ElDialog,
13309
13432
  {
@@ -13313,8 +13436,8 @@ const SystemErrorDialog = defineComponent({
13313
13436
  "showClose": true,
13314
13437
  "closeOnClickModal": false,
13315
13438
  "closeOnPressEscape": false,
13316
- "zIndex": 99999999,
13317
13439
  "style": { padding: "16px 0" },
13440
+ "appendTo": popoverContainer || void 0,
13318
13441
  "onUpdate:modelValue": handleModelValueChange
13319
13442
  },
13320
13443
  {
@@ -13403,7 +13526,20 @@ const SystemErrorDialog = defineComponent({
13403
13526
  )
13404
13527
  ]),
13405
13528
  // 黑色错误信息区域
13406
- 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" } }, [
13529
+ h("div", {
13530
+ style: {
13531
+ backgroundColor: "#2c3e50",
13532
+ color: "#fff",
13533
+ padding: "16px 20px",
13534
+ fontFamily: 'Monaco, Consolas, "Courier New", monospace',
13535
+ fontSize: "12px",
13536
+ lineHeight: 1.5,
13537
+ maxHeight: "200px",
13538
+ overflowY: "auto",
13539
+ cursor: "pointer"
13540
+ },
13541
+ onClick: handleCopyTraceId
13542
+ }, [
13407
13543
  h("div", { style: { marginBottom: "8px", color: "#ecf0f1" } }, `Trace ID: ${props.traceId || "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"}`),
13408
13544
  h("div", { style: { color: "#e74c3c", fontWeight: "bold", whiteSpace: "pre-wrap" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
13409
13545
  ])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moluoxixi/ajax-package",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "AjaxPackage 组件",
5
5
  "sideEffects": [
6
6
  "*.css",