Uploader.cshtml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. @using Bowin.Web.Controls.Mvc;
  2. @{
  3. ViewBag.Title = "附件上传";
  4. }
  5. <link href='@Url.Content("~/Content/bootstrap/css/bootstrap.css")' rel="stylesheet" type="text/css" />
  6. <script src='@Url.Content("~/Scripts/bootstrap/bootstrap.js")' type="text/javascript"></script>
  7. <script src='@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/blueimp-file-upload/js/vendor/jquery.ui.widget.js")' type="text/javascript"></script>
  8. <script src='@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/blueimp-file-upload/js/jquery.iframe-transport.js")' type="text/javascript"></script>
  9. <script src='@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/blueimp-file-upload/js/jquery.fileupload.js")'type="text/javascript"></script>
  10. <script src='@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/blueimp-file-upload/js/jquery.fileupload-process.js")' type="text/javascript"></script>
  11. <script src='@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/blueimp-file-upload/js/jquery.fileupload-validate.js")'type="text/javascript"></script>
  12. <script type="text/javascript">
  13. <!--
  14. $(function () {
  15. /*
  16. var cookieName = $("#hfcookieName").val();
  17. var cookieID = $("#hfcookieID").val();*/
  18. //取得外面传递进去的参数列表
  19. //var fromParam = $("#formFileLoad").attr("action").split('?')[1];
  20. /*参数列表说明
  21. MaxFileNum:最多能上传文件的数量,0或负数为不限制
  22. MaxFileSize:上传单个文件限制大小,单位MB
  23. FileType:文件格式类型 1表示文档,2表示图片或PDF,100表示不限制
  24. */
  25. //var IsMultiple = fromParam.getParamValue("MaxFileNum") == 0 ? true : false; //是否允许多选
  26. //var MaxFileSize = parseFloat(fromParam.getParamValue("MaxFileSize")); //上传单个文件限制大小
  27. var IsMultiple = true;
  28. var MaxFileSize = @(ViewBag.maxSize ?? 1024);
  29. var fileDesc = "", fileExt = "";
  30. var fileType = '@ViewBag.type';
  31. switch (fileType) {
  32. case "@((int)FileType.Document)": //1表示文档
  33. fileDesc = "文档文件 (*.doc,*.wps,*.docx,*txt,*pdf)";
  34. fileExt = "*.doc;*.docx;*.wps;*.txt;*.pdf;*.ppt;";
  35. break;
  36. case "@((int)FileType.Picture)": //2表示图片
  37. fileDesc = "图片文件 (*.gif,*.png,*.jpg,*.jpeg)";
  38. fileExt = "*.gif;*.png;*.jpg;*.jpeg;";
  39. break;
  40. case "@((int)FileType.Video)": //3表示视频片
  41. fileDesc = "视频文件 (*.mpg,*.mpeg,*.rmvb,*.mp4,*.avi,*.rm,*.flv,*.3gp)";
  42. fileExt = "*.mpg;*.mpeg;*.rmvb;*.mp4;*.avi;*.rm;*.flv;*.3gp;";
  43. break;
  44. case "@((int)FileType.PicAndVid)":
  45. fileDesc = "图片和视频文件 (*.gif,*.png,*.jpg,*.jpeg,*.flv)";
  46. fileExt = "*.gif;*.png;*.jpg;*.jpeg;*.flv;";
  47. break;
  48. case "@((int)FileType.Sound)":
  49. fileDesc = "声音文件 (*.mp3,*.wav,*.wma,*.3gp)";
  50. fileExt = "*.mp3;*.wav;*.wma;*.3gp;";
  51. break;
  52. case "@((int)FileType.ALL)": //100表示所有格式
  53. fileDesc = "所有格式文件 (*.*)";
  54. fileExt = "*.*;";
  55. break;
  56. }
  57. var parent = $.getPopupTopWindowInputData();
  58. var uploadScript = $(parent.document).find("fieldset[name='@ViewBag.name']").attr("data-uploadurl");
  59. if (!uploadScript) {
  60. uploadScript = '@Url.Content("~/Common/UploaderSave")';
  61. }
  62. var popupName='@ViewBag.name';
  63. $("#fileupload").attr("accept",fileExt);
  64. //$("#uploadbar").hide();
  65. $("#fileupload").fileupload({
  66. url:uploadScript,
  67. type:'POST',
  68. dataType: 'json',
  69. sequentialUploads: true,
  70. limitMultiFileUploadSize:MaxFileSize,
  71. formData:{ 'mdid': '@ViewBag.value', 'ASPSESSID': '@ViewBag.hfcookieName', 'AUTHID': '@ViewBag.hfcookieID', 'type': fileType, 'n': '@Request["n"]', 'v': '@Request["v"]' },
  72. add: function(e, data) {
  73. $.each(data.files,function(i,file){
  74. var $row=$('<div class="row">'+
  75. '<div class="col-xs-6 row-name" title="'+file.name+'">'+file.name+'</div>'+
  76. '<div class="col-xs-4"><span>'+formatBytes(file.size)+'</span>/<span class="badge">0%</span></div>' +
  77. '<div class="col-xs-2"><a class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-remove-circle"></span></a></div>'+
  78. '</div>').data("fdata",data).appendTo("#fileQueue");
  79. $row.find("a").click(removeFile);
  80. data.context=$row;
  81. });
  82. },
  83. progress:function(e, data){
  84. if(data.context){
  85. var progress = parseInt(data.loaded / data.total * 100, 10);
  86. var $badge=data.context.find(".badge").text(progress+"%");
  87. }
  88. },
  89. progressall: function (e, data) {
  90. var progress = parseInt(data.loaded / data.total * 100, 10);
  91. $('#uploadbar .progress-bar').css('width',progress + '%').text(progress);
  92. },
  93. fail: function (e, data){
  94. if(data.context){
  95. data.context.addClass('row-error');
  96. }
  97. $(this).attr('disabled',false);
  98. },
  99. done: function(e, data){
  100. parent.uploader_addli(popupName, data.result);
  101. if(data.context){
  102. data.context.addClass('row-success');
  103. }
  104. if($("#fileQueue").find("div.row").length==$("#fileQueue").find("div.row-success").length){
  105. closeDialog();
  106. }
  107. //closeDialog();
  108. }
  109. });
  110. $("#btn_add").click(function(){
  111. $("#fileupload").click();
  112. });
  113. $("#btn_upload").click(function(){
  114. $(this).attr('disabled',true);
  115. $("#fileQueue").find("div.row").each(function(i,n){
  116. var $n=$(n);
  117. if($n.is(":not(.row-success)")){
  118. $(n).data("fdata").submit();
  119. }
  120. });
  121. });
  122. });
  123. function removeFile(){
  124. var $row=$(this).parent().parent();
  125. $row.data("fdata").abort();
  126. $row.remove();
  127. }
  128. function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]}
  129. function closeDialog() {
  130. $.closeCurPopupTopWindow();
  131. //parent.window[uploader_winName("@ViewBag.name")].window("close");
  132. }
  133. //-->
  134. </script>
  135. <style>
  136. .upload-panel { margin:5px auto 5px auto; }
  137. .upload-panel>div{ margin:3px auto 3px auto;}
  138. #fileQueue { vertical-align:middle; }
  139. #fileQueue .row{height:26px;}
  140. #fileQueue .row>div{ line-height:24px;margin-top:1px;}
  141. #uploadbar{margin-top:3px;}
  142. .row-name {
  143. overflow:hidden;
  144. text-overflow:ellipsis;
  145. white-space:nowrap;
  146. }
  147. .row-success
  148. {
  149. color:Green !important;
  150. }
  151. .row-error
  152. {
  153. color:Red !important;
  154. }
  155. </style>
  156. <div class="upload-panel">
  157. <div class="container-fluid" >
  158. <div class="row">
  159. <div class="col-xs-2">
  160. <input id="fileupload" type="file" name="Filedata" style="display:none;" multiple />
  161. <button class="btn btn-success btn-sm" id="btn_add"><i class="glyphicon glyphicon-plus"></i>添加</button>
  162. </div>
  163. <div class="col-xs-10">
  164. <div id="uploadbar" class="progress">
  165. <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <div id="fileQueue" class="container" style="height: 200px; overflow: auto; border: solid #d9e5ea 1px;">
  171. </div>
  172. </div>
  173. <div class="container">
  174. <button class="btn btn-primary btn-sm" id="btn_upload" ><i class="glyphicon glyphicon-upload"></i>上传</button>
  175. <button class="btn btn-warning btn-sm" onclick="closeDialog();"><i class="glyphicon glyphicon-ban-circle"></i>取消</button>
  176. </div>
  177. </div>