files.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. *上传附件
  3. *form flie元素ID容
  4. *option 上传附件的参数
  5. *fun 上传成功回调函数
  6. *before 上传附件前回调函数
  7. *going 执行上传附件时显示内容(默认为"请稍后...")
  8. */
  9. /*(function($){
  10. $.isUp = 0;
  11. $.upload = function(form,option,fun,before,going){
  12. var settings = {
  13. type:'image'
  14. },
  15. upload = function(){
  16. $.isUp=1;
  17. $.ajaxFileUpload({
  18. url: qscms.root + '/?c=upload&a=attach',
  19. type: 'POST',
  20. data:settings,
  21. secureuri:false,
  22. fileElementId:form,
  23. dataType:'json',
  24. success:function(result){
  25. if(result.status==1){
  26. fun && fun(result);
  27. }else{
  28. alert(result.msg);
  29. if(result.dialog) location.reload();
  30. }
  31. $.isUp = 0;
  32. }
  33. });
  34. };
  35. if(option) $.extend(settings,option);
  36. $(form).off().on({
  37. 'click':function(){
  38. //if($.isUp) return !1;
  39. if(before && !1 == before()) return !1;
  40. },
  41. 'change':function(){
  42. //if($.isUp || !$.trim($(this).val())) return !1;
  43. if(!$.trim($(this).val())) return !1;
  44. upload();
  45. }
  46. });
  47. };
  48. })(jQuery);*/
  49. (function($){
  50. $.upload = function(form,option,fun,before,going){
  51. var settings = {
  52. type:'image'
  53. };
  54. if(option){
  55. var path = option.path;
  56. if(path.indexOf("images") >= 0 ) {
  57. var url = '/api/common/upload/image';
  58. }
  59. if(path.indexOf("files") >= 0 ) {
  60. var url = '/api/common/upload/file';
  61. }
  62. $.extend(settings,option)
  63. }
  64. new AjaxUpload(form,{
  65. action:url,
  66. name:$(form).attr('name'),
  67. data:settings,
  68. responseType:'json',
  69. /*onChange:function(file,ext){
  70. alert('vdvdvd');
  71. if(!$.trim($(file).val())) return !1;
  72. },*/
  73. onSubmit:function(file,ext){
  74. if(ext && /^(doc|xls)$/.test(ext)){
  75. var af = this._input.files;
  76. var byteSize = af[0].size;
  77. if ((byteSize / 1024) > (10 * 1024)) {
  78. disapperTooltip("remind", '文件大小超出范围');
  79. return false;
  80. } else {
  81. if(before && !1 == before()) return !1;
  82. //ext是后缀名
  83. form.disabled = "disabled";
  84. }
  85. if(before && !1 == before()) return !1;
  86. form.disabled = "disabled";
  87. } else {
  88. disapperTooltip("remind", '仅支持doc,xls文件');
  89. return false;
  90. }
  91. if(before && !1 == before()) return !1;
  92. form.disabled = "disabled";
  93. },
  94. onComplete:function(file,result){
  95. form.disabled = "";
  96. if(result.message=='OK'){
  97. fun && fun(result);
  98. }else{
  99. $.each(result,function (key,val) {
  100. disapperTooltip("remind", val[0]);
  101. return false;
  102. });
  103. }
  104. }
  105. });
  106. };
  107. })(jQuery);