@qy_better_lib/core 0.0.1 → 0.0.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/@qy_better_lib/core.min.js +1 -0
- package/lib/directives/click-outside.js +7 -8
- package/lib/index.js +31 -36
- package/lib/utils/index.d.ts +0 -1
- package/package.json +1 -1
- package/src/utils/index.ts +0 -1
- package/dist/@qy-better-lib/core.min.js +0 -1
- package/lib/utils/ui.d.ts +0 -32
- package/lib/utils/ui.js +0 -57
- package/src/utils/ui.ts +0 -129
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(r,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(r=typeof globalThis<"u"?globalThis:r||self,f(r["@qy_better_lib/core"]={}))})(this,function(r){"use strict";function f(){return Math.floor(Math.random()*1e4)}function E(e){return Math.floor(Math.random()*Math.floor(e))}function v(){const e=p;return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function p(){return Math.floor((1+Math.random())*65536).toString(16).substring(1)}function $(e){return e===void 0}function y(e){return Object.prototype.toString.call(e)==="[object Array]"}function g(e){return typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function M(e){return Object.prototype.toString.call(e)==="[object Date]"}function N(e){return!e&&e!==0||y(e)&&e.length===0||g(e)&&!Object.keys(e).length}function h(e){return typeof Element>"u"?!1:e instanceof Element}const O=typeof window<"u",A=e=>typeof e=="number";function w(e,t="key",n="children"){const o={},i=(a,s)=>{for(let l=0;l<a.length;l++){const u=a[l],d=u[t];if(!o[d]){o[d]=u,s&&(o[d].parent=o[s]);const m=u[n];m&&m.length>0&&i(m,u[t])}}};return i(e),o}function F(e){return e?Object.prototype.toString.call(1)!=="[object Number]"?`${e}`:`${e}`.replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,"$1,"):"0"}function _(){const e=localStorage.getItem("token");if(!e)return;const t=JSON.parse(e);if(t!==null)if(t.expirse!=null&&t.expirse<new Date().getTime())localStorage.removeItem("token");else return t.value;return null}function B(e,t){!t&&(t=7*24*60*60*1e3)||(t=t*1e3);const n={value:e,expirse:new Date().getTime()+t};localStorage.setItem("token",JSON.stringify(n))}function H(){localStorage.removeItem("token")}function R(e,t,n="local"){const o=n=="local"?localStorage:sessionStorage;t!=null&&o.setItem(e,JSON.stringify(t))}function b(e,t="local"){let o=(t=="local"?localStorage:sessionStorage).getItem(e);return o&&JSON.parse(o||"")}function J(e,t="local"){(t=="local"?localStorage:sessionStorage).removeItem(e)}function L(e="local"){(e=="local"?localStorage:sessionStorage).clear()}function T(e){const t=Object.prototype.toString;if(!e||typeof e!="object")return e;if(e.nodeType&&"cloneNode"in e)return e.cloneNode(!0);if(t.call(e)==="[object Date]")return new Date(e.getTime());if(t.call(e)==="[object RegExp]"){const o=[];return e.global&&o.push("g"),e.multiline&&o.push("m"),e.ignoreCase&&o.push("i"),new RegExp(e.source,o.join(""))}if(t.call(e)==="[object FormData]"){const o=new FormData;for(const[i,a]of e.entries())o.append(i,a);return o}const n=Array.isArray(e)?[]:e.constructor?new e.constructor:{};for(const o in e)n[o]=T(e[o]);return n}function k(...e){let t=e.length,n=e[0];g(n)||(n={});for(let o=1;o<t;o++){let i=e[o];if(g(i))for(let a in i)a==="__proto__"||n===i[a]||(g(i[a])?n[a]=k(n[a],i[a]):n[a]=i[a])}return n}function D(e,t){return!e||e.tagName==="BODY"?null:e.classList.contains(t)?e:D(e.parentNode,t)}const c=new Map;let I;O&&(document.addEventListener("mousedown",e=>I=e),document.addEventListener("mouseup",e=>{for(const t of c.values())for(const{documentHandler:n}of t)n(e,I)}));function C(e,t){let n=[];return Array.isArray(t.arg)?n=t.arg:h(t.arg)&&n.push(t.arg),function(o,i){const a=t.instance.popperRef,s=o.target,l=i==null?void 0:i.target,u=!t||!t.instance,d=!s||!l,m=e.contains(s)||e.contains(l),U=e===s,j=n.length&&n.some(S=>S==null?void 0:S.contains(s))||n.length&&n.includes(l),q=a&&(a.contains(s)||a.contains(l));u||d||m||U||j||q||t.value(o,i)}}const P={beforeMount(e,t){var n;c.has(e)||c.set(e,[]),(n=c.get(e))==null||n.push({documentHandler:C(e,t),bindingFn:t.value})},updated(e,t){c.has(e)||c.set(e,[]);const n=c.get(e),o=n==null?void 0:n.findIndex(a=>a.bindingFn===t.oldValue),i={documentHandler:C(e,t),bindingFn:t.value};o&&o>=0?n==null||n.splice(o,1,i):n==null||n.push(i)},unmounted(e){c.delete(e)}};r.ClickOutside=P,r.clearStorage=L,r.deepAssign=k,r.deepClone=T,r.generateId=f,r.generateString=p,r.getParentByClass=D,r.getRandomInt=E,r.getStorage=b,r.getToken=_,r.guiID=v,r.isArray=y,r.isClient=O,r.isDate=M,r.isElement=h,r.isEmpty=N,r.isNumber=A,r.isObject=g,r.isUndefined=$,r.removeStorage=J,r.removeToken=H,r.setStorage=R,r.setToken=B,r.thousandSeparator=F,r.treeFlat=w,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { isClient as
|
|
2
|
-
import "element-plus";
|
|
1
|
+
import { isClient as H, isElement as m } from "../utils/is.js";
|
|
3
2
|
const s = /* @__PURE__ */ new Map();
|
|
4
3
|
let f;
|
|
5
|
-
|
|
4
|
+
H && (document.addEventListener("mousedown", (e) => f = e), document.addEventListener("mouseup", (e) => {
|
|
6
5
|
for (const n of s.values())
|
|
7
6
|
for (const { documentHandler: t } of n)
|
|
8
7
|
t(e, f);
|
|
9
8
|
}));
|
|
10
9
|
function d(e, n) {
|
|
11
10
|
let t = [];
|
|
12
|
-
return Array.isArray(n.arg) ? t = n.arg :
|
|
13
|
-
const c = n.instance.popperRef, r = a.target, u = o == null ? void 0 : o.target, l = !n || !n.instance, p = !r || !u, g = e.contains(r) || e.contains(u),
|
|
14
|
-
l || p || g ||
|
|
11
|
+
return Array.isArray(n.arg) ? t = n.arg : m(n.arg) && t.push(n.arg), function(a, o) {
|
|
12
|
+
const c = n.instance.popperRef, r = a.target, u = o == null ? void 0 : o.target, l = !n || !n.instance, p = !r || !u, g = e.contains(r) || e.contains(u), v = e === r, x = t.length && t.some((i) => i == null ? void 0 : i.contains(r)) || t.length && t.includes(u), E = c && (c.contains(r) || c.contains(u));
|
|
13
|
+
l || p || g || v || x || E || n.value(a, o);
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
|
-
const
|
|
16
|
+
const y = {
|
|
18
17
|
beforeMount(e, n) {
|
|
19
18
|
var t;
|
|
20
19
|
s.has(e) || s.set(e, []), (t = s.get(e)) == null || t.push({
|
|
@@ -37,5 +36,5 @@ const T = {
|
|
|
37
36
|
}
|
|
38
37
|
};
|
|
39
38
|
export {
|
|
40
|
-
|
|
39
|
+
y as default
|
|
41
40
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
import { generateId as
|
|
2
|
-
import { isArray as
|
|
3
|
-
import { treeFlat as
|
|
4
|
-
import { thousandSeparator as
|
|
5
|
-
import { clearStorage as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { default as w } from "./directives/click-outside.js";
|
|
1
|
+
import { generateId as r, generateString as o, getRandomInt as a, guiID as s } from "./utils/random.js";
|
|
2
|
+
import { isArray as i, isClient as m, isDate as g, isElement as p, isEmpty as f, isNumber as d, isObject as l, isUndefined as x } from "./utils/is.js";
|
|
3
|
+
import { treeFlat as u } from "./utils/tree.js";
|
|
4
|
+
import { thousandSeparator as C } from "./utils/number.js";
|
|
5
|
+
import { clearStorage as y, getStorage as I, getToken as T, removeStorage as b, removeToken as v, setStorage as A, setToken as D } from "./utils/storage.js";
|
|
6
|
+
import { deepAssign as O, deepClone as h } from "./utils/object.js";
|
|
7
|
+
import { getParentByClass as B } from "./utils/dom.js";
|
|
8
|
+
import { default as N } from "./directives/click-outside.js";
|
|
10
9
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
P as deepClone,
|
|
17
|
-
t as generateId,
|
|
10
|
+
N as ClickOutside,
|
|
11
|
+
y as clearStorage,
|
|
12
|
+
O as deepAssign,
|
|
13
|
+
h as deepClone,
|
|
14
|
+
r as generateId,
|
|
18
15
|
o as generateString,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
B as getParentByClass,
|
|
17
|
+
a as getRandomInt,
|
|
18
|
+
I as getStorage,
|
|
19
|
+
T as getToken,
|
|
20
|
+
s as guiID,
|
|
21
|
+
i as isArray,
|
|
25
22
|
m as isClient,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
k as thousandSeparator,
|
|
39
|
-
S as treeFlat
|
|
23
|
+
g as isDate,
|
|
24
|
+
p as isElement,
|
|
25
|
+
f as isEmpty,
|
|
26
|
+
d as isNumber,
|
|
27
|
+
l as isObject,
|
|
28
|
+
x as isUndefined,
|
|
29
|
+
b as removeStorage,
|
|
30
|
+
v as removeToken,
|
|
31
|
+
A as setStorage,
|
|
32
|
+
D as setToken,
|
|
33
|
+
C as thousandSeparator,
|
|
34
|
+
u as treeFlat
|
|
40
35
|
};
|
package/lib/utils/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(r,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("element-plus")):typeof define=="function"&&define.amd?define(["exports","element-plus"],u):(r=typeof globalThis<"u"?globalThis:r||self,u(r["@qy-better-lib/core"]={},r["element-plus"]))})(this,function(r,u){"use strict";function M(){return Math.floor(Math.random()*1e4)}function k(e){return Math.floor(Math.random()*Math.floor(e))}function $(){const e=y;return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function y(){return Math.floor((1+Math.random())*65536).toString(16).substring(1)}function A(e){return e===void 0}function p(e){return Object.prototype.toString.call(e)==="[object Array]"}function g(e){return typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function v(e){return Object.prototype.toString.call(e)==="[object Date]"}function B(e){return!e&&e!==0||p(e)&&e.length===0||g(e)&&!Object.keys(e).length}function h(e){return typeof Element>"u"?!1:e instanceof Element}const T=typeof window<"u",N=e=>typeof e=="number";function w(e,t="key",n="children"){const o={},i=(c,s)=>{for(let a=0;a<c.length;a++){const l=c[a],d=l[t];if(!o[d]){o[d]=l,s&&(o[d].parent=o[s]);const m=l[n];m&&m.length>0&&i(m,l[t])}}};return i(e),o}function H(e){return e?Object.prototype.toString.call(1)!=="[object Number]"?`${e}`:`${e}`.replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,"$1,"):"0"}function F(){const e=localStorage.getItem("token");if(!e)return;const t=JSON.parse(e);if(t!==null)if(t.expirse!=null&&t.expirse<new Date().getTime())localStorage.removeItem("token");else return t.value;return null}function L(e,t){!t&&(t=7*24*60*60*1e3)||(t=t*1e3);const n={value:e,expirse:new Date().getTime()+t};localStorage.setItem("token",JSON.stringify(n))}function R(){localStorage.removeItem("token")}function U(e,t,n="local"){const o=n=="local"?localStorage:sessionStorage;t!=null&&o.setItem(e,JSON.stringify(t))}function _(e,t="local"){let o=(t=="local"?localStorage:sessionStorage).getItem(e);return o&&JSON.parse(o||"")}function b(e,t="local"){(t=="local"?localStorage:sessionStorage).removeItem(e)}function J(e="local"){(e=="local"?localStorage:sessionStorage).clear()}function j(e,t,n){const o={beforeClose:(i,c,s)=>{i==="confirm"?setTimeout(()=>{s()},0):s()},...n};u.ElMessageBox.confirm(`此操作将${e}, 是否继续?`,"提示",o).then(async()=>{t&&t()}).catch(()=>{})}function q(e,t,n){return new Promise((o,i)=>{const c={beforeClose:(s,a,l)=>{s==="confirm"?setTimeout(()=>{l()},0):l()},...n};u.ElMessageBox.confirm(`${e}`,"Tip",c).then(()=>{o(t&&t())}).catch(()=>{})})}function P(e,t="",n=!1,o=3e3){u.ElMessage({showClose:!0,message:t,type:e,duration:o,dangerouslyUseHTMLString:n})}function V(e,t="",n=!1,o="bottom-right",i=0){u.ElNotification({title:"消息通知",message:t,type:e,dangerouslyUseHTMLString:n,duration:i,showClose:!0,position:o})}function C(e){const t=Object.prototype.toString;if(!e||typeof e!="object")return e;if(e.nodeType&&"cloneNode"in e)return e.cloneNode(!0);if(t.call(e)==="[object Date]")return new Date(e.getTime());if(t.call(e)==="[object RegExp]"){const o=[];return e.global&&o.push("g"),e.multiline&&o.push("m"),e.ignoreCase&&o.push("i"),new RegExp(e.source,o.join(""))}if(t.call(e)==="[object FormData]"){const o=new FormData;for(const[i,c]of e.entries())o.append(i,c);return o}const n=Array.isArray(e)?[]:e.constructor?new e.constructor:{};for(const o in e)n[o]=C(e[o]);return n}function E(...e){let t=e.length,n=e[0];g(n)||(n={});for(let o=1;o<t;o++){let i=e[o];if(g(i))for(let c in i)c==="__proto__"||n===i[c]||(g(i[c])?n[c]=E(n[c],i[c]):n[c]=i[c])}return n}function O(e,t){return!e||e.tagName==="BODY"?null:e.classList.contains(t)?e:O(e.parentNode,t)}const f=new Map;let D;T&&(document.addEventListener("mousedown",e=>D=e),document.addEventListener("mouseup",e=>{for(const t of f.values())for(const{documentHandler:n}of t)n(e,D)}));function I(e,t){let n=[];return Array.isArray(t.arg)?n=t.arg:h(t.arg)&&n.push(t.arg),function(o,i){const c=t.instance.popperRef,s=o.target,a=i==null?void 0:i.target,l=!t||!t.instance,d=!s||!a,m=e.contains(s)||e.contains(a),z=e===s,G=n.length&&n.some(S=>S==null?void 0:S.contains(s))||n.length&&n.includes(a),K=c&&(c.contains(s)||c.contains(a));l||d||m||z||G||K||t.value(o,i)}}const Y={beforeMount(e,t){var n;f.has(e)||f.set(e,[]),(n=f.get(e))==null||n.push({documentHandler:I(e,t),bindingFn:t.value})},updated(e,t){f.has(e)||f.set(e,[]);const n=f.get(e),o=n==null?void 0:n.findIndex(c=>c.bindingFn===t.oldValue),i={documentHandler:I(e,t),bindingFn:t.value};o&&o>=0?n==null||n.splice(o,1,i):n==null||n.push(i)},unmounted(e){f.delete(e)}};r.ClickOutside=Y,r.clearStorage=J,r.confirmBox=j,r.confirmBoxAsync=q,r.deepAssign=E,r.deepClone=C,r.generateId=M,r.generateString=y,r.getParentByClass=O,r.getRandomInt=k,r.getStorage=_,r.getToken=F,r.guiID=$,r.isArray=p,r.isClient=T,r.isDate=v,r.isElement=h,r.isEmpty=B,r.isNumber=N,r.isObject=g,r.isUndefined=A,r.messageAlert=P,r.notification=V,r.removeStorage=b,r.removeToken=R,r.setStorage=U,r.setToken=L,r.thousandSeparator=H,r.treeFlat=w,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/lib/utils/ui.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 确认提示框
|
|
3
|
-
* @param str 提示信息
|
|
4
|
-
* @param callback 确认回调函数
|
|
5
|
-
* @param options MessageBox配置项,参考element-plus文档
|
|
6
|
-
*/
|
|
7
|
-
export declare function confirmBox(str: string, callback: () => any | void, options?: any): void;
|
|
8
|
-
/**
|
|
9
|
-
* 同步的确认提示框
|
|
10
|
-
* @param str 提示信息
|
|
11
|
-
* @param callback 确认回调函数
|
|
12
|
-
* @param options MessageBox配置项,参考element-plus文档
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare function confirmBoxAsync(str: string, callback: () => any | void, options?: any): Promise<any>;
|
|
16
|
-
/**
|
|
17
|
-
* 消息提示
|
|
18
|
-
* @export
|
|
19
|
-
* @param type 类型
|
|
20
|
-
* @param message 消息
|
|
21
|
-
* @param html 是否为html
|
|
22
|
-
* @param duration 消失时间
|
|
23
|
-
*/
|
|
24
|
-
export declare function messageAlert(type: "success" | "warning" | "error", message?: string, html?: boolean, duration?: number): void;
|
|
25
|
-
/**
|
|
26
|
-
* 侧窗提示
|
|
27
|
-
* @param type
|
|
28
|
-
* @param message
|
|
29
|
-
* @param html
|
|
30
|
-
* @param duration
|
|
31
|
-
*/
|
|
32
|
-
export declare function notification(type: "success" | "warning" | "error" | "info", message?: string, html?: boolean, position?: "top-right" | "top-left" | "bottom-right" | "bottom-left", duration?: number): void;
|
package/lib/utils/ui.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ElMessageBox as f, ElMessage as m, ElNotification as l } from "element-plus";
|
|
2
|
-
function g(o, e, t) {
|
|
3
|
-
const n = {
|
|
4
|
-
beforeClose: (i, r, s) => {
|
|
5
|
-
i === "confirm" ? setTimeout(() => {
|
|
6
|
-
s();
|
|
7
|
-
}, 0) : s();
|
|
8
|
-
},
|
|
9
|
-
...t
|
|
10
|
-
};
|
|
11
|
-
f.confirm(`此操作将${o}, 是否继续?`, "提示", n).then(async () => {
|
|
12
|
-
e && e();
|
|
13
|
-
}).catch(() => {
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
function h(o, e, t) {
|
|
17
|
-
return new Promise((n, i) => {
|
|
18
|
-
const r = {
|
|
19
|
-
beforeClose: (s, u, c) => {
|
|
20
|
-
s === "confirm" ? setTimeout(() => {
|
|
21
|
-
c();
|
|
22
|
-
}, 0) : c();
|
|
23
|
-
},
|
|
24
|
-
...t
|
|
25
|
-
};
|
|
26
|
-
f.confirm(`${o}`, "Tip", r).then(() => {
|
|
27
|
-
n(e && e());
|
|
28
|
-
}).catch(() => {
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function p(o, e = "", t = !1, n = 3e3) {
|
|
33
|
-
m({
|
|
34
|
-
showClose: !0,
|
|
35
|
-
message: e,
|
|
36
|
-
type: o,
|
|
37
|
-
duration: n,
|
|
38
|
-
dangerouslyUseHTMLString: t
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function T(o, e = "", t = !1, n = "bottom-right", i = 0) {
|
|
42
|
-
l({
|
|
43
|
-
title: "消息通知",
|
|
44
|
-
message: e,
|
|
45
|
-
type: o,
|
|
46
|
-
dangerouslyUseHTMLString: t,
|
|
47
|
-
duration: i,
|
|
48
|
-
showClose: !0,
|
|
49
|
-
position: n
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
g as confirmBox,
|
|
54
|
-
h as confirmBoxAsync,
|
|
55
|
-
p as messageAlert,
|
|
56
|
-
T as notification
|
|
57
|
-
};
|
package/src/utils/ui.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ==============================================
|
|
3
|
-
* 强依赖element-plus
|
|
4
|
-
* ==============================================
|
|
5
|
-
*/
|
|
6
|
-
import { ElMessage, ElMessageBox, ElNotification } from "element-plus";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 确认提示框
|
|
10
|
-
* @param str 提示信息
|
|
11
|
-
* @param callback 确认回调函数
|
|
12
|
-
* @param options MessageBox配置项,参考element-plus文档
|
|
13
|
-
*/
|
|
14
|
-
export function confirmBox(
|
|
15
|
-
str: string,
|
|
16
|
-
callback: () => any | void,
|
|
17
|
-
options?: any
|
|
18
|
-
) {
|
|
19
|
-
const option = {
|
|
20
|
-
beforeClose: (
|
|
21
|
-
action: "confirm" | "cancel" | "close",
|
|
22
|
-
instance: any,
|
|
23
|
-
done: () => void
|
|
24
|
-
) => {
|
|
25
|
-
if (action === "confirm") {
|
|
26
|
-
setTimeout(() => {
|
|
27
|
-
done();
|
|
28
|
-
}, 0);
|
|
29
|
-
} else {
|
|
30
|
-
done();
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
...options,
|
|
34
|
-
};
|
|
35
|
-
ElMessageBox.confirm(`此操作将${str}, 是否继续?`, "提示", option)
|
|
36
|
-
.then(async () => {
|
|
37
|
-
callback && callback();
|
|
38
|
-
})
|
|
39
|
-
.catch(() => {});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 同步的确认提示框
|
|
44
|
-
* @param str 提示信息
|
|
45
|
-
* @param callback 确认回调函数
|
|
46
|
-
* @param options MessageBox配置项,参考element-plus文档
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
export function confirmBoxAsync(
|
|
50
|
-
str: string,
|
|
51
|
-
callback: () => any | void,
|
|
52
|
-
options?: any
|
|
53
|
-
): Promise<any> {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
const option = {
|
|
56
|
-
beforeClose: (
|
|
57
|
-
action: "confirm" | "cancel" | "close",
|
|
58
|
-
instance: any,
|
|
59
|
-
done: () => void
|
|
60
|
-
) => {
|
|
61
|
-
if (action === "confirm") {
|
|
62
|
-
setTimeout(() => {
|
|
63
|
-
done();
|
|
64
|
-
}, 0);
|
|
65
|
-
} else {
|
|
66
|
-
done();
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
...options,
|
|
70
|
-
};
|
|
71
|
-
ElMessageBox.confirm(`${str}`, "Tip", option)
|
|
72
|
-
.then(() => {
|
|
73
|
-
resolve(callback && callback());
|
|
74
|
-
})
|
|
75
|
-
.catch(() => {});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 消息提示
|
|
81
|
-
* @export
|
|
82
|
-
* @param type 类型
|
|
83
|
-
* @param message 消息
|
|
84
|
-
* @param html 是否为html
|
|
85
|
-
* @param duration 消失时间
|
|
86
|
-
*/
|
|
87
|
-
export function messageAlert(
|
|
88
|
-
type: "success" | "warning" | "error",
|
|
89
|
-
message: string = "",
|
|
90
|
-
html: boolean = false,
|
|
91
|
-
duration: number = 3000
|
|
92
|
-
) {
|
|
93
|
-
ElMessage({
|
|
94
|
-
showClose: true,
|
|
95
|
-
message: message,
|
|
96
|
-
type: type,
|
|
97
|
-
duration,
|
|
98
|
-
dangerouslyUseHTMLString: html,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* 侧窗提示
|
|
104
|
-
* @param type
|
|
105
|
-
* @param message
|
|
106
|
-
* @param html
|
|
107
|
-
* @param duration
|
|
108
|
-
*/
|
|
109
|
-
export function notification(
|
|
110
|
-
type: "success" | "warning" | "error" | "info",
|
|
111
|
-
message: string = "",
|
|
112
|
-
html: boolean = false,
|
|
113
|
-
position:
|
|
114
|
-
| "top-right"
|
|
115
|
-
| "top-left"
|
|
116
|
-
| "bottom-right"
|
|
117
|
-
| "bottom-left" = "bottom-right",
|
|
118
|
-
duration: number = 0
|
|
119
|
-
) {
|
|
120
|
-
ElNotification({
|
|
121
|
-
title: "消息通知",
|
|
122
|
-
message,
|
|
123
|
-
type,
|
|
124
|
-
dangerouslyUseHTMLString: html,
|
|
125
|
-
duration,
|
|
126
|
-
showClose: true,
|
|
127
|
-
position,
|
|
128
|
-
});
|
|
129
|
-
}
|