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 +1 -1
- package/dist/es/{request-DXNZ2mjR.js → request-nTONcWEZ.js} +104 -102
- package/dist/es/vue.js +1 -1
- package/dist/js/xl-app-sdk.esm.js +425 -423
- package/dist/js/xl-app-sdk.js +6 -6
- package/dist/types/hooks/vue.d.ts +2 -2
- package/dist/types/modules/base.d.ts +4 -0
- package/dist/types/modules/event.d.ts +1 -1
- package/dist/types/modules/request.d.ts +1 -1
- package/package.json +4 -4
package/dist/es/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p from "axios";
|
|
2
2
|
import { v as o } from "./event-CGLPzfQO.js";
|
|
3
|
-
import { s as r, e as
|
|
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
|
|
6
|
-
if (!(a?.type && !
|
|
7
|
-
if (
|
|
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
|
|
40
|
+
function _(e, a = {}) {
|
|
41
41
|
f(e, { ...a, type: "success" });
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function S(e, a = {}) {
|
|
44
44
|
f(e, { ...a, type: "info" });
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function k(e, a = {}) {
|
|
47
47
|
f(e, { ...a, type: "warning" });
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function v(e, a = {}) {
|
|
50
50
|
f(e, { ...a, type: "error" });
|
|
51
51
|
}
|
|
52
|
-
function
|
|
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:
|
|
76
|
-
info:
|
|
77
|
-
loading:
|
|
74
|
+
destroyAll: N,
|
|
75
|
+
error: v,
|
|
76
|
+
info: S,
|
|
77
|
+
loading: h,
|
|
78
78
|
setInstance: M,
|
|
79
|
-
success:
|
|
80
|
-
warning:
|
|
79
|
+
success: _,
|
|
80
|
+
warning: k
|
|
81
81
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
82
82
|
function g(e) {
|
|
83
|
-
const a = o.getMode(!0),
|
|
84
|
-
if (!(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((
|
|
109
|
-
}).catch((
|
|
108
|
+
o.call("notification", e).then((n) => {
|
|
109
|
+
}).catch((n) => {
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function U(e) {
|
|
114
114
|
g({ ...e, type: "success" });
|
|
115
115
|
}
|
|
116
|
-
function
|
|
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
|
|
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:
|
|
146
|
-
info:
|
|
145
|
+
error: A,
|
|
146
|
+
info: q,
|
|
147
147
|
setInstance: j,
|
|
148
|
-
success:
|
|
148
|
+
success: U,
|
|
149
149
|
warning: L
|
|
150
150
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
151
151
|
async function T(e = null, a = {}) {
|
|
152
|
-
const
|
|
153
|
-
|
|
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
|
|
156
|
+
return n.size > 0 ? c + "?" + n.toString() : c;
|
|
157
157
|
} catch {
|
|
158
|
-
return
|
|
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
|
|
164
|
-
Array.isArray(e) && (
|
|
165
|
-
const
|
|
166
|
-
|
|
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:
|
|
172
|
-
filterEmpty:
|
|
171
|
+
cloneData: i = !1,
|
|
172
|
+
filterEmpty: n = !1,
|
|
173
173
|
loading: c = !1,
|
|
174
|
-
replenish:
|
|
175
|
-
showMsg:
|
|
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)),
|
|
180
|
-
const
|
|
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
|
-
}),
|
|
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
|
|
195
|
-
t =
|
|
194
|
+
const l = await p.request(e);
|
|
195
|
+
t = l.data, u && await E(u, y);
|
|
196
196
|
let d = !1;
|
|
197
|
-
if ((
|
|
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
|
|
205
|
-
|
|
206
|
-
},
|
|
203
|
+
return m && setTimeout(() => {
|
|
204
|
+
_(R || "请求成功");
|
|
205
|
+
}, 100), t;
|
|
207
206
|
} catch (t) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
|
255
|
-
throw
|
|
256
|
-
|
|
257
|
-
|
|
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