本文的视频上传方案是基于乐视视频点播做的原理分析
var videoUploadEntity = (function () {
function videoUploadEntity() {
}
videoUploadEntity.upoadConfigEntity = {};
videoUploadEntity.upoadConfigIAPIDocument = (function () {
var upoadConfigIAPIDocument = new leCommonAjax.IAPIDocument();
upoadConfigIAPIDocument.apiUrl = adminBase.reuqestUrl.uploadConfig;
upoadConfigIAPIDocument.apiMeaning = "获取上传配置信息";
upoadConfigIAPIDocument.apiQueryStringParameters = {
};
upoadConfigIAPIDocument.apiResponse = {
panoramic: {
isEmpty: false,
isNull: false
},
v720p: {
isEmpty: false,
isNull: false
},
v1080p: {
isEmpty: false,
isNull: false
}
};
return upoadConfigIAPIDocument;
})();
videoUploadEntity.uploadInitEntity = {
videoName: "",
uploadType: 1,
fileSize: 0,
panoramic: 0,
uc1: 0,
uc2: 0,
v720p: false,
v1080p: false
};
videoUploadEntity.uploadInitIAPIDocument = (function () {
var uploadInitIAPIDocument = new leCommonAjax.IAPIDocument();
uploadInitIAPIDocument.apiUrl = adminBase.reuqestUrl.uploadInit;
uploadInitIAPIDocument.apiMeaning = "视频上传初始化";
uploadInitIAPIDocument.apiQueryStringParameters = {
videoName: {
isEmpty: false,
isNull: false
},
uploadType: {
isEmpty: false,
isNull: false
},
fileSize: {
isEmpty: false,
isNull: false
},
panoramic: {
isEmpty: true,
isNull: true
},
uc1: {
isEmpty: true,
isNull: true
},
uc2: {
isEmpty: true,
isNull: true
},
v720p: {
isEmpty: true,
isNull: true
},
v1080p: {
isEmpty: true,
isNull: true
},
};
uploadInitIAPIDocument.apiResponse = {
uploadUrl: {
isEmpty: false,
isNull: false
},
token: {
isEmpty: false,
isNull: false
},
uploadSize: {
isEmpty: false,
isNull: false
}
};
return uploadInitIAPIDocument;
})();
//获取所有分类
videoUploadEntity.videoCategoryEntity = {
parentId: 0,
};
videoUploadEntity.videoCategoryIAPIDocument = (function () {
var videoCategoryIAPIDocument = new leCommonAjax.IAPIDocument();
videoCategoryIAPIDocument.apiUrl = adminBase.reuqestUrl.category;
return videoCategoryIAPIDocument;
})();
return videoUploadEntity;
})();
var videoUploadDAL = (function () {
function videoUploadDAL() {
}
videoUploadDAL.upoadConfig = function (successCallback, errorCallback) {
leCommonAjax.ajax(videoUploadEntity.upoadConfigIAPIDocument, function (successData) {
successCallback(successData.data);
}, function (errorData) {
errorCallback(errorData);
}, {
data: videoUploadEntity.upoadConfigEntity
});
};
videoUploadDAL.uploadInit = function (successCallback, errorCallback) {
leCommonAjax.ajax(videoUploadEntity.uploadInitIAPIDocument, function (successData) {
successCallback(successData.data);
}, function (errorData) {
errorCallback(errorData);
}, {
type: 'post',
data: videoUploadEntity.uploadInitEntity
});
};
videoUploadDAL.getVideoCategory = function (successCallback, errorCallback) {
leCommonAjax.ajax(videoUploadEntity.videoCategoryIAPIDocument, function (successData) {
successCallback(successData.data);
}, function (errorData) {
errorCallback(errorData);
}, {
data: videoUploadEntity.videoCategoryEntity
});
};
return videoUploadDAL;
})();
var leMd5 = (function () {
function leMd5() {
}
leMd5.getMD5 = function (data) {
// convert number to (unsigned) 32 bit hex, zero filled string
function to_zerofilled_hex(n) {
var t1 = (n >>> 0).toString(16)
return "00000000".substr(0, 8 - t1.length) + t1
}
// convert array of chars to array of bytes
function chars_to_bytes(ac) {
var retval = []
for (var i = 0; i < ac.length; i++) {
retval = retval.concat(str_to_bytes(ac[i]))
}
return retval
}
// convert a 64 bit unsigned number to array of bytes. Little endian
function int64_to_bytes(num) {
var retval = []
for (var i = 0; i < 8; i++) {
retval.push(num & 0xFF)
num = num >>> 8
}
return retval
}
// 32 bit left-rotation
function rol(num, places) {
return ((num << places) & 0xFFFFFFFF) | (num >>> (32 - places))
}
// The 4 MD5 functions
function fF(b, c, d) {
return (b & c) | (~b & d)
}
function fG(b, c, d) {
return (d & b) | (~d & c)
}
function fH(b, c, d) {
return b ^ c ^ d
}
function fI(b, c, d) {
return c ^ (b | ~d)
}
// pick 4 bytes at specified offset. Little-endian is assumed
function bytes_to_int32(arr, off) {
return (arr[off + 3] << 24) | (arr[off + 2] << 16) | (arr[off + 1] << 8) | (arr[off])
}
/*
Conver string to array of bytes in UTF-8 encoding
See:
http://www.dangrossman.info/2007/05/25/handling-utf-8-in-javascript-php-and-non-utf8-databases/
http://stackoverflow.com/questions/1240408/reading-bytes-from-a-javascript-string
How about a String.getBytes(<ENCODING>) for Javascript!? Isn't it time to add it?
*/
function str_to_bytes(str) {
var retval = []
for (var i = 0; i < str.length; i++)
if (str.charCodeAt(i) <= 0x7F) {
retval.push(str.charCodeAt(i))
} else {
var tmp = encodeURIComponent(str.charAt(i)).substr(1).split('%')
for (var j = 0; j < tmp.length; j++) {
retval.push(parseInt(tmp[j], 0x10))
}
}
return retval
}
// convert the 4 32-bit buffers to a 128 bit hex string. (Little-endian is assumed)
function int128le_to_hex(a, b, c, d) {
var ra = ""
var t = 0
var ta = 0
for (var i = 3; i >= 0; i--) {
ta = arguments[i]
t = (ta & 0xFF)
ta = ta >>> 8
t = t << 8
t = t | (ta & 0xFF)
ta = ta >>> 8
t = t << 8
t = t | (ta & 0xFF)
ta = ta >>> 8
t = t << 8
t = t | ta
ra = ra + to_zerofilled_hex(t)
}
return ra
}
// conversion from typed byte array to plain javascript array
function typed_to_plain(tarr) {
var retval = new Array(tarr.length)
for (var i = 0; i < tarr.length; i++) {
retval[i] = tarr[i]
}
return retval
}
// check input data type and perform conversions if needed
var databytes = null
// String
var type_mismatch = null
if (typeof data == 'string') {
// convert string to array bytes
databytes = str_to_bytes(data)
} else if (data.constructor == Array) {
if (data.length === 0) {
// if it's empty, just assume array of bytes
databytes = data
} else if (typeof data[0] == 'string') {
databytes = chars_to_bytes(data)
} else if (typeof data[0] == 'number') {
databytes = data
} else {
type_mismatch = typeof data[0]
}
} else if (typeof ArrayBuffer != 'undefined') {
if (data instanceof ArrayBuffer) {
databytes = typed_to_plain(new Uint8Array(data))
} else if ((data instanceof Uint8Array) || (data instanceof Int8Array)) {
databytes = typed_to_plain(data)
} else if ((data instanceof Uint32Array) || (data instanceof Int32Array) ||
(data instanceof Uint16Array) || (data instanceof Int16Array) ||
(data instanceof Float32Array) || (data instanceof Float64Array)
) {
databytes = typed_to_plain(new Uint8Array(data.buffer))
} else {
type_mismatch = typeof data
}
} else {
type_mismatch = typeof data
}
if (type_mismatch) {
alert('MD5 type mismatch, cannot process ' + type_mismatch)
}
function _add(n1, n2) {
return 0x0FFFFFFFF & (n1 + n2)
}
return do_digest()
function do_digest() {
// function update partial state for each run
function updateRun(nf, sin32, dw32, b32) {
var temp = d
d = c
c = b
//b = b + rol(a + (nf + (sin32 + dw32)), b32)
b = _add(b,
rol(
_add(a,
_add(nf, _add(sin32, dw32))
), b32
)
)
a = temp
}
// save original length
var org_len = databytes.length
// first append the "1" + 7x "0"
databytes.push(0x80)
// determine required amount of padding
var tail = databytes.length % 64
// no room for msg length?
if (tail > 56) {
// pad to next 512 bit block
for (var i = 0; i < (64 - tail) ; i++) {
databytes.push(0x0)
}
tail = databytes.length % 64
}
for (i = 0; i < (56 - tail) ; i++) {
databytes.push(0x0)
}
// message length in bits mod 512 should now be 448
// append 64 bit, little-endian original msg length (in *bits*!)
databytes = databytes.concat(int64_to_bytes(org_len * 8))
// initialize 4x32 bit state
var h0 = 0x67452301
var h1 = 0xEFCDAB89
var h2 = 0x98BADCFE
var h3 = 0x10325476
// temp buffers
var a = 0,
b = 0,
c = 0,
d = 0
// Digest message
for (i = 0; i < databytes.length / 64; i++) {
// initialize run
a = h0
b = h1
c = h2
d = h3
var ptr = i * 64
// do 64 runs
updateRun(fF(b, c, d), 0xd76aa478, bytes_to_int32(databytes, ptr), 7)
updateRun(fF(b, c, d), 0xe8c7b756, bytes_to_int32(databytes, ptr + 4), 12)
updateRun(fF(b, c, d), 0x242070db, bytes_to_int32(databytes, ptr + 8), 17)
updateRun(fF(b, c, d), 0xc1bdceee, bytes_to_int32(databytes, ptr + 12), 22)
updateRun(fF(b, c, d), 0xf57c0faf, bytes_to_int32(databytes, ptr + 16), 7)
updateRun(fF(b, c, d), 0x4787c62a, bytes_to_int32(databytes, ptr + 20), 12)
updateRun(fF(b, c, d), 0xa8304613, bytes_to_int32(databytes, ptr + 24), 17)
updateRun(fF(b, c, d), 0xfd469501, bytes_to_int32(databytes, ptr + 28), 22)
updateRun(fF(b, c, d), 0x698098d8, bytes_to_int32(databytes, ptr + 32), 7)
updateRun(fF(b, c, d), 0x8b44f7af, bytes_to_int32(databytes, ptr + 36), 12)
updateRun(fF(b, c, d), 0xffff5bb1, bytes_to_int32(databytes, ptr + 40), 17)
updateRun(fF(b, c, d), 0x895cd7be, bytes_to_int32(databytes, ptr + 44), 22)
updateRun(fF(b, c, d), 0x6b901122, bytes_to_int32(databytes, ptr + 48), 7)
updateRun(fF(b, c, d), 0xfd987193, bytes_to_int32(databytes, ptr + 52), 12)
updateRun(fF(b, c, d), 0xa679438e, bytes_to_int32(databytes, ptr + 56), 17)
updateRun(fF(b, c, d), 0x49b40821, bytes_to_int32(databytes, ptr + 60), 22)
updateRun(fG(b, c, d), 0xf61e2562, bytes_to_int32(databytes, ptr + 4), 5)
updateRun(fG(b, c, d), 0xc040b340, bytes_to_int32(databytes, ptr + 24), 9)
updateRun(fG(b, c, d), 0x265e5a51, bytes_to_int32(databytes, ptr + 44), 14)
updateRun(fG(b, c, d), 0xe9b6c7aa, bytes_to_int32(databytes, ptr), 20)
updateRun(fG(b, c, d), 0xd62f105d, bytes_to_int32(databytes, ptr + 20), 5)
updateRun(fG(b, c, d), 0x2441453, bytes_to_int32(databytes, ptr + 40), 9)
updateRun(fG(b, c, d), 0xd8a1e681, bytes_to_int32(databytes, ptr + 60), 14)
updateRun(fG(b, c, d), 0xe7d3fbc8, bytes_to_int32(databytes, ptr + 16), 20)
updateRun(fG(b, c, d), 0x21e1cde6, bytes_to_int32(databytes, ptr + 36), 5)
updateRun(fG(b, c, d), 0xc33707d6, bytes_to_int32(databytes, ptr + 56), 9)
updateRun(fG(b, c, d), 0xf4d50d87, bytes_to_int32(databytes, ptr + 12), 14)
updateRun(fG(b, c, d), 0x455a14ed, bytes_to_int32(databytes, ptr + 32), 20)
updateRun(fG(b, c, d), 0xa9e3e905, bytes_to_int32(databytes, ptr + 52), 5)
updateRun(fG(b, c, d), 0xfcefa3f8, bytes_to_int32(databytes, ptr + 8), 9)
updateRun(fG(b, c, d), 0x676f02d9, bytes_to_int32(databytes, ptr + 28), 14)
updateRun(fG(b, c, d), 0x8d2a4c8a, bytes_to_int32(databytes, ptr + 48), 20)
updateRun(fH(b, c, d), 0xfffa3942, bytes_to_int32(databytes, ptr + 20), 4)
updateRun(fH(b, c, d), 0x8771f681, bytes_to_int32(databytes, ptr + 32), 11)
updateRun(fH(b, c, d), 0x6d9d6122, bytes_to_int32(databytes, ptr + 44), 16)
updateRun(fH(b, c, d), 0xfde5380c, bytes_to_int32(databytes, ptr + 56), 23)
updateRun(fH(b, c, d), 0xa4beea44, bytes_to_int32(databytes, ptr + 4), 4)
updateRun(fH(b, c, d), 0x4bdecfa9, bytes_to_int32(databytes, ptr + 16), 11)
updateRun(fH(b, c, d), 0xf6bb4b60, bytes_to_int32(databytes, ptr + 28), 16)
updateRun(fH(b, c, d), 0xbebfbc70, bytes_to_int32(databytes, ptr + 40), 23)
updateRun(fH(b, c, d), 0x289b7ec6, bytes_to_int32(databytes, ptr + 52), 4)
updateRun(fH(b, c, d), 0xeaa127fa, bytes_to_int32(databytes, ptr), 11)
updateRun(fH(b, c, d), 0xd4ef3085, bytes_to_int32(databytes, ptr + 12), 16)
updateRun(fH(b, c, d), 0x4881d05, bytes_to_int32(databytes, ptr + 24), 23)
updateRun(fH(b, c, d), 0xd9d4d039, bytes_to_int32(databytes, ptr + 36), 4)
updateRun(fH(b, c, d), 0xe6db99e5, bytes_to_int32(databytes, ptr + 48), 11)
updateRun(fH(b, c, d), 0x1fa27cf8, bytes_to_int32(databytes, ptr + 60), 16)
updateRun(fH(b, c, d), 0xc4ac5665, bytes_to_int32(databytes, ptr + 8), 23)
updateRun(fI(b, c, d), 0xf4292244, bytes_to_int32(databytes, ptr), 6)
updateRun(fI(b, c, d), 0x432aff97, bytes_to_int32(databytes, ptr + 28), 10)
updateRun(fI(b, c, d), 0xab9423a7, bytes_to_int32(databytes, ptr + 56), 15)
updateRun(fI(b, c, d), 0xfc93a039, bytes_to_int32(databytes, ptr + 20), 21)
updateRun(fI(b, c, d), 0x655b59c3, bytes_to_int32(databytes, ptr + 48), 6)
updateRun(fI(b, c, d), 0x8f0ccc92, bytes_to_int32(databytes, ptr + 12), 10)
updateRun(fI(b, c, d), 0xffeff47d, bytes_to_int32(databytes, ptr + 40), 15)
updateRun(fI(b, c, d), 0x85845dd1, bytes_to_int32(databytes, ptr + 4), 21)
updateRun(fI(b, c, d), 0x6fa87e4f, bytes_to_int32(databytes, ptr + 32), 6)
updateRun(fI(b, c, d), 0xfe2ce6e0, bytes_to_int32(databytes, ptr + 60), 10)
updateRun(fI(b, c, d), 0xa3014314, bytes_to_int32(databytes, ptr + 24), 15)
updateRun(fI(b, c, d), 0x4e0811a1, bytes_to_int32(databytes, ptr + 52), 21)
updateRun(fI(b, c, d), 0xf7537e82, bytes_to_int32(databytes, ptr + 16), 6)
updateRun(fI(b, c, d), 0xbd3af235, bytes_to_int32(databytes, ptr + 44), 10)
updateRun(fI(b, c, d), 0x2ad7d2bb, bytes_to_int32(databytes, ptr + 8), 15)
updateRun(fI(b, c, d), 0xeb86d391, bytes_to_int32(databytes, ptr + 36), 21)
// update buffers
h0 = _add(h0, a)
h1 = _add(h1, b)
h2 = _add(h2, c)
h3 = _add(h3, d)
}
// Done! Convert buffers to 128 bit (LE)
return int128le_to_hex(h3, h2, h1, h0).toUpperCase()
}
};
return leMd5;
})();
var leFileOperation = (function () {
function leFileOperation() {
}
//存一下init传过来的字段 /开始
//上传列表中现有的文件列表
leFileOperation.videoUpload_fileList = [];
leFileOperation.addFileCallback = function () { };
//存一下init传过来的字段 /结束
//文件选择对象
leFileOperation.fileUploadList = {};
//允许上传的文件类型
leFileOperation.fileTypes = "wmv|wm|avi|dat|asf|rm|rmvb|ram|mpg|mpeg|mp4|mov|m4v|mkv|flv|vob|qt|divx|cpk|fli|flc|mod|dvix|dv|f4v|ts";
//获取文件的类型
leFileOperation.getFileType = function (file) {
return file.name.split(".").pop();
};
//计算问价大小
leFileOperation.calculateFileSize = function (file) {
var fSize = file.size / 1024;
fSize = fSize > 1024 ? (((fSize / 1024 * 10) >> 0) / 10).toFixed(1) + "M" : (((fSize * 10) >> 0) / 10).toFixed(1) + "K";
return fSize;
};
//获取文件的key 加MD5
leFileOperation.getFileKey = function (file) {
var key = leMd5.getMD5([leFileOperation.getFileType(file), file.size, file.lastModifiedDate || file.name].join('_')).toLowerCase();
return key;
};
//上传列表中现有的文件列表有没有此文件
leFileOperation.checkParentFileList = function (file) {
if (leFileOperation.videoUpload_fileList) {
for (var f = 0; f < leFileOperation.videoUpload_fileList.length; f++) {
var thisTempMd5 = leFileOperation.getFileKey(file);
if (leFileOperation.videoUpload_fileList[f].md5 == thisTempMd5) {
return true;
}
}
}
return false;
};
//检查选择的文件名称是否合法
leFileOperation.checkFileName = function (file) {
var reg = /^\S{1,60}$/;
var returnStr = file.name;
var tempArr = returnStr.split('.');
if (tempArr.length > 1) {
tempArr.length--;
}
returnStr = tempArr.join('.');
if (returnStr.length > 60 || returnStr.trim().length == 0) {
return true;
} else {
return false;
}
//return !reg.test(returnStr);
};
//选中文件的时候
leFileOperation.inputFileChange = function (e, element, callback) {
dropFunction.removeDrop();
dropFunction.addDrop();
var files = e.target.files || e.dataTransfer.files;
//文件添加信息对象
var fileAddInfoObj = {
errorFiles: [],
successFiles: []
};
for (var i = 0; i < files.length; i++) {
var file = files[i];
var fType = leFileOperation.getFileType(file);
if (file.size <= 0) {
var tempErrorFile = new Object();
tempErrorFile.file = file;
tempErrorFile.errorMsg = "大小为0的文件";
tempErrorFile.code = "101";
fileAddInfoObj.errorFiles.push(tempErrorFile);
} else if (leFileOperation.checkParentFileList(file)) {
var tempErrorFile = new Object();
tempErrorFile.file = file;
tempErrorFile.errorMsg = "文件已在上传列表当中";
tempErrorFile.code = "103";
fileAddInfoObj.errorFiles.push(tempErrorFile);
} else if (!eval("/" + leFileOperation.fileTypes + "$/i").test(fType)) {
var tempErrorFile = new Object();
tempErrorFile.file = file;
tempErrorFile.errorMsg = "不支持的视频格式";
tempErrorFile.code = "102";
fileAddInfoObj.errorFiles.push(tempErrorFile);
} else if (leFileOperation.fileUploadList[leFileOperation.getFileKey(file)]) {
var tempErrorFile = new Object();
tempErrorFile.file = file;
tempErrorFile.errorMsg = "选择了相同的文件";
tempErrorFile.code = "104";
fileAddInfoObj.errorFiles.push(tempErrorFile);
} else if (leFileOperation.checkFileName(file)) {
var tempErrorFile = new Object();
tempErrorFile.file = file;
tempErrorFile.errorMsg = "视频名称不合法";
tempErrorFile.code = "105";
fileAddInfoObj.errorFiles.push(tempErrorFile);
} else {
var tempSuccessFile = new Object();
tempSuccessFile.file = file;
tempSuccessFile.successMsg = "成功";
tempSuccessFile.code = "0";
tempSuccessFile.md5 = leFileOperation.getFileKey(file);
fileAddInfoObj.successFiles.push(tempSuccessFile);
//成功之后直接加上文件
leFileOperation.fileUploadList[tempSuccessFile.md5] = {
md5: tempSuccessFile.md5,
file: file,
parameter: ""
};
if (callback) {
leFileOperation.fileUploadList[tempSuccessFile.md5].parameter = callback({
file: file,
element: element,
md5: tempSuccessFile.md5
}) || "";
}
}
}
//添加文件的回调函数
leFileOperation.addFileCallback(fileAddInfoObj);
};
var dropFunction = (function () {
function dropFunction() {
}
dropFunction.dragover = function (e) {
$("#upload-table-box").css({
background: "#f9fafc",
});
e.stopPropagation();
e.preventDefault();
};
dropFunction.dragleave = function (e) {
$("#upload-table-box").css({
background: "#fff",
});
e.stopPropagation();
e.preventDefault();
};
dropFunction.drop = function (e) {
$("#upload-table-box").css({
background: "#fff",
});
leFileOperation.inputFileChange(e);
e.stopPropagation();
e.preventDefault();
};
dropFunction.addDrop = function () {
try {
document.getElementById("upload-table-box").addEventListener("dragover", dropFunction.dragover, !1);
document.getElementById("upload-table-box").addEventListener("dragleave", dropFunction.dragleave, !1);
document.getElementById("upload-table-box").addEventListener("drop", dropFunction.drop, !1);
} catch (e) { }
};
dropFunction.removeDrop = function () {
try {
document.getElementById("upload-table-box").removeEventListener("dragover", dropFunction.dragover, !1);
document.getElementById("upload-table-box").removeEventListener("dragleave", dropFunction.dragleave, !1);
document.getElementById("upload-table-box").removeEventListener("drop", dropFunction.drop, !1);
} catch (e) { }
};
dropFunction.addDrop();
return dropFunction;
})();
//添加文件//多个文件时调用
leFileOperation.addFile = function (e, callback) {
dropFunction.removeDrop();
$("#fileUploadId_Hsc").remove();
var inpfile = document.getElementById("fileUploadId_Hsc");
if (inpfile) {
inpfile.click && e.target != inpfile && inpfile.click();
} else {
inpfile = document.createElement("input");
$("body").append(inpfile);
inpfile.setAttribute("id", "fileUploadId_Hsc");
inpfile.setAttribute("type", "file");
var tempFileTypeArr = leFileOperation.fileTypes.split("|");
for (var item = 0; item < tempFileTypeArr.length; item++) {
tempFileTypeArr[item] = "." + tempFileTypeArr[item];
}
var acceptFileType = tempFileTypeArr.join(",");
inpfile.setAttribute("accept", acceptFileType);
inpfile.setAttribute('autocomplete', "off");
inpfile.setAttribute('multiple', "true");
inpfile.style.display = "none";
inpfile.addEventListener('change', function (fileObj) {
leFileOperation.inputFileChange(fileObj, e, callback);
}, !1);
inpfile.click && e.target != inpfile && inpfile.click();
dropFunction.addDrop();
}
};
//添加文件//单个文件时调用
leFileOperation.addSingleFile = function (e, callback) {
$("#fileUploadId_Hsc").remove();
var inpfile = document.getElementById("fileUploadId_Hsc");
if (inpfile) {
inpfile.click && e.target != inpfile && inpfile.click();
} else {
inpfile = document.createElement("input");
$("body").append(inpfile);
inpfile.setAttribute("id", "fileUploadId_Hsc");
inpfile.setAttribute("type", "file");
var tempFileTypeArr = leFileOperation.fileTypes.split("|");
for (var item = 0; item < tempFileTypeArr.length; item++) {
tempFileTypeArr[item] = "." + tempFileTypeArr[item];
}
var acceptFileType = tempFileTypeArr.join(",");
inpfile.setAttribute("accept", acceptFileType);
inpfile.style.display = "none";
inpfile.addEventListener('change', function (fileObj) {
leFileOperation.inputFileChange(fileObj, e, callback)
}, !1);
inpfile.click && e.target != inpfile && inpfile.click();
}
};
leFileOperation.initOption = {};
//使用前先调用初始化方法
leFileOperation.init = function (initOption) {
leFileOperation.initOption = initOption;
leFileOperation.fileTypes = initOption.fileTypes || leFileOperation.fileTypes;
leFileOperation.videoUpload_fileList = initOption.videoUpload_fileList;
leFileOperation.addFileCallback = initOption.addFileCallback;
for (var i = 0 ; i < initOption.multipleDomElement.length; i++) {
var element = initOption.multipleDomElement[i];
$(element).on("click", function (e) {
leFileOperation.addFile(e, initOption.multipleCallback);
});
}
};
return leFileOperation;
})();
//使用demo
/*
leFileOperation.init({
multipleDomElement: vaasFileUpload.initOptionObject.multipleDomElement,//一次允许选择多个文件,需要传递页面元素对象
multipleCallback:function(data){},//如果需要额外加什么参数在这里设置如果不需要则 return "";
videoUpload_fileList: vaasFileUpload.fileUploadList, //上传列表中现有的文件列表//临时需要传递null
addFileCallback: vaasFileUpload.addFileCallback, //本次选择文件的回调函数
fileTypes:""
});
*/
// 全部上传的时候需要对 leFileOperation.fileUploadList[md5].parameter 进行参数传递 如:parameter = "&hsc=1&album=123";
var leFileUploadCommon = (function () {
function leFileUploadCommon() {
}
//给数组添加remove函数
Array.prototype.remove = function (index) {
if (isNaN(index) || index > this.length) { return false; }
this.splice(index, 1);
};
//cookie
leFileUploadCommon.operationCookie = (function () {
function operationCookie() {
}
operationCookie.setCookie = function (name, value, iDay) {
operationCookie.removeCookie(name);
var oDate = new Date();
value = encodeURIComponent(value);
oDate.setDate(oDate.getDate() + iDay);
document.cookie = name + '=' + value + ';expires=' + oDate;
if (arguments[3] && typeof arguments[3] == 'function') {
arguments[3]();
}
return operationCookie;
};
operationCookie.getCookie = function (name) {
var arr = document.cookie.split('; ');
for (var i = 0; i < arr.length; i++) {
var arr2 = arr[i].split('=');
if (arr2[0] == name) {
return decodeURI(arr2[1]);
}
}
return '';
};
operationCookie.removeCookie = function (name) {
var value = "";
var iDay = -1;
var oDate = new Date();
value = encodeURIComponent(value);
oDate.setDate(oDate.getDate() + iDay);
document.cookie = name + '=' + value + ';expires=' + oDate;
if (arguments[3] && typeof arguments[3] == 'function') {
arguments[3]();
}
return operationCookie;
};
return operationCookie;
})();
//跨域post带cookie请求
leFileUploadCommon.commonAjax = function (url, success, error, _ajaxOption) {
var IAPIDocument = {
apiUrl:url
};
leCommonAjax.ajax(IAPIDocument, success, error, _ajaxOption);
};
//leFileUploadCommon.commonAjax = function (url, success, error, _ajaxOption) {
// var ajaxOption = {
// url: url,
// type: "post",
// xhrFields: {
// withCredentials: true
// },
// crossDomain: true,
// dataType: "json",
// success: function (data) {
// if (success) {
// success(data);
// }
// },
// error: function (data) {
// if (error) {
// error(data);
// }
// }
// };
// if (_ajaxOption) {
// for (var item in _ajaxOption) {
// ajaxOption[item] = _ajaxOption[item];
// }
// }
// $.ajax(ajaxOption);
//};
return leFileUploadCommon;
})();
var leVideoUpload = (function () {
//全部是必填,最后一个格式是:&sourceId=1&fileId=1 或者为空字符串
function leVideoUpload(_uploadFile, _md5, _fileName, _fileSize, _parameter) {
this.uploadFile = _uploadFile;
this.md5 = _md5;
this.fileName = _fileName;
this.fileSize = _fileSize;
this.parameter = _parameter || "";
}
leVideoUpload.prototype.cellSize = 10485760;
leVideoUpload.prototype.sliceFile = function (file, start) {
var _this = this;
var blob;
start = start || 0;
var range = start + _this.cellSize;
if (start != -1) {
if (file.slice) {
blob = file.slice(start, range);
}
else if (file.webkitSlice) {
blob = file.webkitSlice(start, range);
}
else if (file.mozSlice) {
blob = file.mozSlice(start, range);
}
else {
blob = file;
}
}
else {
return file;
}
return blob;
};
leVideoUpload.prototype.xhr = null;
leVideoUpload.prototype.cellStack = {};
leVideoUpload.prototype.uploadUrl = "";
leVideoUpload.prototype.streamUpload = function (loadedsize) {
loadedsize = loadedsize * 1;
var _this = this;
_this.cellStack.transferedsize = loadedsize;
_this.xhr = new XMLHttpRequest();
_this.xhr.upload.addEventListener("progress", function (e) { _this.progress(e); }, false);
_this.xhr.addEventListener("loadstart", function (e) { _this.loadstart(e); }, false);
_this.xhr.addEventListener("load", function (e) { _this.load(e); }, false);
_this.xhr.addEventListener("error", function (e) { _this.error(e); }, false);
_this.xhr.addEventListener("abort", function (e) { _this.abort(e); }, false);
var cellFile = _this.sliceFile(_this.uploadFile, loadedsize);
var content = loadedsize == -1 ? "bytes *" : "bytes " + (loadedsize + 1) + "-" + (loadedsize + cellFile.size * 1) + "/" + _this.uploadFile.size;
_this.xhr.open("POST", _this.uploadUrl, true);
_this.xhr.setRequestHeader("X_FILENAME", encodeURIComponent(_this.uploadFile.name));
_this.xhr.setRequestHeader("Content-Range", content);
_this.xhr.send(cellFile);
};
leVideoUpload.prototype.xhrAbort = function () {
var _this = this;
_this.xhr && _this.xhr.abort();
};
leVideoUpload.prototype.fileId = "";//本次上传任务的唯一标识
leVideoUpload.prototype.uploadSize = 100;//记录是否为刚开始上传
leVideoUpload.prototype.tryUpload = function () {
var _this = this;
var file = _this.uploadFile;
var initUrl = leVideoUpload.uploadOption.uploadInitUrl + "uploadType=1&videoName=" + encodeURIComponent(_this.fileName) + "&fileSize=" + _this.fileSize + _this.parameter;
//initUrl += "&uc1=0&uc2=2&v720p=false&v1080p=false&panoramic=0";
if (leFileUploadCommon.operationCookie.getCookie(_this.md5) && leFileUploadCommon.operationCookie.getCookie(_this.md5) != "undefined") {
initUrl += "&token=" + leFileUploadCommon.operationCookie.getCookie(_this.md5);
//initUrl += "&fileId=" + leFileUploadCommon.operationCookie.getCookie(_this.md5 + "fileId")
}
leFileUploadCommon.commonAjax(initUrl, function (data) {
if (data.code * 1 == 200) {
if (data.data && data.data.uploadUrl) {
_this.fileId = data.data.fileId || "";
_this.uploadUrl = data.data.uploadUrl.substr(0, data.data.uploadUrl.length - 10);
_this.uploadSize = data.data.uploadSize || 0;
var nextBlob = data.data.uploadSize || 0;
if (data.data.uploadSize == _this.fileSize) {
leVideoUpload.uploadOption.uploadFinish({ md5: _this.md5, code: 0, msg: "上传完成" });
leFileUploadCommon.operationCookie.removeCookie(_this.md5);
leFileUploadCommon.operationCookie.removeCookie(_this.md5 + "fileId");
} else {
_this.streamUpload(nextBlob);
}
} else {
leVideoUpload.uploadOption.uploadError({ md5: _this.md5, code: 506, msg: "服务端返回参数异常" });
}
} else {
leVideoUpload.uploadOption.uploadError({ md5: _this.md5, code: data.code, msg: (data.message || "失败请重试") });
}
}, function (data) {
leVideoUpload.uploadOption.uploadError({ md5: _this.md5, code: 507, msg: "服务端异常,请重试" });
}, { type: "post" });
};
//以下是回调函数相关
leVideoUpload.prototype.loadstart = function (e) {
var _this = this;
var currStack = _this.cellStack;
currStack.inittime = (new Date()).getTime(); //标记开始 即时的 时间
var transferedsize = _this.cellStack ? _this.cellStack.transferedsize : 0;
if (transferedsize == 0 || (_this.uploadSize && _this.uploadSize == transferedsize)) {
delete _this.uploadSize;
leVideoUpload.uploadOption.uploadStart({ md5: _this.md5, code: 0, msg: "开始上传" });
}
currStack.transferedsize = transferedsize;
};
leVideoUpload.prototype.load = function (e) {
var _this = this;
var res = eval("(" + e.target.responseText + ")");
var file = _this.uploadFile;
if (!!res.transferedsize) {
_this.tryNumber = 0;
//记录断点续传token
var tokenUrl = _this.uploadUrl.split('token').pop();
var videoToken = tokenUrl.substr(1, tokenUrl.length - 1);
leFileUploadCommon.operationCookie.setCookie(_this.md5, videoToken, 2);
leFileUploadCommon.operationCookie.setCookie(_this.md5 + "fileId", _this.fileId, 2);
var transferedsize = parseInt(res.transferedsize);
_this.cellStack.transferedsize = transferedsize;
transferedsize < file.size && _this.streamUpload(transferedsize);
}
else {
if (!res.totalsize && res.status != '200') {
_this.xhrAbort();
if (_this.tryNumber == 3) {
leVideoUpload.uploadOption.uploadError({ md5: _this.md5, code: res.status, msg: "存储服务器异常:" + res.msg });
leFileUploadCommon.operationCookie.removeCookie(_this.md5);
leFileUploadCommon.operationCookie.removeCookie(_this.md5 + "fileId");
} else {
_this.tryNumber++;
setTimeout(function () {
_this.streamUpload(_this.cellStack.transferedsize);
}, 500 * _this.tryNumber + 1);
}
}
}
_this.cellStack.starttime = (new Date()).getTime();
if (res.transferedsize && res.transferedsize == res.totalsize) {
//文件上传完成
leVideoUpload.uploadOption.uploadFinish({ md5: _this.md5, code: 0, msg: "上传完成" });
leFileUploadCommon.operationCookie.removeCookie(_this.md5);
leFileUploadCommon.operationCookie.removeCookie(_this.md5 + "fileId");
_this.xhrAbort();
}
};
leVideoUpload.prototype.progress = function (e) {
var _this = this;
var cellstack = _this.cellStack, filetransfered = parseInt(cellstack.transferedsize);
var pc = parseInt((filetransfered + e.loaded) / _this.uploadFile.size * 100), delttime = ((new Date()).getTime() - (cellstack.starttime || cellstack.inittime)) / 1000, rate = e.loaded / delttime;
rate = rate / 1024;
rate = rate > 1024 ? (((rate / 1024 * 10) >> 0) / 10).toFixed(1) + "M/s" : (((rate * 10) >> 0) / 10).toFixed(1) + "K/s";
//在上传过程中如果用户在电脑上删除了视频,会触发视频丢失错误
if (isNaN(pc)) {
leVideoUpload.uploadOption.uploadError({ md5: _this.md5, code: 203, msg: "视频丢失" });
_this.xhrAbort();
}
else {
if (pc == 100) {
pc = 99;
}
//记录断点续传token
//var tokenUrl = _this.uploadUrl.split('token').pop();
//var videoToken = tokenUrl.substr(1, tokenUrl.length - 1);
//if (leFileUploadCommon.operationCookie.getCookie(_this.md5) != videoToken) {
// leFileUploadCommon.operationCookie.setCookie(_this.md5, videoToken, 2);
// leFileUploadCommon.operationCookie.setCookie(_this.md5 + "fileId", _this.fileId, 2);
//}
leVideoUpload.uploadOption.uploadProgress({ md5: _this.md5, progress: pc + "%", speed: rate });
}
};
leVideoUpload.prototype.tryNumber = 0;
leVideoUpload.prototype.error = function (e) {
var _this = this;
_this.xhrAbort();
if (_this.tryNumber == 3) {
leVideoUpload.uploadOption.uploadError({ md5: _this.md5, code: 404, msg: "网络异常" });
} else {
_this.tryNumber++;
setTimeout(function () {
_this.streamUpload(_this.cellStack.transferedsize);
}, 500 * _this.tryNumber + 1);
}
};
leVideoUpload.prototype.abort = function (e) {
var _this = this;
leVideoUpload.uploadOption.uploadAbort({ md5: _this.md5, code: 439, msg: "上传终止" });
};
//上传的回调
leVideoUpload.uploadOption = {};
//使用前先调用初始化方法
leVideoUpload.init = function (initOption) {
leVideoUpload.uploadOption = initOption;
};
return leVideoUpload;
})();
//使用demo
/*
leVideoUpload.init({
uploadInitUrl: "http://realapi.mms.lecloud.com/v1/inner/video/create.do", //上传初始化地址
uploadStart: function (data) {//上传开始回调
},
uploadProgress: function (data) { //进度回调
},
uploadFinish: function (data) { //上传完成回调
},
uploadError: function (data) { //上传错误回调
},
uploadAbort:function(data){ //上传中止
}
});
*/
var vaasFileUpload = (function () {
function vaasFileUpload() {
}
window.onbeforeunload = function (event) {
if (vaasFileUpload.fileUploadList.length > 0) {
return vaasFileUpload.LCT("有未上传完成的文件!离开此页面数据将会丢失!");
}
};
//获取文件名称
vaasFileUpload.getFileName = function (name) {
return name;
};
//计算文件大小
vaasFileUpload.calculateFileSize = function (file) {
var fSize = file.size / 1024;
fSize = fSize > 1024 ? (((fSize / 1024 * 10) >> 0) / 10).toFixed(1) + "M" : (((fSize * 10) >> 0) / 10).toFixed(1) + "K";
return fSize;
};
//通用弹层
vaasFileUpload.modalAlert = function (msg) {
$("#leFileUpload_msg").html(msg);
$("#leFileUpload_Modal").modal("show");
};
//文件上传列表
vaasFileUpload.fileUploadList = [];
//获取文件上传列表下标
vaasFileUpload.getFileUploadListIndex = function (md5) {
for (var i = 0; i < vaasFileUpload.fileUploadList.length; i++) {
if (vaasFileUpload.fileUploadList[i].md5 == md5) {
return i;
}
}
return "nothing";
};
//查看是否可以上传
vaasFileUpload.lookIsNotUpload = function () {
var temp = 0;
$("li[uploading='uploading']").each(function () {
temp++;
});
if (temp > 0) {
return false;
} else {
return true;
}
};
//初始化传递过来的对象
vaasFileUpload.initOptionObject = {};
//当次选中文件的对象
vaasFileUpload.addFileCallback = function (data) {
var modalAlert = false;
for (var item in vaasFileUpload.initOptionObject.leFileOperation.fileUploadList) {
var tempItemObj = vaasFileUpload.initOptionObject.leFileOperation.fileUploadList[item]
var isnotPush = true;
for (var y = 0; y < vaasFileUpload.fileUploadList.length; y++) {
if (tempItemObj.md5 == vaasFileUpload.fileUploadList[y].md5) {
isnotPush = false;
break;
}
}
if (isnotPush) {
var md5IsNotLength = $("#uploader_upload_list").find("li[id='" + tempItemObj.md5 + "']").length;
if (md5IsNotLength > 0) {
$("#" + tempItemObj.md5).find("small[uploadPercent='uploadPercent']").html(vaasFileUpload.LCT("已经上传过的视频"));
$("#" + tempItemObj.md5).find("small[uploadPercent='uploadPercent']").css({
color: "red"
});
break;
}
var fileName = vaasFileUpload.getFileName(tempItemObj.fileName || tempItemObj.file.name);
var fileSize = tempItemObj.file.size;
vaasFileUpload.initOptionObject.leFileOperation.fileUploadList[item].fileUpload = new leVideoUpload(tempItemObj.file, tempItemObj.md5, fileName, fileSize, tempItemObj.parameter);
vaasFileUpload.fileUploadList.push(vaasFileUpload.initOptionObject.leFileOperation.fileUploadList[item]);
var file = tempItemObj.file;
var fileName = vaasFileUpload.getFileName(tempItemObj.fileName || file.name);
var fileSize = vaasFileUpload.calculateFileSize(file);
vaasFileUpload.addFileItemElement(tempItemObj.md5, fileName, fileSize);
modalAlert = true;
}
}
if (modalAlert) {
$("#modal-upload").removeClass("hide");
$(".modal-upload-body").slideDown();
$("#uploadListModalMin").removeClass("modal-min").addClass("modal-max");//弹出框
}
var firstFileMd5 = 0;
for (var item in vaasFileUpload.initOptionObject.leFileOperation.fileUploadList) {
firstFileMd5 = vaasFileUpload.initOptionObject.leFileOperation.fileUploadList[item].md5;
break;
}
vaasFileUpload.initOptionObject.leFileOperation.fileUploadList = {};
if (vaasFileUpload.lookIsNotUpload() && vaasFileUpload.fileUploadList.length > 0) {
var index = vaasFileUpload.getFileUploadListIndex(firstFileMd5);
if (index != "nothing") {
var domMd5Id = vaasFileUpload.fileUploadList[index].fileUpload.md5;
if ($("#" + domMd5Id).find("input[stopItem='stopItem']").hasClass("active")) {
$("#" + domMd5Id).attr("uploading", "uploading");
vaasFileUpload.fileUploadList[index].fileUpload.tryUpload();
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
}
}
};
//构建右下角弹层
vaasFileUpload.structurePageElement = function () {
var element = '<div class="modal-content modal-upload-zj hide" id="modal-upload">' +
'<div class="modal-header modal-header-primary clearfix">' +
'<div class="modal-control pull-right modal-max" id="uploadListModalMin">' +
'<span class="modal-icon"></span>' +
'</div>' +
'<h4 class="modal-title-vod pull-left">' + vaasFileUpload.LCT("视频上传列表") + '</h4>' +
'</div>' +
'<div class="modal-upload-body">' +
'<div class="modal-upload-header clearfix">' +
'<div class="video-name-vod pull-left">' + vaasFileUpload.LCT("视频名称") + '</div>' +
'<div class="video-size pull-left">' + vaasFileUpload.LCT("视频大小") + '</div>' +
'<div class="video-status pull-left video-header-height">' + vaasFileUpload.LCT("上传状态") + '</div>' +
'<div class="video-operate pull-left">' + vaasFileUpload.LCT("操作") + '</div>' +
'</div>' +
'<div class="uploader-list" id="uploader-list">' +
'<ul id="uploader_upload_list">' +
'</ul>' +
'</div>' +
'</div>' +
'</div>';
$("body").append(element);
//展开/关闭
$("body").on("click", ".modal-control", function (e) {
if ($(this).hasClass("modal-max")) {
$(".modal-upload-body").slideUp();
$(this).removeClass("modal-max").addClass("modal-min");
} else {
$(".modal-upload-body").slideDown();
$(this).removeClass("modal-min").addClass("modal-max");
}
});
//构建弹层
var modalDomStr = '<div id="leFileUpload_Modal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">' +
'<div class="modal-dialog modal-sm">' +
'<div class="modal-content" id="leFileUpload_msg">' +
'</div>' +
'</div>' +
'</div>';
$("body").append(modalDomStr);
};
//添加一条上传显示行
vaasFileUpload.addFileItemElement = function (md5, fileName, fileSize) {
var src = '<li id="' + md5 + '" uploading="">' +
'<div class="info clearfix">' +
'<div class="video-name-vod pull-left" title="' + fileName + '">' + fileName + '</div>' +
'<div class="video-size pull-left">' + fileSize + '</div>' +
'<div class="video-status pull-left">' +
'<small class="ml-10" uploadPercent="uploadPercent">0%</small>' +
'<div class="progress progress-sm">' +
'<div uploadProgressbar="uploadProgressbar" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>' +
'</div>' +
'<small class="text-qianlan" uploadSpeed="uploadSpeed">' + vaasFileUpload.LCT("等待上传") + '</small>' +
'</div>' +
'<div class="video-operate pull-left mt-20">' +
'<input class="icon-video-play active" type="button" stopItem="stopItem" disabled="disabled" >' +
'<input class="icon-video-del ml-15" type="button" deleteItem="deleteItem">' +
'</div>' +
'</div>' +
'</li>';
$("#uploader_upload_list").append(src);
};
//暂停标识
vaasFileUpload.stopMd5 = "";
//绑定页面元素的事件
vaasFileUpload.bindWebPageHandle = function () {
vaasFileUpload.structurePageElement();
$("#uploader_upload_list").on("click", "input[stopItem='stopItem']", function () {
$(this).prop("disabled", "disabled");
$("input[stopItem='stopItem']").prop("disabled", "disabled");
var md5 = $($(this).parents("li")).attr("id");
var index = vaasFileUpload.getFileUploadListIndex(md5);
if ($(this).hasClass("active")) {
$(this).removeClass("active");
vaasFileUpload.stopMd5 = md5;
$("#" + md5).find("div[uploadProgressbar='uploadProgressbar']").css({ "backgroundColor": "#337ab7" });//失败是 #fa5258
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("class", "text-qianlan").html("0KB/S");
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("title", "0KB/S");
vaasFileUpload.stopMd5 = md5;
vaasFileUpload.fileUploadList[index].fileUpload.xhrAbort();
vaasFileUpload.stopMd5 = md5;
if (vaasFileUpload.fileUploadList.length > (index + 1)) {
if (vaasFileUpload.lookIsNotUpload()) {
var domMd5Id = vaasFileUpload.fileUploadList[index + 1].fileUpload.md5;
if ($("#" + domMd5Id).find("input[stopItem='stopItem']").hasClass("active")) {
$("#" + domMd5Id).attr("uploading", "uploading");
vaasFileUpload.fileUploadList[index + 1].fileUpload.tryUpload();
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
}
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
} else {
$(this).addClass("active");
//$("input[stopItem='stopItem']").addClass("active");
if (vaasFileUpload.lookIsNotUpload()) {
var domMd5Id = vaasFileUpload.fileUploadList[index].fileUpload.md5;
if ($("#" + domMd5Id).find("input[stopItem='stopItem']").hasClass("active")) {
$("#" + domMd5Id).attr("uploading", "uploading");
vaasFileUpload.fileUploadList[index].fileUpload.tryUpload();
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
}
}
});
$("#uploader_upload_list").on("click", "input[deleteItem='deleteItem']", function () {
var md5 = $($(this).parents("li")).attr("id");
vaasFileUpload.uploadDelete(md5);
});
};
//上传错误的回调
vaasFileUpload.uploadError = function (md5, msg) {
var index = vaasFileUpload.getFileUploadListIndex(md5);
$("#" + md5).find("div[uploadProgressbar='uploadProgressbar']").css({ "backgroundColor": "#fa5258" });//正常是 #337ab7
$("#" + md5).find("input[stopItem='stopItem']").removeClass("active");
$("#" + md5).find("input[stopItem='stopItem']").prop("disabled", "disabled");
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("class", "text-danger").html(msg);
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("title", msg);
if (vaasFileUpload.fileUploadList.length > (index + 1)) {
if (vaasFileUpload.lookIsNotUpload()) {
var domMd5Id = vaasFileUpload.fileUploadList[index + 1].fileUpload.md5;
if ($("#" + domMd5Id).find("input[stopItem='stopItem']").hasClass("active")) {
$("#" + domMd5Id).attr("uploading", "uploading");
vaasFileUpload.fileUploadList[index + 1].fileUpload.tryUpload();
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
}
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
};
//进度的回调
vaasFileUpload.uploadProgress = function (md5, uploadPercent, uploadSpeed) {
$("#" + md5).find("div[uploadProgressbar='uploadProgressbar']").css({ "backgroundColor": "#337ab7", "width": uploadPercent });//失败是 #fa5258
$("#" + md5).find("small[uploadPercent='uploadPercent']").html(uploadPercent);
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("class", "text-qianlan").html(uploadSpeed);
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("title", uploadSpeed);
if (vaasFileUpload.stopMd5) {
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").html("0KB/S");
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("title", "0KB/S");
vaasFileUpload.stopMd5 = "";
}
};
//上传完成回调
vaasFileUpload.uploadFinish = function (md5) {
$("#" + md5).find("div[uploadProgressbar='uploadProgressbar']").css({ "backgroundColor": "#337ab7", "width": "100%" });//失败是 #fa5258
$("#" + md5).find("small[uploadPercent='uploadPercent']").html("100%");
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("class", "text-success").html(vaasFileUpload.LCT("已上传"));
$("#" + md5).find("small[uploadSpeed='uploadSpeed']").attr("title", vaasFileUpload.LCT("已上传"));
$("#" + md5).find("input[stopItem='stopItem']").hide();
var index = vaasFileUpload.getFileUploadListIndex(md5);
vaasFileUpload.fileUploadList[index].fileUpload.xhrAbort();
vaasFileUpload.fileUploadList.remove(index);
if (vaasFileUpload.fileUploadList.length != index && vaasFileUpload.fileUploadList.length > index) {
if (vaasFileUpload.lookIsNotUpload()) {
var domMd5Id = vaasFileUpload.fileUploadList[index].fileUpload.md5;
if ($("#" + domMd5Id).find("input[stopItem='stopItem']").hasClass("active")) {
$("#" + domMd5Id).attr("uploading", "uploading");
vaasFileUpload.fileUploadList[index].fileUpload.tryUpload();
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
}
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
$("input[stopItem='stopItem']").removeClass("active");
}
};
//上传删除
vaasFileUpload.uploadDelete = function (md5) {
try { //单独为恶心的媒资添加处理
if (vaasFileUpload.initOptionObject.uploadStatusCallback) {
var index = vaasFileUpload.getFileUploadListIndex(md5);
var tempFileId = vaasFileUpload.fileUploadList[index].fileUpload.fileId;
vaasFileUpload.initOptionObject.uploadStatusCallback({ code: 438, md5: md5, msg: "删除", fileId: tempFileId });
}
} catch (e) {
}
$("#" + md5).remove();
//隐藏弹出层
if ($("#uploader_upload_list").html().trim() == "") {
$("#modal-upload").addClass("hide");
}
//此处中断上传
if (vaasFileUpload.fileUploadList.length > 0) {
var index = vaasFileUpload.getFileUploadListIndex(md5);
if (index != "nothing") {
vaasFileUpload.fileUploadList[index].fileUpload.xhrAbort();
vaasFileUpload.fileUploadList.remove(index);
if (vaasFileUpload.lookIsNotUpload()) {
if (vaasFileUpload.fileUploadList.length != index && vaasFileUpload.fileUploadList.length > index) {
var domMd5Id = vaasFileUpload.fileUploadList[index].fileUpload.md5;
if ($("#" + domMd5Id).find("input[stopItem='stopItem']").hasClass("active")) {
$("#" + domMd5Id).attr("uploading", "uploading");
vaasFileUpload.fileUploadList[index].fileUpload.tryUpload();
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
} else {
//if (vaasFileUpload.fileUploadList.length > 0) {
// var domMd5Id = vaasFileUpload.fileUploadList[0].fileUpload.md5;
// $("#" + domMd5Id).attr("uploading", "uploading");
// vaasFileUpload.fileUploadList[0].fileUpload.tryUpload();
//} else {
// $("input[stopItem='stopItem']").removeAttr("disabled");
//}
$("input[stopItem='stopItem']").removeAttr("disabled");
}
}
} else {
if (vaasFileUpload.lookIsNotUpload()) {
if (index != "nothing") {
if (vaasFileUpload.fileUploadList.length != index && vaasFileUpload.fileUploadList.length > index) {
var domMd5Id = vaasFileUpload.fileUploadList[index].fileUpload.md5;
if ($("#" + domMd5Id).find("input[stopItem='stopItem']").hasClass("active")) {
$("#" + domMd5Id).attr("uploading", "uploading");
vaasFileUpload.fileUploadList[index].fileUpload.tryUpload();
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
} else {
//if (vaasFileUpload.fileUploadList.length > 0) {
// var domMd5Id = vaasFileUpload.fileUploadList[0].fileUpload.md5;
// $("#" + domMd5Id).attr("uploading", "uploading");
// vaasFileUpload.fileUploadList[0].fileUpload.tryUpload();
//} else {
// $("input[stopItem='stopItem']").removeAttr("disabled");
//}
$("input[stopItem='stopItem']").removeAttr("disabled");
}
}
}
} else {
$("input[stopItem='stopItem']").removeAttr("disabled");
}
};
//初始化上传文件的对象、
vaasFileUpload.initLeVideoUpload = function () {
leVideoUpload.init({
uploadInitUrl: vaasFileUpload.initOptionObject.uploadInitUrl, //上传初始化地址
uploadStart: function (data) {//上传开始回调
window.poling = setInterval(function () {
leFileUploadCommon.commonAjax(vaasFileUpload.initOptionObject.polingUrl + "?timeStamp=" + (new Date()).getTime(), function (data) {
}, function (data) {
}, { cache: false });
}, 60000 * 3);
try {
if (vaasFileUpload.initOptionObject.uploadStatusCallback) {
var index = vaasFileUpload.getFileUploadListIndex(data.md5);
var tempFileId = vaasFileUpload.fileUploadList[index].fileUpload.fileId;
vaasFileUpload.initOptionObject.uploadStatusCallback({ code: 200, md5: data.md5, msg: "上传开始", fileId: tempFileId });
}
} catch (e) {
}
$("#" + data.md5).find("input[stopItem='stopItem']").removeAttr("disabled");
},
uploadProgress: function (data) { //进度回调
vaasFileUpload.uploadProgress(data.md5, data.progress, data.speed);
try {
if (vaasFileUpload.initOptionObject.uploadStatusCallback) {
var index = vaasFileUpload.getFileUploadListIndex(data.md5);
var tempFileId = vaasFileUpload.fileUploadList[index].fileUpload.fileId;
vaasFileUpload.initOptionObject.uploadStatusCallback({ code: 4, md5: data.md5, msg: "上传中", fileId: tempFileId, progress: data.progress, speed: data.speed });
}
} catch (e) {
}
},
uploadFinish: function (data) { //上传完成回调
clearInterval(window.poling);
$("#" + data.md5).attr("uploading", "");
try {
if (vaasFileUpload.initOptionObject.uploadStatusCallback) {
var index = vaasFileUpload.getFileUploadListIndex(data.md5);
var tempFileId = vaasFileUpload.fileUploadList[index].fileUpload.fileId;
vaasFileUpload.initOptionObject.uploadStatusCallback({ code: 201, md5: data.md5, msg: "上传完成", fileId: tempFileId });
}
} catch (e) {
}
vaasFileUpload.uploadFinish(data.md5);
},
uploadError: function (data) { //上传错误回调
clearInterval(window.poling);
$("#" + data.md5).attr("uploading", "");
try {
if (vaasFileUpload.initOptionObject.uploadStatusCallback) {
var index = vaasFileUpload.getFileUploadListIndex(data.md5);
var tempFileId = vaasFileUpload.fileUploadList[index].fileUpload.fileId;
vaasFileUpload.initOptionObject.uploadStatusCallback({ code: 400, md5: data.md5, msg: "上传错误", fileId: tempFileId });
}
} catch (e) {
}
vaasFileUpload.uploadError(data.md5, vaasFileUpload.LCT(data.msg));
},
uploadAbort: function (data) { //中止上传
clearInterval(window.poling);
$("#" + data.md5).attr("uploading", "");
}
});
};
//初始化选择文件的对象
vaasFileUpload.initLeFileOperation = function () {
vaasFileUpload.initOptionObject.leFileOperation.init({
multipleDomElement: vaasFileUpload.initOptionObject.multipleDomElement,//一次允许选择多个文件,需要传递页面元素对象
multipleCallback: vaasFileUpload.initOptionObject.multipleCallback,//如果需要额外加什么参数在这里设置如果不需要则 return "";
videoUpload_fileList: vaasFileUpload.fileUploadList, //上传列表中现有的文件列表
addFileCallback: vaasFileUpload.addFileCallback, //本次选择文件的回调函数
fileTypes: vaasFileUpload.initOptionObject.fileTypes,//支持的文件类型
});
};
//语言
vaasFileUpload.language = "zh_cn";
vaasFileUpload.LCT = function (chinese) {
if (vaasFileUpload.language == "zh_cn") {
return chinese;
}
var local_language = {
"大小为0的文件": "The file size is 0",
"文件已在上传列表当中": "File already exists in the upload list",
"不支持的视频格式": "Unsupported video format",
"选择了相同的文件": "Have the same file(in the selected files)",
"视频名称不合法": "Video name irregularities",
"成功": "Success",
"上传完成": "completed",
"服务端返回参数异常": "Server exception",
"服务端异常": "Server exception",
"开始上传": "Start uploading",
"存储服务器异常": "Storage server exception",
"视频丢失": "Video loss",
"网络异常": "Network exception",
"上传终止": "Stop uploading",
"有未上传完成的文件!离开此页面数据将会丢失!": "There is an upload file! Leaving the page your data will be lost!",
"已经上传过的视频": "Uploaded",
"视频上传列表": "Video upload list",
"视频名称": "Name",
"视频大小": "Size",
"上传状态": "Status",
"操作": "Action",
"等待上传": "Waiting",
"已上传": "Uploaded",
"开始上传": "Start uploading",
"上传中": "Uploading"
};
if (chinese.indexOf("存储服务器异常") > 0) {
chinese = "存储服务器异常";
}
return local_language[chinese];
};
//使用前先调用初始化方法
vaasFileUpload.init = function (initOption) {
vaasFileUpload.language = initOption.language || "zh_cn";
vaasFileUpload.initOptionObject = initOption;
// vaasFileUpload.initLeFileOperation();
vaasFileUpload.initLeVideoUpload();
vaasFileUpload.bindWebPageHandle();
};
return vaasFileUpload;
})();
//demo
/*
vaasFileUpload.init({
leFileOperation: leFileOperation, // 把 leFileOperation传过来
uploadInitUrl:"http://realapi.mms.lecloud.com/v1/inner/video/create.do",//上传初始化地址
polingUrl:"http://mms.lecloud.com/videoController/refreshSessionTime.do",// 心跳地址
uploadStatusCallback:function(){}//上传状态回调
});
*/
var videoUploadUI = (function () {
function videoUploadUI() {
}
videoUploadUI.uploadConfig = (function () {
function uploadConfig() { }
uploadConfig.config = {
panoramic: false,
v720p: false,
v1080p: false
};
uploadConfig.init = function () {
videoUploadDAL.upoadConfig(function (successData) {
for (var item in uploadConfig.config) {
uploadConfig.config[item] = successData[item]
}
if (!successData.panoramic) {
$("[allQuanJing='allQuanJing']").addClass("hide");
}
if (successData.v1080p == false && successData.v720p == false) {
$("[allZhuangTai='allZhuangTai']").addClass("hide");
}
if (!successData.v720p) {
$("div[allv720p='allv720p']").addClass("hide");
}
if (!successData.v1080p) {
$("div[allv1080p='allv1080p']").addClass("hide");
}
}, function () { });
};
return uploadConfig;
})();
videoUploadUI.showOrHideSelect = function (command) {
if (command == "show") {
$("#fileSelectButton").removeClass("hide");
$("#uploadVideoBtn").removeClass("btn-ipt-blue").addClass("btn-ipt-hui");
$("#selectAllDelete").addClass("disable");
} else {
$("#fileSelectButton").addClass("hide");
$("#uploadVideoBtn").removeClass("btn-ipt-hui").addClass("btn-ipt-blue");
$("#selectAllDelete").removeClass("disable");
}
};
videoUploadUI.fileNameDeleteType = function (fileName) {
var returnStr = fileName;
var tempArr = returnStr.split('.');
if (tempArr.length > 1) {
tempArr.length--;
}
returnStr = tempArr.join('.');
return returnStr;
};
videoUploadUI.addOneData = function (data) {
var dom = '<tr md5="' + data.md5 + '">' +
'<td>' +
'<div class="pull-left"><input type="text" class="common-input-style" maxlength="60" videoName="videoName" style="width:190px;" value="' + videoUploadUI.fileNameDeleteType(data.file.name) + '"></div><div class="pull-left icon-box mr-10 ml-10"><svg class="icon icon-gou size-14 svg-duihao pull-left"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-gou"></use></svg></div><div class="pull-left icon-box"><svg class="icon icon-guanbi size-12 svg-cha pull-right"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-guanbi"></use></svg></div>' +
'</td>' +
'<td><div class="td-2">' + leFileOperation.calculateFileSize(data.file) + '</div></td>' +
'<td v720pAndv1080p="v720pAndv1080p">' +
'<div v720p="v720p" class="icheckbox pull-left"><input type="checkbox" 720P="720P">720P</div>' +
'<div v1080p="v1080p" class="icheckbox pull-left"><input type="checkbox" 1080P="1080P">1080P</div>' +
'</td>' +
'<td class="list-td">' +
'<div class="common-pull-down pull-left color-73737c mt-5 mr-5 width-100" oneSingleClass="oneSingleClass">' +
'<div class="pull-down-head height-md-30" oneSingleClassHead="oneSingleClassHead">' +
'<span class="display-i-b width-all text-hide" oneSingleClassHeadShow="oneSingleClassHeadShow" oneClass="0">--请选择--</span>' +
'<i class="ml-10 icon-arrow" style="top: 13px;"><svg class="icon icon-arrow-down size-8 gray-33333c"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-arrow-down"></use></svg></i>' +
'</div>' +
'<ul class="pl-10 pr-10 list-down text-left" style="top:29px;max-height: 200px;overflow:auto;" oneSingleClassListDown="oneSingleClassListDown">' +
'<li oneClass="0" class="active">--请选择--</li>' +
'</ul>' +
'</div>' +
'<div class="common-pull-down pull-left color-73737c mt-5 width-100" twoSingleClass="twoSingleClass">' +
'<div class="pull-down-head height-md-30" twoSingleClassHead="twoSingleClassHead">' +
'<span class="display-i-b width-all text-hide" twoSingleClassHeadShow="twoSingleClassHeadShow" twoClass="0">--请选择--</span>' +
'<i class="ml-10 icon-arrow" style="top: 13px;"><svg class="icon icon-arrow-down size-8 gray-33333c"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-arrow-down"></use></svg></i>' +
'</div>' +
'<ul class="pl-10 pr-10 list-down text-left" style="top:29px;max-height: 200px;overflow:auto;" twoSingleClassListDown="twoSingleClassListDown">' +
'<li twoClass="0" class="active">--请选择--</li>' +
'</ul>' +
'</div>' +
'</td>' +
'<td panoramicAttr="panoramicAttr">' +
'<div class="icheckbox pull-left"><input type="checkbox" panoramic="panoramic">全景视频</div>' +
'</td>' +
'<td class="del-td">' +
'<a href="javascript:void(0)" selectTbodyDelete="selectTbodyDelete">删除</a>' +
'</td>' +
'</tr>';
$("#videoSelectTbody").append(dom);
$("#videoSelectTbody").find("tr[md5='" + data.md5 + "']").find("ul[oneSingleClassListDown='oneSingleClassListDown']").html(videoUploadUI.globalDom);
leDropDownFold.config("videoSelectTbody tr[md5='" + data.md5 + "'] div[oneSingleClass='oneSingleClass']", function (parentId) {
$("#" + parentId).toggleClass("active");
});
leDropDownFold.config("videoSelectTbody tr[md5='" + data.md5 + "'] div[twoSingleClass='twoSingleClass']", function (parentId) {
$("#" + parentId).toggleClass("active");
});
$("#videoSelectTbody").find("tr[md5='" + data.md5 + "']").find("input").iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%',// optional
});
if (!videoUploadUI.uploadConfig.config.panoramic) {
$("#videoSelectTbody").find("tr[md5='" + data.md5 + "']").find("td[panoramicAttr='panoramicAttr']").addClass("hide");
}
if (videoUploadUI.uploadConfig.config.v1080p == false && videoUploadUI.uploadConfig.config.v720p == false) {
$("#videoSelectTbody").find("tr[md5='" + data.md5 + "']").find("td[v720pAndv1080p='v720pAndv1080p']").addClass("hide");
}
if (!videoUploadUI.uploadConfig.config.v720p) {
$("#videoSelectTbody").find("tr[md5='" + data.md5 + "']").find("div[v720p='v720p']").addClass("hide");
}
if (!videoUploadUI.uploadConfig.config.v1080p) {
$("#videoSelectTbody").find("tr[md5='" + data.md5 + "']").find("div[v1080p='v1080p']").addClass("hide");
}
};
videoUploadUI.bindWebPageEvent = function () {
$("#videoSelectTbody").on("click", "a[selectTbodyDelete='selectTbodyDelete']", function () {
var md5 = $(this).parents("tr").attr("md5");
delete leFileOperation.fileUploadList[md5];
$(this).parents("tr").remove();
if ($("#videoSelectTbody").find("tr[md5]").length == 0) {
videoUploadUI.showOrHideSelect("show");
}
});
//全部删除
$("#selectAllDelete").on("click", function () {
if ($(this).hasClass("disable")) {
return;
} else {
$("#videoSelectTbody").find("tr[md5]").each(function () {
var md5 = $(this).attr("md5");
delete leFileOperation.fileUploadList[md5];
});
$("#videoSelectTbody").find("tr[md5]").remove();
videoUploadUI.showOrHideSelect("show");
}
});
//全部720p
$("#all720P").on("ifChecked", function () {
$("input[720P='720P']").each(function () {
if (!this.disabled) {
$(this).iCheck("check");
}
});
//$("input[720P='720P']").iCheck("check");
});
$("#all720P").on("ifUnchecked", function () {
$("input[720P='720P']").each(function () {
if (!this.disabled) {
$(this).iCheck("uncheck");
}
});
//$("input[720P='720P']").iCheck("uncheck");
});
//全部1080p
$("#all1080P").on("ifChecked", function () {
$("input[1080P='1080P']").each(function () {
if (!this.disabled) {
$(this).iCheck("check");
}
});
//$("input[1080P='1080P']").iCheck("check");
});
$("#all1080P").on("ifUnchecked", function () {
$("input[1080P='1080P']").each(function () {
if (!this.disabled) {
$(this).iCheck("uncheck");
}
});
//$("input[1080P='1080P']").iCheck("uncheck");
});
//全部全景
$("#allPanoramic").on("ifChecked", function () {
$("input[panoramic='panoramic']").iCheck("check");
$("#all1080P").iCheck("uncheck");
$("#all720P").iCheck("uncheck");
$("#all1080P").iCheck("disable");
$("#all720P").iCheck("disable");
});
$("#allPanoramic").on("ifUnchecked", function () {
$("input[panoramic='panoramic']").iCheck("uncheck");
$("#all1080P").iCheck("enable");
$("#all720P").iCheck("enable");
});
//单个全景选中
$("#videoSelectTbody").on("ifChecked", "input[panoramic='panoramic']", function () {
$(this).parents("tr").find("input[1080P='1080P']").iCheck("uncheck");
$(this).parents("tr").find("input[720P='720P']").iCheck("uncheck");
$(this).parents("tr").find("input[1080P='1080P']").iCheck("disable");
$(this).parents("tr").find("input[720P='720P']").iCheck("disable");
});
$("#videoSelectTbody").on("ifUnchecked", "input[panoramic='panoramic']", function () {
$(this).parents("tr").find("input[1080P='1080P']").iCheck("enable");
$(this).parents("tr").find("input[720P='720P']").iCheck("enable");
});
//上传
$("#uploadVideoBtn").on("click", function () {
if ($(this).hasClass("btn-ipt-hui")) {
return;
} else {
var notUpload = false;
$("#videoSelectTbody").find("tr[md5]").find("input[videoName='videoName']").each(function () {
var videoName = $(this).val().trim();
var md5 = $(this).parents("tr").attr("md5");
if (videoName == "") {
//当前视频列表中有名称相同的视频
leToolFunction.showAlertTip("当前视频列表中有名称为空的视频");
notUpload = true;
return;
} else {
leFileOperation.fileUploadList[md5].fileName = videoName;
leFileOperation.fileUploadList[md5].parameter += "&v720p=" + $("tr[md5='" + md5 + "']").find("input[720P='720P']")[0].checked;
leFileOperation.fileUploadList[md5].parameter += "&v1080p=" + $("tr[md5='" + md5 + "']").find("input[1080P='1080P']")[0].checked;
leFileOperation.fileUploadList[md5].parameter += "&panoramic=" + ($("tr[md5='" + md5 + "']").find("input[panoramic='panoramic']")[0].checked ? 1 : 0);
leFileOperation.fileUploadList[md5].parameter += "&uc1=" + $("tr[md5='" + md5 + "']").find("span[oneSingleClassHeadShow='oneSingleClassHeadShow']").attr("oneClass");
leFileOperation.fileUploadList[md5].parameter += "&uc2=" + $("tr[md5='" + md5 + "']").find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").attr("twoClass");
}
});
if (!notUpload) {
$("#videoSelectTbody").find("tr[md5]").remove();
videoUploadUI.showOrHideSelect("show");
vaasFileUpload.addFileCallback();
}
}
});
leDropDownFold.config("oneSelectAll", function (parentId) {
$("#oneSelectAll").toggleClass("active");
});
leDropDownFold.config("twoSelectAll", function (parentId) {
$("#twoSelectAll").toggleClass("active");
});
//批量一级分类
$("#oneSelectAllHead").on("click", function () {
$("#oneSelectAll").toggleClass("active");
if ($("#oneSelectAll").hasClass("active")) {
leDropDownFold.startUsing("oneSelectAll");
} else {
leDropDownFold.destroy("oneSelectAll");
}
});
$("#oneSelectAllListDown").on("click", "li", function () {
$("#oneSelectAll").toggleClass("active");
leDropDownFold.destroy("oneSelectAll");
$("#oneSelectAllListDown").find("li").removeClass("active");
$(this).addClass("active");
$("#videoSelectTbody").find("tr[md5]").find("ul[oneSingleClassListDown='oneSingleClassListDown'] li").removeClass("active");
$("#videoSelectTbody").find("tr[md5]").find("ul[oneSingleClassListDown='oneSingleClassListDown']").find("li[twoClass='" + $(this).attr("twoClass") + "']").addClass("active");
$("#oneSelectAllHeadShow").html($(this).html());
$("#oneSelectAllHeadShow").attr("oneClass", $(this).attr("oneClass"));
$("#videoSelectTbody").find("tr[md5]").find("span[oneSingleClassHeadShow='oneSingleClassHeadShow']").html($(this).html());
$("#videoSelectTbody").find("tr[md5]").find("span[oneSingleClassHeadShow='oneSingleClassHeadShow']").attr("oneClass", $(this).attr("oneClass"));
$("#twoSelectAllHeadShow").html("--请选择--");
$("#twoSelectAllHeadShow").attr("twoClass", "0");
$("#videoSelectTbody").find("tr[md5]").find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").html("--请选择--");
$("#videoSelectTbody").find("tr[md5]").find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").attr("twoClass", "0");
if ($(this).attr("oneClass") == "0") {
var dom = '<li twoClass="0" class="active">--请选择--</li>';
$("#twoSelectAllListDown").html(dom);
$("#videoSelectTbody").find("tr[md5]").find("ul[twoSingleClassListDown='twoSingleClassListDown']").html(dom);
return;
}
videoUploadEntity.videoCategoryEntity.parentId = $(this).attr("oneClass");
if (videoUploadUI.twoClassfiy[$(this).attr("oneClass")]) {
var dom = '<li twoClass="0" class="active">--请选择--</li>';
for (var i = 0; i < videoUploadUI.twoClassfiy[$(this).attr("oneClass")].length; i++) {
dom += '<li twoClass="' + videoUploadUI.twoClassfiy[$(this).attr("oneClass")][i].categoryId + '" title="' + videoUploadUI.twoClassfiy[$(this).attr("oneClass")][i].categoryName + '">' + videoUploadUI.twoClassfiy[$(this).attr("oneClass")][i].categoryName + '</li>';
}
$("#twoSelectAllListDown").html(dom);
$("#videoSelectTbody").find("tr[md5]").find("ul[twoSingleClassListDown='twoSingleClassListDown']").html(dom);
} else {
videoUploadDAL.getVideoCategory(function (successData) {
videoUploadUI.twoClassfiy[videoUploadEntity.videoCategoryEntity.parentId] = successData.list;
var dom = '<li twoClass="0" class="active">--请选择--</li>';
for (var i = 0; i < successData.list.length; i++) {
dom += '<li twoClass="' + successData.list[i].categoryId + '" title="' + successData.list[i].categoryName + '">' + successData.list[i].categoryName + '</li>';
}
$("#twoSelectAllListDown").html(dom);
$("#videoSelectTbody").find("tr[md5]").find("ul[twoSingleClassListDown='twoSingleClassListDown']").html(dom);
}, function (errorData) { });
}
});
//批量二级分类
$("#twoSelectAllHead").on("click", function () {
$("#twoSelectAll").toggleClass("active");
if ($("#twoSelectAll").hasClass("active")) {
leDropDownFold.startUsing("twoSelectAll");
} else {
leDropDownFold.destroy("twoSelectAll");
}
});
$("#twoSelectAllListDown").on("click", "li", function () {
$("#twoSelectAll").toggleClass("active");
leDropDownFold.destroy("twoSelectAll");
$("#twoSelectAllListDown").find("li").removeClass("active");
$(this).addClass("active");
$("#twoSelectAllHeadShow").html($(this).html());
$("#twoSelectAllHeadShow").attr("twoClass", $(this).attr("twoClass"));
$("#videoSelectTbody").find("tr[md5]").find("ul[twoSingleClassListDown='twoSingleClassListDown'] li").removeClass("active");
$("#videoSelectTbody").find("tr[md5]").find("ul[twoSingleClassListDown='twoSingleClassListDown']").find("li[twoClass='" + $(this).attr("twoClass") + "']").addClass("active");
$("#videoSelectTbody").find("tr[md5]").find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").html($(this).html());
$("#videoSelectTbody").find("tr[md5]").find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").attr("twoClass", $(this).attr("twoClass"));
});
//单个一级分类
$("#videoSelectTbody").on("click", "tr[md5] div[oneSingleClassHead='oneSingleClassHead']", function () {
var md5 = $(this).parents("tr").attr("md5");
$(this).parent().toggleClass("active");
if ($("#videoSelectTbody tr[md5='" + md5 + "'] div[oneSingleClass='oneSingleClass']").hasClass("active")) {
leDropDownFold.startUsing("videoSelectTbody tr[md5='" + md5 + "'] div[oneSingleClass='oneSingleClass']");
} else {
leDropDownFold.destroy("videoSelectTbody tr[md5='" + md5 + "'] div[oneSingleClass='oneSingleClass']");
}
});
$("#videoSelectTbody").on("click", "tr[md5] ul[oneSingleClassListDown='oneSingleClassListDown'] li", function () {
var md5 = $(this).parents("tr").attr("md5");
$(this).parent().parent().toggleClass("active");
leDropDownFold.destroy("videoSelectTbody tr[md5='" + md5 + "'] div[oneSingleClass='oneSingleClass']");
$(this).parent().find("li").removeClass("active");
$(this).addClass("active");
$(this).parent().parent().find("span[oneSingleClassHeadShow='oneSingleClassHeadShow']").html($(this).html());
$(this).parent().parent().find("span[oneSingleClassHeadShow='oneSingleClassHeadShow']").attr("oneClass", $(this).attr("oneClass"));
$(this).parent().parent().parent().find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").html("--请选择--");
$(this).parent().parent().parent().find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").attr("twoClass", "0");
if ($(this).attr("oneClass") == "0") {
var dom = '<li twoClass="0" class="active">--请选择--</li>';
$(this).parent().parent().parent().find("ul[twoSingleClassListDown='twoSingleClassListDown']").html(dom);
return;
}
videoUploadEntity.videoCategoryEntity.parentId = $(this).attr("oneClass");
if (videoUploadUI.twoClassfiy[$(this).attr("oneClass")]) {
var dom = '<li twoClass="0" class="active">--请选择--</li>';
for (var i = 0; i < videoUploadUI.twoClassfiy[$(this).attr("oneClass")].length; i++) {
dom += '<li twoClass="' + videoUploadUI.twoClassfiy[$(this).attr("oneClass")][i].categoryId + '" title="' + videoUploadUI.twoClassfiy[$(this).attr("oneClass")][i].categoryName + '">' + videoUploadUI.twoClassfiy[$(this).attr("oneClass")][i].categoryName + '</li>';
}
$(this).parent().parent().parent().find("ul[twoSingleClassListDown='twoSingleClassListDown']").html(dom);
} else {
var _this = this;
videoUploadDAL.getVideoCategory(function (successData) {
videoUploadUI.twoClassfiy[videoUploadEntity.videoCategoryEntity.parentId] = successData.list;
var dom = '<li twoClass="0" class="active">--请选择--</li>';
for (var i = 0; i < successData.list.length; i++) {
dom += '<li twoClass="' + successData.list[i].categoryId + '" title="' + successData.list[i].categoryName + '">' + successData.list[i].categoryName + '</li>';
}
$(_this).parent().parent().parent().find("ul[twoSingleClassListDown='twoSingleClassListDown']").html(dom);
}, function (errorData) { });
}
});
//单个二级分类
$("#videoSelectTbody").on("click", "tr[md5] div[twoSingleClassHead='twoSingleClassHead']", function () {
var md5 = $(this).parents("tr").attr("md5");
$(this).parent().toggleClass("active");
if ($("#videoSelectTbody tr[md5='" + md5 + "'] div[twoSingleClass='twoSingleClass']").hasClass("active")) {
leDropDownFold.startUsing("videoSelectTbody tr[md5='" + md5 + "'] div[twoSingleClass='twoSingleClass']");
} else {
leDropDownFold.destroy("videoSelectTbody tr[md5='" + md5 + "'] div[twoSingleClass='twoSingleClass']");
}
});
$("#videoSelectTbody").on("click", "tr[md5] ul[twoSingleClassListDown='twoSingleClassListDown'] li", function () {
var md5 = $(this).parents("tr").attr("md5");
$(this).parent().parent().toggleClass("active");
leDropDownFold.destroy("videoSelectTbody tr[md5='" + md5 + "'] div[twoSingleClass='twoSingleClass']");
$(this).parent().find("li").removeClass("active");
$(this).addClass("active");
$(this).parent().parent().find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").html($(this).html());
$(this).parent().parent().find("span[twoSingleClassHeadShow='twoSingleClassHeadShow']").attr("twoClass", $(this).attr("twoClass"));
});
};
videoUploadUI.globalDom = "";
videoUploadUI.oneClassfiy = [];
videoUploadUI.twoClassfiy = {};
videoUploadUI.init = (function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%',// optional
});
//获取配置
videoUploadUI.uploadConfig.init();
leFileOperation.init({
multipleDomElement: [$("#selectSystemFile1")[0], $("#openFileSelectBox")[0]], //一次允许选择多个文件,需要传递页面元素对象
multipleCallback: function (data) {
return "";
}, //如果需要额外加什么参数在这里设置如果不需要则 return "";
videoUpload_fileList: vaasFileUpload.fileUploadList, //上传列表中现有的文件列表//临时需要传递null
addFileCallback: function (data) {
var addFileErrorObj = {
"大小为0的文件": 0,
"不支持的视频格式": 0,
"文件已在上传列表当中": 0,
"选择了相同的文件": 0,
"视频名称不合法": 0
};
for (var i = 0; i < data.errorFiles.length; i++) {
if (data.errorFiles[i].errorMsg) {
addFileErrorObj[data.errorFiles[i].errorMsg]++;
}
}
var tipErrorMsg = "";
if (addFileErrorObj["大小为0的文件"] > 0) {
tipErrorMsg += "文件大小不能为0:数量为:" + addFileErrorObj["大小为0的文件"];
}
if (addFileErrorObj["不支持的视频格式"] > 0) {
tipErrorMsg += "<br/>不支持的视频格式:数量为:" + addFileErrorObj["不支持的视频格式"] + "<br/> <span style='margin-top: 15px;color:#FFB335;display: inline-block;word-break: break-all;text-align: left;width: 80%;'>支持上传的视频格式包括:" + vaasFileUpload.initOptionObject.leFileOperation.fileTypes + "</span>";
}
if (addFileErrorObj["文件已在上传列表当中"] > 0) {
tipErrorMsg += "<br/>您所选择的视频文件已经存在于上传列表中:数量为:" + addFileErrorObj["文件已在上传列表当中"];
}
if (addFileErrorObj["选择了相同的文件"] > 0) {
tipErrorMsg += "<br/>当次选择了相同的文件:数量为:" + addFileErrorObj["选择了相同的文件"];
}
if (addFileErrorObj["视频名称不合法"] > 0) {
tipErrorMsg += "<br/>您所选择文件的视频名称不合法:数量为:" + addFileErrorObj["视频名称不合法"];
}
if (tipErrorMsg) {
leToolFunction.showAlertTip(tipErrorMsg);
}
if (data.successFiles.length > 0) {
videoUploadUI.showOrHideSelect("hide");
}
for (var i = 0; i < data.successFiles.length; i++) {
videoUploadUI.addOneData(data.successFiles[i]);
}
}, //本次选择文件的回调函数
fileTypes: "wmv|wm|avi|dat|asf|rm|rmvb|ram|mpg|mpeg|mp4|mov|m4v|mkv|flv|vob|qt|divx|cpk|fli|flc|mod|dvix|dv|f4v|ts"
});
vaasFileUpload.init({
language: "zh_cn",
leFileOperation: leFileOperation, // 把 leFileOperation传过来
uploadInitUrl: adminBase.reuqestUrl.uploadInit + "?", //上传初始化地址
polingUrl: adminBase.reuqestUrl.heartbeat, // 心跳地址
uploadStatusCallback: function (data) {
}
});
//批量一级分类
videoUploadDAL.getVideoCategory(function (successData) {
videoUploadUI.oneClassfiy = successData.list;
var dom = '<li oneClass="0" class="active">--请选择--</li>';
for (var i = 0; i < successData.list.length; i++) {
dom += '<li oneClass="' + successData.list[i].categoryId + '" title="' + successData.list[i].categoryName + '">' + successData.list[i].categoryName + '</li>';
}
$("#oneSelectAllListDown").html(dom);
videoUploadUI.globalDom = dom;
}, function (errorData) { });
videoUploadUI.bindWebPageEvent();
})();
return videoUploadUI;
})();