You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
16 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, shallowRef, openBlock, createElementBlock, normalizeClass, unref, withKeys, withModifiers, createBlock, withCtx, renderSlot, createElementVNode } from 'vue';\nimport { cloneDeep, isEqual } from 'lodash-unified';\nimport UploadDragger from './upload-dragger2.mjs';\nimport { uploadContentProps } from './upload-content.mjs';\nimport { genFileId } from './upload.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { entriesOf } from '../../../utils/objects.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { useFormDisabled } from '../../form/src/hooks/use-form-common-props.mjs';\nimport { isPlainObject, isFunction } from '@vue/shared';\nconst __default__ = defineComponent({\n name: \"ElUploadContent\",\n inheritAttrs: false\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: uploadContentProps,\n setup(__props, {\n expose\n }) {\n const props = __props;\n const ns = useNamespace(\"upload\");\n const disabled = useFormDisabled();\n const requests = shallowRef({});\n const inputRef = shallowRef();\n const uploadFiles = files => {\n if (files.length === 0) return;\n const {\n autoUpload,\n limit,\n fileList,\n multiple,\n onStart,\n onExceed\n } = props;\n if (limit && fileList.length + files.length > limit) {\n onExceed(files, fileList);\n return;\n }\n if (!multiple) {\n files = files.slice(0, 1);\n }\n for (const file of files) {\n const rawFile = file;\n rawFile.uid = genFileId();\n onStart(rawFile);\n if (autoUpload) upload(rawFile);\n }\n };\n const upload = async rawFile => {\n inputRef.value.value = \"\";\n if (!props.beforeUpload) {\n return doUpload(rawFile);\n }\n let hookResult;\n let beforeData = {};\n try {\n const originData = props.data;\n const beforeUploadPromise = props.beforeUpload(rawFile);\n beforeData = isPlainObject(props.data) ? cloneDeep(props.data) : props.data;\n hookResult = await beforeUploadPromise;\n if (isPlainObject(props.data) && isEqual(originData, beforeData)) {\n beforeData = cloneDeep(props.data);\n }\n } catch (e) {\n hookResult = false;\n }\n if (hookResult === false) {\n props.onRemove(rawFile);\n return;\n }\n let file = rawFile;\n if (hookResult instanceof Blob) {\n if (hookResult instanceof File) {\n file = hookResult;\n } else {\n file = new File([hookResult], rawFile.name, {\n type: rawFile.type\n });\n }\n }\n doUpload(Object.assign(file, {\n uid: rawFile.uid\n }), beforeData);\n };\n const resolveData = async (data, rawFile) => {\n if (isFunction(data)) {\n return data(rawFile);\n }\n return data;\n };\n const doUpload = async (rawFile, beforeData) => {\n const {\n headers,\n data,\n method,\n withCredentials,\n name: filename,\n action,\n onProgress,\n onSuccess,\n onError,\n httpRequest\n } = props;\n try {\n beforeData = await resolveData(beforeData != null ? beforeData : data, rawFile);\n } catch (e) {\n props.onRemove(rawFile);\n return;\n }\n const {\n uid\n } = rawFile;\n const options = {\n headers: headers || {},\n withCredentials,\n file: rawFile,\n data: beforeData,\n method,\n filename,\n action,\n onProgress: evt => {\n onProgress(evt, rawFile);\n },\n onSuccess: res => {\n onSuccess(res, rawFile);\n delete requests.value[uid];\n },\n onError: err => {\n onError(err, rawFile);\n delete requests.value[uid];\n }\n };\n const re