实现表格列表显示图片名称,点击可下载

显示如图效果:



jsp代码:

 <td>
                             <a href="javascript:downloadMaterial1('${item[12] }');" title="${fn:split(item[12], ',')[0]}">
                                  <c:if test="${item[6]==0 }">身份证正面</c:if>
  <c:if test="${item[6]==1 }">军官证正面</c:if>
                             <c:if test="${item[6]==2 }">临时身份证正面</c:if>
                             </a>
                           &nbsp;&nbsp;
                           <a href="javascript:downloadMaterial2('${item[12] }');" title="${fn:split(item[12], ',')[1]}">
                                   <c:if test="${item[6]==0 }">身份证反面</c:if>
  <c:if test="${item[6]==1 }">军官证反面</c:if>
                             <c:if test="${item[6]==2 }">临时身份证反面</c:if>
                             </a>
                       </td>


js:

function downloadMaterial1(fileName){
   var fileName1 = fileName.split(",")[0];
   window.location.href="<%=path %>/download_downFile.action?fileName="+fileName1;
}
function downloadMaterial2(fileName){
   var fileName2 = fileName.split(",")[1];
   window.location.href="<%=path %>/download_downFile.action?fileName="+fileName2;
}



后台代码:

package cn.com.p2p.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class DownLoadFile extends ActionSupport{
private static final long serialVersionUID = -2207648627734251737L;


@SuppressWarnings("deprecation")
public String downFile() throws Exception{
   HttpServletRequest request = ServletActionContext.getRequest();
   HttpServletResponse response = ServletActionContext.getResponse();
  
   String fileminitype = request.getParameter("fileType");
   String fileName = new String(request.getParameter("fileName").getBytes("ISO8859-1"),"UTF-8");
   String filepath = StringUtil.getUploadPath();
   File f = new File(filepath+"/"+fileName);
   Long filelength = f.length();
   int cacheTime = 10;
  
   response.setContentType(fileminitype);
   response.setHeader("Location",fileName);
   response.setHeader("Cache-Control", "max-age=" + cacheTime);
  
   response.setContentType("application/octet-stream");
   byte[] b = fileName.getBytes("GBK");   
   fileName = new String(b,"8859_1");   
   response.setHeader("Content-Disposition", "attachment;filename=" + fileName); 
   response.setContentLength(filelength.intValue());
   OutputStream outputStream = response.getOutputStream();
   InputStream inputStream = new FileInputStream(f);
   byte[] buffer = new byte[1024];
   int i = -1;
   while ((i = inputStream.read(buffer)) != -1) {
        outputStream.write(buffer, 0, i);
   }
   outputStream.flush();
   outputStream.close();
   inputStream.close();
   return null ;
   }
}

Ant Design Vue 的 Table 组件支持自定义列,你可以在自定义列中添加一个点击事件来实现图片的放大效果。具体步骤如下: 1. 在 Table 的 columns 中添加一个自定义列,如下所示: ```javascript { title: '图片', dataIndex: 'imageUrl', scopedSlots: { customRender: 'imageUrl' } }, ``` 这里的 `scopedSlots` 属性用于定义自定义列的渲染方式。 2. 在 Table 的 `template` 中定义 `customRender` 的具体实现,如下所示: ```html <template> <a-table :columns="columns" :data-source="dataSource"> <template slot="imageUrl" slot-scope="text"> <a @click="showModal(text)"> <img :src="text" style="width: 50px; height: 50px"> </a> </template> </a-table> </template> ``` 这里的 `slot` 属性用于定义自定义列的名称,`slot-scope` 属性用于获取当前行的数据对象。 3. 在 `methods` 中定义 `showModal` 方法,用于显示放大后的图片: ```javascript methods: { showModal(text) { this.imageUrl = text; this.visible = true; }, }, ``` 在 `showModal` 方法中,我们将当前行的图片地址保存到 `imageUrl` 变量中,并将 `visible` 变量设置为 `true`,以显示 `Modal` 弹窗。 4. 在 `template` 中添加 `Modal` 弹窗组件,如下所示: ```html <template> <a-table :columns="columns" :data-source="dataSource"> <template slot="imageUrl" slot-scope="text"> <a @click="showModal(text)"> <img :src="text" style="width: 50px; height: 50px"> </a> </template> </a-table> <a-modal v-model="visible"> <img :src="imageUrl" style="max-width: 100%"> </a-modal> </template> ``` 这里的 `v-model` 属性用于控制 `Modal` 弹窗的显示和隐藏,当 `visible` 变量为 `true` 时,弹窗显示;当 `visible` 变量为 `false` 时,弹窗隐藏。 这样,当用户点击表格中的图片时,就会弹出一个模态框,显示放大后的图片。用户点击模态框外部区域或者关闭按钮,模态框就会关闭,放大后的图片也会随之消失。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值