@aplus-frontend/ui
Version:
108 lines (107 loc) • 4.25 kB
JavaScript
import { defineComponent as M, ref as p, useSlots as S, computed as o, cloneVNode as U, toRaw as f, unref as W, createVNode as t, createTextVNode as _ } from "vue";
import { Tooltip as j, Popover as K } from "@aplus-frontend/antdv";
import "../../config-provider/index.mjs";
import { ApAttachmentProps as B } from "./constans.mjs";
import { getHexWithOpacity as G, getFileInfo as w } from "../../ap-download/utils/getFileInfo.mjs";
import { useOssInit as H } from "../../ap-download/hooks/index.mjs";
import { debounce as R, isArray as q } from "lodash-unified";
import { LoadingOutlined as v } from "@ant-design/icons-vue";
import { warning as D } from "../../utils/warning.mjs";
import { useNamespace as E } from "../../config-provider/hooks/use-namespace.mjs";
import { useGlobalConfig as g } from "../../config-provider/hooks/use-global-config.mjs";
import { useLocale as J } from "../../config-provider/hooks/use-locale.mjs";
const ce = /* @__PURE__ */ M({
name: "ApAttachment",
props: B(),
setup(e) {
const {
b: y,
e: l
} = E("ap-attachment"), F = g("uiMode"), b = g("apUpload"), h = g("downloadCenterTriggerConfig"), {
lang: x,
t: m
} = J(), i = p(!1), c = p(""), u = S(), O = o(() => x.value === "zh-cn" ? "zh_CN" : "en_US"), r = o(() => e.attachmentList.length === 1), N = o(() => e.needName ? e.attachmentList.length > 0 && e.needName && e.needName.nameKey ? e.attachmentList[0][e.needName.nameKey] : "" : e.attachmentList.length > 0 ? e.attachmentList[0].fileName : ""), T = o(() => r.value ? N.value : m("ap.apAttachment.downloadall")), L = o(() => e.color ? e.color : F.value === "aplus" ? "#0070FF" : "#1890FF"), A = o(() => ({
"--download-main-color": L.value,
"--download-main-color-opacity": G(L.value, 0.6)
})), P = o(() => e.getOssAccess || b.value?.getOssAccess), k = o(() => {
const a = u.default ? u.default()[0] : null;
return a ? U(a, {
style: {
"font-size": "16px"
}
}) : null;
}), d = R(async (a, s) => {
if (!e.disabled) {
i.value = !0, s && (c.value = s);
try {
const n = q(f(a)) ? f(a) : [f(a)];
if (h.value?.trigger) {
const I = w(e.needName, n).map((C) => ({
objectName: C.path,
fileName: C.fileName
}));
h.value?.trigger(I);
} else
await (await H(P.value, W(O))).downloadFile(w(e.needName, n));
} catch (n) {
D(!1, n);
} finally {
i.value = !1, c.value = "";
}
}
}, 500), V = (a) => a && a.length > 0 ? t("ul", {
class: [l("file-list")],
style: A.value
}, [a.map((s, n) => t("li", {
key: n,
class: [l("file-item")],
onClick: () => d(s, n + 1)
}, [i.value && c.value === n + 1 ? t("span", {
class: [l("spin")]
}, [t(v, {
spin: !0
}, null)]) : null, s.fileName])), t("li", {
class: [l("down-load-all")],
onClick: () => d(e.attachmentList, "all")
}, [i.value && c.value === "all" ? t("span", {
class: [l("spin")]
}, [t(v, {
spin: !0
}, null)]) : null, m("ap.apAttachment.downloadall")])]) : null;
return () => e.attachmentList?.length > 0 && t("div", {
class: [y()],
style: [A.value]
}, [t(j, {
title: T.value,
placement: e.textToolTipPlacement,
color: e.toolTipBgColor
}, {
default: () => [t("div", {
class: [l("content")],
onClick: () => d(r.value ? e.attachmentList[0] : e.attachmentList, "global")
}, [i.value && c.value === "global" ? t("div", {
class: [l("spin")]
}, [t(v, {
spin: !0
}, null)]) : null, u.default ? t("div", {
class: [l("text-render")]
}, [k.value, _(" ")]) : null, t("div", {
class: [l("text-inner")],
style: {
"max-width": e.maxWidth ? e.maxWidth + "px" : "auto"
}
}, [N.value])])]
}), t(K, {
content: V(e.attachmentList),
placement: e.fileMorePopoverPlacement,
color: "#fff"
}, {
default: () => [!r.value && t("div", {
class: [l("more")]
}, [m("ap.apAttachment.more")])]
})]);
}
});
export {
ce as default
};