UNPKG

@aplus-frontend/ui

Version:

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