UNPKG

@aplus-frontend/ui

Version:

149 lines (148 loc) 4.78 kB
import { defineComponent as I, ref as P, useSlots as T, computed as l, unref as t, createBlock as j, openBlock as n, mergeProps as V, withCtx as s, createElementVNode as C, normalizeClass as D, createElementBlock as p, createCommentVNode as m, createVNode as r, renderSlot as M, createSlots as U, toDisplayString as b, createTextVNode as E, withModifiers as G } from "vue"; import { LoadingOutlined as R } from "@ant-design/icons-vue"; import { Button as W, Tooltip as k } from "@aplus-frontend/antdv"; import { IconApAdLineDownload as $ } from "@aplus-frontend/icon"; import { isArray as q, omit as H } from "lodash-unified"; import "../../config-provider/index.mjs"; import { ApFilePreview as J } from "../ap-file-preview/index.mjs"; import { useOssInit as K } from "./hooks/index.mjs"; import { useStyle as Q } from "./hooks/useStyle.mjs"; import { getFileInfo as f } from "./utils/getFileInfo.mjs"; import { useLocale as X } from "../../config-provider/hooks/use-locale.mjs"; import { useGlobalConfig as h } from "../../config-provider/hooks/use-global-config.mjs"; const Y = { key: 0, class: "spin" }, Z = { key: 1, class: "icon" }, ee = { class: "text" }, fe = /* @__PURE__ */ I({ name: "ApDownload", __name: "ap-download", props: { prefixCls: {}, type: { default: "link" }, htmlType: {}, shape: {}, size: { default: "middle" }, loading: { type: [Boolean, Object] }, disabled: { type: Boolean, default: !1 }, ghost: { type: Boolean }, block: { type: Boolean }, danger: { type: Boolean }, icon: {}, href: {}, target: {}, title: {}, onClick: {}, onMousedown: {}, autoInsertSpace: { type: Boolean }, iconPosition: {}, color: {}, variant: {}, text: {}, fileName: {}, needName: { type: [Boolean, Object], default: void 0 }, getOssAccess: {}, preview: { type: Boolean, default: !1 } }, emits: ["downloadCallback"], setup(_, { emit: A }) { const u = A, c = P(!1), { lang: B, t: g } = X(), O = T(), z = l(() => B.value === "zh-cn" ? "zh_CN" : "en_US"), e = _, i = h("apUpload"), v = h( "downloadCenterTriggerConfig" ), w = l(() => e.disabled), x = l(() => e.size), d = l( () => e.preview && (q(e.fileName) ? e.fileName.length === 1 : !0) ), { getInnerWrapperClass: F } = Q(x, w), L = l(() => e.getOssAccess || i.value?.getOssAccess), S = () => { const o = f( e.needName ?? i?.value?.needName, e.fileName )?.[0]; J.createFilePreviewModal({ src: o.path, fileName: o.fileName }); }, N = async () => { if (!e.disabled) { c.value = !0; try { if (v.value?.trigger) { let a = f( e.needName ?? i?.value?.needName, e.fileName ).map((y) => ({ objectName: y.path, fileName: y.fileName })); await v.value?.trigger(a), u("downloadCallback", a); } else { const a = await (await K( L.value, t(z) )).downloadFile( f( e.needName ?? i?.value?.needName, e.fileName ) ); u("downloadCallback", a); } } catch (o) { console.error(o); } finally { c.value = !1; } } }; return (o, a) => (n(), j(t(W), V(t(H)(e, ["getOssAccess", "fileName", "needName"]), { type: e.type, size: e.size, disabled: w.value, onClick: a[0] || (a[0] = () => (d.value ? S : N)()) }), { default: s(() => [ C("div", { class: D(t(F)) }, [ c.value ? (n(), p("span", Y, [ r(t(R), { spin: !0 }) ])) : m("", !0), t(O).icon ? (n(), p("span", Z, [ M(o.$slots, "icon") ])) : m("", !0), r(t(k), null, U({ default: s(() => [ C("span", ee, b(o.text), 1) ]), _: 2 }, [ d.value ? { name: "title", fn: s(() => [ E(b(t(g)("ap.apAppendix.previewFile")), 1) ]), key: "0" } : void 0 ]), 1024), d.value ? (n(), p("span", { key: 2, class: "preview-icon", onClick: G(N, ["stop"]) }, [ r(t(k), { title: t(g)("ap.apAppendix.downloadFile") }, { default: s(() => [ r(t($)) ]), _: 1 }, 8, ["title"]) ])) : m("", !0) ], 2) ]), _: 3 }, 16, ["type", "size", "disabled"])); } }); export { fe as default };