jfu.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Created by hzd on 2017/10/23.
  3. */
  4. /**
  5. * 移除图片
  6. */
  7. function removePic(_self,deleteurl){
  8. $(_self).parent().remove();
  9. if(deleteurl){
  10. $.post(deleteurl,{path:$(_self).parent().find('img').attr('src')});
  11. }
  12. }
  13. /**
  14. * 图片上传
  15. */
  16. function imgfiveup (object){
  17. /*
  18. <button class="btn-flat btn btn-success btn-sm jqfivefile" type="button">
  19. 上传图片<span id="progress"></span>
  20. <input id="imgUpload" type="file" accept="image/*" data-url="{:U('File/uploadPicture')}" />
  21. </button>
  22. */
  23. this.target = object.target?object.target:"#imgUpload", //上传按钮id
  24. this.progress = object.progress?object.progress:"#progress",//进度条id
  25. this.imgbox = object.imgbox?object.imgbox:"#imgsbox",//头像图片id
  26. this.multi = object.multi?object.multi:false; //多图/单图
  27. this.name = object.name?object.name:'img'; //表单name
  28. this.deleteurl = object.deleteurl?object.deleteurl:''; //表单name
  29. if(this.multi){
  30. this.name = this.name+'[]';
  31. $(this.target).attr('multiple','multiple');
  32. }else{
  33. $(this.target).removeAttr('multiple');
  34. }
  35. that = this;
  36. this.upload = function(){
  37. $(that.target).fileupload({
  38. dataType: 'json',
  39. done: function (e, data) {
  40. if (data.result && data.result.status == 1) {
  41. /*
  42. <div id="imgsbox" class="imgsbox">
  43. <div class="imgbox">
  44. <div class="removePic" onclick="removePic(this)">×</div>
  45. <input type="hidden" name="site_video_img" value="/Uploads/Picture/2017-10-23/59ed852565a94.png">
  46. <img src="/Uploads/Picture/2017-10-23/59ed852565a94.png">
  47. </div>
  48. </div>
  49. */
  50. var img = '<div class="imgbox">';
  51. img += '<div class="removePic" onclick="removePic(this,\''+that.deleteurl+'\')">×</div>';
  52. img += '<input type="hidden" name="' + that.name + '" value="' + data.result.path + '">';
  53. img += '<img src="' + data.result.path + '">';
  54. img += '</div>';
  55. if(that.multi){
  56. $(that.imgbox).append(img);
  57. }else{
  58. $(that.imgbox).html(img);
  59. }
  60. } else {
  61. layer.msg(data.result.msg);
  62. }
  63. },
  64. progressall: function (e, data) {
  65. var progressnum = parseInt(data.loaded / data.total * 100);
  66. if (progressnum == 100) {
  67. $(that.progress).text('');
  68. } else {
  69. $(that.progress).text(progressnum + "%");
  70. }
  71. },
  72. error: function(e,data){
  73. layer.msg('上传请求失败');
  74. }
  75. });
  76. }
  77. }