UNPKG

@hopeio/utils

Version:
192 lines (191 loc) 7.45 kB
import { defineComponent as P, ref as I, computed as w, resolveComponent as F, createElementBlock as C, openBlock as m, Fragment as A, renderList as L, unref as O, createBlock as k, mergeProps as D, createSlots as q, withCtx as y, resolveDynamicComponent as M, createElementVNode as G, createCommentVNode as J, normalizeClass as N, toDisplayString as R, createVNode as j, createTextVNode as t } from "vue"; import { useTimeoutFn as T } from "@vueuse/core"; import { isFunction as $, withInstall as K } from "@pureadmin/utils"; const Q = { width: 24, height: 24, body: '<path fill="currentColor" d="M16 3h6v6h-2V5h-4V3ZM2 3h6v2H4v4H2V3Zm18 16v-4h2v6h-6v-2h4ZM4 19h4v2H2v-6h2v4Z"/>' }, E = { width: 24, height: 24, body: '<path fill="currentColor" d="M18 7h4v2h-6V3h2v4ZM8 9H2V7h4V3h2v6Zm10 8v4h-2v-6h6v2h-4ZM8 15v6H6v-4H2v-2h6Z"/>' }, W = { key: 0, class: "flex items-center justify-between" }, X = ["id"], Y = ["onClick"], x = { key: 1 }, s = /* @__PURE__ */ P({ name: "ReDialog", __name: "index", setup(a) { const f = I({}), h = I(!1), Z = w(() => (u) => { var c; return ((c = u == null ? void 0 : u.footerButtons) == null ? void 0 : c.length) > 0 ? u.footerButtons : [ { label: "取消", text: !0, bg: !0, btnClick: ({ dialog: { options: l, index: d } }) => { const _ = () => H(l, d, { command: "cancel" }); l != null && l.beforeCancel && $(l == null ? void 0 : l.beforeCancel) ? l.beforeCancel(_, { options: l, index: d }) : _(); } }, { label: "确定", type: "primary", text: !0, bg: !0, popconfirm: u == null ? void 0 : u.popconfirm, btnClick: ({ dialog: { options: l, index: d } }) => { l != null && l.sureBtnLoading && (f.value[d] = Object.assign( {}, f.value[d], { loading: !0 } )); const _ = () => { l != null && l.sureBtnLoading && (f.value[d].loading = !1); }, n = () => { _(), H(l, d, { command: "sure" }); }; l != null && l.beforeSure && $(l == null ? void 0 : l.beforeSure) ? l.beforeSure(n, { options: l, index: d, closeLoading: _ }) : n(); } } ]; }), U = w(() => [ "el-icon", "el-dialog__close", "-translate-x-2", "cursor-pointer", "hover:!text-[red]" ]); function B(u, c, l, d = !1) { if (d || (h.value = (c == null ? void 0 : c.fullscreen) ?? !1), c != null && c[u] && $(c == null ? void 0 : c[u])) return c == null ? void 0 : c[u]({ options: c, index: l }); } function S(u, c, l = { command: "close" }) { H(u, c, l), B("close", u, c); } return (u, c) => { const l = F("IconifyIconOffline"), d = F("el-button"), _ = F("el-popconfirm"), n = F("el-dialog"); return m(!0), C(A, null, L(O(V), (e, v) => (m(), k(n, D({ key: v, ref_for: !0 }, e, { modelValue: e.visible, "onUpdate:modelValue": (r) => e.visible = r, class: "pure-dialog", fullscreen: h.value ? !0 : !!(e != null && e.fullscreen), onClosed: (r) => S(e, v), onOpened: (r) => B("open", e, v), onOpenAutoFocus: (r) => B("openAutoFocus", e, v), onCloseAutoFocus: (r) => B("closeAutoFocus", e, v) }), q({ default: y(() => [ (m(), k(M(e.contentRenderer({ options: e, index: v })), D({ ref_for: !0 }, e == null ? void 0 : e.props, { onClose: (r) => S(e, v, r) }), null, 16, ["onClose"])) ]), _: 2 }, [ e != null && e.fullscreenIcon || e != null && e.headerRenderer ? { name: "header", fn: y(({ close: r, titleId: g, titleClass: b }) => [ e != null && e.fullscreenIcon ? (m(), C("div", W, [ G("span", { id: g, class: N(b) }, R(e == null ? void 0 : e.title), 11, X), e != null && e.fullscreen ? J("", !0) : (m(), C("i", { key: 0, class: N(U.value), onClick: () => { h.value = !h.value, B( "fullscreenCallBack", { ...e, fullscreen: h.value }, v, !0 ); } }, [ j(l, { class: "pure-dialog-svg", icon: e != null && e.fullscreen ? O(E) : h.value ? O(E) : O(Q) }, null, 8, ["icon"]) ], 10, Y)) ])) : (m(), k(M(e == null ? void 0 : e.headerRenderer({ close: r, titleId: g, titleClass: b })), { key: 1 })) ]), key: "0" } : void 0, e != null && e.hideFooter ? void 0 : { name: "footer", fn: y(() => [ e != null && e.footerRenderer ? (m(), k(M(e == null ? void 0 : e.footerRenderer({ options: e, index: v })), { key: 0 })) : (m(), C("span", x, [ (m(!0), C(A, null, L(Z.value(e), (r, g) => { var b; return m(), C(A, { key: g }, [ r.popconfirm ? (m(), k(_, D({ key: 0, ref_for: !0 }, r.popconfirm, { onConfirm: (z) => r.btnClick({ dialog: { options: e, index: v }, button: { btn: r, index: g } }) }), { reference: y(() => [ j(d, D({ ref_for: !0 }, r), { default: y(() => [ t(R(r == null ? void 0 : r.label), 1) ]), _: 2 }, 1040) ]), _: 2 }, 1040, ["onConfirm"])) : (m(), k(d, D({ key: 1, ref_for: !0 }, r, { loading: g === 1 && ((b = f.value[v]) == null ? void 0 : b.loading), onClick: (z) => r.btnClick({ dialog: { options: e, index: v }, button: { btn: r, index: g } }) }), { default: y(() => [ t(R(r == null ? void 0 : r.label), 1) ]), _: 2 }, 1040, ["loading", "onClick"])) ], 64); }), 128)) ])) ]), key: "1" } ]), 1040, ["modelValue", "onUpdate:modelValue", "fullscreen", "onClosed", "onOpened", "onOpenAutoFocus", "onCloseAutoFocus"]))), 128); }; } }), V = I([]), ee = (a) => { const f = () => V.value.push(Object.assign(a, { visible: !0 })); a != null && a.openDelay ? T(() => { f(); }, a.openDelay) : f(); }, H = (a, f, h) => { V.value[f].visible = !1, a.closeCallBack && a.closeCallBack({ options: a, index: f, args: h }); const Z = (a == null ? void 0 : a.closeDelay) ?? 200; T(() => { V.value.splice(f, 1); }, Z); }, le = (a, f = "title", h = 0) => { V.value[h][f] = a; }, re = () => { V.value = []; }, ce = K(s); export { ce as ReDialog, ee as addDialog, re as closeAllDialog, H as closeDialog, V as dialogStore, le as updateDialog };