Uploader.cshtml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. @using Bowin.Web.Controls.Mvc;
  2. @{
  3. ViewBag.Title = "附件上传";
  4. }
  5. <script src="@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/jquery.uploadify.v2.1.4.min.js")" type="text/javascript"></script>
  6. <script src="@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/swfobject.js")" type="text/javascript"></script>
  7. <link href="@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/OwnUploadify.css")" rel="stylesheet" type="text/css" />
  8. <script type="text/javascript">
  9. <!--
  10. $(function () {
  11. /*
  12. var cookieName = $("#hfcookieName").val();
  13. var cookieID = $("#hfcookieID").val();*/
  14. //取得外面传递进去的参数列表
  15. //var fromParam = $("#formFileLoad").attr("action").split('?')[1];
  16. /*参数列表说明
  17. MaxFileNum:最多能上传文件的数量,0或负数为不限制
  18. MaxFileSize:上传单个文件限制大小,单位MB
  19. FileType:文件格式类型 1表示文档,2表示图片或PDF,100表示不限制
  20. */
  21. //var IsMultiple = fromParam.getParamValue("MaxFileNum") == 0 ? true : false; //是否允许多选
  22. //var MaxFileSize = parseFloat(fromParam.getParamValue("MaxFileSize")); //上传单个文件限制大小
  23. var IsMultiple = true;
  24. var MaxFileSize = 1024;
  25. var fileDesc = "", fileExt = "";
  26. var fileType = '@ViewBag.type';
  27. switch (fileType) {
  28. case "@((int)FileType.Document)": //1表示文档
  29. fileDesc = "文档文件 (*.doc,*.wps,*.docx,*txt,*pdf)";
  30. fileExt = "*.doc;*.docx;*.wps;*.txt;*.pdf;*.ppt;";
  31. break;
  32. case "@((int)FileType.Picture)": //2表示图片
  33. fileDesc = "图片文件 (*.gif,*.png,*.jpg,*.jpeg)";
  34. fileExt = "*.gif;*.png;*.jpg;*.jpeg;";
  35. break;
  36. case "@((int)FileType.Video)": //3表示视频片
  37. fileDesc = "视频文件 (*.mpg,*.mpeg,*.rmvb,*.mp4,*.avi,*.rm,*.flv,*.3gp)";
  38. fileExt = "*.mpg;*.mpeg;*.rmvb;*.mp4;*.avi;*.rm;*.flv;*.3gp;";
  39. break;
  40. case "@((int)FileType.PicAndVid)":
  41. fileDesc = "图片和视频文件 (*.gif,*.png,*.jpg,*.jpeg,*.flv)";
  42. fileExt = "*.gif;*.png;*.jpg;*.jpeg;*.flv;";
  43. break;
  44. case "@((int)FileType.Sound)":
  45. fileDesc = "声音文件 (*.mp3,*.wav,*.wma,*.3gp)";
  46. fileExt = "*.mp3;*.wav;*.wma;*.3gp;";
  47. break;
  48. case "@((int)FileType.ALL)": //100表示所有格式
  49. fileDesc = "所有格式文件 (*.*)";
  50. fileExt = "*.*;";
  51. break;
  52. }
  53. var parent = $.getPopupTopWindowInputData();
  54. var uploadScript = $(parent.document).find("fieldset[name='@ViewBag.name']").attr("data-uploadurl");
  55. if (!uploadScript) {
  56. uploadScript = '@Url.Content("~/Common/UploaderSave")';
  57. }
  58. $("#uploadify").uploadify({
  59. 'uploader': '@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/uploadify.swf")',
  60. 'script': uploadScript,
  61. 'cancelImg': '@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/cancel.png")',
  62. 'buttonImg': '@Url.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/add_file.png")',
  63. 'width': 65,
  64. 'height': 24,
  65. 'folder': 'DownFile',
  66. 'queueID': 'fileQueue',
  67. 'sizeLimit': 1024 * 1024 * MaxFileSize,
  68. 'auto': false,
  69. 'method': 'GET',
  70. 'scriptData': { 'mdid': '@ViewBag.value', 'ASPSESSID': '@ViewBag.hfcookieName', 'AUTHID': '@ViewBag.hfcookieID', 'type': fileType, 'n': '@Request["n"]', 'v': '@Request["v"]' },
  71. //当允许多文件生成时,设置选择文件的个数,默认值:999 。
  72. // "queueSizeLimit": parseInt(fromParam.getParamValue("MaxFileNum").length > 0 ? parseInt(fromParam.getParamValue("MaxFileNum") == "0" ? "999" : fromParam.getParamValue("MaxFileNum")) : 0),
  73. 'multi': IsMultiple, //是否允许多选
  74. "fileDesc": fileDesc,
  75. "fileExt": fileExt,
  76. 'onInit': function () {
  77. //此处可以做一些初始化操作
  78. },
  79. "onSelect": function (a, b, c) { /*选择文件上传时可以禁用某些按钮*/
  80. if (c.size > 1024 * 1024 * MaxFileSize) {
  81. alert("您选择的文件大小超过最大限制值,只能上传" + MaxFileSize + "M以下的文件!");
  82. }
  83. },
  84. "onComplete": function (event, queueID, fileObj, reposnse, data) {
  85. parent.uploader_addli("@ViewBag.name", eval("(" + reposnse + ")"));
  86. },
  87. "onAllComplete": function (a, b) {
  88. setTimeout(function () {
  89. //jQuery("#btn_dialog_close").click();
  90. closeDialog();
  91. }, 500);
  92. },
  93. "onCancel": function (a, b, c, d, e) {
  94. },
  95. "onError": function (a, b, c, d, e) {
  96. }
  97. });
  98. $('#btn_upload').click(function () {
  99. $('#uploadify').uploadifyUpload();
  100. })
  101. });
  102. function closeDialog() {
  103. $.closeCurPopupTopWindow();
  104. //parent.window[uploader_winName("@ViewBag.name")].window("close");
  105. }
  106. //-->
  107. </script>
  108. <table border="0" style="width: 95%; height: 95%; margin: 5px auto 0;">
  109. <tr>
  110. <td class="td-right" style="height: 120%">
  111. <input type="file" name="uploadify" id="uploadify" />
  112. <div id="fileQueue" style="margin: 3px 0 10px; height: 200px; overflow: auto; border: solid #d9e5ea 1px;">
  113. </div>
  114. </td>
  115. </tr>
  116. <tr>
  117. <td class="td-left">
  118. <input type="button" id="btn_upload" class="uploadify" value="&nbsp;&nbsp;&nbsp;&nbsp;上传" />
  119. <input type="button" class="uploadifycancel" value="&nbsp;&nbsp;&nbsp;取消上传" onclick="closeDialog();" />
  120. </td>
  121. </tr>
  122. <tr>
  123. <td style="height: 5px;">
  124. </td>
  125. </tr>
  126. </table>