1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| let element = layui.element let demoListPeople = $('#demoListPeople') upload.render({ elem: '#upload-people-btn', size: 102400, url: '/import-people', accept: 'file', multiple: false, auto: false, bindAction: '#fileListActionPeople', xhr: function (index, e) { $('#demoListPeople').find('.layui-progress ').each(function () { let progressBarName = $(this).attr('lay-filter') let percent = Math.floor((e.loaded / e.total) * 100) element.progress(progressBarName, percent + '%') }) }, choose: function (obj) { let files = this.files = obj.pushFile() obj.preview(function (index, file, result) { let tr = $(` <tr id="upload-${index}"> <td>${file.name}</td> <td>${(file.size / 1024).toFixed(1)}kb</td> <td> <div class="layui-progress layui-progress-big" lay-filter="progress_${index}" lay-showPercent="true"> <div class="layui-progress-bar" lay-percent="0%"></div> </div> </td> <td>等待上传</td> <td> <div> <button class="layui-btn layui-btn-xs demo-reload-people layui-hide">重传</button> <button class="layui-btn layui-btn-xs layui-btn-danger demo-delete-people">删除</button> </div> </td> </tr> `)
tr.find('.demo-reload-people').on('click', function () { obj.upload(index, file) })
tr.find('.demo-delete-people').on('click', function () { delete files[index] tr.remove() }) demoListPeople.append(tr) }) }, done: function (res, index, upload) { let tr = demoListPeople.find(`#upload-${index}`), tds = tr.children() tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>') tds.eq(4).html('') layer.msg('上传成功') }, error: function (index, upload) { let tr = demoListPeople.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') } })
|