mgacn-commonsdk 1.2.1 → 1.2.4

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.
@@ -1,569 +0,0 @@
1
- import F from "axios";
2
- const D = "__MGACN_COMMONSDK_SYSTEM_ID__", P = "__MGACN_COMMONSDK_USER_ID__";
3
- function G(t) {
4
- globalThis[D] = t == null ? "" : String(t);
5
- }
6
- function S() {
7
- return globalThis[D] || "";
8
- }
9
- function H(t) {
10
- globalThis[P] = t == null ? "" : String(t);
11
- }
12
- function K() {
13
- return globalThis[P] || "";
14
- }
15
- function L(t = {}) {
16
- const {
17
- baseURL: e = "",
18
- timeout: n = 6e4,
19
- tokenKey: r,
20
- systemId: i,
21
- userId: s,
22
- loginUrl: l = "/login"
23
- } = t;
24
- i != null && i !== "" && G(i), s != null && s !== "" && H(s);
25
- const a = F.create({ baseURL: e, timeout: n });
26
- let f = !1;
27
- function c() {
28
- typeof localStorage < "u" && localStorage.clear(), !f && (f = !0, setTimeout(() => {
29
- typeof window < "u" && window.location.replace(l);
30
- }, 1500));
31
- }
32
- return a.interceptors.request.use(
33
- (o) => {
34
- if (o.headers["Content-Type"] = "application/json;charset=UTF-8", typeof localStorage < "u" && r) {
35
- const m = localStorage.getItem(r);
36
- m && (o.headers.Authorization = m);
37
- }
38
- const u = S();
39
- return u && (o.headers.systemId = u), o;
40
- },
41
- (o) => Promise.reject(o)
42
- ), a.interceptors.response.use(
43
- (o) => {
44
- if (o.status !== 200)
45
- return Promise.reject(new Error(`请求发生错误,状态码 ${o.status}`));
46
- const { data: u, config: m } = o;
47
- if (m.responseType === "arraybuffer" || m.responseType === "blob")
48
- return u;
49
- if (u && u.code === 0) return u.data;
50
- const y = Number(u == null ? void 0 : u.code);
51
- if (y === 401 || y === 403)
52
- return c(), Promise.reject(new Error("登录失效,请重新登录"));
53
- const N = A(u) || "请求失败", g = new Error(N);
54
- return g.code = y, g.data = u == null ? void 0 : u.data, g.biz = u, Promise.reject(g);
55
- },
56
- (o) => {
57
- var N, g;
58
- const u = (N = o == null ? void 0 : o.response) == null ? void 0 : N.status;
59
- if (u === 401 || u === 403)
60
- return c(), Promise.reject(new Error("登录失效,请重新登录"));
61
- const m = (g = o == null ? void 0 : o.response) == null ? void 0 : g.data, y = A(m) || (o == null ? void 0 : o.message) || "请求失败";
62
- return Promise.reject(new Error(String(y)));
63
- }
64
- ), a;
65
- }
66
- function A(t) {
67
- if (t == null) return "";
68
- if (typeof t == "string") {
69
- const n = t.trim();
70
- return n ? /^<!DOCTYPE html>/i.test(n) || /^<html[\s>]/i.test(n) ? "接口地址无效或未配置代理" : n.length > 200 ? `${n.slice(0, 200)}…` : n : "";
71
- }
72
- if (typeof t != "object") return String(t);
73
- const e = [t.message, t.msg, t.data, t.error];
74
- for (const n of e)
75
- if (!(n == null || n === "") && (typeof n == "string" || typeof n == "number")) {
76
- const r = String(n).trim();
77
- return /^<!DOCTYPE html>/i.test(r) || /^<html[\s>]/i.test(r) ? "接口地址无效或未配置代理" : r.length > 200 ? `${r.slice(0, 200)}…` : r;
78
- }
79
- return "";
80
- }
81
- function gt(t = {}) {
82
- const e = L(t);
83
- return {
84
- GET(n, r = {}) {
85
- return e({ method: "get", url: n, ...r });
86
- },
87
- POST(n, r, i = {}) {
88
- return e({ method: "post", url: n, data: r, ...i });
89
- },
90
- DELETE(n, r = {}) {
91
- return e({ method: "delete", url: n, ...r });
92
- }
93
- };
94
- }
95
- const $ = "__MGACN_COMMONSDK_REQUEST__";
96
- function pt(t) {
97
- globalThis[$] = t;
98
- }
99
- function B() {
100
- const t = globalThis[$];
101
- if (!t)
102
- throw new Error("[mgacn-commonsdk] 请先 app.use(MgacnCommonSdk, { tokenKey, baseURL })");
103
- return t;
104
- }
105
- function Y(t, e, n = "application/vnd.ms-excel") {
106
- if (t == null || typeof window > "u") return;
107
- const r = t instanceof Blob ? t : new Blob([t], { type: n }), i = window.URL.createObjectURL(r), s = document.createElement("a");
108
- s.href = i, s.download = e || "download", s.style.display = "none", document.body.appendChild(s), s.click(), document.body.removeChild(s), window.URL.revokeObjectURL(i);
109
- }
110
- function b(t) {
111
- return String(t).padStart(2, "0");
112
- }
113
- function q(t = /* @__PURE__ */ new Date()) {
114
- return `${t.getFullYear()}${b(t.getMonth() + 1)}${b(t.getDate())}${b(t.getHours())}${b(t.getMinutes())}${b(t.getSeconds())}`;
115
- }
116
- async function z(t) {
117
- if (!(t instanceof Blob) || !t.type || !/json/i.test(t.type)) return;
118
- const e = await t.text();
119
- let n = "导出失败";
120
- try {
121
- const r = JSON.parse(e);
122
- n = (r == null ? void 0 : r.message) || (r == null ? void 0 : r.msg) || n;
123
- } catch {
124
- }
125
- throw new Error(n);
126
- }
127
- async function k(t = {}) {
128
- const {
129
- url: e,
130
- data: n,
131
- params: r,
132
- method: i = "POST",
133
- filename: s,
134
- ext: l = "xlsx"
135
- } = t;
136
- if (!e) throw new Error("导出地址不能为空");
137
- if (!s) throw new Error("导出文件名不能为空");
138
- const a = B(), f = String(i).toUpperCase();
139
- let c;
140
- f === "GET" ? c = await a.GET(e, { params: r, responseType: "blob" }) : c = await a.POST(e, n, { responseType: "blob" }), await z(c);
141
- const u = /\.[a-z0-9]+$/i.test(s) ? s : `${s}_${q()}.${l}`;
142
- return Y(c, u), u;
143
- }
144
- let d = null, p = null;
145
- function Q(t, e) {
146
- if (!t || e == null || e === "") return !1;
147
- if (typeof e == "object")
148
- return e.id != null && e.id !== "" && String(t.id) === String(e.id) || e.platformName != null && e.platformName !== "" && String(t.platformName || "") === String(e.platformName).trim();
149
- const n = String(e).trim();
150
- return t.id != null && String(t.id) === n || String(t.platformName || "") === n;
151
- }
152
- function I(t) {
153
- d = Array.isArray(t) ? t : [];
154
- }
155
- function X() {
156
- d = null, p = null;
157
- }
158
- function J(t) {
159
- if (!Array.isArray(d) || !d.length) return "";
160
- const e = d.find((n) => Q(n, t));
161
- return (e == null ? void 0 : e.platformLogo) || "";
162
- }
163
- async function Z() {
164
- return d ?? (p || (p = (async () => {
165
- try {
166
- const t = await lt().listPlatformInfoAll();
167
- return I(t), d;
168
- } finally {
169
- p = null;
170
- }
171
- })(), p));
172
- }
173
- function O(t) {
174
- const e = String(t || "").trim().toUpperCase();
175
- if (/^\d{15}$/.test(e)) {
176
- const c = +`19${e.slice(6, 8)}`, o = Number(e.slice(8, 10)), u = Number(e.slice(10, 12)), m = new Date(c, o - 1, u);
177
- return m.getFullYear() === c && m.getMonth() + 1 === o && m.getDate() === u;
178
- }
179
- if (!/^\d{17}[\dX]$/.test(e)) return !1;
180
- const n = Number(e.slice(6, 10)), r = Number(e.slice(10, 12)), i = Number(e.slice(12, 14)), s = new Date(n, r - 1, i);
181
- if (s.getFullYear() !== n || s.getMonth() + 1 !== r || s.getDate() !== i) return !1;
182
- const l = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2], a = "10X98765432";
183
- let f = 0;
184
- for (let c = 0; c < 17; c++) f += Number(e[c]) * l[c];
185
- return a[f % 11] === e[17];
186
- }
187
- function C(t) {
188
- const e = String(t || "").trim().replace(/\s+/g, "");
189
- return e ? /^1\d{10}$/.test(e) || /^\+[1-9]\d{6,14}$/.test(e) : !1;
190
- }
191
- function x(t) {
192
- const e = String(t || "").trim();
193
- return e ? /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e) : !1;
194
- }
195
- function _(t) {
196
- return t == null || t === "";
197
- }
198
- function V(t, e, n) {
199
- if (_(e)) {
200
- n();
201
- return;
202
- }
203
- if (!O(e)) {
204
- n(new Error("请输入正确的身份证号(15/18位)"));
205
- return;
206
- }
207
- n();
208
- }
209
- function W(t, e, n) {
210
- if (_(e)) {
211
- n();
212
- return;
213
- }
214
- if (!C(e)) {
215
- n(new Error("请输入正确的国内或海外手机号"));
216
- return;
217
- }
218
- n();
219
- }
220
- function v(t, e, n) {
221
- if (_(e)) {
222
- n();
223
- return;
224
- }
225
- if (!x(e)) {
226
- n(new Error("请输入正确的邮箱"));
227
- return;
228
- }
229
- n();
230
- }
231
- function tt(t) {
232
- return !!(t == null || typeof t == "string" && t.trim() === "" || Array.isArray(t) && t.length === 0 || typeof t == "object" && !Array.isArray(t) && Object.keys(t).length === 0);
233
- }
234
- function T(t) {
235
- if (t === null || typeof t != "object") return t;
236
- if (t instanceof Date) return new Date(t.getTime());
237
- if (Array.isArray(t)) return t.map((n) => T(n));
238
- const e = {};
239
- return Object.keys(t).forEach((n) => {
240
- e[n] = T(t[n]);
241
- }), e;
242
- }
243
- function et(t, e = 300) {
244
- let n = null;
245
- return function(...i) {
246
- n && clearTimeout(n), n = setTimeout(() => {
247
- t.apply(this, i);
248
- }, e);
249
- };
250
- }
251
- function nt(t, e = 300) {
252
- let n = 0;
253
- return function(...i) {
254
- const s = Date.now();
255
- s - n >= e && (n = s, t.apply(this, i));
256
- };
257
- }
258
- function R(t) {
259
- if (t == null || t === "") return null;
260
- if (t instanceof Date)
261
- return Number.isNaN(t.getTime()) ? null : t;
262
- if (typeof t == "number") {
263
- const i = new Date(t);
264
- return Number.isNaN(i.getTime()) ? null : i;
265
- }
266
- const e = String(t).trim();
267
- if (!e) return null;
268
- if (/^\d{10,13}$/.test(e)) {
269
- const i = e.length === 10 ? Number(e) * 1e3 : Number(e), s = new Date(i);
270
- return Number.isNaN(s.getTime()) ? null : s;
271
- }
272
- if (/[Zz]$|[+-]\d{2}:?\d{2}$/.test(e)) {
273
- const i = new Date(e);
274
- return Number.isNaN(i.getTime()) ? null : i;
275
- }
276
- const n = e.match(
277
- /^(\d{4})[-/.年](\d{1,2})[-/.月](\d{1,2})日?(?:[\sT]+(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?(?:\.(\d{1,3}))?)?/
278
- );
279
- if (n) {
280
- const [, i, s, l, a = "0", f = "0", c = "0", o = "0"] = n, u = new Date(
281
- Number(i),
282
- Number(s) - 1,
283
- Number(l),
284
- Number(a),
285
- Number(f),
286
- Number(c),
287
- Number(String(o).padEnd(3, "0"))
288
- );
289
- return Number.isNaN(u.getTime()) ? null : u;
290
- }
291
- const r = new Date(e);
292
- return Number.isNaN(r.getTime()) ? null : r;
293
- }
294
- function w(t, e = "YYYY-MM-DD HH:mm:ss") {
295
- const n = R(t);
296
- if (!n) return "";
297
- const r = n.getFullYear(), i = n.getMonth() + 1, s = n.getDate(), l = n.getHours(), a = n.getMinutes(), f = n.getSeconds(), c = {
298
- YYYY: String(r),
299
- MM: String(i).padStart(2, "0"),
300
- DD: String(s).padStart(2, "0"),
301
- HH: String(l).padStart(2, "0"),
302
- mm: String(a).padStart(2, "0"),
303
- ss: String(f).padStart(2, "0"),
304
- M: String(i),
305
- D: String(s),
306
- H: String(l),
307
- m: String(a),
308
- s: String(f)
309
- };
310
- return e.replace(/YYYY|MM|DD|HH|mm|ss|M|D|H|m|s/g, (o) => c[o]);
311
- }
312
- function rt() {
313
- const t = /* @__PURE__ */ new Date();
314
- t.setHours(23, 59, 59, 0);
315
- const e = /* @__PURE__ */ new Date();
316
- return e.setDate(e.getDate() - 30), e.setHours(0, 0, 0, 0), {
317
- start: w(e, "YYYY-MM-DD HH:mm:ss"),
318
- end: w(t, "YYYY-MM-DD HH:mm:ss")
319
- };
320
- }
321
- function h(t) {
322
- const e = {};
323
- return Object.keys(t || {}).forEach((n) => {
324
- const r = t[n];
325
- r == null || r === "" || Array.isArray(r) && r.length === 0 || (e[n] = r);
326
- }), e;
327
- }
328
- function it(t) {
329
- return t == null || t === "" ? "-" : t;
330
- }
331
- function M(t, e = 2) {
332
- if (!Number.isFinite(t)) return t;
333
- const n = Math.max(0, Math.floor(Number(e) || 0));
334
- return +(Math.round(+`${t}e${n}`) + `e-${n}`);
335
- }
336
- function E(t, e = 2) {
337
- if (t == null || t === "") return "-";
338
- const n = Number(t);
339
- if (Number.isNaN(n)) return t;
340
- const r = M(n, e).toFixed(e), [i, s] = r.split("."), l = i.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
341
- if (s == null) return l;
342
- const a = s.replace(/0+$/, "");
343
- return a ? `${l}.${a}` : l;
344
- }
345
- function st(t) {
346
- if (t == null || t === "") return "-";
347
- const e = Number(t);
348
- return Number.isNaN(e) ? "-" : Math.abs(e) > 1e4 ? `${E(e / 1e4, 2)}w` : String(E(e, 0));
349
- }
350
- function ot(t, e = 4, n = "toDecimal") {
351
- if (n === "toPercent" || n === "toPercentText") {
352
- if (t == null || t === "") return n === "toPercentText" ? "-" : t;
353
- const i = Number(t);
354
- if (!Number.isFinite(i) || Number.isNaN(i)) return n === "toPercentText" ? "-" : t;
355
- if (i === 0) return n === "toPercentText" ? "0%" : 0;
356
- const s = Number(String(Number((i * 100).toFixed(2))).replace(/(?:\.0*|(\.\d+?)0+)$/, "$1"));
357
- return n === "toPercentText" ? `${s}%` : s;
358
- }
359
- if (t === "" || t == null) return;
360
- const r = Number(t);
361
- if (Number.isFinite(r))
362
- return Number((r / 100).toFixed(e));
363
- }
364
- function ut(t) {
365
- if (t === "" || t == null) return "";
366
- const e = Number(t);
367
- return Number.isFinite(e) ? e : "";
368
- }
369
- function ct(t, e = 2, n = 9999999999999) {
370
- if (t === 0 || t === "0") return 0;
371
- if (t == null || t === "") return "";
372
- let r = Number(t);
373
- if (!Number.isFinite(r)) return "";
374
- const i = Number(n), s = Number.isFinite(i) ? Math.abs(i) : 9999999999999;
375
- return Math.abs(r) >= s && (r = r < 0 ? -s : s), Number.isInteger(r) ? r : M(r, e);
376
- }
377
- function at(t = "id") {
378
- return `${t}_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
379
- }
380
- const yt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
381
- __proto__: null,
382
- cleanNumber: ct,
383
- cleanParams: h,
384
- clearPlatformCache: X,
385
- debounce: et,
386
- deepClone: T,
387
- downloadBlob: Y,
388
- exportFile: k,
389
- findPlatformLogo: J,
390
- formatDate: w,
391
- formatEmpty: it,
392
- formatFansCount: st,
393
- formatNum: E,
394
- getRecentMonthRange: rt,
395
- isEmail: x,
396
- isEmpty: tt,
397
- isMainlandIdCard: O,
398
- isMobile: C,
399
- parseDate: R,
400
- preloadPlatformList: Z,
401
- roundHalfUp: M,
402
- setPlatformCache: I,
403
- throttle: nt,
404
- toNumberOrEmpty: ut,
405
- toRebateRatio: ot,
406
- uniqueId: at,
407
- validateEmail: v,
408
- validateIdCardNo: V,
409
- validateMobile: W
410
- }, Symbol.toStringTag, { value: "Module" }));
411
- function bt(t) {
412
- if (!t)
413
- throw new Error("[mgacn-commonsdk] createApi 需要传入 request 实例");
414
- return {
415
- // ---------- 注销登录 ----------
416
- logout(e) {
417
- return t.GET(`/yhAdmin/login/exit/${e}`);
418
- },
419
- // ---------- 用户 ----------
420
- getUserInfo(e) {
421
- return t.GET(`/yhAdmin/user/queryUser/${e}`);
422
- },
423
- /**
424
- * 用户下拉选择列表
425
- * POST /yhAdmin/user/listForSelect
426
- * @param {object} [params]
427
- * @param {0|1} [params.status] 0 正常/有效,1 禁用/锁定;不传查全部
428
- * @param {0|1} [params.isDelete] 0 否,1 是;不传默认查未删除
429
- * @param {string} [params.realName] 真实姓名,模糊
430
- * @param {string} [params.username] 登录账号/工号,模糊
431
- * @param {string} [params.mobile] 手机号,模糊
432
- * @param {string} [params.openId] 第三方 openId,模糊
433
- * @param {string} [params.createTimeStart]
434
- * @param {string} [params.createTimeEnd]
435
- * @param {string} [params.updateTimeStart]
436
- * @param {string} [params.updateTimeEnd]
437
- * @returns {Promise<Array>} 用户列表(兼容 result / list / 直接数组)
438
- */
439
- async listUserForSelect(e = {}) {
440
- const n = await t.POST("/yhAdmin/user/listForSelect", h(e));
441
- return Array.isArray(n) ? n : Array.isArray(n == null ? void 0 : n.result) ? n.result : Array.isArray(n == null ? void 0 : n.list) ? n.list : [];
442
- },
443
- /**
444
- * 按角色名称查询用户列表(下拉)
445
- * POST /yhAdmin/user/queryUserByRoleName
446
- * systemId 由组件库自动填充,宿主勿传
447
- * @param {object} params
448
- * @param {string} params.roleName 角色名称
449
- */
450
- async queryByRoleName(e = {}) {
451
- const { systemId: n, ...r } = e && typeof e == "object" ? e : {}, i = await t.POST(
452
- "/yhAdmin/user/queryUserByRoleName",
453
- h({
454
- ...r,
455
- systemId: S()
456
- })
457
- );
458
- return Array.isArray(i) ? i : Array.isArray(i == null ? void 0 : i.result) ? i.result : Array.isArray(i == null ? void 0 : i.list) ? i.list : [];
459
- },
460
- /**
461
- * 媒介供应商全量列表(下拉)
462
- * GET /yhAccount/mediaSupplier/listAll
463
- */
464
- listMediaSupplierAll() {
465
- return t.GET("/yhAccount/mediaSupplier/listAll");
466
- },
467
- /**
468
- * 账号库平台配置全量列表(下拉)
469
- * GET /yhAccount/platformInfo/listAll
470
- */
471
- listPlatformInfoAll() {
472
- return t.GET("/yhAccount/platformInfo/listAll");
473
- },
474
- /**
475
- * 标签配置全量列表
476
- * GET /yhShared/tagConfig/queryAllTagConfigs
477
- * @param {object} [params]
478
- * @param {string} [params.businessKey]
479
- */
480
- queryAllTagConfigs(e = {}) {
481
- return t.GET("/yhShared/tagConfig/queryAllTagConfigs", {
482
- params: h(e)
483
- });
484
- },
485
- /**
486
- * 写入埋点数据
487
- * POST /yhAdmin/trace/addTraceData
488
- * userId / projectId(系统 id) / clientType 由组件库自动填充,宿主勿传
489
- * @param {object} params 宿主业务参数
490
- * @param {string} params.traceId 事件 ID
491
- * @param {string} [params.route] 页面路由
492
- * @param {string} [params.wxUserId] 微信用户 ID
493
- */
494
- addTraceData(e = {}) {
495
- const { userId: n, projectId: r, clientType: i, ...s } = e && typeof e == "object" ? e : {};
496
- return t.POST(
497
- "/yhAdmin/trace/addTraceData",
498
- h({
499
- ...s,
500
- userId: K(),
501
- projectId: S(),
502
- clientType: 1
503
- })
504
- );
505
- },
506
- // ---------- OSS ----------
507
- getOssSts(e) {
508
- return t.GET("/yhAdmin/oss/getStsToken", { params: { dir: e } });
509
- }
510
- };
511
- }
512
- const j = "__MGACN_COMMONSDK_API__";
513
- function ht(t) {
514
- globalThis[j] = t;
515
- }
516
- function lt() {
517
- const t = globalThis[j];
518
- if (!t)
519
- throw new Error("[mgacn-commonsdk] 请先 app.use(MgacnCommonSdk, { tokenKey, baseURL })");
520
- return t;
521
- }
522
- const U = "__MGACN_COMMONSDK_PERMISSION_GETTER__";
523
- function Nt(t) {
524
- globalThis[U] = typeof t == "function" ? t : null;
525
- }
526
- function ft() {
527
- return globalThis[U] || null;
528
- }
529
- function mt(t, e, n = "and") {
530
- const r = (Array.isArray(e) ? e : [e]).map((s) => String(s ?? "").trim()).filter(Boolean);
531
- if (!r.length) return !0;
532
- const i = new Set((t || []).map(String));
533
- return n === "or" ? r.some((s) => i.has(s)) : r.every((s) => i.has(s));
534
- }
535
- function St(t, e = "and") {
536
- const n = ft();
537
- return typeof n != "function" ? !0 : mt(n(), t, e);
538
- }
539
- const Tt = (t, e) => {
540
- const n = t.__vccOpts || t;
541
- for (const [r, i] of e)
542
- n[r] = i;
543
- return n;
544
- };
545
- export {
546
- Tt as _,
547
- G as a,
548
- B as b,
549
- mt as c,
550
- T as d,
551
- h as e,
552
- et as f,
553
- lt as g,
554
- E as h,
555
- it as i,
556
- St as j,
557
- Nt as k,
558
- gt as l,
559
- bt as m,
560
- pt as n,
561
- ht as o,
562
- L as p,
563
- ft as q,
564
- S as r,
565
- H as s,
566
- ot as t,
567
- K as u,
568
- yt as v
569
- };