@moluoxixi/ajax-package 0.0.35 → 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,6 +16,7 @@ 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;
@@ -30,6 +31,11 @@ export default class BaseHttpClient {
30
31
  * @returns 是否在浏览器环境
31
32
  */
32
33
  protected get hasDocument(): boolean;
34
+ /**
35
+ * 解析 appendTo 配置,返回目标 HTMLElement
36
+ * @returns 目标元素,默认为 document.body
37
+ */
38
+ protected resolveAppendToTarget(): HTMLElement;
33
39
  /**
34
40
  * 获取或创建 ajaxPackage-container 容器元素
35
41
  * @returns 容器元素,如果不是浏览器环境则返回 null
@@ -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
  }
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("59b794d1-a3ef-4b37-9b28-cc9399203b57")) {
5
+ if (!document.getElementById("55abf58f-b1b4-4e82-ab0d-ee119c15bd62")) {
6
6
  var elementStyle = document.createElement("style");
7
- elementStyle.id = "59b794d1-a3ef-4b37-9b28-cc9399203b57";
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
  }
@@ -12217,6 +12217,7 @@ const _BaseHttpClient = class _BaseHttpClient {
12217
12217
  __publicField(this, "onTimeout");
12218
12218
  __publicField(this, "getToken");
12219
12219
  __publicField(this, "onLoginRequired");
12220
+ __publicField(this, "appendTo");
12220
12221
  __publicField(this, "instance");
12221
12222
  __publicField(this, "messageInstance");
12222
12223
  __publicField(this, "notificationInstance");
@@ -12228,11 +12229,13 @@ const _BaseHttpClient = class _BaseHttpClient {
12228
12229
  },
12229
12230
  getToken = defaultGetToken,
12230
12231
  onLoginRequired = defaultOnLoginRequired,
12232
+ appendTo,
12231
12233
  addSign,
12232
12234
  ...axiosConfig
12233
12235
  } = config;
12234
12236
  this.baseURL = baseURL;
12235
12237
  this.timeout = timeout;
12238
+ this.appendTo = appendTo;
12236
12239
  this.getContainer();
12237
12240
  const messageContainer = this.getMessageContainer();
12238
12241
  this.messageInstance = createMessageWrapper(this.hasDocument, messageContainer);
@@ -12256,6 +12259,30 @@ const _BaseHttpClient = class _BaseHttpClient {
12256
12259
  get hasDocument() {
12257
12260
  return _BaseHttpClient.hasDocument;
12258
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
+ }
12259
12286
  /**
12260
12287
  * 获取或创建 ajaxPackage-container 容器元素
12261
12288
  * @returns 容器元素,如果不是浏览器环境则返回 null
@@ -12268,7 +12295,8 @@ const _BaseHttpClient = class _BaseHttpClient {
12268
12295
  if (!container) {
12269
12296
  container = document.createElement("div");
12270
12297
  container.id = "ajaxPackage-container";
12271
- document.body.appendChild(container);
12298
+ const targetElement = this.resolveAppendToTarget();
12299
+ targetElement.appendChild(container);
12272
12300
  const popoverContainer = document.createElement("div");
12273
12301
  popoverContainer.id = "ajaxPackage-popover";
12274
12302
  container.appendChild(popoverContainer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moluoxixi/ajax-package",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "AjaxPackage 组件",
5
5
  "sideEffects": [
6
6
  "*.css",