UNPKG

@aplus-frontend/ui

Version:

105 lines (104 loc) 3.38 kB
import { defineComponent as F, computed as n, ref as S, watchEffect as U, createBlock as d, openBlock as l, unref as s, mergeProps as f, withCtx as j, renderSlot as B, normalizeProps as E, guardReactiveProps as I, createElementVNode as p, normalizeClass as L, createElementBlock as D, Fragment as M, renderList as P, resolveDynamicComponent as R, createVNode as T } from "vue"; import { Image as x } from "@aplus-frontend/antdv"; import { DownloadOutlined as z } from "@ant-design/icons-vue"; import { injectLocaleToOss as V, getOssInstance as W, getSignatureUrl as G } from "./hooks/useOss.mjs"; import "../../config-provider/index.mjs"; import $ from "./imgs/admin-fallback.jpg.mjs"; import q from "./imgs/aplus-fallback.jpg.mjs"; import { omit as H } from "lodash-unified"; import { useNamespace as J } from "../../config-provider/hooks/use-namespace.mjs"; import { useGlobalConfig as c } from "../../config-provider/hooks/use-global-config.mjs"; import { useLocale as K } from "../../config-provider/hooks/use-locale.mjs"; const le = /* @__PURE__ */ F({ __name: "ApImage", props: { getOssAccess: {}, width: {}, height: {}, alt: {}, fallback: {}, src: {}, fileName: {}, preview: { type: [Boolean, Object], default: !0 } }, setup(g) { const { b: i } = J("ap-image"), e = g, m = { aplus: q, admin: $ }, b = c("uiMode"), v = c("apUpload"), u = c( "downloadCenterTriggerConfig" ), { t: k, lang: w } = K(), h = n( () => e.getOssAccess || v.value?.getOssAccess ), C = n( () => m[b.value] || m.aplus ), O = n(() => e?.fallback || C.value), a = S(""); V(k, w), U(async () => { if (!e?.src) { a.value = ""; return; } if (!e.src?.startsWith("Frontend-Upload")) { a.value = e.src; return; } try { const t = await W(h.value), o = await G({ oss: t, fileName: e.src }); o && (a.value = o); } catch { a.value = ""; } }); async function A() { if (!e?.src) return; const t = e.src, o = e.fileName ?? e.src; if (!e.src?.startsWith("Frontend-Upload")) { N(t, o); return; } if (u.value?.trigger) { let r = [ { objectName: t, fileName: o } ]; await u.value?.trigger(r); } } const N = (t, o) => { const r = document.createElement("a"); r.href = t, r.rel = "noopener noreferrer", r.setAttribute("download", o), document.body.appendChild(r), r.click(), document.body.removeChild(r); }; return (t, o) => (l(), d(s(x), f({ class: [s(i)()] }, { ...s(H)(e, ["src", "getOssAccess"]), fallback: O.value, src: a.value }), { toolbarRender: j((r) => [ B(t.$slots, "toolbarRender", E(I({ ...r })), () => [ p("div", { class: L([s(i)("toolbar")]) }, [ (l(!0), D(M, null, P(r.originalNodes, (y, _) => (l(), d(R(y), f({ ref_for: !0 }, e, { key: _ }), null, 16))), 128)), p("div", { class: "ant-image-preview-operations-operation", onClick: A }, [ T(s(z)) ]) ], 2) ]) ]), _: 3 }, 16, ["class"])); } }); export { le as default };