layui.use(['jquery', 'upload'], function () { let $ = layui.jquery; let upload = layui.upload; let imgUploadUrl = '/manager/upload/image'; // 组图组件:替换图片 if ($('.layui-layer-content .operate2 .img-change').length > 0) { $('.img-change').each(function (index, item) { let that = $(this); let idx = 'img-change-edit' + index; that.addClass(idx); upload.render({ elem: '.operate2 .'+idx, url: imgUploadUrl, data: {_token:''}, field: 'image', multiple: true, before: function(obj) { layer.msg('图片上传中...', { icon: 16, shade: 0.01, time: 0 }) }, done: function(res, index, upload) { layer.close(layer.msg()); if (res.code == 0) { $(this.item).closest('dd.item_img').find('.info .info-src').val(res.data.src); $(this.item).closest('dd.item_img').find('.imgs .layer-photos img').attr({"src":res.data.src, "layer-src":res.data.src}); } else { layer.msg('图片替换失败', {time: 2000}); } } }); }); } });