@ithinkdt/naive
Version:
iThinkDT Naive UI
72 lines (71 loc) • 1.93 kB
JavaScript
import { shallowReactive as f, defineComponent as d, shallowRef as s, watch as u, reactive as c, createVNode as m, isVNode as p } from "vue";
import { NFlex as y } from "ithinkdt-ui";
import { debouncedWatch as g } from "@vueuse/core";
import { CORE_CTX as o } from "@ithinkdt/core";
import { i as h } from "./index-CDEm3BS5.js";
function b(i) {
return typeof i == "function" || Object.prototype.toString.call(i) === "[object Object]" && !p(i);
}
const r = f({});
g(r, (i) => {
const a = Object.keys(i);
a.length !== 0 && o.fileInfo(a).then((l) => {
for (const e of l) {
const t = r[e.fileId];
delete r[e.fileId], t.name = e.fileName;
}
});
}, {
debounce: 1e3 / 60
});
const j = /* @__PURE__ */ d({
name: "NFiles",
props: {
type: {
type: String,
default: "file"
},
files: {
type: [Array, String],
default: () => []
}
},
setup(i) {
const a = s([]);
return u([() => i.type, () => i.files], ([l, e]) => {
typeof e == "string" && (e = e.split(",")), a.value = e.map((t) => {
let n = typeof t == "string" ? {
id: t,
fileId: t,
_name: t,
name: "",
status: "finished",
type: l === "image" ? "image/*" : void 0,
thumbnailUrl: o.filePreview(t),
url: l === "image" ? o.filePreview(t) : o.fileDownload(t)
} : t;
return l !== "image" && !n.name && (n = c(n), r[n.fileId] = n), n;
});
}, {
immediate: !0
}), () => {
let l;
return i.type === "file" ? m(y, {
size: "small"
}, b(l = a.value.map((e) => m("a", {
href: e.url,
download: e.name
}, [e.name || e._name]))) ? l : {
default: () => [l]
}) : m(h, {
disabled: !0,
listType: "image-card",
max: a.value.length,
fileList: a.value
}, null);
};
}
});
export {
j as NFiles
};