magtool 1.0.9 → 1.1.2
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/util.js +89 -92
- package/package.json +2 -2
package/dist/util.js
CHANGED
|
@@ -1,166 +1,163 @@
|
|
|
1
1
|
const j = (c) => {
|
|
2
2
|
window.$getLang = () => localStorage.getItem("lang");
|
|
3
|
-
const
|
|
4
|
-
const { alpha:
|
|
5
|
-
return `${
|
|
3
|
+
const w = (e = {}) => {
|
|
4
|
+
const { alpha: o, name: t } = e, n = ["blue", "red", "orange", "green", "pink", "yellow", "purple", "primary", "dark"], r = ["", 1, 3, 5, 7];
|
|
5
|
+
return `${t || n[parseInt(Math.random() * n.length)]}${o === 0 ? "" : r[parseInt(Math.random() * r.length)]}`;
|
|
6
6
|
};
|
|
7
|
-
window.$randomColor =
|
|
8
|
-
let
|
|
9
|
-
return
|
|
7
|
+
window.$randomColor = w, window.$rc = w, c.config.globalProperties.$rc = w, window.$rn = (e, o = 0) => {
|
|
8
|
+
let t = parseInt(Math.random() * e);
|
|
9
|
+
return t += o, t;
|
|
10
10
|
}, window.$elc = (e = {}) => {
|
|
11
|
-
let { i:
|
|
11
|
+
let { i: o = 0, color: t } = e;
|
|
12
12
|
const n = window.global.config.color;
|
|
13
|
-
return
|
|
13
|
+
return t = t || n[o], { type: "linear", x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: t + "FF" }, { offset: 1, color: t + "00" }] };
|
|
14
14
|
}, window.$egc = (e = {}) => {
|
|
15
|
-
let { i:
|
|
15
|
+
let { i: o = 0, color: t } = e;
|
|
16
16
|
const n = window.global.config.color;
|
|
17
|
-
return
|
|
18
|
-
}, window.$fd = (e,
|
|
19
|
-
let
|
|
20
|
-
for (let n = 0; n < e; n++)
|
|
21
|
-
return
|
|
17
|
+
return t = t || n[o], { type: "radial", x: 0.1, y: 0.5, r: 1, colorStops: [{ offset: 0, color: t + "00" }, { offset: 1, color: t + "FF" }] };
|
|
18
|
+
}, window.$fd = (e, o) => {
|
|
19
|
+
let t = [];
|
|
20
|
+
for (let n = 0; n < e; n++) t.push(o(n));
|
|
21
|
+
return t;
|
|
22
22
|
}, c.config.globalProperties.$setTimeout = function(e = () => {
|
|
23
|
-
},
|
|
23
|
+
}, o) {
|
|
24
24
|
this.timer && (clearTimeout(this.timer), this.timer = null), this.timer = setTimeout(() => {
|
|
25
25
|
e(), clearTimeout(this.timer);
|
|
26
|
-
},
|
|
26
|
+
}, o);
|
|
27
27
|
};
|
|
28
|
-
const
|
|
29
|
-
c.config.globalProperties.$toUpperCamel =
|
|
30
|
-
const
|
|
31
|
-
const
|
|
28
|
+
const u = (e) => e.substr(0, 1).toUpperCase() + e.substr(1, e.length).toLowerCase();
|
|
29
|
+
c.config.globalProperties.$toUpperCamel = u, window.$toUpperCamel = u;
|
|
30
|
+
const g = (e, o = 2) => {
|
|
31
|
+
const t = window.$getType(e);
|
|
32
32
|
let n;
|
|
33
|
-
|
|
33
|
+
t === "Number" ? (e = e.toFixed(o), n = String(e), e = String(Math.abs(e))) : t === "String" && (n = e, e = String(Math.abs(Number(e))));
|
|
34
34
|
const r = e.split(".");
|
|
35
35
|
let i = r[0].split("");
|
|
36
36
|
i = i.reverse();
|
|
37
37
|
let p = [];
|
|
38
|
-
i.forEach((
|
|
39
|
-
|
|
38
|
+
i.forEach((T, y) => {
|
|
39
|
+
y !== 0 && y % 3 == 0 && p.push(","), p.push(T);
|
|
40
40
|
});
|
|
41
|
-
let
|
|
42
|
-
return window.$getType(
|
|
41
|
+
let l = p.reverse().join("");
|
|
42
|
+
return window.$getType(o) === "Number" && o > 0 && (l += ".", r[1] ? l += r[1].padEnd(o, 0).substr(0, o) : l += "0".padEnd(o, "0")), Number(n) !== Number(e) ? `-${l}` : l;
|
|
43
43
|
};
|
|
44
|
-
window.$fa =
|
|
45
|
-
const
|
|
44
|
+
window.$fa = g, c.config.globalProperties.$fa = g;
|
|
45
|
+
const f = ({ prop: e, currency: o, value: t, obj: n = window.$map.asa.asaMetric.allObj }) => {
|
|
46
46
|
const r = n[e];
|
|
47
|
-
return r.unit === "currency" ?
|
|
47
|
+
return r.unit === "currency" ? o ? `${o} ${window.$fa(t, r == null ? void 0 : r.precision)}` : window.$fa(t, r == null ? void 0 : r.precision) : r.unit === "%" ? `${window.$fa(t, r == null ? void 0 : r.precision)}%` : window.$fa(t, r == null ? void 0 : r.precision);
|
|
48
48
|
};
|
|
49
|
-
window.$fu2 =
|
|
50
|
-
const
|
|
51
|
-
},
|
|
52
|
-
let
|
|
49
|
+
window.$fu2 = f, c.config.globalProperties.$fu2 = f;
|
|
50
|
+
const m = (e = () => {
|
|
51
|
+
}, o = 2) => {
|
|
52
|
+
let t = null;
|
|
53
53
|
return new Promise((n, r) => {
|
|
54
|
-
|
|
55
|
-
e(n, r), clearTimeout(
|
|
56
|
-
}, 100 *
|
|
54
|
+
t = setTimeout(() => {
|
|
55
|
+
e(n, r), clearTimeout(t), n(!0);
|
|
56
|
+
}, 100 * o);
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
|
-
window.$pm =
|
|
60
|
-
const
|
|
61
|
-
},
|
|
62
|
-
let
|
|
59
|
+
window.$pm = m, window.$promise = m;
|
|
60
|
+
const $ = (e = () => {
|
|
61
|
+
}, o = 500) => {
|
|
62
|
+
let t;
|
|
63
63
|
return function(...n) {
|
|
64
|
-
|
|
64
|
+
t && clearTimeout(t), t = setTimeout(() => {
|
|
65
65
|
e.apply(this, n);
|
|
66
|
-
},
|
|
66
|
+
}, o);
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
|
-
window.$db =
|
|
69
|
+
window.$db = $, window.$debounce = $, Number.prototype.toFixedNumber = function(e) {
|
|
70
70
|
return Number(this.toFixed(e));
|
|
71
71
|
}, Array.prototype.filter1 = function(e) {
|
|
72
72
|
if (!e || typeof e != "function") throw new Error(e + " is not a function");
|
|
73
|
-
let
|
|
73
|
+
let o, t;
|
|
74
74
|
for (let n = 0; n < this.length; n++) if (e(this[n], n, this)) {
|
|
75
|
-
|
|
75
|
+
t = n, o = this[n];
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
|
-
return { index:
|
|
78
|
+
return { index: t, data: o };
|
|
79
79
|
}, window.$getType = (e) => Object.prototype.toString.call(e).slice(8, -1);
|
|
80
|
-
const
|
|
80
|
+
const b = (e, o) => {
|
|
81
81
|
if (!e) return;
|
|
82
|
-
const
|
|
82
|
+
const t = window.$l("Copied");
|
|
83
83
|
let n;
|
|
84
|
-
if (n =
|
|
85
|
-
c.config.globalProperties.$message.success({ message: n, center: !0, duration:
|
|
84
|
+
if (n = o ? window.$getType(o) !== "Boolean" ? `${t} ${o}: ${e}` : `${t}: ${e}` : t, navigator.clipboard && window.isSecureContext) navigator.clipboard.writeText(e).then(() => {
|
|
85
|
+
c.config.globalProperties.$message.success({ message: n, center: !0, duration: 5e3 });
|
|
86
86
|
});
|
|
87
87
|
else {
|
|
88
88
|
let r = document.createElement("textarea");
|
|
89
|
-
r.value = e, r.style.position = "fixed", r.style.opacity = 0, document.body.appendChild(r), r.select(), document.execCommand("Copy"), r.remove(), c.config.globalProperties.$message.success({ message: n, center: !0, duration:
|
|
89
|
+
r.value = e, r.style.position = "fixed", r.style.opacity = 0, document.body.appendChild(r), r.select(), document.execCommand("Copy"), r.remove(), c.config.globalProperties.$message.success({ message: n, center: !0, duration: 5e3 });
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
window.$copy =
|
|
93
|
-
const
|
|
94
|
-
window.$nr = (e,
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
}, window.$nro = (e,
|
|
98
|
-
objMap[
|
|
92
|
+
window.$copy = b, c.config.globalProperties.$copy = b, window.$sc = (e) => e < 1e3 ? e : e < 1e6 ? parseInt(e / 1e3) + "K" : parseInt(e / 1e6) + "M";
|
|
93
|
+
const v = { cpa: "avgCPA", cpt: "avgCPT" };
|
|
94
|
+
window.$nr = (e, o = v) => {
|
|
95
|
+
const t = o[e.name];
|
|
96
|
+
t && (e.name = t);
|
|
97
|
+
}, window.$nro = (e, o) => (Object.keys(e).forEach((t) => {
|
|
98
|
+
objMap[t] && (e[objMap[t]] = e[t], delete e[t]);
|
|
99
99
|
}), e), window.$pc = (e) => {
|
|
100
|
-
let
|
|
101
|
-
return Object.keys(e).forEach((
|
|
102
|
-
(window.$getType(e[
|
|
103
|
-
}),
|
|
100
|
+
let o = 0;
|
|
101
|
+
return Object.keys(e).forEach((t) => {
|
|
102
|
+
(window.$getType(e[t]) === "Array" && e[t].length !== 0 || e[t]) && o++;
|
|
103
|
+
}), o;
|
|
104
104
|
};
|
|
105
|
-
const
|
|
105
|
+
const s = (e = "info", o) => {
|
|
106
106
|
e === "success" && (e = "info");
|
|
107
107
|
};
|
|
108
108
|
window.$console = { info: (...e) => {
|
|
109
|
-
|
|
109
|
+
s("info");
|
|
110
110
|
}, log: (...e) => {
|
|
111
|
-
|
|
111
|
+
s("log");
|
|
112
112
|
}, error: (...e) => {
|
|
113
|
-
|
|
113
|
+
s("error");
|
|
114
114
|
}, warn: (...e) => {
|
|
115
|
-
|
|
115
|
+
s("warn");
|
|
116
116
|
}, success: (...e) => {
|
|
117
|
-
|
|
118
|
-
} }, window.$loadImage = (e) => new Promise((
|
|
117
|
+
s("success");
|
|
118
|
+
} }, window.$loadImage = (e) => new Promise((o, t) => {
|
|
119
119
|
const n = new Image();
|
|
120
|
-
n.src = window.$getType(e) === "String" ? e : URL.createObjectURL(e), n.onload = () =>
|
|
121
|
-
}), window.$loadVideo = (e) => new Promise((
|
|
120
|
+
n.src = window.$getType(e) === "String" ? e : URL.createObjectURL(e), n.onload = () => o(n), n.onerror = () => t(new Error("Could not load image"));
|
|
121
|
+
}), window.$loadVideo = (e) => new Promise((o, t) => {
|
|
122
122
|
const n = document.createElement("video");
|
|
123
123
|
n.preload = "metadata", window.$getType(e) === "String" ? n.src = e : n.src = URL.createObjectURL(e), n.onloadedmetadata = () => {
|
|
124
|
-
window.URL.revokeObjectURL(e),
|
|
124
|
+
window.URL.revokeObjectURL(e), o(n);
|
|
125
125
|
};
|
|
126
126
|
});
|
|
127
|
-
const
|
|
127
|
+
const h = (e) => {
|
|
128
128
|
if (e && window.$getType(e) === "Object") {
|
|
129
|
-
const
|
|
130
|
-
return Object.keys(e).forEach((
|
|
131
|
-
const n = e[
|
|
129
|
+
const o = {};
|
|
130
|
+
return Object.keys(e).forEach((t) => {
|
|
131
|
+
const n = e[t];
|
|
132
132
|
switch (window.$getType(n)) {
|
|
133
133
|
case "Object":
|
|
134
|
-
Object.keys(n) !== 0 && (t
|
|
134
|
+
Object.keys(n) !== 0 && (o[t] = n);
|
|
135
135
|
break;
|
|
136
136
|
case "Array":
|
|
137
|
-
n.length !== 0 && (t
|
|
137
|
+
n.length !== 0 && (o[t] = n);
|
|
138
138
|
break;
|
|
139
139
|
case "String":
|
|
140
|
-
n && (t
|
|
140
|
+
n && (o[t] = n.toLowerCase());
|
|
141
141
|
break;
|
|
142
142
|
default:
|
|
143
|
-
[void 0, null, ""].indexOf(n) === -1 && (t
|
|
143
|
+
[void 0, null, ""].indexOf(n) === -1 && (o[t] = n);
|
|
144
144
|
}
|
|
145
|
-
}),
|
|
145
|
+
}), o;
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
|
-
window.$removeEmptyParams =
|
|
149
|
-
let a = null,
|
|
148
|
+
window.$removeEmptyParams = h, window.$rep = h;
|
|
149
|
+
let a = null, d = null;
|
|
150
150
|
window.$download = async (e) => {
|
|
151
|
-
let { type:
|
|
152
|
-
if (a = document.createElement("a"),
|
|
151
|
+
let { type: o = "img", url: t, name: n, data: r } = e;
|
|
152
|
+
if (a = document.createElement("a"), o === "csv") {
|
|
153
153
|
const i = new Blob(["\uFEFF" + r], { type: "text/csv,charset=UTF-8" });
|
|
154
154
|
a.href = URL.createObjectURL(i);
|
|
155
|
-
} else
|
|
156
|
-
const { access_token: i, scope: p, token_type: s } = store.launch().login.info, l = {};
|
|
157
|
-
t === "excel" && (l.method = l.method || "GET", l.headers = { [p]: `${s} ${i}` }), await fetch(o, l).then((w) => w.blob()).then((w) => {
|
|
158
|
-
a.href = URL.createObjectURL(w);
|
|
159
|
-
});
|
|
160
|
-
} else (t = "table") ? await fetch(o).then((i) => i.blob()).then((i) => {
|
|
155
|
+
} else o === "video" || o === "excel" ? await fetch(t, e).then((i) => i.blob()).then((i) => {
|
|
161
156
|
a.href = URL.createObjectURL(i);
|
|
162
|
-
}) :
|
|
163
|
-
|
|
157
|
+
}) : (o = "table") ? await fetch(t).then((i) => i.blob()).then((i) => {
|
|
158
|
+
a.href = URL.createObjectURL(i);
|
|
159
|
+
}) : a.href = t;
|
|
160
|
+
d = new MouseEvent("click"), a.download = n || "download", a.dispatchEvent(d), o !== "csv" && o !== "video" || URL.revokeObjectURL(a.url), a = null, d = null;
|
|
164
161
|
};
|
|
165
162
|
};
|
|
166
163
|
export {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magtool",
|
|
3
3
|
"packageManager": "yarn@4.4.1",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"author": "magxl",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dist/*"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"magtool": "^1.0.
|
|
38
|
+
"magtool": "^1.0.9",
|
|
39
39
|
"moment": "^2.30.1",
|
|
40
40
|
"pinia": "^3.0.0",
|
|
41
41
|
"vue": "^3.3.4"
|