jeecg-vue3-slots插槽搭配upload文件上传的简单使用

1.test.vue(文件内容对多个文件。一对多实现方式,可调整)

<BasicTable @register="registerTable">
      <template #upload="{ record }">
        <a-upload
          name="file"
          :multiple="true"
          :beforeUpload="beforeUpload"
          :action="uploadUrl"
          :headers="headers"
          @success="uploadChange"
          :showUploadList="false"
          :maxCount="5"
          :disabled="isDisabled"
        >
          <a-button>
            上传文件<Icon icon="ant-design:upload-outlined" />
          </a-button>
          <div class="upload-error">
            只能上传PDF、Word或Excel文件!
          </div>
        </a-upload>
        <div v-if="record.urlList && record.urlList.length > 0">
          <h4>已上传文件列表:</h4>
          <div v-for="url in record.urlList" :key="url" class="list-view">
            {{ url.wjmc }}
            <a-space wrap>
              <!-- 根据文件类型展示不同的按钮 -->
              <a-button type="primary" size="small" @click="handleDeleteFile(url)" v-show="!isDisabled">删除</a-button>
            </a-space>
          </div>
        </div>
      </template>
    </BasicTable>

2.test.data.api

export const fileUploadColumns: BasicColumn[] = [
    {
        title: '内容',
        dataIndex: 'wjmc',
    },
    {
        title: '操作',
        dataIndex: 'operation',
        slots: { customRender: 'upload' },
    },
]

3.依赖导入

  import { Icon } from '/@/components/Icon';

  import { BasicTable } from '/@/components/Table';

  import { useMessage } from '/@/hooks/web/useMessage';  //文件上传成功依赖

  import { fileUploadColumns } from './test.data';

4.注意和总结

1.<template #upload="{ record }"> record 是集合的遍历,可以修改; upload与slots: { customRender: 'upload' }相对应
2.实现了table文件上传,table文件删除,table文件列表展示,table文件格式限制,table上传个数限制

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Jeecg-Boot是一款基于Spring Boot和Mybatis-Plus的开发平台,主要用于快速开发企业级的后台管理系统。而Vue.js是一款流行的前端JavaScript框架。在Jeecg-Boot中使用Vue.js可以实现前后端分离的开发模式,提高开发效率和可维护性。 针对将.xls文件转为.zip文件的需求,你可以在Vue.js使用jsZip库来实现。具体步骤如下: 1.安装jsZip库 可以使用npm安装jsZip库: ``` npm install jszip --save ``` 2.在Vue.js中导入jsZip库 在需要使用jsZip的组件中,导入jsZip库: ``` import JSZip from 'jszip' ``` 3.编写jsZip代码 在Vue.js组件中,可以编写如下代码将.xls文件转为.zip文件: ``` // 读取.xls文件 axios.get('/api/getExcel') .then(res => { const fileData = res.data // 实例化jsZip对象 const zip = new JSZip() // 将.xls文件添加到zip包中 zip.file('example.xls', fileData, { binary: true }) // 生成zip包 zip.generateAsync({ type: 'blob' }) .then(content => { // 下载zip包 const link = document.createElement('a') link.href = URL.createObjectURL(content) link.download = 'example.zip' link.click() }) }) ``` 这段代码通过axios库向服务器请求获取.xls文件,然后使用jsZip库将文件添加到zip包中,并生成zip包并下载。需要注意的是,这里使用了二进制方式读取文件内容,需要在axios请求中设置responseType为'arraybuffer'。 以上就是在Jeecg-Boot框架中使用Vue.js将.xls文件转为.zip文件的方法,希望能对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值