|
|
@ -4,87 +4,85 @@ |
|
|
|
|
|
|
|
|
|
|
|
//全局的配置文件
|
|
|
|
//全局的配置文件
|
|
|
|
var config = { |
|
|
|
var config = { |
|
|
|
fileTypes : "txt|epub|umd", //允许上传的文件格式 "txt|epub" // |doc|docx|wps|xls|xlsx|et|ppt|pptx|dps
|
|
|
|
fileTypes: "txt|epub|umd", //允许上传的文件格式 "txt|epub" // |doc|docx|wps|xls|xlsx|et|ppt|pptx|dps
|
|
|
|
//url : "http://"+location.host+"?action=addBook",//"http://localhost/t/post.php",//
|
|
|
|
//url : "http://"+location.host+"?action=addBook",//"http://localhost/t/post.php",//
|
|
|
|
url: "http://192.168.1.16:1122/addLocalBook", |
|
|
|
url: "../addLocalBook", |
|
|
|
fileLimitSize : 500 * 1024 *1024 |
|
|
|
fileLimitSize: 500 * 1024 * 1024 |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var file = { |
|
|
|
var file = { |
|
|
|
"inQueue" : [], //已经在队列里面的文件,包括 HTML5上传和 Flash上传的
|
|
|
|
"inQueue": [], //已经在队列里面的文件,包括 HTML5上传和 Flash上传的
|
|
|
|
"clientHaveFiles" : [] // 客户端已经存在的文件列表
|
|
|
|
"clientHaveFiles": [] // 客户端已经存在的文件列表
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* HTML5 和 flash 公用,所有文件对象集合 |
|
|
|
* HTML5 和 flash 公用,所有文件对象集合 |
|
|
|
* @var array
|
|
|
|
* @var array
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var filesUpload = []; //
|
|
|
|
var filesUpload = []; //
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
$.ajax({ |
|
|
|
url : "http://"+location.host+'?action=getBooksList&t='+(+new Date()),//"http://localhost/t/t.php",//
|
|
|
|
url: "http://" + location.host + '?action=getBooksList&t=' + (+new Date()),//"http://localhost/t/t.php",//
|
|
|
|
async:false,//同步获取数据
|
|
|
|
async: false,//同步获取数据
|
|
|
|
dataType : "json", |
|
|
|
dataType: "json", |
|
|
|
success:function(data){ |
|
|
|
success: function (data) { |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
try { |
|
|
|
var dataLen = data.length; |
|
|
|
var dataLen = data.length; |
|
|
|
if(dataLen > 0 ){ |
|
|
|
if (dataLen > 0) { |
|
|
|
for(var i=0; i < dataLen; i++){ |
|
|
|
for (var i = 0; i < dataLen; i++) { |
|
|
|
filesUpload.push(data[i]); |
|
|
|
filesUpload.push(data[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}catch(e){} |
|
|
|
} catch (e) { } |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
//统计文件大小
|
|
|
|
//统计文件大小
|
|
|
|
function countFileSize(fileSize) |
|
|
|
function countFileSize(fileSize) { |
|
|
|
{ |
|
|
|
var KB = 1024; |
|
|
|
var KB = 1024; |
|
|
|
|
|
|
|
var MB = 1024 * 1024; |
|
|
|
var MB = 1024 * 1024; |
|
|
|
if(KB >= fileSize){ |
|
|
|
if (KB >= fileSize) { |
|
|
|
return fileSize+"B"; |
|
|
|
return fileSize + "B"; |
|
|
|
}else if(MB >= fileSize){ |
|
|
|
} else if (MB >= fileSize) { |
|
|
|
return (fileSize/KB).toFixed(2)+"KB"; |
|
|
|
return (fileSize / KB).toFixed(2) + "KB"; |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
return (fileSize/MB).toFixed(2)+"MB"; |
|
|
|
return (fileSize / MB).toFixed(2) + "MB"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//如果文件太长进行截取
|
|
|
|
//如果文件太长进行截取
|
|
|
|
function substr_string(name) |
|
|
|
function substr_string(name) { |
|
|
|
{ |
|
|
|
|
|
|
|
var maxLen = 15; |
|
|
|
var maxLen = 15; |
|
|
|
var len = name.length; |
|
|
|
var len = name.length; |
|
|
|
if(len < 17 )return name; |
|
|
|
if (len < 17) return name; |
|
|
|
|
|
|
|
|
|
|
|
var lastIndex = name.lastIndexOf("."); |
|
|
|
var lastIndex = name.lastIndexOf("."); |
|
|
|
var suffix = name.substr(lastIndex); |
|
|
|
var suffix = name.substr(lastIndex); |
|
|
|
var pre = name.substr(0,lastIndex); |
|
|
|
var pre = name.substr(0, lastIndex); |
|
|
|
var preLen = pre.length; |
|
|
|
var preLen = pre.length; |
|
|
|
var preStart = preLen - 10; |
|
|
|
var preStart = preLen - 10; |
|
|
|
//前面10个 + 后面5个
|
|
|
|
//前面10个 + 后面5个
|
|
|
|
var fileName = pre.substr(0,10) + "...." + pre.substr( preStart > 4 ? -4 : -preStart , 4)+suffix; |
|
|
|
var fileName = pre.substr(0, 10) + "...." + pre.substr(preStart > 4 ? -4 : -preStart, 4) + suffix; |
|
|
|
return fileName |
|
|
|
return fileName |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function checkFile(file) { |
|
|
|
function checkFile(file) { |
|
|
|
|
|
|
|
|
|
|
|
if(file.size > config.fileLimitSize){ |
|
|
|
if (file.size > config.fileLimitSize) { |
|
|
|
return jsonLang.t11; |
|
|
|
return jsonLang.t11; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!file.name || !file.name.toLowerCase().match('('+config.fileTypes+')$')) { |
|
|
|
if (!file.name || !file.name.toLowerCase().match('(' + config.fileTypes + ')$')) { |
|
|
|
return jsonLang.t12; |
|
|
|
return jsonLang.t12; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var len = filesUpload.length; |
|
|
|
var len = filesUpload.length; |
|
|
|
for(var i=0; i< len; i++){ |
|
|
|
for (var i = 0; i < len; i++) { |
|
|
|
if(filesUpload[i].name == file.name) { |
|
|
|
if (filesUpload[i].name == file.name) { |
|
|
|
return jsonLang.t13; |
|
|
|
return jsonLang.t13; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -101,34 +99,32 @@ function checkFile(file) { |
|
|
|
* @param object file 文件对象 |
|
|
|
* @param object file 文件对象 |
|
|
|
* @param int type 0 是swf 上传的,1 是html5上传的 |
|
|
|
* @param int type 0 是swf 上传的,1 是html5上传的 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function fileQueued(file, type) |
|
|
|
function fileQueued(file, type) { |
|
|
|
{ |
|
|
|
var size = 0, fid = file.id, name = ""; |
|
|
|
var size=0 ,fid=file.id, name=""; |
|
|
|
|
|
|
|
type = type || 0; |
|
|
|
type = type || 0; |
|
|
|
|
|
|
|
|
|
|
|
if(file != undefined ) |
|
|
|
if (file != undefined) { |
|
|
|
{ |
|
|
|
|
|
|
|
//计算文件大小 单位MB
|
|
|
|
//计算文件大小 单位MB
|
|
|
|
size = countFileSize(file.size); |
|
|
|
size = countFileSize(file.size); |
|
|
|
name = substr_string(file.name) |
|
|
|
name = substr_string(file.name) |
|
|
|
//创建要插入的元素
|
|
|
|
//创建要插入的元素
|
|
|
|
// "<tr id='tr_'"+fid+"><td><div class='bh-poStion'><h1>"+name+"</h1>"+
|
|
|
|
// "<tr id='tr_'"+fid+"><td><div class='bh-poStion'><h1>"+name+"</h1>"+
|
|
|
|
// "<div class='bh-tip bh-tip3' id='progress_bar_"+fid+"'>"+
|
|
|
|
// "<div class='bh-tip bh-tip3' id='progress_bar_"+fid+"'>"+
|
|
|
|
// "<span id='progress_bar_span_"+fid+"'></span></div>"+
|
|
|
|
// "<span id='progress_bar_span_"+fid+"'></span></div>"+
|
|
|
|
// "</div></td><td><span class='bh-M'>"+size+"</span></td><td><div class='bh-link' id='handle_button_"+fid+"'>"+
|
|
|
|
// "</div></td><td><span class='bh-M'>"+size+"</span></td><td><div class='bh-link' id='handle_button_"+fid+"'>"+
|
|
|
|
// "<a href='javascript:void(0)' onclick=userCancelUpload('"+fid+"',"+type+")>取消</a></div></td></tr>";
|
|
|
|
// "<a href='javascript:void(0)' onclick=userCancelUpload('"+fid+"',"+type+")>取消</a></div></td></tr>";
|
|
|
|
|
|
|
|
|
|
|
|
var HTML = '<li id="tr_"'+fid+'>'+ |
|
|
|
var HTML = '<li id="tr_"' + fid + '>' + |
|
|
|
'<dl class="grybg">'+ |
|
|
|
'<dl class="grybg">' + |
|
|
|
'<dt>'+name+'</dt>'+ |
|
|
|
'<dt>' + name + '</dt>' + |
|
|
|
'<dd>'+size+'</dd>'+ |
|
|
|
'<dd>' + size + '</dd>' + |
|
|
|
'<dd id="handle_button_'+fid+'" onclick=userCancelUpload("'+fid+'",'+type+') class="orange">'+ |
|
|
|
'<dd id="handle_button_' + fid + '" onclick=userCancelUpload("' + fid + '",' + type + ') class="orange">' + |
|
|
|
'<span id="progress_bar_span_'+fid+'">0%</span> '+jsonLang.t9+'</dd>'+ |
|
|
|
'<span id="progress_bar_span_' + fid + '">0%</span> ' + jsonLang.t9 + '</dd>' + |
|
|
|
'</dl>'+ |
|
|
|
'</dl>' + |
|
|
|
'<div class="jdt"><p id="progress_bar_p_'+fid+'" ></p></div>'+ |
|
|
|
'<div class="jdt"><p id="progress_bar_p_' + fid + '" ></p></div>' + |
|
|
|
'</li>'; |
|
|
|
'</li>'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jQuery("#tableStyle").append(HTML); |
|
|
|
jQuery("#tableStyle").append(HTML); |
|
|
|
//保存falsh_id,为上传做准备
|
|
|
|
//保存falsh_id,为上传做准备
|
|
|
|
//global_flash_id.push(file.id);
|
|
|
|
//global_flash_id.push(file.id);
|
|
|
@ -137,55 +133,51 @@ function fileQueued(file, type) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function changeTrBackGroundColor() |
|
|
|
function changeTrBackGroundColor() { |
|
|
|
{ |
|
|
|
var getTr = document.getElementById("tableStyle").getElementsByTagName("dl"); |
|
|
|
var getTr=document.getElementById("tableStyle").getElementsByTagName("dl"); |
|
|
|
trNum = getTr.length; |
|
|
|
trNum=getTr.length; |
|
|
|
for (var i = 0; i < trNum; i++) { |
|
|
|
for(var i=0;i<trNum;i++){ |
|
|
|
if (i % 2 == 0) { |
|
|
|
if(i%2==0){ |
|
|
|
getTr[i].style.backgroundColor = "#f3f3f3"; |
|
|
|
getTr[i].style.backgroundColor="#f3f3f3"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//上传时返回的状态
|
|
|
|
//上传时返回的状态
|
|
|
|
function uploadProgress(file, bytesLoaded, bytesTotal)
|
|
|
|
function uploadProgress(file, bytesLoaded, bytesTotal) { |
|
|
|
{ |
|
|
|
if (!$("#progress_bar_p_" + file.id).hasClass("orange")) { |
|
|
|
if(!$("#progress_bar_p_"+file.id).hasClass("orange")){ |
|
|
|
$("#progress_bar_p_" + file.id).addClass("orange"); |
|
|
|
$("#progress_bar_p_"+file.id).addClass("orange"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
$("#progress_bar_p_"+file.id).css("width",(bytesLoaded/bytesTotal)*100+"%"); |
|
|
|
$("#progress_bar_p_" + file.id).css("width", (bytesLoaded / bytesTotal) * 100 + "%"); |
|
|
|
$("#progress_bar_span_"+file.id).html(parseInt((bytesLoaded/bytesTotal)*100)+"%"); |
|
|
|
$("#progress_bar_span_" + file.id).html(parseInt((bytesLoaded / bytesTotal) * 100) + "%"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//上传成功
|
|
|
|
//上传成功
|
|
|
|
function uploadSuccess(file, serverData, res) |
|
|
|
function uploadSuccess(file, serverData, res) { |
|
|
|
{ |
|
|
|
var id = "handle_button_" + file.id; |
|
|
|
var id = "handle_button_"+file.id; |
|
|
|
$("#" + id).replaceWith("<dd>" + jsonLang.t10 + "</dd>") |
|
|
|
$("#"+id).replaceWith("<dd>"+jsonLang.t10+"</dd>") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//取消上传
|
|
|
|
//取消上传
|
|
|
|
function userCancelUpload(file_id, type) |
|
|
|
function userCancelUpload(file_id, type) { |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (type == 0) { |
|
|
|
if(type==0){ |
|
|
|
|
|
|
|
SWFFuns.cancelUpload(file_id); |
|
|
|
SWFFuns.cancelUpload(file_id); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
HTML5Funs.cancelUpload(file_id); |
|
|
|
HTML5Funs.cancelUpload(file_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$("#handle_button_"+file_id).html(jsonLang.t14).removeClass("orange").addClass("gray"); |
|
|
|
$("#handle_button_" + file_id).html(jsonLang.t14).removeClass("orange").addClass("gray"); |
|
|
|
//如果已经上传一部分了
|
|
|
|
//如果已经上传一部分了
|
|
|
|
if($("#progress_bar_p_"+file_id).hasClass("orange")){ |
|
|
|
if ($("#progress_bar_p_" + file_id).hasClass("orange")) { |
|
|
|
$("#progress_bar_p_"+file_id).removeClass("orange"); |
|
|
|
$("#progress_bar_p_" + file_id).removeClass("orange"); |
|
|
|
$("#progress_bar_p_"+file_id).addClass("gray"); |
|
|
|
$("#progress_bar_p_" + file_id).addClass("gray"); |
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -193,14 +185,14 @@ function userCancelUpload(file_id, type) |
|
|
|
* 通过文件名称 从全局的文件列表中获取文件对象 |
|
|
|
* 通过文件名称 从全局的文件列表中获取文件对象 |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function getFileFomeFilesUpload(filename){ |
|
|
|
function getFileFomeFilesUpload(filename) { |
|
|
|
var len = filesUpload.length; |
|
|
|
var len = filesUpload.length; |
|
|
|
for(var i=0; i < len; i++){ |
|
|
|
for (var i = 0; i < len; i++) { |
|
|
|
if(filesUpload[i].name == filename){ |
|
|
|
if (filesUpload[i].name == filename) { |
|
|
|
return filesUpload[i]; |
|
|
|
return filesUpload[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -208,42 +200,42 @@ function getFileFomeFilesUpload(filename){ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 往全局的 上传列表添加一个数据 |
|
|
|
* 往全局的 上传列表添加一个数据 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function addFileToFilesUpload(file){ |
|
|
|
function addFileToFilesUpload(file) { |
|
|
|
|
|
|
|
|
|
|
|
if(typeof file == "string"){ |
|
|
|
if (typeof file == "string") { |
|
|
|
filesUpload.push({"name":file}) |
|
|
|
filesUpload.push({ "name": file }) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}else if(typeof file == "object"){ |
|
|
|
} else if (typeof file == "object") { |
|
|
|
filesUpload.push(file); |
|
|
|
filesUpload.push(file); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 往全局的 上传列表添加一个数据 |
|
|
|
* 往全局的 上传列表添加一个数据 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function updateFileToFilesUpload(file){ |
|
|
|
function updateFileToFilesUpload(file) { |
|
|
|
|
|
|
|
|
|
|
|
var len = filesUpload.length; |
|
|
|
var len = filesUpload.length; |
|
|
|
for(var i=0; i < len; i++){ |
|
|
|
for (var i = 0; i < len; i++) { |
|
|
|
if(filesUpload[i].name == file.name){ |
|
|
|
if (filesUpload[i].name == file.name) { |
|
|
|
filesUpload[i] = file; |
|
|
|
filesUpload[i] = file; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 查找在数组中的位置 |
|
|
|
* 查找在数组中的位置 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function findObjectKey (object, fid){ |
|
|
|
function findObjectKey(object, fid) { |
|
|
|
var len = object.length;
|
|
|
|
var len = object.length; |
|
|
|
for(var i=0; i<len; i++){ |
|
|
|
for (var i = 0; i < len; i++) { |
|
|
|
if(object[i].id == fid){ |
|
|
|
if (object[i].id == fid) { |
|
|
|
return i; |
|
|
|
return i; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -256,14 +248,14 @@ function findObjectKey (object, fid){ |
|
|
|
* @param int fid 要删除的文件id |
|
|
|
* @param int fid 要删除的文件id |
|
|
|
* @return 删除后的数组, 其实数组是引用类型可以不返回 |
|
|
|
* @return 删除后的数组, 其实数组是引用类型可以不返回 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function removeFileFromFilesUpload(files, fid){ |
|
|
|
function removeFileFromFilesUpload(files, fid) { |
|
|
|
|
|
|
|
|
|
|
|
var filesUploadKey = -1; |
|
|
|
var filesUploadKey = -1; |
|
|
|
|
|
|
|
|
|
|
|
filesUploadKey = findObjectKey(files, fid); |
|
|
|
filesUploadKey = findObjectKey(files, fid); |
|
|
|
//从全局文件中移除
|
|
|
|
//从全局文件中移除
|
|
|
|
if(filesUploadKey > -1) |
|
|
|
if (filesUploadKey > -1) |
|
|
|
files.splice(filesUploadKey, 1); |
|
|
|
files.splice(filesUploadKey, 1); |
|
|
|
|
|
|
|
|
|
|
|
return files; |
|
|
|
return files; |
|
|
|
} |
|
|
|
} |