layui商品相册多规格多域批量上传实现

<table width="100%" id="attrTable" class="layui-table">
  <thead>
    <tr>
      <th colspan="2">
        <b>
          商品相册
        </b>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="label" style="width: 120px; text-align: right;">
        通用
      </td>
      <td class="spec" style="text-align: left;">
        <div class="photolist">
        </div>
        <button type="button" class="upload goods_photo_upload" lay-data="{url: '/admin/goods/upfile.html'}"
        goods_attr_id="0" title="上传图片">
        </button>
      </td>
    </tr>
    <tr>
      <td class="label" style="width: 120px; text-align: right;">
        红
      </td>
      <td class="spec" style="text-align: left;">
        <div class="photolist">
        </div>
        <button type="button" class="upload goods_photo_upload" lay-data="{url: '/admin/goods/upfile/goods_attr_id/142228.html'}"
        goods_attr_id="142228" title="上传图片">
        </button>
      </td>
    </tr>
    <tr>
      <td class="label" style="width: 120px; text-align: right;">
        白
      </td>
      <td class="spec" style="text-align: left;">
        <div class="photolist">
        </div>
        <button type="button" class="upload goods_photo_upload" lay-data="{url: '/admin/goods/upfile/goods_attr_id/142229.html'}"
        goods_attr_id="142229" title="上传图片">
        </button>
      </td>
    </tr>
  </tbody>
</table>
//商品相册上传
      var uploadInst= function(element){
          upload.render({
              elem: element
              ,method: 'post'  //可选项。HTTP类型,默认post
              ,data: {goods_id:'32948'} //可选项。额外的参数,如:{id: 123, abc: 'xxx'}
              ,accept:"images"//指定允许上传时校验的文件类型,可选值有:images(图片)、file(所有文件)、video(视频)、audio(音频)
              ,acceptMime:'image/*'//(只显示图片文件)'image/jpg, image/png'(只显示 jpg 和 png 文件)
              ,size:1024*2//单位 KB
              ,multiple:'true'//是否允许多文件上传。设置 true即可开启。不支持ie8/9
              ,before: function(obj){
                  //预读本地文件示例,不支持ie8
                  obj.preview(function(index, file, result){
                      //$('#demo1').attr('src', result); //图片链接(base64)
                  });
              }
              ,done: function(res){
                  var that = this;
                  var item = this.item;
                  if (res.code ==200) {
                      $(item).siblings('.photolist').append(res.data);
                      layer.msg(res.msg);
                  } else {
                      layer.msg(res.msg);
                  }

                  console.log(item);

              }
              ,error: function(){
                  //演示失败状态,并实现重传
                  layer.msg('上传失败');
              }
          });
      }
      uploadInst('.goods_photo_upload');

当html部分是自己生成时,加载完成后 不要忘记重新渲染,要不然不能上传,生成代码后调用uploadInst('.goods_photo_upload');渲染

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

和顺和

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值