UNPKG

@aplus-frontend/ui

Version:

107 lines (106 loc) 3.4 kB
import { defineComponent as F, ref as L, useSlots as S, computed as t, unref as a, createBlock as x, openBlock as i, mergeProps as A, withCtx as j, createElementVNode as m, normalizeClass as I, createElementBlock as u, createCommentVNode as f, createVNode as M, renderSlot as T, toDisplayString as U } from "vue"; import { Button as V } from "@aplus-frontend/antdv"; import { LoadingOutlined as D } from "@ant-design/icons-vue"; import "../config-provider/index.mjs"; import { useOssInit as E } from "./hooks/index.mjs"; import { getFileInfo as g } from "./utils/getFileInfo.mjs"; import { useStyle as P } from "./hooks/useStyle.mjs"; import { useLocale as G } from "../config-provider/hooks/use-locale.mjs"; import { useGlobalConfig as r } from "../config-provider/hooks/use-global-config.mjs"; const R = { key: 0, class: "spin" }, W = { key: 1, class: "icon" }, $ = { class: "text" }, oe = /* @__PURE__ */ F({ 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] }, getOssAccess: {} }, emits: ["downloadCallback"], setup(y, { emit: C }) { const N = C, n = L(!1), { lang: b } = G(), v = S(), h = t(() => b.value === "zh-cn" ? "zh_CN" : "en_US"), w = r("uiMode"), e = y, l = r("apUpload"), c = r( "downloadCenterTriggerConfig" ), d = t(() => e.disabled), _ = t(() => e.color ? e.color : w.value === "aplus" ? "#0070FF" : "#1890FF"), k = t(() => e.size), { getInnerWrapperClass: B } = P(_, k, d), z = t(() => e.getOssAccess || l.value?.getOssAccess), O = async () => { if (!e.disabled) { n.value = !0; try { if (c.value?.trigger) { let s = g( e.needName ?? l?.value?.needName, e.fileName ).map((p) => ({ objectName: p.path, fileName: p.fileName })); await c.value?.trigger(s); } else { const s = await (await E( z.value, a(h) )).downloadFile( g( e.needName ?? l?.value?.needName, e.fileName ) ); N("downloadCallback", s); } } catch (o) { console.error(o); } finally { n.value = !1; } } }; return (o, s) => (i(), x(a(V), A(e, { type: e.type, size: e.size, disabled: d.value, onClick: O }), { default: j(() => [ m("div", { class: I(a(B)) }, [ n.value ? (i(), u("span", R, [ M(a(D), { spin: !0 }) ])) : f("", !0), a(v).icon ? (i(), u("span", W, [ T(o.$slots, "icon") ])) : f("", !0), m("span", $, U(o.text), 1) ], 2) ]), _: 3 }, 16, ["type", "size", "disabled"])); } }); export { oe as default };