upload.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var upload_pic = [];
  2. var upload_file = [];
  3. var upload = [];
  4. function loadUpload(i,e,key,upload)
  5. {
  6. var value = e.attr('v');
  7. upload[value] = true;
  8. var id = e.attr('id');
  9. layui.use(['upload','layer'], function() {
  10. var layer = layui.layer;
  11. var layer_1 = false;
  12. var layuiUpload = layui.upload;
  13. var uploadInst = layuiUpload.render({
  14. elem: '#' + id
  15. ,data: {'key' : key}
  16. ,field: 'imgFile'
  17. ,url: upload
  18. //,multiple: true
  19. ,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
  20. layer.load(); //上传loading
  21. }
  22. ,done: function(data) {
  23. //var data = eval('('+res+')');
  24. layer.closeAll('loading');
  25. var l = $('.pics').length;
  26. if (l > 10) {
  27. layer.alert('请不要超过9张图片');
  28. return;
  29. }
  30. html = '<li><img src="'+data.url+'" class="pics"><em class="close"></em></li>';
  31. e.before(html)
  32. close();
  33. }
  34. ,error: function(){
  35. //请求异常回调
  36. }
  37. });
  38. });
  39. }