xl-app-sdk 0.1.3 → 0.1.5

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/dist/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { v as o } from "./event-CGLPzfQO.js";
2
- import { g as q, m as k, n as B, r as U } from "./request-DXNZ2mjR.js";
2
+ import { g as q, m as k, n as B, r as U } from "./request-nTONcWEZ.js";
3
3
  function m() {
4
4
  return o;
5
5
  }
@@ -1,10 +1,10 @@
1
- import O from "axios";
1
+ import p from "axios";
2
2
  import { v as o } from "./event-CGLPzfQO.js";
3
- import { s as r, e as D, h as P, v as S, j as m } from "./utils-CnDqFMmf.js";
3
+ import { s as r, e as O, h as D, v as P, j as w } from "./utils-CnDqFMmf.js";
4
4
  function f(e, a = {}) {
5
- const n = o.getMode(!0), i = ["info", "warning", "error", "success", "loading"];
6
- if (!(a?.type && !i.includes(a.type))) {
7
- if (n === null || n === "window") {
5
+ const i = o.getMode(!0), n = ["info", "warning", "error", "success", "loading"];
6
+ if (!(a?.type && !n.includes(a.type))) {
7
+ if (i === null || i === "window") {
8
8
  if (a?.duration === 0 && a?.type !== "loading")
9
9
  return;
10
10
  if ((!a?.duration || a?.duration < 0) && (a.duration = 2e3), a?.type !== "loading" && a?.duration === 0 && (a.duration = 2e3), !a?.type) {
@@ -37,22 +37,22 @@ function f(e, a = {}) {
37
37
  });
38
38
  }
39
39
  }
40
- function v(e, a = {}) {
40
+ function _(e, a = {}) {
41
41
  f(e, { ...a, type: "success" });
42
42
  }
43
- function k(e, a = {}) {
43
+ function S(e, a = {}) {
44
44
  f(e, { ...a, type: "info" });
45
45
  }
46
- function N(e, a = {}) {
46
+ function k(e, a = {}) {
47
47
  f(e, { ...a, type: "warning" });
48
48
  }
49
- function h(e, a = {}) {
49
+ function v(e, a = {}) {
50
50
  f(e, { ...a, type: "error" });
51
51
  }
52
- function A(e, a = {}) {
52
+ function h(e, a = {}) {
53
53
  f(e, { ...a, type: "loading" });
54
54
  }
55
- function _() {
55
+ function N() {
56
56
  o.getParent(!0) && o.call("message", {});
57
57
  try {
58
58
  if (!window?.naive?.message) {
@@ -71,17 +71,17 @@ function M(e) {
71
71
  const C = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
72
72
  __proto__: null,
73
73
  create: f,
74
- destroyAll: _,
75
- error: h,
76
- info: k,
77
- loading: A,
74
+ destroyAll: N,
75
+ error: v,
76
+ info: S,
77
+ loading: h,
78
78
  setInstance: M,
79
- success: v,
80
- warning: N
79
+ success: _,
80
+ warning: k
81
81
  }, Symbol.toStringTag, { value: "Module" }));
82
82
  function g(e) {
83
- const a = o.getMode(!0), n = ["info", "warning", "error", "success"];
84
- if (!(e?.type && !n.includes(e.type))) {
83
+ const a = o.getMode(!0), i = ["info", "warning", "error", "success"];
84
+ if (!(e?.type && !i.includes(e.type))) {
85
85
  if (e?.closable === void 0 && (e.closable = !0), a === null || a === "window") {
86
86
  if (e.closable === !1 && e.duration === 0 && (e.duration = 5e3), (!e?.duration || e?.duration < 0) && (e.duration = 5e3), !e?.type) {
87
87
  if (!window?.naive?.notification) {
@@ -105,21 +105,21 @@ function g(e) {
105
105
  }
106
106
  return;
107
107
  }
108
- o.call("notification", e).then((i) => {
109
- }).catch((i) => {
108
+ o.call("notification", e).then((n) => {
109
+ }).catch((n) => {
110
110
  });
111
111
  }
112
112
  }
113
- function q(e) {
113
+ function U(e) {
114
114
  g({ ...e, type: "success" });
115
115
  }
116
- function U(e) {
116
+ function q(e) {
117
117
  g({ ...e, type: "info" });
118
118
  }
119
119
  function L(e) {
120
120
  g({ ...e, type: "warning" });
121
121
  }
122
- function p(e) {
122
+ function A(e) {
123
123
  g({ ...e, type: "error" });
124
124
  }
125
125
  function $() {
@@ -142,42 +142,42 @@ const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
142
142
  __proto__: null,
143
143
  create: g,
144
144
  destroyAll: $,
145
- error: p,
146
- info: U,
145
+ error: A,
146
+ info: q,
147
147
  setInstance: j,
148
- success: q,
148
+ success: U,
149
149
  warning: L
150
150
  }, Symbol.toStringTag, { value: "Module" }));
151
151
  async function T(e = null, a = {}) {
152
- const n = new URLSearchParams(window.location.search), i = new URLSearchParams(a);
153
- n.has("_token") && i.append("_token", n.get("_token"));
152
+ const i = new URLSearchParams(window.location.search), n = new URLSearchParams(a);
153
+ i.has("_token") && n.append("_token", i.get("_token"));
154
154
  try {
155
155
  const c = await o.call("getRequestBaseURL", e);
156
- return i.size > 0 ? c + "?" + i.toString() : c;
156
+ return n.size > 0 ? c + "?" + n.toString() : c;
157
157
  } catch {
158
- return i.size > 0 ? e + "?" + i.toString() : e;
158
+ return n.size > 0 ? e + "?" + n.toString() : e;
159
159
  }
160
160
  }
161
161
  async function E(e, a) {
162
162
  if (!e) return;
163
- let n = 300, i = 0;
164
- Array.isArray(e) && (n = e[0] || 300, i = e[1] || 0);
165
- const l = Date.now() - a;
166
- i > 0 ? l > i && l < n && await new Promise((w) => setTimeout(w, n - l)) : l < n && await new Promise((w) => setTimeout(w, n - l));
163
+ let i = 300, n = 0;
164
+ typeof e == "number" && (i = e), Array.isArray(e) && (i = e[0] || 300, n = e[1] || 0);
165
+ const u = Date.now() - a;
166
+ n > 0 ? u > n && u < i && await new Promise((m) => setTimeout(m, i - u)) : u < i && await new Promise((m) => setTimeout(m, i - u));
167
167
  }
168
168
  async function F(e) {
169
169
  let {
170
170
  crossWindow: a = void 0,
171
- cloneData: n = !1,
172
- filterEmpty: i = !1,
171
+ cloneData: i = !1,
172
+ filterEmpty: n = !1,
173
173
  loading: c = !1,
174
- replenish: l = !1,
175
- showMsg: w = !1,
174
+ replenish: u = !1,
175
+ showMsg: m = !1,
176
176
  showErrorMsg: b = !1,
177
177
  msgField: s = "msg"
178
178
  } = e;
179
- a === void 0 && o.getMode(!0) === "iframe" && (a = !0), a && o.getMode(!0) === null && (e.method === "get" || e.method === "GET" ? e.url = await T(e?.url, e?.data) : e.url = await T(e?.url)), n && e.data && (e.data = D(e.data)), i && e.data && typeof e.data == "object" && (e.data = P(e.data)), c && A(typeof c == "string" ? c : "加载中", { duration: 0 });
180
- const R = Date.now();
179
+ a === void 0 && o.getMode(!0) === "iframe" && (a = !0), a && o.getMode(!0) === null && (e.method === "get" || e.method === "GET" ? e.url = await T(e?.url, e?.data) : e.url = await T(e?.url)), i && e.data && (e.data = O(e.data)), n && e.data && typeof e.data == "object" && (e.data = D(e.data)), c && h(typeof c == "string" ? c : "加载中", { duration: 0 });
180
+ const y = Date.now();
181
181
  try {
182
182
  let t;
183
183
  if (a)
@@ -188,76 +188,78 @@ async function F(e) {
188
188
  loading: !1,
189
189
  showMsg: !1,
190
190
  showErrorMsg: !1
191
- }), l && await E(l, R);
191
+ }), u && await E(u, y);
192
192
  else {
193
193
  (e.method === "get" || e.method === "GET") && (e.params = e.data, e.data = null);
194
- const u = await O.request(e);
195
- t = u.data, l && await E(l, R);
194
+ const l = await p.request(e);
195
+ t = l.data, u && await E(u, y);
196
196
  let d = !1;
197
- if ((u.config.responseType === "json" || u.config.responseType === void 0) && (d = !0), d && !S(u.request.responseText))
197
+ if ((l.config.responseType === "json" || l.config.responseType === void 0) && (d = !0), d && !P(l.request.responseText))
198
198
  throw t.code = "ERR_BAD_RESPONSE", t;
199
199
  }
200
- _();
201
- const y = m(t, s || "msg");
200
+ const R = w(t, s || "msg");
202
201
  if (t?.code < 0 || t?.code == 404 || t?.code == 403 || t?.code == 500)
203
202
  throw t;
204
- return w && setTimeout(() => {
205
- v(y || "请求成功");
206
- }, 300), t;
203
+ return m && setTimeout(() => {
204
+ _(R || "请求成功");
205
+ }, 100), t;
207
206
  } catch (t) {
208
- switch (await E(l, R), _(), t.request_code = t.code, t.code) {
209
- case "ECONNABORTED":
210
- r(t, s, "连接被中止"), r(t, "msg", "连接被中止");
211
- break;
212
- case "ERR_BAD_OPTION":
213
- r(t, s, "错误的选项"), r(t, "msg", "错误的选项");
214
- break;
215
- case "ERR_BAD_OPTION_VALUE":
216
- r(t, s, "错误的选项数值"), r(t, "msg", "错误的选项数值");
217
- break;
218
- case "ERR_CANCELED":
219
- r(t, s, "操作被取消"), r(t, "msg", "操作被取消");
220
- break;
221
- case "ERR_DEPRECATED":
222
- r(t, s, "已废弃的功能"), r(t, "msg", "已废弃的功能");
223
- break;
224
- case "ERR_FR_TOO_MANY_REDIRECTS":
225
- r(t, s, "页面重定向次数过多"), r(t, "msg", "页面重定向次数过多");
226
- break;
227
- case "ERR_INVALID_URL":
228
- r(t, s, "无效的URL"), r(t, "msg", "无效的URL");
229
- break;
230
- case "ERR_NETWORK":
231
- r(t, s, "无法连接目标地址"), r(t, "msg", "无法连接目标地址");
232
- break;
233
- case "ERR_NOT_SUPPORT":
234
- r(t, s, "不支持的功能"), r(t, "msg", "不支持的功能");
235
- break;
236
- case "ETIMEDOUT":
237
- r(t, s, "连接超时"), r(t, "msg", "连接超时");
238
- break;
239
- case "ERR_BAD_REQUEST":
240
- r(t, s, "错误的请求"), r(t, "msg", "错误的请求");
241
- break;
242
- case "ERR_BAD_RESPONSE":
243
- if (r(t, s, "错误的响应"), r(t, "msg", "错误的响应"), t?.request?.responseText)
244
- try {
245
- const u = JSON.parse(t.request.responseText), d = m(u, s) || m(u, "msg");
246
- d && (r(t, s, d), r(t, "msg", d));
247
- } catch {
248
- r(t, s, t.request.responseText), r(t, "msg", t.request.responseText);
249
- }
250
- break;
251
- default:
252
- r(t, s, t.message), r(t, "msg", t.message);
207
+ if (await E(u, y), t?.code && typeof t.code == "string") {
208
+ switch (t.code) {
209
+ case "ECONNABORTED":
210
+ r(t, s, "连接被中止"), r(t, "msg", "连接被中止");
211
+ break;
212
+ case "ERR_BAD_OPTION":
213
+ r(t, s, "错误的选项"), r(t, "msg", "错误的选项");
214
+ break;
215
+ case "ERR_BAD_OPTION_VALUE":
216
+ r(t, s, "错误的选项数值"), r(t, "msg", "错误的选项数值");
217
+ break;
218
+ case "ERR_CANCELED":
219
+ r(t, s, "操作被取消"), r(t, "msg", "操作被取消");
220
+ break;
221
+ case "ERR_DEPRECATED":
222
+ r(t, s, "已废弃的功能"), r(t, "msg", "已废弃的功能");
223
+ break;
224
+ case "ERR_FR_TOO_MANY_REDIRECTS":
225
+ r(t, s, "页面重定向次数过多"), r(t, "msg", "页面重定向次数过多");
226
+ break;
227
+ case "ERR_INVALID_URL":
228
+ r(t, s, "无效的URL"), r(t, "msg", "无效的URL");
229
+ break;
230
+ case "ERR_NETWORK":
231
+ r(t, s, "无法连接目标地址"), r(t, "msg", "无法连接目标地址");
232
+ break;
233
+ case "ERR_NOT_SUPPORT":
234
+ r(t, s, "不支持的功能"), r(t, "msg", "不支持的功能");
235
+ break;
236
+ case "ETIMEDOUT":
237
+ r(t, s, "连接超时"), r(t, "msg", "连接超时");
238
+ break;
239
+ case "ERR_BAD_REQUEST":
240
+ r(t, s, "错误的请求"), r(t, "msg", "错误的请求");
241
+ break;
242
+ case "ERR_BAD_RESPONSE":
243
+ if (r(t, s, "错误的响应"), r(t, "msg", "错误的响应"), t?.request?.responseText)
244
+ try {
245
+ const l = JSON.parse(t.request.responseText), d = w(l, s) || w(l, "msg");
246
+ d && (r(t, s, d), r(t, "msg", d));
247
+ } catch {
248
+ r(t, s, t.request.responseText), r(t, "msg", t.request.responseText);
249
+ }
250
+ break;
251
+ default:
252
+ r(t, s, t?.message), r(t, "msg", t?.message);
253
+ }
254
+ throw t.code = 0, A({
255
+ title: "请求错误",
256
+ description: t?.message || t?.msg || "未知错误"
257
+ }), t;
253
258
  }
254
- const y = m(t, s || "msg") || m(t, "msg");
255
- throw t.code && typeof t.code == "string" ? (t.code = 0, p({
256
- title: "请求错误",
257
- description: y
258
- }), t) : (b && setTimeout(() => {
259
- h(y || "请求失败");
260
- }, 300), t);
259
+ const R = w(t, s || "msg") || w(t, "msg");
260
+ throw b && setTimeout(() => {
261
+ v(R || "请求失败");
262
+ }, 100), t;
261
263
  }
262
264
  }
263
265
  export {
package/dist/es/vue.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ref as o, onUnmounted as f, computed as a } from "vue";
2
2
  import { v as s } from "./event-CGLPzfQO.js";
3
- import { r as c } from "./request-DXNZ2mjR.js";
3
+ import { r as c } from "./request-nTONcWEZ.js";
4
4
  function p() {
5
5
  return s;
6
6
  }