upload2.mjs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { defineComponent, shallowRef, computed, onBeforeUnmount, provide, toRef, openBlock, createElementBlock, unref, createBlock, createSlots, withCtx, createVNode, mergeProps, renderSlot, createCommentVNode } from 'vue';
  2. import { uploadContextKey } from './constants.mjs';
  3. import UploadList from './upload-list2.mjs';
  4. import UploadContent from './upload-content2.mjs';
  5. import { useHandlers } from './use-handlers.mjs';
  6. import { uploadProps } from './upload.mjs';
  7. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  8. import { useFormDisabled } from '../../form/src/hooks/use-form-common-props.mjs';
  9. const __default__ = defineComponent({
  10. name: "ElUpload"
  11. });
  12. const _sfc_main = /* @__PURE__ */ defineComponent({
  13. ...__default__,
  14. props: uploadProps,
  15. setup(__props, { expose }) {
  16. const props = __props;
  17. const disabled = useFormDisabled();
  18. const uploadRef = shallowRef();
  19. const {
  20. abort,
  21. submit,
  22. clearFiles,
  23. uploadFiles,
  24. handleStart,
  25. handleError,
  26. handleRemove,
  27. handleSuccess,
  28. handleProgress,
  29. revokeFileObjectURL
  30. } = useHandlers(props, uploadRef);
  31. const isPictureCard = computed(() => props.listType === "picture-card");
  32. const uploadContentProps = computed(() => ({
  33. ...props,
  34. fileList: uploadFiles.value,
  35. onStart: handleStart,
  36. onProgress: handleProgress,
  37. onSuccess: handleSuccess,
  38. onError: handleError,
  39. onRemove: handleRemove
  40. }));
  41. onBeforeUnmount(() => {
  42. uploadFiles.value.forEach(revokeFileObjectURL);
  43. });
  44. provide(uploadContextKey, {
  45. accept: toRef(props, "accept")
  46. });
  47. expose({
  48. abort,
  49. submit,
  50. clearFiles,
  51. handleStart,
  52. handleRemove
  53. });
  54. return (_ctx, _cache) => {
  55. return openBlock(), createElementBlock("div", null, [
  56. unref(isPictureCard) && _ctx.showFileList ? (openBlock(), createBlock(UploadList, {
  57. key: 0,
  58. disabled: unref(disabled),
  59. "list-type": _ctx.listType,
  60. files: unref(uploadFiles),
  61. crossorigin: _ctx.crossorigin,
  62. "handle-preview": _ctx.onPreview,
  63. onRemove: unref(handleRemove)
  64. }, createSlots({
  65. append: withCtx(() => [
  66. createVNode(UploadContent, mergeProps({
  67. ref_key: "uploadRef",
  68. ref: uploadRef
  69. }, unref(uploadContentProps)), {
  70. default: withCtx(() => [
  71. _ctx.$slots.trigger ? renderSlot(_ctx.$slots, "trigger", { key: 0 }) : createCommentVNode("v-if", true),
  72. !_ctx.$slots.trigger && _ctx.$slots.default ? renderSlot(_ctx.$slots, "default", { key: 1 }) : createCommentVNode("v-if", true)
  73. ]),
  74. _: 3
  75. }, 16)
  76. ]),
  77. _: 2
  78. }, [
  79. _ctx.$slots.file ? {
  80. name: "default",
  81. fn: withCtx(({ file, index }) => [
  82. renderSlot(_ctx.$slots, "file", {
  83. file,
  84. index
  85. })
  86. ])
  87. } : void 0
  88. ]), 1032, ["disabled", "list-type", "files", "crossorigin", "handle-preview", "onRemove"])) : createCommentVNode("v-if", true),
  89. !unref(isPictureCard) || unref(isPictureCard) && !_ctx.showFileList ? (openBlock(), createBlock(UploadContent, mergeProps({
  90. key: 1,
  91. ref_key: "uploadRef",
  92. ref: uploadRef
  93. }, unref(uploadContentProps)), {
  94. default: withCtx(() => [
  95. _ctx.$slots.trigger ? renderSlot(_ctx.$slots, "trigger", { key: 0 }) : createCommentVNode("v-if", true),
  96. !_ctx.$slots.trigger && _ctx.$slots.default ? renderSlot(_ctx.$slots, "default", { key: 1 }) : createCommentVNode("v-if", true)
  97. ]),
  98. _: 3
  99. }, 16)) : createCommentVNode("v-if", true),
  100. _ctx.$slots.trigger ? renderSlot(_ctx.$slots, "default", { key: 2 }) : createCommentVNode("v-if", true),
  101. renderSlot(_ctx.$slots, "tip"),
  102. !unref(isPictureCard) && _ctx.showFileList ? (openBlock(), createBlock(UploadList, {
  103. key: 3,
  104. disabled: unref(disabled),
  105. "list-type": _ctx.listType,
  106. files: unref(uploadFiles),
  107. crossorigin: _ctx.crossorigin,
  108. "handle-preview": _ctx.onPreview,
  109. onRemove: unref(handleRemove)
  110. }, createSlots({
  111. _: 2
  112. }, [
  113. _ctx.$slots.file ? {
  114. name: "default",
  115. fn: withCtx(({ file, index }) => [
  116. renderSlot(_ctx.$slots, "file", {
  117. file,
  118. index
  119. })
  120. ])
  121. } : void 0
  122. ]), 1032, ["disabled", "list-type", "files", "crossorigin", "handle-preview", "onRemove"])) : createCommentVNode("v-if", true)
  123. ]);
  124. };
  125. }
  126. });
  127. var Upload = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "upload.vue"]]);
  128. export { Upload as default };
  129. //# sourceMappingURL=upload2.mjs.map