// 郑子民 15互联网G5-3陈卓锐
Namespace.register("U.Control.Upload"); //命名空间
U.Control.Upload.SCC = 0; //记录每次上传文件的个数
U.Control.Upload.SCI = 0; //记录文件上传的记录
//页面初始化 生成上传按钮并回调
U.Control.Upload.init = function () {
var Upload_button = $$("div", { "className": "Upload-button", "innerHTML": "上传" });
var Upload_Button = $$("div", { "className": "UPbutton", "style": { "position": "relative", "width": "100%", "height": "100%", "top": "-100%"} }, Upload_button);
var Upload_button_button = $$("div", { "className": "Upload-button-button none", "innerHTML": "上传文件" }, Upload_button);
var Upload_button_window = $$("div", { "className": "Upload-button-window none" }, Upload_button);
var Upload_button_window_head = $$("div", { "className": "Upload-button-window-head" }, Upload_button_window);
$$("div", { "innerHTML": "正在上传" }, Upload_button_window_head);
$$("div", { "innerHTML": "(0/0)" }, Upload_button_window_head);
$$("div", {}, Upload_button_window_head);
var Upload_button_window_type = $$("div", { "className": "Upload-button-window-type" }, Upload_button_window);
$$("div", { "innerHTML": "文件名" }, Upload_button_window_type);
$$("div", { "innerHTML": "大小" }, Upload_button_window_type);
$$("div", { "innerHTML": "状态" }, Upload_button_window_type);
$$("div", { "innerHTML": "操作" }, Upload_button_window_type);
U.Control.Upload.Main(Upload_button_window_head, Upload_Button)
return Upload_button;
}
//主函数
U.Control.Upload.Main = function (a, b) {
U.UP.AddFAN(b, "Upbutton", { "width": "100%", "height": "100%" });
U.UP.FAFZ({ "width": "100%", "height": "100%" },
{ "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);
a.children[2].onclick = function () { $('.Upload-button-window')[0].className = 'Upload-button-window none'; }
}
//获取解析文件的md5
U.Control.Upload.jx = function (m) {
// alert(m);
U.Control.Upload.SCZ();
}
//删除此条上传记录
U.Control.Upload.SCJL = function (a) {
var num = 0;
if (a.previousSibling.innerHTML == "100%") { $("#span0")[0].innerHTML = parseInt($("#span0")[0].innerHTML) - 1 }
a.parentNode.remove();
$("#span1")[0].innerHTML = parseInt($("#span1")[0].innerHTML) - 1;
for (var i = 0; i < $(".Upload-button-window-file").length; i++) {
if (a.parentNode == $(".Upload-button-window-file")[i]) {
num = i;
}
}
$("*Upbutton")[0].DF(num, 0);
}
//上传功能主要函数
U.Control.Upload.SCZ = function () {
$("*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);
}
//上传成功获取服务器返回值
U.Control.Upload.SCCG = function () {
// var file = $$("div", { "className": "Upload-button-window-file" }, $(".Upload-button-window")[0]);
// $$("div", { "innerHTML": '文件名' + '类型名' }, file);
// $$("div", {}, file);
// $$("div", { "className": "Upload-button-window-file-finish" }, file);
// var close = $$("div", { "onclick": "U.Control.Upload.SCJL(this)" }, file);
}
//点击上传文件即调用函数
U.Control.Upload.SC = function (a) {
$(".Upload-button-window")[0].className = "Upload-button-window block";
for (var i = 0; i < a.length; i++) {
var file = $$("div", { "className": "Upload-button-window-file" }, $(".Upload-button-window")[0]);
$$("div", { "innerHTML": a[i].name }, file);
$$("div", { "innerHTML": U.UP.FileSize(a[i].size) }, file);
$$("div", { "className": "Upload-button-window-file-finish" }, file); //因无失败icon,后面修改var close = $$("div", {}, file);
var close = $$("div", { "onclick": "U.Control.Upload.SCJL(this)" }, file);
}
$(".Upload-button-window-head span")[1].innerText = parseInt($(".Upload-button-window-head span")[1].innerText) + a.length; $("*Upbutton")[0].UpLoad(0, 0, "");
}
//上传失败的函数
U.Control.Upload.SCSB = function () {
alert("服务器繁忙 文件上传失败");
}
//上传文件返回百分比进度
U.Control.Upload.ZT = function (a, b, c) {
$(".Upload-button-window-file-finish")[U.Control.Upload.SCI].innerHTML = ((a.Loaded / a.Total) * 100).toFixed(0) + "%";
console.log(a.Loaded / a.Total);
if ((a.Loaded / a.Total) == 1) {
var qa = parseInt($("#span0")[0].innerHTML); ++qa; $("#span0")[0].innerHTML = qa;
U.Control.Upload.SCC++;
U.Control.Upload.SCI++;
if ($("#span1")[0].innerHTML == U.Control.Upload.SCI) { U.Control.Upload.SCC = 0; return; }
$("*Upbutton")[0].UpLoad(U.Control.Upload.SCC, 0, "");
}
}
//显示隐藏上传按钮
// var dis = 0;
// $(".UPbutton")[0].onclick = function () {
// if (dis == 0) {
// $(".Upload-button").Child()[0].className = "Upload-button-button block";
// dis = 1;
// return;
// }
// if (dis == 1) {
// $(".Upload-button").Child()[0].className = "Upload-button-button none";
// dis = 0;
// return;
// }
// }
// $(".Upload-button").Child()[0].onclick = function (event) {
// U.Control.Upload.File(event); //选择上传文件
// }
// $(".Upload-button").Child()[1].onclick = function (event) {
// event.stopPropagation(event); //阻止冒泡事件
// }
// $(".Upload-button-window-head").Child()[2].onclick = function () {
// $(".Upload-button").Child()[1].className = "Upload-button-window none";
// }
// 选择上传文件及现实详情
//U.Control.Upload.File = function (event) {
// var len = $(".Upload-button").Child()[1].children.length - 2;
// $("#file")[0].click();
// $("#file")[0].onchange = function () {
// var files = $("#file")[0].value;
// var strFileName = files.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi, "$1");
// var FileExt = files.replace(/.+\./, "");
// var file = $$("div", { "className": "Upload-button-window-file" }, $(".Upload-button").Child()[1]);
// $$("div", {}, file);
// $$("div", { "innerHTML": strFileName + '.' + FileExt }, file);
// $$("div", {}, file);
// $$("div", { "className": "Upload-button-window-file-finish" }, file);
// var close = $$("div", {}, file);
// $(".Upload-button-window-head").Child()[1].innerHTML = "(" + (len + 1) + "/" + (len + 1) + ")";
// len++;
// close.onclick = function () {
// this.parentNode.parentNode.removeChild(this.parentNode);
// var len = $(".Upload-button").Child()[1].children.length - 2;
// $(".Upload-button-window-head").Child()[1].innerHTML = "(" + len + "/" + len + ")";
// }
// }
// $(".Upload-button").Child()[1].className = "Upload-button-window block";
// event.stopPropagation(); //阻止冒泡事件
//