Upload.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // 郑子民 15互联网G5-3陈卓锐
  2. Namespace.register("U.Control.Upload"); //命名空间
  3. U.Control.Upload.SCC = 0; //记录每次上传文件的个数
  4. U.Control.Upload.SCI = 0; //记录文件上传的记录
  5. //页面初始化 生成上传按钮并回调
  6. U.Control.Upload.init = function () {
  7. var Upload_button = $$("div", { "className": "Upload-button", "innerHTML": "上传" });
  8. var Upload_Button = $$("div", { "className": "UPbutton", "style": { "position": "relative", "width": "100%", "height": "100%", "top": "-100%"} }, Upload_button);
  9. var Upload_button_button = $$("div", { "className": "Upload-button-button none", "innerHTML": "上传文件" }, Upload_button);
  10. var Upload_button_window = $$("div", { "className": "Upload-button-window none" }, Upload_button);
  11. var Upload_button_window_head = $$("div", { "className": "Upload-button-window-head" }, Upload_button_window);
  12. $$("div", { "innerHTML": "正在上传" }, Upload_button_window_head);
  13. $$("div", { "innerHTML": "(<span id='span0'>0</span>/<span id='span1'>0</span>)" }, Upload_button_window_head);
  14. $$("div", {}, Upload_button_window_head);
  15. var Upload_button_window_type = $$("div", { "className": "Upload-button-window-type" }, Upload_button_window);
  16. $$("div", { "innerHTML": "文件名" }, Upload_button_window_type);
  17. $$("div", { "innerHTML": "大小" }, Upload_button_window_type);
  18. $$("div", { "innerHTML": "状态" }, Upload_button_window_type);
  19. $$("div", { "innerHTML": "操作" }, Upload_button_window_type);
  20. U.Control.Upload.Main(Upload_button_window_head, Upload_Button)
  21. return Upload_button;
  22. }
  23. //主函数
  24. U.Control.Upload.Main = function (a, b) {
  25. U.UP.AddFAN(b, "Upbutton", { "width": "100%", "height": "100%" });
  26. U.UP.FAFZ({ "width": "100%", "height": "100%" },
  27. { "EX": "U.Control.Upload.SCSB", "ADD": "U.Control.Upload.SC", "ACP": "", "CP": "", "JDT": "U.Control.Upload.ZT", "FCP": "U.Control.Upload.SCCG", "FUP": "U.Control.Upload.jx" }, null);
  28. a.children[2].onclick = function () { $('.Upload-button-window')[0].className = 'Upload-button-window none'; }
  29. }
  30. //获取解析文件的md5
  31. U.Control.Upload.jx = function (m) {
  32. // alert(m);
  33. U.Control.Upload.SCZ();
  34. }
  35. //删除此条上传记录
  36. U.Control.Upload.SCJL = function (a) {
  37. var num = 0;
  38. if (a.previousSibling.innerHTML == "100%") { $("#span0")[0].innerHTML = parseInt($("#span0")[0].innerHTML) - 1 }
  39. a.parentNode.remove();
  40. $("#span1")[0].innerHTML = parseInt($("#span1")[0].innerHTML) - 1;
  41. for (var i = 0; i < $(".Upload-button-window-file").length; i++) {
  42. if (a.parentNode == $(".Upload-button-window-file")[i]) {
  43. num = i;
  44. }
  45. }
  46. $("*Upbutton")[0].DF(num, 0);
  47. }
  48. //上传功能主要函数
  49. U.Control.Upload.SCZ = function () {
  50. $("*Upbutton")[0].URRUP("http://disk.1473.cn/USupfile.ashx?iframename=UploadFlashfile&DirectoryId=" + US.NU + "&UserId=aabffd06-aa7f-4baf-8ade-f93b6f3bf103&IsF=true", Guid.newGuid(), 0, 0);
  51. }
  52. //上传成功获取服务器返回值
  53. U.Control.Upload.SCCG = function () {
  54. // var file = $$("div", { "className": "Upload-button-window-file" }, $(".Upload-button-window")[0]);
  55. // $$("div", { "innerHTML": '文件名' + '类型名' }, file);
  56. // $$("div", {}, file);
  57. // $$("div", { "className": "Upload-button-window-file-finish" }, file);
  58. // var close = $$("div", { "onclick": "U.Control.Upload.SCJL(this)" }, file);
  59. }
  60. //点击上传文件即调用函数
  61. U.Control.Upload.SC = function (a) {
  62. $(".Upload-button-window")[0].className = "Upload-button-window block";
  63. for (var i = 0; i < a.length; i++) {
  64. var file = $$("div", { "className": "Upload-button-window-file" }, $(".Upload-button-window")[0]);
  65. $$("div", { "innerHTML": a[i].name }, file);
  66. $$("div", { "innerHTML": U.UP.FileSize(a[i].size) }, file);
  67. $$("div", { "className": "Upload-button-window-file-finish" }, file); //因无失败icon,后面修改var close = $$("div", {}, file);
  68. var close = $$("div", { "onclick": "U.Control.Upload.SCJL(this)" }, file);
  69. }
  70. $(".Upload-button-window-head span")[1].innerText = parseInt($(".Upload-button-window-head span")[1].innerText) + a.length; $("*Upbutton")[0].UpLoad(0, 0, "");
  71. }
  72. //上传失败的函数
  73. U.Control.Upload.SCSB = function () {
  74. alert("服务器繁忙 文件上传失败");
  75. }
  76. //上传文件返回百分比进度
  77. U.Control.Upload.ZT = function (a, b, c) {
  78. $(".Upload-button-window-file-finish")[U.Control.Upload.SCI].innerHTML = ((a.Loaded / a.Total) * 100).toFixed(0) + "%";
  79. console.log(a.Loaded / a.Total);
  80. if ((a.Loaded / a.Total) == 1) {
  81. var qa = parseInt($("#span0")[0].innerHTML); ++qa; $("#span0")[0].innerHTML = qa;
  82. U.Control.Upload.SCC++;
  83. U.Control.Upload.SCI++;
  84. if ($("#span1")[0].innerHTML == U.Control.Upload.SCI) { U.Control.Upload.SCC = 0; return; }
  85. $("*Upbutton")[0].UpLoad(U.Control.Upload.SCC, 0, "");
  86. }
  87. }
  88. //显示隐藏上传按钮
  89. // var dis = 0;
  90. // $(".UPbutton")[0].onclick = function () {
  91. // if (dis == 0) {
  92. // $(".Upload-button").Child()[0].className = "Upload-button-button block";
  93. // dis = 1;
  94. // return;
  95. // }
  96. // if (dis == 1) {
  97. // $(".Upload-button").Child()[0].className = "Upload-button-button none";
  98. // dis = 0;
  99. // return;
  100. // }
  101. // }
  102. // $(".Upload-button").Child()[0].onclick = function (event) {
  103. // U.Control.Upload.File(event); //选择上传文件
  104. // }
  105. // $(".Upload-button").Child()[1].onclick = function (event) {
  106. // event.stopPropagation(event); //阻止冒泡事件
  107. // }
  108. // $(".Upload-button-window-head").Child()[2].onclick = function () {
  109. // $(".Upload-button").Child()[1].className = "Upload-button-window none";
  110. // }
  111. // 选择上传文件及现实详情
  112. //U.Control.Upload.File = function (event) {
  113. // var len = $(".Upload-button").Child()[1].children.length - 2;
  114. // $("#file")[0].click();
  115. // $("#file")[0].onchange = function () {
  116. // var files = $("#file")[0].value;
  117. // var strFileName = files.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi, "$1");
  118. // var FileExt = files.replace(/.+\./, "");
  119. // var file = $$("div", { "className": "Upload-button-window-file" }, $(".Upload-button").Child()[1]);
  120. // $$("div", {}, file);
  121. // $$("div", { "innerHTML": strFileName + '.' + FileExt }, file);
  122. // $$("div", {}, file);
  123. // $$("div", { "className": "Upload-button-window-file-finish" }, file);
  124. // var close = $$("div", {}, file);
  125. // $(".Upload-button-window-head").Child()[1].innerHTML = "(" + (len + 1) + "/" + (len + 1) + ")";
  126. // len++;
  127. // close.onclick = function () {
  128. // this.parentNode.parentNode.removeChild(this.parentNode);
  129. // var len = $(".Upload-button").Child()[1].children.length - 2;
  130. // $(".Upload-button-window-head").Child()[1].innerHTML = "(" + len + "/" + len + ")";
  131. // }
  132. // }
  133. // $(".Upload-button").Child()[1].className = "Upload-button-window block";
  134. // event.stopPropagation(); //阻止冒泡事件
  135. //