📄 ixs_upload.js
字号:
var iXuErUpLoadDataUrl = document.getElementById("UpLoaddingUrl").innerHTML;
document.getElementById("iXuErUpLoadForm").target = oframe;
// 设置上传表单
var oFiles = document.getElementById("Files");
var oUpLoadNum = document.getElementById("UpLoadNum");
var oTempData = document.getElementById("TempData");
var otestframe = document.getElementById("testframe");
var oFileMaxSize = document.getElementById("FileMaxSize");
var sAllowExt = document.getElementById("FileAllowExt").innerHTML;
var oFormAction = "";
var iXuErMaxFileNum = Math.abs(document.getElementById("UpLoadMaxNum").innerHTML);
var iXuErUpLoadHTML = oFiles.innerHTML;
var intTimeStep = 1000, lngUsedTime = 0, lngTotalSize = 0, lngReadSize = 0;
var n, i, oUpLoaddingNum = 0, oCount = 0;
// 初始化
oFileMaxSize.innerHTML = checkFileSize(oFileMaxSize.innerHTML);
// 打开/关闭指定模块
function OpenContent(p_ID){
var oObj = document.getElementById(p_ID);
if(oObj.style.display == "none"){
oObj.style.display = "";
} else {
oObj.style.display = "none";
}
}
// 开始执行上传
function StartUpLoad(){
var oFile;
for(i = 1; i <= oUpLoadNum.value; i ++){
oFile = document.getElementById("File" + i);
if(oFile.value != "" && oFile.value != null){oUpLoaddingNum += 1;}
}
if(oUpLoaddingNum == 0){alert("请至少选择一个合法文件进行上传!");return false;}
// 禁用表单项目
document.getElementById("UpLoadNumOption").style.display = "none";
document.getElementById("UpLoadButton").style.display = "none";
oFiles.className = "FontColor_001";
// 设置验证码
try{
var oForm = document.getElementById("iXuErUpLoadForm");
if(oFormAction == ""){oFormAction = oForm.action;}
var oGetCode = document.getElementById("GetCodeForm").value;
if(oGetCode == "" || oGetCode == null){oGetCode = "";}
oForm.action = oFormAction.replace(/=\[\$GetCode\]/g, "=" + oGetCode);
}
catch(e){};
//oFiles.innerHTML = "文件正在上传中……";
// 开始上传
upLoadData();
return true;
}
// 表单重置
function DoReset(){
if(document.getElementById("UpLoadProgress").style.display == ""){document.getElementById("UpLoadProgressOption").checked = true;}
if(document.getElementById("UpLoadFileList").style.display == ""){document.getElementById("UpLoadFileListOption").checked = true;}
setUpLoadCount();
return false;
}
// 设定上传表单
function setUpLoadCount(){
var Temp = "", TempHtml;
var oCreatPreview = Math.abs(document.getElementById("CreatPreview").innerHTML);
switch (oCreatPreview){
case 1 :
oCreatPreview = 1;
break;
case 2 :
oCreatPreview = 0;
break;
case 3 :
oCreatPreview = 1;
break;
default :
oCreatPreview = 0;
break;
}
if(!oUpLoadNum.value){oUpLoadNum.value = 1;}
if(oUpLoadNum.value - 0 != oUpLoadNum.value){oUpLoadNum.value = 1;}
if(oUpLoadNum.value <= 0){oUpLoadNum.value = 1;}
if(oUpLoadNum.value > iXuErMaxFileNum){
alert("您一次最多只可以上传 " + iXuErMaxFileNum + " 个文件!");
oUpLoadNum.value = iXuErMaxFileNum;
setUpLoadCount();
}
oFiles.style.display = "";
// 清空原有HTML
oFiles.innerHTML = "";
for(i = 1; i <= oUpLoadNum.value; i ++){
if(i == 1){
Temp = iXuErUpLoadHTML;
oFiles.innerHTML = "正在初始化....";
} else {
TempHtml = iXuErUpLoadHTML;
if(i.toString(10).length == 1){n = "00" + i;}
if(i.toString(10).length == 2){n = "0" + i;}
if(i.toString(10).length == 3){n = i;}
TempHtml = TempHtml.replace(/文件001/g, "文件" + n);
TempHtml = TempHtml.replace(/File1/g, "File" + i);
TempHtml = TempHtml.replace(/iXuErImgesOption1/g, "iXuErImgesOption" + i);
TempHtml = TempHtml.replace(/AddWaterMark1/g, "AddWaterMark" + i);
TempHtml = TempHtml.replace(/MakePreviewImage1/g, "MakePreviewImage" + i);
Temp += TempHtml;
//oFiles.insertAdjacentHTML("beforeEnd", TempHtml); //FierFox不支持此方法
}
}
if(oCreatPreview == 1){
Temp = Temp.replace(/\{\$MakePreviewImageIschecked\}/g, " checked=\"checked\"");
} else {
Temp = Temp.replace(/\{\$MakePreviewImageIschecked\}/g, "");
}
oFiles.innerHTML = Temp; Temp = null;
lngUsedTime = 0, lngTotalSize = 0; lngReadSize = 0;
try{document.getElementById("GetCodeForm").value = "";}catch(e){};
document.getElementById("UpLoaddingProgress").style.width = 0;
document.getElementById("UpLoaddingProgress").innerHTML = " ";
document.getElementById("UpLoaddingPercent").innerHTML = 0;
document.getElementById("UpLoaddingNum").innerHTML = 0;
document.getElementById("UpLoaddingUsedTime").innerHTML = "<strong>0</strong> 秒";
document.getElementById("UpLoaddingSpeed").innerHTML = 0;
document.getElementById("UpLoaddingTransfers").innerHTML = 0;
document.getElementById("UpLoaddingTotalSize").innerHTML = 0;
document.getElementById("UpLoadNumOption").style.display = "";
document.getElementById("UpLoadButton").style.display = "";
document.getElementById("UpLoadErrMsg").innerHTML = "True";
oFiles.className = "";
}
// 是否有效的扩展名
function IsExt(url, opt){
var sTemp;
var b = false;
var s = opt.toUpperCase().split("|");
for (var i = 0; i < s.length; i ++ ){
sTemp = url.substr(url.length-s[i].length - 1);
sTemp = sTemp.toUpperCase();
s[i] = "."+s[i];
if (s[i] == sTemp){
b = true;
break;
}
}
return b;
}
// 检测上传表单 检测扩展名是否有效
function CheckUploadForm() {
var oFile;
for(n = 1; n <= oUpLoadNum.value; n ++){
oFile = document.getElementById("File" + n);
if(!IsExt(oFile.value, sAllowExt) && oFile.value != ""){
alert("提示:\n\n第 [" + n + "] 个文件无效!\n\n请选择一个有效的文件,\n支持的格式有:\n" + sAllowExt);
oFile.style.backgroundColor = "#FFFFCC";
oFile.style.border = "1px solid #FF0000";
return false;
}
oFile.style.backgroundColor = "#FFFFFF";
oFile.style.border = "1px solid #D2D3D9";
// 如果是可操作的图像文件,则显示水印和缩略图选项
if(IsExt(oFile.value, "bmp|jpg|jpeg") && oFile.value != ""){
document.getElementById("iXuErImgesOption" + n).style.display = "";
} else {
document.getElementById("iXuErImgesOption" + n).style.display = "none";
}
}
return true
}
// 更新数据
function downLoadData(url){
try{
oTempData.src = url;
}
catch(e){
return false;
}
}
// 开始更新进度条
function upLoadData(){
upLoadding();
return true;
}
// 进度条数据计算
function upLoadding(){
if(iXuErUpLoadDataUrl.indexOf("iXs_UpLoadAspUp3.asp") != -1){
downLoadData(iXuErUpLoadDataUrl + "&y=" + Math.random());
} else {
downLoadData(iXuErUpLoadDataUrl + "?y=" + Math.random());
}
// lngTotalSize lngReadSize
var lngLeftSize = lngTotalSize - lngReadSize;
var dblPercent = (lngTotalSize) ? lngReadSize * 100 / lngTotalSize : 0;
var dblSpeed = (lngUsedTime > 0) ? lngReadSize / (lngUsedTime * 1.024) : 0;
var lngLeftTime = (dblSpeed > 0) ? lngLeftSize / dblSpeed : 0;
var strTemp = (lngUsedTime >= 60000)? "<strong>" + fxFormat(lngUsedTime / 60000) + "</strong> 分" : "<strong>" + lngUsedTime / 1000 + "</strong> 秒";
var strTemp2 = (lngLeftTime > 60000)? "<strong>" + fxFormat(lngLeftTime / 60000) + "</strong> 分" : "<strong>" + fxFormat(lngLeftTime / 1000) + "</strong> 秒";
document.getElementById("UpLoaddingProgress").style.width = fxFormat(dblPercent) + "%";
document.getElementById("UpLoaddingProgress").innerHTML = fxFormat(dblPercent) + "%";
document.getElementById("UpLoaddingPercent").innerHTML = fxFormat(dblPercent);
document.getElementById("UpLoaddingPercent2").innerHTML = fxFormat(dblPercent) + "%";
document.getElementById("UpLoaddingNum").innerHTML = oUpLoaddingNum;
document.getElementById("UpLoaddingUsedTime").innerHTML = strTemp;
document.getElementById("UpLoaddingLeftTime").innerHTML = strTemp2;
document.getElementById("UpLoaddingSpeed").innerHTML = fxFormat(dblSpeed);
document.getElementById("UpLoaddingTransfers").innerHTML = fxFormat(lngReadSize / 1048576);
document.getElementById("UpLoaddingTotalSize").innerHTML = fxFormat(lngTotalSize / 1048576);
lngUsedTime += intTimeStep;
if((lngReadSize < lngTotalSize || !dblSpeed) && document.getElementById("UpLoadErrMsg").innerHTML != "False"){
var TimeoutID = window.setTimeout("upLoadding();", intTimeStep);
}else{
// 上传完毕
lngUsedTime = 0, lngTotalSize = 0; lngReadSize = 0, dblSpeed = null;
document.getElementById("UpLoaddingProgress").style.width = "100%";
document.getElementById("UpLoaddingProgress").innerHTML = "100%";
document.getElementById("UpLoaddingPercent").innerHTML = 100;
document.getElementById("UpLoaddingPercent2").innerHTML = "100%";
document.getElementById("UpLoaddingTransfers").innerHTML = fxFormat(lngTotalSize / 1048576);
document.getElementById("UpLoaddingNum").innerHTML = 0;
document.getElementById("UpLoaddingUsedTime").innerHTML = "<strong>0</strong> 秒";
document.getElementById("UpLoaddingLeftTime").innerHTML = "<strong>0</strong> 秒";
document.getElementById("UpLoaddingSpeed").innerHTML = 0;
document.getElementById("UpLoaddingTotalSize").innerHTML = 0;
window.clearTimeout(TimeoutID);
}
}
// 格式化数字 保留2位浮点
function fxFormat(num){
return Math.round(Number(num) * 100) / 100;
}
// 文件大小转换
function checkFileSize(p_FileSize){
p_FileSize = Math.abs(p_FileSize);
if(p_FileSize < 1024){
return p_FileSize + " byte";
} else if(p_FileSize < 1048576){
return fxFormat(p_FileSize / 1024) + " KB";
} else if(p_FileSize < 1073741824){
return fxFormat(p_FileSize / 1048576) + " MB";
} else if(p_FileSize < 1099511627776){
return fxFormat(p_FileSize / 1073741824) + " GB";
}
}
// 文件类型判断
function checkFileType(p_FileType){
switch (Math.abs(p_FileType)){
case 1 :
return "图像文件";
break;
case 2 :
return "动画文件";
break;
case 3 :
return "WMP音频";
break;
case 4 :
return "Real文件";
break;
case 5 :
return "WMP视频";
break;
case 6 :
return "其他文件";
break;
default :
return "未知文件";
break;
}
}
// 插入文件
function InsertFile(p_FileID, p_FileName, p_FilePath, p_FileSize, p_FileContentType, p_FileType, p_FileExt, p_FileWidth, p_FileHeight, p_FilePreview, p_TotalSize, p_ImgPreview){
try{
// 向文件列表当中添加项目
var oFileList = document.getElementById("iXuErFileList");
var iXuErFileListHTML = document.getElementById("iXuErFileListTemplates").innerHTML;
document.getElementById("iXuErListNone").style.display = "none"; oFileList.style.display = "";
iXuErFileListHTML = iXuErFileListHTML.replace(/FileID/g, p_FileID);
iXuErFileListHTML = iXuErFileListHTML.replace(/FileName/g, p_FileName);
iXuErFileListHTML = iXuErFileListHTML.replace(/FileSize/g, checkFileSize(p_FileSize));
iXuErFileListHTML = iXuErFileListHTML.replace(/FileType/g, checkFileType(p_FileType));
oFileList.innerHTML += iXuErFileListHTML;
if(p_FilePreview == "" || p_FilePreview == null){p_FilePreview = 0;}
// 返回值到文本框
insertTextForm(o_FileID, p_FileID);
insertTextForm(o_FileName, p_FileName);
insertTextForm(o_FilePath, p_FilePath);
insertTextForm(o_FileSize, p_FileSize);
insertTextForm(o_FileContentType, p_FileContentType);
insertTextForm(o_FileType, p_FileType);
insertTextForm(o_FileExt, p_FileExt);
insertTextForm(o_FileWidth, p_FileWidth);
insertTextForm(o_FileHeight, p_FileHeight);
insertTextForm(o_FilePreview, p_FilePreview);
insertTextForm(o_TotalSize, p_TotalSize);
insertTextForm(o_ImgPreview, p_ImgPreview);
// 返回值到下拉菜单
InsertSelectOption(s_FileID, p_FileID);
InsertSelectOption(s_FileName, p_FileName);
InsertSelectOption(s_FilePath, p_FilePath);
InsertSelectOption(s_FileSize, p_FileSize);
InsertSelectOption(s_FileContentType, p_FileContentType);
InsertSelectOption(s_FileType, p_FileType);
InsertSelectOption(s_FileExt, p_FileExt);
InsertSelectOption(s_FileWidth, p_FileWidth);
InsertSelectOption(s_FileHeight, p_FileHeight);
InsertSelectOption(s_FilePreview, p_FilePreview);
InsertSelectOption(s_TotalSize, p_TotalSize);
InsertSelectOption(s_ImgPreview, p_ImgPreview);
}
catch(e){};
}
function insertTextForm(p_Obj, p_Value){
var Obj = document.getElementById(p_Obj);
if(Obj.value != "" && Obj.value != null){
Obj.value = Obj.value + "|" + p_Value;
} else {
Obj.value = p_Value;
}
}
function InsertSelectOption(p_Obj, p_Value){
var Obj = document.getElementById(p_Obj);
oOption = document.createElement("OPTION");
//var oSucNum = document.getElementById("UpLoadSucNum");
//var i = Math.abs(oSucNum.innerHTML);
//Obj.children(i).insertAdjacentElement("beforeEnd", oOption);
// 暂时没有解决FF的兼容问题。
Obj.add(oOption);
oOption.innerText = p_Value;
oOption.value = p_Value;
oOption.id = p_Obj + "_" + p_Value;
oOption.style.color = "#006600";
oOption.selected = true;
}
setUpLoadCount();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -