magtool 1.0.6 → 1.0.7

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/directive.js CHANGED
@@ -1,23 +1,30 @@
1
- const c = (o) => {
2
- o.directive("focus", {
3
- mounted(t, i, m) {
1
+ const m = (o) => {
2
+ o.directive("copy", {
3
+ mounted(t, i) {
4
+ let { value: l, arg: e } = i;
5
+ t.onclick = () => {
6
+ window.$copy(l, e);
7
+ };
8
+ }
9
+ }), o.directive("focus", {
10
+ mounted(t, i, l) {
4
11
  let { value: e = 0, arg: d = "time" } = i;
5
12
  if (e === null)
6
13
  return;
7
- let r = 100, l = 0;
8
- d !== "time" ? l = e : r = Number(e);
14
+ let c = 100, r = 0;
15
+ d !== "time" ? r = e : c = Number(e);
9
16
  const n = setTimeout(() => {
10
17
  let u = t.querySelectorAll("input, textarea");
11
- u[l].focus(), u[l].select(), clearTimeout(n);
12
- }, r);
18
+ u[r].focus(), u[r].select(), clearTimeout(n);
19
+ }, c);
13
20
  }
14
21
  }), o.directive("pms", {
15
- mounted(t, i, m) {
22
+ mounted(t, i, l) {
16
23
  var e;
17
24
  (e = i.value) != null && e.readonly && t.remove();
18
25
  }
19
26
  });
20
27
  };
21
28
  export {
22
- c as d
29
+ m as d
23
30
  };
package/dist/index.js CHANGED
@@ -1,11 +1,17 @@
1
- import r from "moment";
1
+ import _ from "moment";
2
2
  import { c as t } from "./cps.js";
3
- import { d as m } from "./util.js";
4
- import { d as i } from "./directive.js";
5
- import { s } from "./store.js";
6
- const c = (o, e) => (o.use(m).use(i), window.$m = r, {
3
+ import { d as s } from "./util.js";
4
+ import { d as e } from "./directive.js";
5
+ import { s as i } from "./store.js";
6
+ const c = (o, m) => (o.use(s).use(e), localStorage.getItem("lang").includes("cn") && _.locale("zh-cn", {
7
+ months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),
8
+ monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),
9
+ weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),
10
+ weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"),
11
+ weekdaysMin: "日_一_二_三_四_五_六".split("_")
12
+ }), window.$m = _, window.$moment = _, {
7
13
  composition: t,
8
- store: s
14
+ store: i
9
15
  });
10
16
  export {
11
17
  c as default
package/dist/util.js CHANGED
@@ -1,132 +1,191 @@
1
1
  const M = (i) => {
2
- const b = (e, t = 0) => {
2
+ window.$getLang = () => localStorage.getItem("lang");
3
+ const u = (e = {}) => {
4
+ const { alpha: n, name: o } = e, t = [
5
+ "blue",
6
+ "red",
7
+ "orange",
8
+ "green",
9
+ "pink",
10
+ "yellow",
11
+ "purple",
12
+ "primary",
13
+ "dark"
14
+ ], r = ["", 1, 3, 5, 7], c = o || t[parseInt(Math.random() * t.length)], l = n === 0 ? "" : r[parseInt(Math.random() * r.length)];
15
+ return `${c}${l}`;
16
+ };
17
+ window.$randomColor = u, window.$rc = u, i.config.globalProperties.$rc = u;
18
+ const U = (e, n = 0) => {
3
19
  let o = parseInt(Math.random() * e);
4
- return o += t, o;
20
+ return o += n, o;
5
21
  };
6
- window.$rn = b;
7
- const $ = (e, t) => {
22
+ window.$rn = U, window.$elc = (e = {}) => {
23
+ let { i: n = 0, color: o } = e;
24
+ const t = window.global.config.color;
25
+ o = o || t[n];
26
+ const r = o + "FF", c = o + "00";
27
+ return {
28
+ type: "linear",
29
+ x: 0,
30
+ y: 0,
31
+ x2: 0,
32
+ y2: 1,
33
+ colorStops: [
34
+ {
35
+ offset: 0,
36
+ color: r
37
+ },
38
+ {
39
+ offset: 1,
40
+ color: c
41
+ }
42
+ ]
43
+ };
44
+ }, window.$egc = (e = {}) => {
45
+ let { i: n = 0, color: o } = e;
46
+ const t = window.global.config.color;
47
+ o = o || t[n];
48
+ const r = o + "FF";
49
+ return {
50
+ type: "radial",
51
+ x: 0.1,
52
+ y: 0.5,
53
+ r: 1,
54
+ colorStops: [
55
+ {
56
+ offset: 0,
57
+ color: o + "00"
58
+ },
59
+ {
60
+ offset: 1,
61
+ color: r
62
+ }
63
+ ]
64
+ };
65
+ };
66
+ const C = (e, n) => {
8
67
  let o = [];
9
- for (let r = 0; r < e; r++)
10
- o.push(t(r));
68
+ for (let t = 0; t < e; t++)
69
+ o.push(n(t));
11
70
  return o;
12
71
  };
13
- window.$fd = $, i.config.globalProperties.$setTimeout = function(e = () => {
14
- }, t) {
72
+ window.$fd = C, i.config.globalProperties.$setTimeout = function(e = () => {
73
+ }, n) {
15
74
  this.timer && (clearTimeout(this.timer), this.timer = null), this.timer = setTimeout(() => {
16
75
  e(), clearTimeout(this.timer);
17
- }, t);
76
+ }, n);
18
77
  };
19
- const y = (e) => e.substr(0, 1).toUpperCase() + e.substr(1, e.length).toLowerCase();
20
- window.$toUpperCamel = y;
21
- const f = (e, t = 2) => {
78
+ const p = (e) => e.substr(0, 1).toUpperCase() + e.substr(1, e.length).toLowerCase();
79
+ i.config.globalProperties.$toUpperCamel = p, window.$toUpperCamel = p;
80
+ const g = (e, n = 2) => {
22
81
  const o = window.$getType(e);
23
- let r;
24
- o === "Number" ? (e = e.toFixed(t), r = String(e), e = String(Math.abs(e))) : o === "String" && (r = e, e = String(Math.abs(Number(e))));
25
- const n = e.split(".");
26
- let a = n[0].split("");
27
- a = a.reverse();
82
+ let t;
83
+ o === "Number" ? (e = e.toFixed(n), t = String(e), e = String(Math.abs(e))) : o === "String" && (t = e, e = String(Math.abs(Number(e))));
84
+ const r = e.split(".");
85
+ let c = r[0].split("");
86
+ c = c.reverse();
28
87
  let l = [];
29
- a.forEach((N, m) => {
30
- m !== 0 && m % 3 === 0 && l.push(","), l.push(N);
88
+ c.forEach((d, T) => {
89
+ T !== 0 && T % 3 === 0 && l.push(","), l.push(d);
31
90
  });
32
- let c = l.reverse().join("");
33
- return window.$getType(t) === "Number" && t > 0 && (c += ".", n[1] ? c += n[1].padEnd(t, 0).substr(0, t) : c += "0".padEnd(t, "0")), Number(r) !== Number(e) ? `-${c}` : c;
91
+ let a = l.reverse().join("");
92
+ return window.$getType(n) === "Number" && n > 0 && (a += ".", r[1] ? a += r[1].padEnd(n, 0).substr(0, n) : a += "0".padEnd(n, "0")), Number(t) !== Number(e) ? `-${a}` : a;
34
93
  };
35
- window.$fa = f, i.config.globalProperties.$fa = f;
36
- const u = ({
94
+ window.$fa = g, i.config.globalProperties.$fa = g;
95
+ const m = ({
37
96
  prop: e,
38
- currency: t,
97
+ currency: n,
39
98
  value: o,
40
- obj: r = window.$map.asa.asaMetric.allObj
99
+ obj: t = window.$map.asa.asaMetric.allObj
41
100
  }) => {
42
- const n = r[e];
43
- return n.unit === "currency" ? t ? `${t} ${window.$fa(o, n == null ? void 0 : n.precision)}` : window.$fa(o, n == null ? void 0 : n.precision) : n.unit === "%" ? `${window.$fa(o, n == null ? void 0 : n.precision)}%` : window.$fa(o, n == null ? void 0 : n.precision);
101
+ const r = t[e];
102
+ return r.unit === "currency" ? n ? `${n} ${window.$fa(o, r == null ? void 0 : r.precision)}` : window.$fa(o, r == null ? void 0 : r.precision) : r.unit === "%" ? `${window.$fa(o, r == null ? void 0 : r.precision)}%` : window.$fa(o, r == null ? void 0 : r.precision);
44
103
  };
45
- window.$fu = u, i.config.globalProperties.$fu = u;
46
- const d = (e = () => {
47
- }, t = 2) => {
104
+ window.$fu2 = m, i.config.globalProperties.$fu2 = m;
105
+ const b = (e = () => {
106
+ }, n = 2) => {
48
107
  let o = null;
49
- return new Promise((r, n) => {
50
- o = setTimeout(async () => {
51
- await e(r, n), await clearTimeout(o), await r(!0);
52
- }, t * 100);
108
+ return new Promise((t, r) => {
109
+ o = setTimeout(() => {
110
+ e(t, r), clearTimeout(o), t(!0);
111
+ }, n * 100);
53
112
  });
54
113
  };
55
- window.$pm = d, window.$promise = d;
56
- const w = (e = () => {
57
- }, t = 500) => {
114
+ window.$pm = b, window.$promise = b;
115
+ const $ = (e = () => {
116
+ }, n = 500) => {
58
117
  let o;
59
- return function(...r) {
118
+ return function(...t) {
60
119
  o && clearTimeout(o), o = setTimeout(() => {
61
- e.apply(this, r);
62
- }, t);
120
+ e.apply(this, t);
121
+ }, n);
63
122
  };
64
123
  };
65
- window.$db = w, window.$debounce = w, Number.prototype.toFixedNumber = function(e) {
124
+ window.$db = $, window.$debounce = $, Number.prototype.toFixedNumber = function(e) {
66
125
  return Number(this.toFixed(e));
67
126
  }, Array.prototype.filter1 = function(e) {
68
127
  if (!e || typeof e != "function")
69
128
  throw new Error(e + " is not a function");
70
- let t, o;
71
- for (let r = 0; r < this.length; r++)
72
- if (e(this[r], r, this)) {
73
- o = r, t = this[r];
129
+ let n, o;
130
+ for (let t = 0; t < this.length; t++)
131
+ if (e(this[t], t, this)) {
132
+ o = t, n = this[t];
74
133
  break;
75
134
  }
76
135
  return {
77
136
  index: o,
78
- data: t
137
+ data: n
79
138
  };
80
139
  }, window.$getType = (e) => Object.prototype.toString.call(e).slice(8, -1);
81
- const p = (e, t) => {
140
+ const h = (e, n) => {
82
141
  if (!e) {
83
142
  console.info("No Value");
84
143
  return;
85
144
  }
86
145
  const o = window.$l("Copied");
87
- let r;
88
- if (t ? window.$getType(t) !== "Boolean" ? r = `${o} ${t}: ${e}` : r = `${o}: ${e}` : r = o, navigator.clipboard && window.isSecureContext)
146
+ let t;
147
+ if (n ? window.$getType(n) !== "Boolean" ? t = `${o} ${n}: ${e}` : t = `${o}: ${e}` : t = o, navigator.clipboard && window.isSecureContext)
89
148
  navigator.clipboard.writeText(e).then(() => {
90
149
  i.config.globalProperties.$message.success({
91
- message: r,
150
+ message: t,
92
151
  // grouping: true,
93
152
  center: !0,
94
153
  duration: 0
95
154
  });
96
155
  });
97
156
  else {
98
- let n = document.createElement("textarea");
99
- n.value = e, n.style.position = "fixed", n.style.opacity = 0, document.body.appendChild(n), n.select(), document.execCommand("Copy"), n.remove(), i.config.globalProperties.$message.success({
100
- message: r,
157
+ let r = document.createElement("textarea");
158
+ r.value = e, r.style.position = "fixed", r.style.opacity = 0, document.body.appendChild(r), r.select(), document.execCommand("Copy"), r.remove(), i.config.globalProperties.$message.success({
159
+ message: t,
101
160
  // grouping: true,
102
161
  center: !0,
103
162
  duration: 0
104
163
  });
105
164
  }
106
165
  };
107
- window.$copy = p, i.config.globalProperties.$copy = p;
108
- const h = (e) => e < 1e3 ? e : e < 1e6 ? parseInt(e / 1e3) + "K" : parseInt(e / 1e6) + "M";
109
- window.$sc = h;
110
- const F = {
166
+ window.$copy = h, i.config.globalProperties.$copy = h;
167
+ const L = (e) => e < 1e3 ? e : e < 1e6 ? parseInt(e / 1e3) + "K" : parseInt(e / 1e6) + "M";
168
+ window.$sc = L;
169
+ const O = {
111
170
  cpa: "avgCPA",
112
171
  cpt: "avgCPT"
113
- }, C = (e, t = F) => {
114
- const o = t[e.name];
172
+ }, j = (e, n = O) => {
173
+ const o = n[e.name];
115
174
  o && (e.name = o);
116
175
  };
117
- window.$nr = C;
118
- const T = (e, t) => (Object.keys(e).forEach((o) => {
176
+ window.$nr = j;
177
+ const E = (e, n) => (Object.keys(e).forEach((o) => {
119
178
  objMap[o] && (e[objMap[o]] = e[o], delete e[o]);
120
179
  }), e);
121
- window.$nro = T;
122
- const k = (e) => {
123
- let t = 0;
180
+ window.$nro = E;
181
+ const P = (e) => {
182
+ let n = 0;
124
183
  return Object.keys(e).forEach((o) => {
125
- (window.$getType(e[o]) === "Array" && e[o].length !== 0 || e[o]) && t++;
126
- }), t;
184
+ (window.$getType(e[o]) === "Array" && e[o].length !== 0 || e[o]) && n++;
185
+ }), n;
127
186
  };
128
- window.$pc = k;
129
- const g = {
187
+ window.$pc = P;
188
+ const y = {
130
189
  info: {
131
190
  tag: "background-color:#0085FF; color:#f1f7ff;",
132
191
  style: "background-color:#f1f7ff; color:#0085FF;"
@@ -147,30 +206,89 @@ const M = (i) => {
147
206
  tag: "background-color:#20c997; color:#f6fffc;",
148
207
  style: "background-color:#f6fffc; color:#20c997;"
149
208
  }
150
- }, s = (e = "info", t) => {
209
+ }, f = (e = "info", n) => {
151
210
  e === "success" && (e = "info"), console[e](
152
- `%c ${e.toUpperCase()} %c┆${t}┆`,
153
- `${g[e].tag}`,
154
- `${g[e].style}`
211
+ `%c ${e.toUpperCase()} %c┆${n}┆`,
212
+ `${y[e].tag}`,
213
+ `${y[e].style}`
155
214
  );
156
215
  };
157
216
  window.$console = {
158
217
  info: (...e) => {
159
- s("info", e);
218
+ f("info", e);
160
219
  },
161
220
  log: (...e) => {
162
- s("log", e);
221
+ f("log", e);
163
222
  },
164
223
  error: (...e) => {
165
- s("error", e);
224
+ f("error", e);
166
225
  },
167
226
  warn: (...e) => {
168
- s("warn", e);
227
+ f("warn", e);
169
228
  },
170
229
  success: (...e) => {
171
- s("success", e);
230
+ f("success", e);
172
231
  }
173
232
  };
233
+ const R = (e) => new Promise((n, o) => {
234
+ const t = new Image();
235
+ t.src = window.$getType(e) === "String" ? e : URL.createObjectURL(e), t.onload = () => n(t), t.onerror = () => o(new Error("Could not load image"));
236
+ });
237
+ window.$loadImage = R;
238
+ const S = (e) => new Promise((n, o) => {
239
+ const t = document.createElement("video");
240
+ t.preload = "metadata", window.$getType(e) === "String" ? t.src = e : t.src = URL.createObjectURL(e), t.onloadedmetadata = () => {
241
+ window.URL.revokeObjectURL(e), console.info([t]), n(t);
242
+ };
243
+ });
244
+ window.$loadVideo = S;
245
+ const k = (e) => {
246
+ if (e && window.$getType(e) === "Object") {
247
+ const o = {};
248
+ return Object.keys(e).forEach((t) => {
249
+ const r = e[t];
250
+ switch (window.$getType(r)) {
251
+ case "Object":
252
+ Object.keys(r) !== 0 && (o[t] = r);
253
+ break;
254
+ case "Array":
255
+ r.length !== 0 && (o[t] = r);
256
+ break;
257
+ case "String":
258
+ r && (o[t] = r.toLowerCase());
259
+ break;
260
+ // case 'Number':
261
+ // r[it] = String(itv);
262
+ // break;
263
+ default:
264
+ [void 0, null, ""].indexOf(r) === -1 && (o[t] = r);
265
+ break;
266
+ }
267
+ }), o;
268
+ }
269
+ };
270
+ window.$removeEmptyParams = k, window.$rep = k;
271
+ let s = null, w = null;
272
+ const x = async (e) => {
273
+ let { type: n = "img", url: o, name: t, data: r } = e;
274
+ if (s = document.createElement("a"), n === "csv") {
275
+ const c = new Blob(["\uFEFF" + r], {
276
+ type: "text/csv,charset=UTF-8"
277
+ });
278
+ s.href = URL.createObjectURL(c);
279
+ } else if (n === "video" || n === "excel") {
280
+ const { access_token: c, scope: l, token_type: F } = store.launch().login.info, a = {};
281
+ n === "excel" && (a.method = a.method || "GET", a.headers = {
282
+ [l]: `${F} ${c}`
283
+ }), await fetch(o, a).then((d) => d.blob()).then((d) => {
284
+ s.href = URL.createObjectURL(d);
285
+ });
286
+ } else (n = "table") ? await fetch(o).then((c) => c.blob()).then((c) => {
287
+ s.href = URL.createObjectURL(c);
288
+ }) : s.href = o;
289
+ w = new MouseEvent("click"), s.download = t || "download", s.dispatchEvent(w), (n === "csv" || n === "video") && URL.revokeObjectURL(s.url), s = null, w = null;
290
+ };
291
+ window.$download = x;
174
292
  };
175
293
  export {
176
294
  M as d
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "magtool",
3
3
  "packageManager": "yarn@4.4.1",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
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.3",
38
+ "magtool": "^1.0.6",
39
39
  "moment": "^2.30.1",
40
40
  "pinia": "^3.0.0",
41
41
  "vue": "^3.3.4"