Skip to content

附件上传

表单中需要附件上传时使用

基础用法

引入组件 import AttachmentUpload from "@/components/attachment-upload/index.vue" 使用v-model进行双向绑定即可。双向绑定的数据为逗号分隔格式,返回的数据为后台附件表sys_attachment的主键id

image-20250221151925930

vue
<template>
  <a-flex vertical :gap="8">
    <a-typography-title :level="4">基础用法</a-typography-title>
    <a-typography-text>绑定数据:{{modelValue}}</a-typography-text>
    <attachment-upload v-model="modelValue"/>
  </a-flex>
</template>

<script setup lang="ts">
import AttachmentUpload from "@/components/attachment-upload/index.vue";
import {ref} from "vue";
const modelValue = ref<string>()
</script>

图片预览

设置model="picture"即可

image-20250221152410921

vue
<template>
  <a-flex vertical :gap="8">
    <a-typography-title :level="4">图片预览</a-typography-title>
    <a-typography-text>绑定数据:{{modelValue}}</a-typography-text>
    <attachment-upload v-model="modelValue" model="picture"/>
  </a-flex>
</template>

<script setup lang="ts">
import AttachmentUpload from "@/components/attachment-upload/index.vue";
import {ref} from "vue";
const modelValue = ref<string>()
</script>

拖拽上传

设置model="dragger"即可

image-20250221152553597

vue
<template>
  <a-flex vertical :gap="8">
    <a-typography-title :level="4">拖拽上传</a-typography-title>
    <a-typography-text>绑定数据:{{modelValue}}</a-typography-text>
    <attachment-upload v-model="modelValue" model="dragger"/>
  </a-flex>
</template>

<script setup lang="ts">
import AttachmentUpload from "@/components/attachment-upload/index.vue";
import {ref} from "vue";
const modelValue = ref<string>()
</script>

分片上传

分片上传也支持图片预览、拖拽上传模式

设置chunk="true" 即可,还可以设置每个片段大小,分片同时上传数量

image-20250221152744912

vue
<template>
  <a-flex vertical :gap="8">
    <a-typography-title :level="4">分片上传</a-typography-title>
    <a-typography-text>绑定数据:{{modelValue}}</a-typography-text>
    <attachment-upload v-model="modelValue" :max-size="100" chunk :chunk-size="10" :chunk-upload-count="2"/>
  </a-flex>
</template>

<script setup lang="ts">
import AttachmentUpload from "@/components/attachment-upload/index.vue";
import {ref} from "vue";
const modelValue = ref<string>()
</script>

API

双向绑定

属性名称描述类型默认值是否必填
v-model双向绑定string-

属性

属性名称描述类型默认值是否必填
model模式切换button|picture|draggerbutton
icon附件图标string(图标组件名称)-
text描述文本string-
uploadType可上传附件类型string[]-
description详细说明(仅拖拽生效)string-
maxCount最大上传数量(超出后不会调用上传)number10
maxSize最大上传大小,分片上传注意调整大小(MB)number10
multiple是否支持多选(分片上传不支持)booleantrue
directory是否支持文件夹上传(分片上传不支持)booleanfalse
businessCode业务编码string路由名称
businessName业务名称string菜单名称
chunk是否分片上传booleanfalse
chunkSize最大分片大小number20
chunkUploadCount分片同时上传数量number3

方法

方法名称描述参数
uploadSuccess上传成功触发附件,附件列表
remove附件删除时触发删除的附件
uploadError上传失败触发附件,失败原因
exceedMaxCount超出附件最大数限制时触发超出的附件