ElFileUpload.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <script lang="ts" setup>
  2. import config from '@/config/defaultSetting'
  3. import { useUpload } from '@/hooks/useUpload'
  4. import type { BasicFormItem } from '@/types/form'
  5. interface Props {
  6. modelValue: any
  7. item?: BasicFormItem
  8. fileSize?: number | string
  9. action?: string
  10. oss?: boolean
  11. }
  12. const props = withDefaults(defineProps<Props>(), {
  13. action: config.uploadApi,
  14. fileSize: 100,
  15. oss: config.oss
  16. })
  17. const emits = defineEmits(['update:modelValue'])
  18. const { modelValue, headers, action, uploadAttrs, beforeUpload, handleRemove } = useUpload(props, emits, 'file')
  19. </script>
  20. <template>
  21. <el-upload
  22. v-model:file-list="modelValue"
  23. :action="action"
  24. :headers="headers"
  25. :before-upload="beforeUpload"
  26. :on-remove="handleRemove"
  27. v-bind="{ ...uploadAttrs, ...$attrs }"
  28. >
  29. <template #[slot.name]="slotProps" v-for="slot in item?.slots" :key="slot.alias">
  30. <slot :name="slot.alias" v-bind="slotProps">
  31. <el-button type="primary">上传</el-button>
  32. </slot>
  33. </template>
  34. </el-upload>
  35. </template>
  36. <style lang="scss" scoped></style>