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