UNPKG

@aplus-frontend/ui

Version:

189 lines (188 loc) 6.61 kB
import { defineComponent as j, computed as c, ref as f, watch as x, nextTick as m, onMounted as G, createElementBlock as i, createCommentVNode as C, openBlock as l, normalizeClass as n, unref as t, createVNode as S, withCtx as y, createElementVNode as $, normalizeStyle as h, renderSlot as L, createBlock as E, toDisplayString as u, resolveDynamicComponent as z, Fragment as A, renderList as J, createTextVNode as P } from "vue"; import { DownOutlined as Q } from "@ant-design/icons-vue"; import { Alert as U, Tooltip as X } from "@aplus-frontend/antdv"; import { isNil as Y, isString as B } from "lodash-unified"; import { ApActionItem as Z } from "../../ap-action/index.mjs"; import "../../config-provider/index.mjs"; import _ from "./style/index.mjs"; import { useLocale as ee } from "../../config-provider/hooks/use-locale.mjs"; import { useNamespace as te } from "../../config-provider/hooks/use-namespace.mjs"; const le = ["onClick"], fe = /* @__PURE__ */ j({ __name: "ApExpandAlert", props: { type: { default: "warning" }, data: { default: () => [] }, prefix: { default: "" }, tipTitle: { default: "" }, mapLabel: {}, separator: { default: "|" }, separatorStyle: { default: () => ({}) }, contentStyle: { default: () => ({}) }, prefixStyle: { default: () => ({}) }, rows: { default: 2 }, defaultExpand: { type: Boolean, default: !0 }, showIcon: { type: Boolean, default: !0 }, closable: { type: Boolean }, afterClose: {} }, emits: ["choose", "expand", "close"], setup(D, { expose: V, emit: R }) { const v = R, p = D, { t: N } = ee(), q = c(() => { if (p.type != "card") return p.type; }), a = f(""), d = f(null), F = c(() => ({ fontWeight: "400", wordBreak: "break-all", overflow: "hidden", display: "-webkit-box", webkitLineClamp: a.value, webkitBoxOrient: "vertical", lineHeight: "18px" })); function M() { a.value === "1" ? (a.value = "", v("expand", "expand")) : (a.value = "1", v("expand", "collapse")); } const O = c(() => a.value === "1" ? N("ap.apExpandAlert.expand") : N("ap.apExpandAlert.collapse")), k = f(!0), T = c(() => a.value !== "1"); function w(e) { e ? a.value = "" : a.value = "1"; } const H = f(!1); function K(e) { v("close", e), H.value = !0; } x( () => p.data, () => { a.value = "", m(() => { if (d.value) { const e = Number(d.value.clientHeight), r = Number( parseInt(d.value.style.lineHeight) ); e < r * Number(p.rows) && T.value ? k.value = !1 : k.value = !0; } }); }, { immediate: !0 } ), x( () => p.defaultExpand, (e) => { e ? m(() => { w(e); }) : m(() => { w(e); }); }, { immediate: !0 } ), G(() => { x( () => p.contentStyle, (e) => { Y(e.lineHeight) || m(() => { const r = document.querySelector( `#${b} .ant-alert-action` ), s = document.querySelector( `#${b} .ant-alert-icon` ); r && r.setAttribute("style", `line-height: ${e.lineHeight}`), s && s.setAttribute("style", `line-height: ${e.lineHeight}`); }); }, { deep: !0, immediate: !0, flush: "post" } ); }); const { b: I, e: o } = te("ap-expand-alert"), W = _("ap-expand-alert"), b = `${I()}-key-${Date.now()}-${(Math.random() * 1e6).toFixed(0)}`; return V({ setExpand: w }), (e, r) => H.value ? C("", !0) : (l(), i("div", { key: 0, id: b, class: n([t(I)(), t(W)]) }, [ S(t(U), { type: q.value, "show-icon": e.showIcon, closable: e.closable, class: n([t(o)("antAlert"), e.type == "card" ? "card-alert" : ""]), "after-close": e.afterClose, onClose: K }, { action: y(() => [ k.value ? (l(), E(t(Z), { key: 0, size: "small", style: { "font-size": "12px", "padding-left": "16px" }, onClick: r[0] || (r[0] = (s) => M()) }, { default: y(() => [ $("span", { class: n(t(o)("expandText")) }, u(O.value), 3), S(t(Q), { class: n(T.value ? t(o)("expandIcon") : t(o)("collapseIcon")) }, null, 8, ["class"]) ]), _: 1 })) : C("", !0) ]), message: y(() => [ $("div", { ref_key: "ellipsisBoxRef", ref: d, style: h({ ...F.value, ...e.contentStyle }), class: n(t(o)("alertContent")) }, [ L(e.$slots, "default", {}, () => [ t(B)(e.prefix) ? (l(), i("span", { key: 0, class: n(t(o)("prefix")), style: h(e.prefixStyle) }, u(e.prefix), 7)) : (l(), E(z(e.prefix), { key: 1, style: h(e.prefixStyle) }, null, 8, ["style"])), t(B)(e.data) ? (l(), i("span", { key: 2, class: n(t(o)("text")) }, u(e.data), 3)) : (l(!0), i(A, { key: 3 }, J(e.data, (s, g) => (l(), i(A, { key: g }, [ S(t(X), { title: e.tipTitle ? e.tipTitle : null }, { default: y(() => [ L(e.$slots, "item", { record: s, index: g }, () => [ $("span", { class: n(t(o)("showItem")), onClick: (ae) => e.$emit("choose", s) }, u(e.mapLabel ? s[e.mapLabel] : s), 11, le) ]) ]), _: 2 }, 1032, ["title"]), g !== e.data.length - 1 ? (l(), i("span", { key: 0, class: n(t(o)("spliter")), style: h(e.separatorStyle) }, [ t(B)(e.separator) ? (l(), i(A, { key: 0 }, [ P(u(e.separator), 1) ], 64)) : (l(), E(z(e.separator), { key: 1 })) ], 6)) : C("", !0) ], 64))), 128)) ]) ], 6) ]), _: 3 }, 8, ["type", "show-icon", "closable", "class", "after-close"]) ], 2)); } }); export { fe as default };