@cmstops/pro-compo
Version:
[物料平台文档中心](https://arco.design/docs/material/guide)
81 lines (80 loc) • 3.12 kB
JavaScript
import { defineComponent, ref, openBlock, createElementBlock, Fragment, createVNode, unref, isRef } from "vue";
import { fileAdapter } from "./script/fileTypeAdapter.js";
import { uploadFile, uploadAddRequest } from "./script/fileUpload.js";
import _sfc_main$1 from "./components/UploadForClick.js";
import _sfc_main$2 from "./components/UploadBefore.js";
import { DEFAULT_BASE_API } from "../config.js";
import { useToggle } from "../hooks/toggle.js";
import { to } from "../utils/index.js";
import { usePreUploadOptions, useUplaodList } from "./script/uploadHooks.js";
const _sfc_main = defineComponent({
...{ name: "uploadBefore" },
__name: "component",
props: {
BASE_API: {},
uploadMethod: {}
},
emits: ["onProgress", "onListReady"],
setup(__props, { emit: __emit }) {
const { state: visBeforeUpload, open: openBeforePannel } = useToggle();
const { state: visUploadList, open: openListPannel } = useToggle();
const props = __props;
const emits = __emit;
const baseApi = ref(props.BASE_API || DEFAULT_BASE_API);
const { preOptionsList, uploadFileToShowFileTrans } = usePreUploadOptions();
const { fileList, uploadFileAdd } = useUplaodList();
const afterChoose = (file) => {
const retFile = fileAdapter(file);
if (!retFile)
return;
uploadFileAdd(retFile);
uploadFileToShowFileTrans(retFile);
!visBeforeUpload.value && openBeforePannel();
};
const afterPayload = (fl) => {
emits("onListReady", fl);
!visUploadList.value && openListPannel();
for (const file of fileList.value) {
handleProcess(file, fl);
}
};
async function handleProcess(file, fl) {
file.id;
const sId = file.dirId || file.id;
const [err, uploadRet] = await to(
uploadFile(file.file, (p) => emits("onProgress", sId, p, 0))
);
if (err || !uploadRet || !uploadRet.url)
return emits("onProgress", sId, 0, -1);
emits("onProgress", sId, 100, 2);
const showFileData = fl.find((item) => item.id === sId);
if (!showFileData)
return false;
uploadAddRequest(
showFileData,
{ rid: 4, dirId: 0, url: uploadRet.url },
baseApi.value,
(data) => {
}
);
return true;
}
return (_ctx, _cache) => {
return openBlock(), createElementBlock(Fragment, null, [
createVNode(_sfc_main$1, {
"upload-method": _ctx.uploadMethod,
onAfterChoose: afterChoose
}, null, 8, ["upload-method"]),
createVNode(_sfc_main$2, {
visable: unref(visBeforeUpload),
"onUpdate:visable": _cache[0] || (_cache[0] = ($event) => isRef(visBeforeUpload) ? visBeforeUpload.value = $event : null),
"file-list": unref(preOptionsList),
"onUpdate:fileList": _cache[1] || (_cache[1] = ($event) => isRef(preOptionsList) ? preOptionsList.value = $event : null),
BASE_API: baseApi.value,
onConfirm: afterPayload
}, null, 8, ["visable", "file-list", "BASE_API"])
], 64);
};
}
});
export { _sfc_main as default };