欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

layui實現(xiàn)文件或圖片上傳記錄

 更新時間:2018年08月28日 14:40:50   作者:數(shù)據(jù)挖掘新手  
這篇文章主要為大家詳細介紹了layui實現(xiàn)文件或圖片上傳記錄,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文為大家分享了layui實現(xiàn)文件或圖片上傳記錄的具體代碼,供大家參考,具體內容如下

首先是layui自己的官網(wǎng)關于圖片/文件上傳的幫助文檔

接下來是我自己的使用記錄:

1.首先在js中定義一個全局變量

var uploadListIns;

2.進行賦值

//多文件列表示例
/**
 * 圖片上傳
 */
layui.use('upload', function(){
 var $ = layui.jquery,upload = layui.upload;
 var demoListView = $('#proImageList');
 uploadListIns = upload.render({
  elem: '#chooseFile', //選擇文件的按鈕
  url: 'upload!ftp.action', //后臺處理文件長傳的方法
  data:{'serviceName':'外協(xié)訂單供應商上傳檢驗報告','tableName':'T_OUTSOURCE_ORDER','fileType':'圖片'},
  accept: 'file', 
  multiple: true,  //是否允許多文件上傳
  acceptMime: 'image/*', //規(guī)定打開文件選擇框時,篩選出的文件類型
  field:'upload',  
  auto: false, 
  bindAction: '#upload', //用來觸發(fā)上傳的按鈕ID
  choose: function(obj){ //選擇文件后的回調函數(shù),本例中在此將選擇的文件進行展示
   var files = this.files = obj.pushFile(); //將每次選擇的文件追加到文件隊列
   //讀取本地文件
   obj.preview(function(index, file, result){
    var tr = $(['<tr id="upload-'+ index +'">'
     ,'<td>'+ file.name +'</td>'
     ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>'
     ,'<td>等待上傳</td>'
     ,'<td>'
     ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重傳</button>'
     ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">刪除</button>'
     ,'</td>'
     ,'</tr>'].join(''));
 
    //單個重傳
    tr.find('.demo-reload').on('click', function(){
     obj.upload(index, file);
    });
 
    //刪除
    tr.find('.demo-delete').on('click', function(){
     delete files[index]; //刪除對應的文件
     tr.remove();
     uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免刪除后出現(xiàn)同名文件不可選
    });
    demoListView.append(tr);
   });
  },  
  done: function(res, index, upload){    //多文件上傳時,只要有一個文件上傳成功后就會觸發(fā)這個回調函數(shù)
   console.info(res);
   if(res.status == "success"){ //上傳成功
    var tr = demoListView.find('tr#upload-'+ index)
     ,tds = tr.children();
    tds.eq(2).html('<span style="color: #5FB878;">上傳成功</span>');
    tds.eq(3).html('<a href="'+res.url+'" rel="external nofollow" >查看</a>'); //清空操作
    return delete this.files[index]; //刪除文件隊列已經(jīng)上傳成功的文件
   }else{
    alert(res.message);
   }
   this.error(index, upload);
  },
  allDone: function(obj){ //當文件全部被提交后,才觸發(fā)
   if(obj.total > obj.successful){
    layer.msg("有文件上傳失敗,暫不更新生產(chǎn)進度,請重試或聯(lián)系管理員");
   }else {
    //更新生產(chǎn)進度
    updateProductionSchedule(currentId, currentSchedule);
   }
  },
  error: function(index, upload){
   var tr = demoListView.find('tr#upload-'+ index)
    ,tds = tr.children();
   tds.eq(2).html('<span style="color: #FF5722;">上傳失敗</span>');
   tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //顯示重傳
  }
 });
 $(".layui-upload-file").hide();
});

上述js代碼中出現(xiàn)的相關html元素如下,相關引入js文件和css為:bootstrap3的js和css及l(fā)ayui的js文件即可

<!-- 模態(tài)框(Modal) -->
<div class="modal fade" id="uploadModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <div class="modal-dialog">
  <div class="modal-content">
   <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
     ×
    </button>
    <h4 class="modal-title" id="myModalLabel">
     上傳檢驗報告
    </h4>
   </div>
   <div class="modal-body">
    <button type="button" class="btn btn-primary" id="chooseFile">選擇多文件</button>
    <button type="button" class="btn btn-success" id="upload">開始上傳</button>
    <div class="table-responsive">
     <table class="table table-hover">
      <thead><tr>
       <th>文件名</th>
       <th>大小</th>
       <th>狀態(tài)</th>
       <th>操作</th>
      </tr></thead>
      <tbody id="proImageList"></tbody>
     </table>
    </div>
   </div>
   <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">關閉
    </button>
   </div>
  </div><!-- /.modal-content -->
 </div><!-- /.modal -->
</div>

3.在打開模態(tài)框時可以對1中定義的變量進行動態(tài)賦值,這些變量會相應的傳到后臺中:

function showUploadModal(id) {
 //動態(tài)賦值
 uploadListIns.config.data.tableRecordId = id;
 uploadListIns.config.data.filenamePrefix = id+".自檢pass.";
 $("#uploadModal").modal("show");
}

4.最終前端實現(xiàn)效果如下:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論