yanzhen-design-vue
Version:
45 lines (44 loc) • 1.15 kB
JavaScript
import { ref, unref, reactive } from "vue";
import { useFileListConfig } from "./hooks/use-file-list-config.mjs";
function useUploadPreview(props, emit) {
const imagePreviewRef = ref();
const filePreviewRef = ref();
const { fileListRef, isImageType } = useFileListConfig(props, emit);
function handleOpenPreviewImage(file) {
var _a, _b;
if ((_a = unref(imagePreviewRef)) == null ? void 0 : _a.open) {
(_b = unref(imagePreviewRef)) == null ? void 0 : _b.open(file);
}
}
function handleOpenPreviewFile(file) {
var _a, _b;
if ((_a = unref(filePreviewRef)) == null ? void 0 : _a.open) {
(_b = unref(filePreviewRef)) == null ? void 0 : _b.open(file);
}
}
function handleOpenPreview(file) {
if (unref(isImageType)) {
handleOpenPreviewImage(file);
} else {
handleOpenPreviewFile(file);
}
}
const ctx = {
handleOpenPreviewImage,
handleOpenPreviewFile,
handleOpenPreview,
imagePreviewRef,
filePreviewRef,
fileListRef,
isImageType
};
const exposeCtx = reactive(ctx);
return {
...ctx,
ctx,
exposeCtx
};
}
export {
useUploadPreview
};