/** * 基于upload.js扩展 */ layui.use(['jquery', 'upload'], function () { let $ = layui.jquery, upload = layui.upload; let url = '/manager/upload/image'; let field = 'image_image'; let multiple = false; let accept = 'images'; //images(图片)、file(所有文件)、video(视频)、audio(音频) let acceptMime = 'images/*'; let exts = 'jpg|png|gif|bmp|jpeg'; let size = 10 * 1024; //size KB let number = 0; /* * 海报上传 */ let upPorter = upload.render({ elem: '.upload-btn-porter' , url: url ,data: {"type":"porter"} , auto: true , field: field , accept: accept , acceptMime: acceptMime , exts: exts , size: size , number: number , multiple: true , before: function (obj) { layer.load(2); } , done: function (res, index, upload) { console.log('上传成功', res); layer.closeAll('loading'); //关闭loading let item = this.item; let div = item.parents('.upload-file-div'); if (res.code === 0 || res.code === 200) { let inputValue = $(div).find('.upload-file-value').val(); if (inputValue.length > 0) { inputValue += ','; } inputValue += res.data.src; $(div).find('.upload-file-value').val(inputValue); initPreviewList(); } else { layer.msg(res.msg); } } }); });