/******************************************************************************************************** * swfuInit *---------------------------------------------------------------------------------------------------- * 封装swfupload上传 * document.write("<script language=\"javascript\" src='..\/js\/j.js' > <\/script>"); *---------------------------------------------------------------------------------------------------- * @authour Kith Yang * @Date 2013-12-22 * @Version 1.3.3 * @jQueryVersion 1.4+ * @SWFUploadVersion 2.0+ * artDialog 4.2+ **/ var UN_SWFUpload = UN_SWFUpload || {}; UN_SWFUpload.version = "1.3.3 2013-12-22"; UN_SWFUpload.swfuploadList = {}; UN_SWFUpload.swfuList = []; UN_SWFUpload.SPLITE = ':'; UN_SWFUpload.ART_DIALOG_VER = art && art.dialog ? art.dialog.fn.version: ''; UN_SWFUpload.movieCount = 0; UN_SWFUpload.uploadTip; // expand object UN_SWFUpload.add = function(id, o) { return UN_SWFUpload.swfuploadList[id] = o; }; UN_SWFUpload.get = function(id) { return UN_SWFUpload.swfuploadList[id]; }; UN_SWFUpload.destroy = function(id) { if (!id || id == undefined || id == null || id == "") { for (var o in UN_SWFUpload.swfuploadList) { UN_SWFUpload.swfuploadList[o].destroy(); if (document.getElementById(o)) { document.getElementById(o).innerHTML = ''; } } } else { UN_SWFUpload.swfuploadList[id].destroy(); if (document.getElementById(id)) { document.getElementById(id).innerHTML = ''; } } }; UN_SWFUpload.serializeData = function() { var _data = new Array(); for (var o in UN_SWFUpload.swfuploadList) { _data.push(UN_SWFUpload.swfuploadList[o].getPostData()); } return _data.join('&'); }; (function($) { "use strict"; $.swfu = $.swfu || {}; $.extend($.swfu, { version: "1.3.3", getAccessor: function(obj, expr) { /* obj:swfuInit * 方法名/方法参数 * $("#list").swfu('getParam', 'param'); */ var ret, p, prm = [], i; if (typeof expr === 'function') { return expr(obj); } ret = obj[expr]; if (ret === undefined) { try { if (typeof expr === 'string') { prm = expr.split('.'); } i = prm.length; if (i) { ret = obj; while (ret && i--) { p = prm.shift(); ret = ret[p]; } } } catch(e) {} } return ret; }, htmlDecode: function(value) { if (value && (value == ' ' || value == ' ' || (value.length === 1 && value.charCodeAt(0) === 160))) { return ""; } return ! value ? value: String(value).replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"').replace(/&/g, "&"); }, htmlEncode: function(value) { return ! value ? value: String(value).replace(/&/g, "&").replace(/\"/g, """).replace(/</g, "<").replace(/>/g, ">"); }, format: function(format) { //jqgformat var args = $.makeArray(arguments).slice(1); if (format === undefined) { format = ""; } return format.replace(/\{(\d+)\}/g, function(m, i) { return args[i]; }); }, isNumeric: function(obj) { return ! isNaN(parseFloat(obj)) && isFinite(obj); }, isWindow: function(obj) { return obj != null && obj == obj.window; }, extend: function(methods) { // swfu可以使用$.swfu.extend({});extend other methods $.extend($.fn.swfuInit, methods); // if (!this.no_legacy_api) { $.fn.extend(methods); // } } }); $.fn.swfuInit = function(settings) { if (typeof settings == 'string') { // var fn = $.swfuInit[pin]; var fn = $.swfu.getAccessor($.fn.swfuInit, settings); if (!fn) { throw ("swfuInit - No such method: " + settings); } var args = $.makeArray(arguments).slice(1); return fn.apply(this, args); } return this.each(function() { var elem = $(this); if (!elem || elem.length == 0) { alert('该对象不存在.'); return; } if (this._swfu) { return; } /* 合并默认参数和用户自定义参数 */ var p = $.extend(true, {}, $.fn.swfuInit.defaults, settings || {}); var _swfu = new SRMSwfu(elem, p); _swfu.generate(); // expandable object this._swfu = _swfu; this.st = p; }); // return _swfu; }; /** * $("#list").getParam(id); * $("#list").swfu('getParam', 'selarrrow'); * typeof($t.p[pName]) != "undefined" ? $t.p[pName] : null; */ $.swfu.extend({ getSwfu: function() { // return this[0]._swfu; }, getSwfuParam: function(pName) { // this 为 swfuInit var $t = this[0]; if (!$t || !$t._swfu) { return; } if (!pName) { return $t.st; } else { var ret = typeof($t.st[pName]) != "undefined" ? $t.st[pName] : (typeof($t._swfu[pName]) != "undefined" ? $t._swfu[pName] : null); return ret; } }, destroySwfu: function() { if (this[0]._swfu != null) { this[0]._swfu.destroy(); } }, getSwfuPostData: function() { return this[0]._swfu.getPostData(); }, getFileIdArr: function() { return this[0]._swfu.fileIdValArr; }, getUploadFileNameArr: function() { return this[0]._swfu.uploadFileNameValArr; }, getPicturePathArr: function() { return this[0]._swfu.picturePathValArr; }, getPictureSizeArr: function() { return this[0]._swfu.pictureSizeValArr; } }); /** * 对外默认参数 */ $.fn.swfuInit.defaults = { // 文件ID参数名称 fileId: 'fileId', // 上传控件ID参数名称 businessId: 'businessId', // 附件ID,submit to server appendixId: 'appendixId', // 附件源文件名, uploadFileName: 'uploadFileName', // 附件重命名后 文件名 oldPath: 'oldPath', // 上传文件时 的临时路径 picturePath: 'picturePath', // 上传文件的大小 单位:字节 pictureSize: 'pictureSize', // 上传控件ID参数值 businessIdVal: '', // 文件ID参数值 fileIdVal: [], // 附件ID,submit to server,多个附件ID以数组形式 appendixIdVal: [], // 附件源文件名, uploadFileNameVal: [], // 附件重命名后 文件名 oldPathVal: [], // 上传文件时 的临时路径 picturePathVal: [], // 上传文件的大小 单位:字节 pictureSizeVal: [], // 上传按钮后的描述信息 descInfo: null, // 文件的存放路径 filePath: '', // 是否多选 multiple: false, // 上传文件URL uploadFileUrl: "../upload/upload.action", // // 删除文件URL // delFileUrl: "../upload/delTempFile.action", // 提交文件域的参数名称 filePostName: 'uploadFile', // 允许上传文件的类型,以 ; 分割,*.jpg;*.doc fileTyps: '*.*', fileTypesDesc: 'All File', // 默认单位是KB fileSizeLimit: '10 MB', fileUploadLimit: 10000, fileQueueLimit: 10, postParams: {}, confirmTip:false, showTip: false, showPercent: false, downFile: function(serverData, filePath, originalName) { /* * url:ServerData * filePath:Renamed FileName * originalName:OriginalFileName */ // 下载temp文件 if (!filePath || filePath == '') { if (serverData && serverData.indexOf(UN_SWFUpload.SPLITE) >= 0) { var urlArr = serverData.split(UN_SWFUpload.SPLITE); for (var i = 0; i < urlArr.length; i++) { if (urlArr[i] && urlArr[i] != '') { window.open("../upload/download.action?fileUrl=" + urlArr[i]); } } } else { window.open("../upload/download.action?fileUrl=" + serverData); } } else { if (serverData && serverData.indexOf(UN_SWFUpload.SPLITE) >= 0) { var urlArr = serverData.split(UN_SWFUpload.SPLITE); for (var i = 0; i < urlArr.length; i++) { if (urlArr[i] && urlArr[i] != '') { window.open("../upload/download.action?fileUrl=" + urlArr[i] + "&filePath=" + filePath); } } } else { window.open("../upload/download.action?fileUrl=" + serverData + "&filePath=" + filePath) } } }, delFile : function (serverData) { // 删除临时文件的function // serverData为上传时服务器返回的数据 $.ajax({ url: '../upload/delTempFile.action', type: "POST", data: { 'fileUrl': serverData }, timeout: 10000, cache: false, success: function(data) { try { //var json = $.parseJSON(data); } catch(e) {} }, error: function() {} }); }, uploadSuccedHandle: function(postData) {} }; /* * 私有函数 */ var SRMSwfu = function(elem, settings) { if (settings.multiple && (settings.multiple == true || settings.multiple == 'true')) { settings.multiple = true; } if (settings.showTip && (settings.showTip == true || settings.showTip == 'true')) { settings.showTip = true; } if (settings.confirmTip && (settings.confirmTip == true || settings.confirmTip == 'true')) { settings.confirmTip = true; } if (settings.showPercent && (settings.showPercent == true || settings.showPercent == 'true')) { settings.showPercent = true; } this.settings = settings; // 下载文件的保存路径 this.filePath = settings.filePath, this.uploadDiv = elem; this.prefixName = elem.attr("id"); this.prefixIndex = UN_SWFUpload.movieCount++; this.contextName = elem.attr("id"); this.progressTarget = elem.attr("id") + "fsUploadProgress"; this.cancelButtonId = elem.attr("id") + "btnCancel"; this.buttonId = elem.attr("id") + "spanButtonPlaceHolder"; this.divStatusId = elem.attr("id") + "divStatus"; this.biddingFileId = elem.attr("id") + "biddingFile"; this.delFileButtonId = elem.attr("id") + "delFileButton"; this.filePostName = settings.filePostName ? settings.filePostName: "uploadFile"; this.postParams = settings.postParams; // 已经上传成功后的文件名 this.SWF_SELECT_FILE_NAME = ""; this.swfuObject = {}; // 事件队列 this.eventQueue = []; // 一次选择的文件数量 this.selectFileCount = 0; // 已上传文件list this.fileList = []; // 各个参数Array(argumentArray instanceof Array) this.fileIdValArr = (settings.fileIdVal instanceof Array) ? (settings.fileIdVal.length == 1 && settings.fileIdVal[0] == '' ? [] : settings.fileIdVal): (settings.fileIdVal ? [settings.fileIdVal] : []); this.appendixIdValArr = (settings.appendixIdVal instanceof Array) ? (settings.appendixIdVal.length == 1 && settings.appendixIdVal[0] == '' ? [] : settings.appendixIdVal): (settings.appendixIdVal ? [settings.appendixIdVal] : []); this.uploadFileNameValArr = (settings.uploadFileNameVal instanceof Array) ? (settings.uploadFileNameVal.length == 1 && settings.uploadFileNameVal[0] == '' ? [] : settings.uploadFileNameVal): (settings.uploadFileNameVal ? [settings.uploadFileNameVal] : []); this.oldPathValArr = (settings.oldPathVal instanceof Array) ? (settings.oldPathVal.length == 1 && settings.oldPathVal[0] == '' ? [] : settings.oldPathVal): (settings.oldPathVal ? [settings.oldPathVal] : []); this.picturePathValArr = (settings.picturePathVal instanceof Array) ? (settings.picturePathVal.length == 1 && settings.picturePathVal[0] == '' ? [] : settings.picturePathVal): (settings.picturePathVal ? [settings.picturePathVal] : []); this.pictureSizeValArr = (settings.pictureSizeVal instanceof Array) ? (settings.pictureSizeVal.length == 1 && settings.pictureSizeVal[0] == '' ? [] : settings.pictureSizeVal): (settings.pictureSizeVal ? [settings.pictureSizeVal] : []); this.fileOrder = this.uploadFileNameValArr.length + 1; // flash是否初始化完成 this.falshReady = false; // 是否正在上传中 this.isUploding = false; this.fileSizeWithUnit = $.swfu.isNumeric(settings.fileSizeLimit) ? settings.fileSizeLimit + ' KB': settings.fileSizeLimit; // 是否有上传过文件 this.isUploaded = false; }; SRMSwfu.prototype = { generate: function() { var self = this; // 初始化调用SWFUpload对象初始化 if (self.uploadDiv) { self.uploadDiv.html(""); } var htmls = self.getFlashHTML(self.uploadDiv); var upObjId = self.prefixName; // 所有已经选择的文件名称for多选 var currSelectFile = ''; var _swfSet = { file_types: self.settings.fileTyps, file_types_description: self.settings.fileTypesDesc, file_size_limit: self.settings.fileSizeLimit, // 最多上传文件数量 file_upload_limit: self.settings.fileUploadLimit, // 队列文件数量 file_queue_limit: self.settings.fileQueueLimit, debug: false, // Button settings // 单选OR多选 button_action: self.settings.multiple ? SWFUpload.BUTTON_ACTION.SELECT_FILES: SWFUpload.BUTTON_ACTION.SELECT_FILE, button_image_url: "../images/swf_btn_bg.gif", button_width: "76", button_height: "26", button_text: "<span class='theFont'>上传</span>", button_text_style: ".theFont { font-size: 11;font-weight:bold;text-align:center; color:#323d1f;background-color:transparent; }", button_text_left_padding: 1, button_text_top_padding: 4, flash_url: "../js/SWFUpload/swfupload.swf", upload_url: (self.settings.uploadFileUrl && self.settings.uploadFileUrl != "") ? self.settings.uploadFileUrl: "../upload/upload.action", // file_dialog_start_handler : fileDialogStart, file_post_name: self.filePostName, custom_settings: { progressTarget: self.progressTarget, cancelButtonId: self.cancelButtonId }, button_cursor: SWFUpload.CURSOR.HAND, post_params: self.postParams, button_placeholder_id: self.buttonId, // 选中文件后确定后执行,然后file_dialog_complete_handler file_queued_handler: function(file) { // alert('选中文件后确定后执行file_queued_handler'); // 当文件选择对话框关闭消失时,如果选择的文件成功加入上传队列,那么针对每个成功加入的文件都会触发一次该事件(N个文件成功加入队列,就触发N次此事件)。 // this.customSettings.queue = this.customSettings.queue || new Array(); // while (this.customSettings.queue.length > 0) { // this.cancelUpload(this.customSettings.queue.pop(), false); // } // this.customSettings.queue.push(file); var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setStatus("Pending..."); progress.toggleCancel(true, this); if (self.settings.multiple) { // 多选所有已选 的文件名 currSelectFile += file.name + '<br/>'; } else { currSelectFile = file.name; } }, file_dialog_complete_handler: function(numFilesSelected, numFilesQueued) { if (numFilesSelected > 0 && numFilesQueued > 0) { if (self.settings.multiple) { self.selectFileCount += numFilesQueued; // 多选文件 if (self.settings.confirmTip && (self.settings.confirmTip == true || self.settings.confirmTip == 'true')) { var dialog = art.dialog.confirm("确认要上传已选的 " + numFilesQueued + " 个文件吗?", function() { try { // 开始上传 self.swfuObject.startUpload(); } catch(ex) { dialog.close(); } }, function() { self.swfuObject.cancelQueue(); }); } else { // 开始上传 self.swfuObject.startUpload(); } } else { // 单选文件 self.selectFileCount = numFilesQueued; if (self.settings.confirmTip && (self.settings.confirmTip == true || self.settings.confirmTip == 'true')) { var dialog = art.dialog.confirm("确认要上传 " + currSelectFile + " 吗?", function() { try { // 单选文件时,删除上一次的文件 self.delAllFile(); self.swfuObject.startUpload(); currSelectFile = ''; } catch(ex) { dialog.close(); } }, function() { // 取消了队列 self.swfuObject.cancelQueue(); }); } else { self.delAllFile(); self.swfuObject.startUpload(); currSelectFile = ''; } } } }, upload_start_handler: function(file) { if (!self.isUploding) { self.isUploding = true; } try { //完成上传前的最后验证以及其他你需要的操作,例如添加、修改、删除post数据等。 var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setStatus("Uploading..."); progress.toggleCancel(true, this); if (self.settings.showTip) { self.settings.showPercent = false; if (!UN_SWFUpload.uploadTip) { UN_SWFUpload.uploadTip = //art.dialog.tips('正在上传文件 '+file.name+' ,请稍等...', 60); self.getUploadTips('正在上传文件 ' + file.name); } else { UN_SWFUpload.uploadTip.content('正在上传文件 ' + file.name).title('上传中...').show(); } } } catch(ex) { } return true; }, upload_success_handler: function(file, serverData) { /* * 注意不能 * this.cancelUpload(); * 不然导致 * 一个上传完成(发送file信息,并返回200状态时调用此方法)后, * 取消只会取消当前文件的上传,而不是取消整个队列上传,所以每隔一个就会被取消 * 这个upload_success_handler每个文件上传完成都会调用一次,一个文件上传周期没有完成,还会触发upload_complete_handler;uploadComplete(file) * */ if (serverData != null && serverData != "") { // self.isUploaded = !self.isUploaded ? true : self.isUploaded; if (!self.isUploaded) { self.isUploaded = true; } try { // 将上传成功的file保存 self.fileList.push(file); // 上传成功后加入 self.SWF_SELECT_FILE_NAME = self.SWF_SELECT_FILE_NAME + file.name + UN_SWFUpload.SPLITE; //file.id = "singlefile"; var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setComplete(); progress.setStatus("Complete."); progress.toggleCancel(false); var _fileId = $("#" + self.contextName + "fileId"); var _uploadFileName = $("#" + self.contextName + self.settings.uploadFileName); var _picturePath = $("#" + self.contextName + self.settings.picturePath); var _pictureSize = $("#" + self.contextName + self.settings.pictureSize); if (self.settings.multiple) { _fileId.val(_fileId.val() + file.id + UN_SWFUpload.SPLITE); _uploadFileName.val(_uploadFileName.val() + file.name + UN_SWFUpload.SPLITE); _picturePath.val(_picturePath.val() + serverData + UN_SWFUpload.SPLITE); _pictureSize.val(_pictureSize.val() + file.size + UN_SWFUpload.SPLITE); var _biddingFile = $("#" + self.biddingFileId); if (_biddingFile.html() == "") { $("#" + self.biddingFileId).append('[' + self.fileOrder + '] ' + file.name); } else { $("#" + self.biddingFileId).append('<br/>' + '[' + self.fileOrder + '] ' + file.name); } // 保存提交参数 self.fileIdValArr.push(file.id); self.uploadFileNameValArr.push(file.name); self.picturePathValArr.push(serverData); self.pictureSizeValArr.push(file.size); } else { // 单选只填入选择的文件 _fileId.val(file.id); _uploadFileName.val(file.name); _picturePath.val(serverData); _pictureSize.val(file.size); // 保存提交参数 self.fileIdValArr = [file.id]; self.uploadFileNameValArr = [file.name]; self.picturePathValArr = [serverData]; self.pictureSizeValArr = [file.size]; } } catch(e) { art.dialog.alert("upload_success_handler" + e); } } }, upload_complete_handler: function(file) { if (SWFUpload.FILE_STATUS.COMPLETE == file.filestatus) { self.fileOrder++; // 多选文件,清除初始化的文件名,把已经上传的加入文件名value // oldPath不需要清空,后台需要删除上次的文件 if (!self.isUploaded) { var _picturePath = $("#" + self.contextName + self.settings.picturePath); _picturePath.val(""); var _uploadFileName = $("#" + self.contextName + self.settings.uploadFileName); _uploadFileName.val(""); self.uploadFileNameValArr = []; self.picturePathValArr = []; // 选择第一个文件 self.delAllFile(); } } /* * 计算上传进度,总数量selectFileCount */ if (self.settings.showPercent) { var percent = Math.ceil(((self.selectFileCount - this.getStats().files_queued) / self.selectFileCount) * 100); if (!UN_SWFUpload.uploadTip) { //art.dialog.tips('正在上传文件 '+file.name+' ,请稍等...', 60); UN_SWFUpload.uploadTip = self.getUploadTips(percent + ' %'); } else { UN_SWFUpload.uploadTip.content(percent + ' %').show(); } } // SWFUpload.FILE_STATUS = { // QUEUED : -1, // IN_PROGRESS : -2, // ERROR : -3, // COMPLETE : -4, // CANCELLED : -5 // }; if (this.getStats().files_queued === 0) { self.isUploding = false; // 队列文件全部上传完成 document.getElementById(this.customSettings.cancelButtonId).disabled = true; // // 把最后的一个:去掉,java SPLITE最后一个舍弃 // var _fileId = $("#"+self.contextName+"fileId"); // _fileId.val(self.getLastSplitStr(_fileId.val(), UN_SWFUpload.SPLITE)); var _uploadFileName = $("#" + self.contextName + self.settings.uploadFileName); // _uploadFileName.val(self.getLastSplitStr(_uploadFileName.val(), UN_SWFUpload.SPLITE)); var _picturePath = $("#" + self.contextName + self.settings.picturePath); // _picturePath.val(self.getLastSplitStr(_picturePath.val(), UN_SWFUpload.SPLITE)); // var _pictureSize = $("#"+self.contextName+self.settings.pictureSize); // _pictureSize.val(self.getLastSplitStr(_pictureSize.val(), UN_SWFUpload.SPLITE)); // 加入参数ARRAY' if (self.SWF_SELECT_FILE_NAME != "") { var _biddingFileId = $("#" + self.biddingFileId); if (!self.settings.multiple) { // // 单选'<a href="javascript:void(0);">', // _biddingFileId.html('<a href="javascript:void(0);" rname="'+_picturePath.val()+'" fname="'+_uploadFileName.val()+'">'+_uploadFileName.val()+'</a>'); // $("#"+self.delFileButtonId).html("删 除"); self.SWF_SELECT_FILE_NAME = ''; } else { // 多选,下载链接不一样 // <span><a href="javascript:void(0);">'++'</a></span> // var bidFileNameArr = self.uploadFileNameValArr; // var biddingFileHtmlArr = []; // var picturePathArr = self.picturePathValArr; // var bl = bidFileNameArr.length; // $.each(bidFileNameArr, function(i, v){ // if(i != bl - 1) { // // 下载文件获取文件名称rname,fname真实文件名 // biddingFileHtmlArr.push('<a href="javascript:void(0);" rname="'+picturePathArr[i]+'" fname="'+v+'">['+(i+1)+'] '+v+'</a> <span id="'+i+'delMultipleBtn" class="delMultipleBtn" rname="'+picturePathArr[i]+'" ><a href="javascript:void(0);">删 除</a></span><br/>'); // } else { // biddingFileHtmlArr.push('<a href="javascript:void(0);" rname="'+picturePathArr[i]+'" fname="'+v+'">['+(i+1)+'] '+v+'</a> <span id="'+i+'delMultipleBtn" class="delMultipleBtn" rname="'+picturePathArr[i]+'" ><a href="javascript:void(0);">删 除</a></span>'); // } // }); // 多选删除所有文件 if (self.uploadFileNameValArr.length > 1) { $("#" + self.delFileButtonId).html("删除所有文件"); } } self.getUploadFileNameHtml(); } // 判断队列没有文件,关闭上传tip if (self.settings.showTip || self.settings.showPercent) { if (UN_SWFUpload.uploadTip) { //UN_SWFUpload.uploadTip.content('上传完成.'); UN_SWFUpload.uploadTip.title('完成'); UN_SWFUpload.uploadTip.hide(); // UN_SWFUpload.uploadTip.button( // { // name: '确定', // callback: function () { // this.hide(); // }, // disabled: false // } // ) self.uploadCompleteTip('上传完成.'); } } if (self.settings.uploadSuccedHandle) { self.handleEvent("uploadSuccedHandle", self.getPostData()); } } }, file_queue_error_handler: function(file, errorCode, message) { // this 已经是swfupload对象 try { if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) { // art.dialog.alert("文件队列已满,最多可上传 "+this.settings.file_upload_limit+" 个文件."); art.dialog.alert("一次最多能选择 " + this.settings.file_queue_limit + " 个文件."); return; } var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setError(); progress.toggleCancel(false); switch (errorCode) { case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: progress.setStatus("File is too big."); art.dialog.alert("文件:" + file.name + " 过大,请选择 " + self.fileSizeWithUnit + " 以内的文件进行上传."); //this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: progress.setStatus("Cannot upload Zero Byte files."); art.dialog.alert("文件:" + file.name + " 小大为0KB,请选择大于0KB,小于" + self.fileSizeWithUnit + "的文件进行上传."); //this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: progress.setStatus("Invalid File Type."); art.dialog.alert("请选择类型为 " + this.settings.file_types_description + " 的文件进行上传."); //this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; default: if (file !== null) { progress.setStatus("Unhandled Error"); } //this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message); break; } } catch(ex) { // this.debug(ex); art.dialog.error("上传文件失败,请刷新页面后重试."); } }, // upload_progress_handler : function (file, bytesLoaded, bytesTotal) { // try { // var percent = Math.ceil((bytesLoaded / bytesTotal) * 100); // var progress = new FileProgress(file, this.customSettings.progressTarget); // progress.setProgress(percent); // progress.setStatus("Uploading..."); // $(document.body).prepend(percent); // } catch (ex) { // this.debug(ex); // } // }, upload_error_handler: function(file, errorCode, message) { var progress = new FileProgress(file, this.customSettings.progressTarget); progress.setError(); progress.toggleCancel(false); switch (errorCode) { case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: progress.setStatus("Upload Error: " + message); art.dialog.alert("文件 " + file.name + " 上传失败, 网络错误. Message: " + message); break; case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: progress.setStatus("Upload Failed."); art.dialog.alert("文件 " + file.name + " 尺寸过大. " + file.size + " 请重新选择. Message: " + message); break; case SWFUpload.UPLOAD_ERROR.IO_ERROR: progress.setStatus("Server (IO) Error"); art.dialog.alert("服务器I/O设备错误, 文件 " + file.name + ". Message: " + message); break; case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: progress.setStatus("Security Error"); art.dialog.alert("服务拒绝上传此文件, 文件 " + file.name + ". Message: " + message); break; case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: progress.setStatus("Upload limit exceeded."); art.dialog.alert("文件队列已满,文件 " + file.name + " 上传失败. Message: " + message); break; case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED: progress.setStatus("Failed Validation. Upload skipped."); art.dialog.alert("文件验证失败,文件 " + file.name + ". Message: " + message); break; case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: // If there aren't any files left (they were all cancelled) disable the cancel button if (this.getStats().files_queued === 0) { document.getElementById(this.customSettings.cancelButtonId).disabled = true; } progress.setStatus("Cancelled"); progress.setCancelled(); break; case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED: progress.setStatus("Stopped"); break; default: progress.setStatus("Unhandled Error: " + errorCode); art.dialog.alert("未知错误,错误代码 " + errorCode + ", 文件 " + file.name + ", 大小: " + file.size + ". Message: " + message); break; } }, swfupload_loaded_handler: function() { self.falshReady = true; } }; self.swfuObject = new SWFUpload(_swfSet); self.addToList(self.prefixName, self); }, getFlashHTML: function(divObj) { var self = this; var delFileButtonHtml = '<span><a style="padding-left:10px;" href="javascript:void(0);" id="' + self.delFileButtonId + '"></a> </span>'; if (self.uploadFileNameValArr && self.uploadFileNameValArr.length > 1) { delFileButtonHtml = '<span><a style="padding-left:10px;" href="javascript:void(0);" id="' + self.delFileButtonId + '">删除所有文件</a> </span>'; } // // 显示Bidding文件名 // var bl = self.uploadFileNameValArr.length; // var _uploadFileNameHtmlArr = []; // $.each(self.uploadFileNameValArr, function(i, v){ // if(i != bl - 1) { // _uploadFileNameHtmlArr.push('<a href="javascript:void(0);" rname="'+self.picturePathValArr[i]+'" fname="'+v+'">['+(i+1)+'] '+v+'</a> <span id="'+i+'delMultipleBtn" class="delMultipleBtn"><a href="javascript:void(0);">删 除</a></span><br/>'); // } else { // _uploadFileNameHtmlArr.push('<a href="javascript:void(0);" rname="'+self.picturePathValArr[i]+'" fname="'+v+'">['+(i+1)+'] '+v+'</a> <span id="'+i+'delMultipleBtn" class="delMultipleBtn"><a href="javascript:void(0);">删 除</a></span>'); // } // }); var _fileIdValHtml = self.fileIdValArr.join(UN_SWFUpload.SPLITE); var _uploadFileNameValue = self.uploadFileNameValArr.join(UN_SWFUpload.SPLITE); // 附件IDappendixId var _appendixIdValHtml = self.appendixIdValArr.join(UN_SWFUpload.SPLITE); // oldPathValArr var _oldPathValHtml = self.oldPathValArr.join(UN_SWFUpload.SPLITE); // picturePathValArr var _picturePathValHtml = self.picturePathValArr.join(UN_SWFUpload.SPLITE); // pictureSizeValArr var _pictureSizeValHtml = self.pictureSizeValArr.join(UN_SWFUpload.SPLITE); var divHtml = [ // fsUploadProgress '<div style="display:none;" id="' + self.progressTarget + '" ></div>', '<div style="display:none;" id="' + self.divStatusId + 'divStatus" ></div>', '<div style="height:28px;">', '<div style="float:left;padding-top:5px;min-width:20px">', '<span id="' + self.biddingFileId + '">' + self.getInitUploadFileNameHtml() + '</span>', delFileButtonHtml, '</div>', '<div style="" id="' + self.buttonId + '"></div>', '<input id="' + self.cancelButtonId + '" type="button" value="Cancel All Uploads" disabled="disabled" style="display:none;"/>', '<span id="' + self.prefixName + 'desc">' + (self.settings.descInfo && self.settings.descInfo == "" ? "点此按钮可以上传小于 " + self.fileSizeWithUnit + " 的文件": (self.settings.descInfo == null ? "":self.settings.descInfo)) + '</span>', '<input name="' + self.settings.businessId + '" id="' + self.contextName + self.settings.businessId + '" type="hidden" value="' + self.settings.businessIdVal + '"/>', '<input name="multiple" id="' + self.contextName + 'multiple" type="hidden" value="' + self.settings.multiple + '"/>', '<input name="' + self.settings.fileId + '" id="' + self.contextName + self.settings.fileId + '" type="hidden" value="' + _fileIdValHtml + '"/>', '<input name="' + self.settings.appendixId + '" id="' + self.contextName + self.settings.appendixId + '" type="hidden" value="' + _appendixIdValHtml + '"/>', '<input name="' + self.settings.uploadFileName + '" id="' + self.contextName + self.settings.uploadFileName + '" type="hidden" value="' + _uploadFileNameValue + '"/>', '<input name="' + self.settings.oldPath + '" id="' + self.contextName + self.settings.oldPath + '" type="hidden" value="' + _oldPathValHtml + '"/>', '<input name="' + self.settings.picturePath + '" id="' + self.contextName + self.settings.picturePath + '" type="hidden" value="' + _picturePathValHtml + '"/>', '<input name="' + self.settings.pictureSize + '" id="' + self.contextName + self.settings.pictureSize + '" type="hidden" value="' + _pictureSizeValHtml + '"/>', '<input name="isUploaded" id="' + self.contextName + 'isUploaded" type="hidden" value="' + self.isUploaded + '"/>', '</div>', ''].join(""); divObj.html(divHtml); $("#" + self.delFileButtonId).click(function() { self.delAllFile(); }); self.bindFileEnvent(); // $("#"+self.biddingFileId).children('a').click( function () { // // 每个链接下载 // self.handleEvent('downFile', $(this)); // }); // $("#"+self.biddingFileId).children('span').click( function () { // // 每个链接删除.删除各个参数里的文件,那么这时候删除拼接的字符串,不好操作,那么就将所有的参数不保存到页面,保存到内存中,放入数组/MAP // delMultipleFile($(this)); // }); return divHtml; }, handleEvent: function(handleName, params) { var fp = this.filePath; if (handleName && handleName == "downFile") { this.queueEvent(handleName, [params.attr("rname"), fp, params.attr("fname")]); } else { if (!params) { params = []; } this.queueEvent(handleName, params); } }, delAllFile: function() { // 删除了所有文件 // save 旧文件路径,用来删除旧文件 var picturePath = this.picturePathValArr.join(UN_SWFUpload.SPLITE); // 提交到后台的参数清空 this.fileIdValArr = []; this.uploadFileNameValArr = []; this.picturePathValArr = []; this.pictureSizeValArr = []; // reset input value this.refreshFormData(); $("#" + this.biddingFileId).html(""); $("#" + this.biddingFileId).html(""); $("#" + this.delFileButtonId).html(""); this.SWF_SELECT_FILE_NAME = ''; this.fileOrder = 1; if (picturePath != '') { // 删除临时路径的文件 this.delFile(picturePath); } }, delMultipleFile: function(clickObj) { // 多选删除一个文件 var swfu = this; var _index = $.inArray(clickObj.prev().attr('rname'), swfu.picturePathValArr); if (_index >= 0) { var _tempPath = swfu.picturePathValArr[_index]; // 删除这个文件 swfu.fileIdValArr.splice(_index, 1); swfu.uploadFileNameValArr.splice(_index, 1); swfu.picturePathValArr.splice(_index, 1); swfu.pictureSizeValArr.splice(_index, 1); swfu.fileOrder = swfu.uploadFileNameValArr.length + 1; // reset input value this.refreshFormData(); var pa = clickObj.prev(); clickObj.remove(); pa.remove(); if (swfu.uploadFileNameValArr.length == 0) { $("#" + swfu.delFileButtonId).html(""); } else { // 重新显示文件名并且绑定事件 swfu.getUploadFileNameHtml(); } // 删除临时路径的文件 if (_tempPath != '') { swfu.delFile(_tempPath); } } }, delFile: function (serverData) { // serverData为上传时服务器返回的数据 this.handleEvent("delFile", serverData); }, getInitUploadFileNameHtml: function() { var swfu = this; // 初始化显示文件html var bl = swfu.uploadFileNameValArr.length; if (bl > 0) { var _orderHtml = swfu.settings.multiple ? '[{0}]': ''; var _uploadFileNameHtmlArr = []; $.each(swfu.uploadFileNameValArr, function(i, v) { if(v != '') { if (i != bl - 1) { _uploadFileNameHtmlArr.push('<a href="javascript:void(0);" rname="' + swfu.picturePathValArr[i] + '" fname="' + v + '">' + _orderHtml.format(i + 1) + ' ' + v + '</a> <span id="' + i + 'delMultipleBtn" class="delMultipleBtn"><a href="javascript:void(0);">删 除</a></span><br/>'); } else { _uploadFileNameHtmlArr.push('<a href="javascript:void(0);" rname="' + swfu.picturePathValArr[i] + '" fname="' + v + '">' + _orderHtml.format(i + 1) + ' ' + v + '</a> <span id="' + i + 'delMultipleBtn" class="delMultipleBtn"><a href="javascript:void(0);">删 除</a></span>'); } } }); return _uploadFileNameHtmlArr.join(''); } else { return ''; } }, getUploadFileNameHtml: function() { // 上传后显示文件html var swfu = this; var bl = swfu.uploadFileNameValArr.length; var _uploadFileNameHtmlArr = []; var _orderHtml = swfu.settings.multiple ? '[{0}]': ''; $.each(swfu.uploadFileNameValArr, function(i, v) { if (v != "") { if (i != bl - 1) { _uploadFileNameHtmlArr.push('<a href="javascript:void(0);" rname="' + swfu.picturePathValArr[i] + '" fname="' + v + '">' + _orderHtml.format((i + 1)) + ' ' + v + '</a> <span id="' + i + 'delMultipleBtn" class="delMultipleBtn"><a href="javascript:void(0);">删 除</a></span><br/>'); } else { _uploadFileNameHtmlArr.push('<a href="javascript:void(0);" rname="' + swfu.picturePathValArr[i] + '" fname="' + v + '">' + _orderHtml.format((i + 1)) + ' ' + v + '</a> <span id="' + i + 'delMultipleBtn" class="delMultipleBtn"><a href="javascript:void(0);">删 除</a></span>'); } } }); var _html = _uploadFileNameHtmlArr.join(''); $("#" + swfu.biddingFileId).html(_html); swfu.bindFileEnvent(); return _html; }, bindFileEnvent: function() { // self swfu绑定下载/删除事件 var self = this; $("#" + self.biddingFileId).children('a').click(function() { // 每个链接下载 self.handleEvent('downFile', $(this)); }); $("#" + self.biddingFileId).children('span').click(function() { // 每个链接删除.删除各个参数里的文件,那么这时候删除拼接的字符串,不好操作,那么就将所有的参数不保存到页面,保存到内存中,放入数组/MAP self.delMultipleFile($(this)); }); }, queueEvent: function(handlerName, argumentArray) { var self = this; // 加入队列事件 // window.open("../upload/download.action?fileUrl=" + $("#"+this.settings.picturePathVal).val()); if (argumentArray == undefined) { argumentArray = []; } else if (! (argumentArray instanceof Array)) { argumentArray = [argumentArray]; } if (typeof self.settings[handlerName] === "function") { // Queue the event this.eventQueue.push(function() { this.settings[handlerName].apply(this, argumentArray); }); // Execute the next queued event setTimeout(function() { self.executeNextEvent(); }, 0); } else if (self.settings[handlerName] !== null) { alert(handlerName + '方法未定义.'); throw "Event handler '" + handlerName + "' is unknown or is not a function"; } }, executeNextEvent: function() { var f = this.eventQueue ? this.eventQueue.shift() : null; if (typeof(f) === "function") { f.apply(this); } }, addToList: function(swfuName, swfuObj) { // 属性名 = 属性值 UN_SWFUpload.add(swfuName, swfuObj); UN_SWFUpload.swfuList.push(swfuObj); }, hide: function() { // 隐藏div $("#" + this.contextName).hide(); }, show: function() { // 显示div $("#" + this.contextName).show(); }, getSwfu: function() { return this.swfuObject; }, refreshFormData: function() { this.fileIdValArr && this.fileIdValArr.length > 0 ? this.setFileId(this.fileIdValArr.join(UN_SWFUpload.SPLITE)) : this.setFileId(''); this.uploadFileNameValArr && this.uploadFileNameValArr.length > 0 ? this.setUploadFileName(this.uploadFileNameValArr.join(UN_SWFUpload.SPLITE)) : this.setUploadFileName(''); this.picturePathValArr && this.picturePathValArr.length > 0 ? this.setPicturePath(this.picturePathValArr.join(UN_SWFUpload.SPLITE)) : this.setPicturePath(''); this.pictureSizeValArr && this.pictureSizeValArr.length > 0 ? this.setPictureSize(this.pictureSizeValArr.join(UN_SWFUpload.SPLITE)) : this.setPictureSize(''); this.setIsUploaded(this.isUploaded); }, setFileId: function(val) { $("#" + this.contextName + this.settings.fileId).val(val); }, setUploadFileName: function(val) { $("#" + this.contextName + this.settings.uploadFileName).val(val); }, setPicturePath: function(val) { $("#" + this.contextName + this.settings.picturePath).val(val); }, setPictureSize: function(val) { $("#" + this.contextName + this.settings.pictureSize).val(val); }, setIsUploaded: function(val) { $("#" + this.contextName + 'isUploaded').val(val); }, destroy: function() { if (!this.isUploding) { this.delAllFile(); this.swfuObject.destroy(); $("#" + this.prefixName).html(""); } else { alert('文件正在上传中,请稍候操作.'); return; } }, cancle: function() { this.swfuObject.cancelQueue(); }, uploadCompleteTip: function(content, title) { return art.dialog.succeed({ // id:'uploadCompleteTip', // title:title?title:'消息', // content: content, // icon: 'succeed', // fixed: true, // resize: false, // drag: true , // width:'200', // esc:false, // yesFn:function (){ // return ; // } }).content(content); }, getSplitePostion: function(str, sIndex, splite, count) { /* * str 从sIndex开始到splite第count出现的位置 之间的位置 * 超过最大出现次数,返回最后一次出现的位置 * substring包括开始,不包括结束 */ if (!str) { return - 1; } // count不能超过总次数 var tsrc = str.substring(sIndex); var acount = this.getCountInstances(tsrc, splite); if (count > acount) { // 超过返回最后一次出现的次数 return this.getSplitePostion(tsrc, 0, splite, acount); } // str: 是你的原字符串 // splite: 是你的要找的字符串 // count: 寻找的次数 var re = new RegExp(splite, "g"); while (count--) { re.test(tsrc); } var pos = re.lastIndex - splite.length; if (pos < 0) return - 1; else return pos; }, getSplitStr: function(str, sIndex, splite, count) { if (!str) { return ''; } /* * str 从sIndex开始到splite第count出现的位置 之间的 的字符串 * substring包括开始,不包括结束 */ var pos = this.getSplitePostion(str, sIndex, splite, count); if (pos < 0) { // 没有找到,返回str return str; } else { return str.substring(sIndex, pos); } }, getCountInstances: function(mainStr, subStr) { if (!mainStr) { return 0; } // 字符串在mainstr中出现的次数 var count = 0; var offset = 0; do { offset = mainStr.indexOf(subStr, offset); if (offset != -1) { count++; offset += subStr.length; } } while ( offset != - 1 ) return count; }, getLastSplitStr: function(str, split) { if (!str) { return ''; } // 字符串split在源str最后出现的位置 之间的str return this.getSplitStr(str, 0, split, this.getCountInstances(str, split)); }, eachArrToString: function(arr, joinStr) { var str = ''; $.each(arr, function(i, v) { str += str + joinStr; }); return str; }, getPostData: function() { // 获取提交参数 var self = this; self.refreshFormData(); var postArr = ['multiple' + '=' + self.settings.multiple, self.settings.businessId + '=' + self.settings.businessIdVal, self.settings.fileId + '=' + self.fileIdValArr.join(UN_SWFUpload.SPLITE), self.settings.appendixId + '=' + self.appendixIdValArr.join(UN_SWFUpload.SPLITE), self.settings.uploadFileName + '=' + self.uploadFileNameValArr.join(UN_SWFUpload.SPLITE), self.settings.oldPath + '=' + self.oldPathValArr.join(UN_SWFUpload.SPLITE), self.settings.picturePath + '=' + self.picturePathValArr.join(UN_SWFUpload.SPLITE), self.settings.pictureSize + '=' + self.pictureSizeValArr.join(UN_SWFUpload.SPLITE), 'isUploaded' + '=' + self.isUploaded]; return encodeURIComponent(postArr.join('&')); }, getUploadTips: function(content, title) { return art.dialog({ id: '_uploadTips', title: title ? title: '', width: 300, content: content, fixed: true, resize: false, drag: true, yesFn: false, noFn: false, esc: false // , // button: [ // { // name: '确定', // disabled: true // } // ] }); } }; })(jQuery);
添加自定义删除function:delFile(severData) {
}
相关推荐
- **JavaScript API**:jQuery Swfupload 提供了一系列JavaScript接口,如初始化、开始上传、暂停上传、取消上传等,方便开发者进行控制和定制。 - **事件驱动**:插件基于事件模型,如文件选择、文件上传进度、...
利用JQuery插件方式,对MultiUpload的Flash上传功能做了皮肤优化及调用方面的便捷处理。内含2种皮肤,一句JS轻松调用Flash上传:$(".upload1").missdeUpload();
SWFUpload是一个强大的文件上传插件,它结合了Flash和JavaScript技术,提供了一种无刷新的文件上传体验。虽然SWFUpload已经不再更新,并且官方文档可能无法访问,但了解其工作原理和使用方法仍然对某些场景有帮助,...
2. **初始化配置**:使用jQuery选择器找到上传按钮元素,然后通过`.swfupload()`方法创建一个SwfUpload实例,并配置相关参数,如服务器端接收文件的URL、文件类型限制等。 3. **绑定事件**:利用jQuery的事件绑定...
jquery.uploadify-3.1.min.js 修改了SWFUpload.prototype.getFlashHTML ()方法,解决了在ie9在点击上传按钮后,不能弹出浏览文件的对话框问题。
SWFUpload 是一款开源的JavaScript库,用于在网页上实现高级的文件上传功能。这个"SWFUpload-v2.2.0.1-Samples.zip_V2"压缩包包含的是SWFUpload的版本2.2.0.1的示例代码,专为ASP.NET环境设计,提供了丰富的功能和...
2. 初始化SWFUpload实例,设置上传参数(如URL、文件类型限制等)和回调函数。 3. 将SWFUpload对象绑定到特定的HTML元素,通常是按钮或隐藏的IFrame。 4. 使用SWFUpload提供的方法启动上传,如`startUpload()`和`...
SWFUpload 是一款基于Flash技术的文件上传组件,它允许用户在网页中实现高级的文件上传功能,包括显示上传进度、支持多文件同时上传以及提供自定义操作按钮等特性。标题中的"SWFUpload-v2.2.0.1-Samples.rar"表明这...
- **相关插件(SWFUpload Plugins)**: 社区开发的插件扩展了SWFUpload的功能,例如预览图片、文件类型检查等。 总之,SWFUpload 2.5.0中文版提供了一个强大的多文件上传解决方案,其丰富的API和事件系统允许开发者...
在网页中引入jQuery和SWFUpload库,然后配置SWFUpload实例。这包括设置上传URL、文件类型限制、文件大小限制等参数。 ```html <script src="jquery.js"> <script src="swfupload.js"> $(document).ready(function...
**标题:“SwfUpload 闪存插件上传”** SwfUpload 是一款开源的JavaScript库,它利用Flash技术实现文件的上传功能。在Web开发中,SwfUpload因其支持多文件选择、进度条显示和断点续传等功能,而成为一种流行的选择...
2. **初始化 SwfUpload**:创建一个新的 SwfUpload 实例,配置相关参数,如上传URL、文件类型限制、最大文件大小等。 3. **设置事件监听器**:添加事件处理函数,如文件选择、上传开始、上传进度、上传成功或失败等...
SWFUpload是一款经典的JavaScript与Flash结合的文件上传插件,它在Web开发中被广泛用于实现多文件上传功能。这款插件允许用户在不刷新页面的情况下上传文件,提供了友好的用户体验,尤其在处理大文件或者批量上传时...
**SwfUpload 插件详解** SwfUpload 是一款经典的前端文件上传插件,它结合了Flash技术,能够在不刷新页面的情况下实现多文件上传功能。这个插件在jQuery库的支持下,提供了简单易用的API,让开发者可以方便地集成到...
- **编写jQuery交互**:使用jQuery监听SWFUpload的事件,例如文件开始上传、上传进度更新、文件上传成功或失败等,以更新UI状态。 - **PHP处理文件**:创建PHP脚本来接收SWFUpload发送的文件,验证文件大小、类型,...
初始化SWFUpload通常包括以下步骤: ```javascript var swfUploadInstance = new SWFUpload({ upload_url: "upload_handler.php", file_post_name: "Filedata", file_size_limit : "10 MB", file_types : "*....
- **初始化设置**:配置SwfUpload对象,如设置服务器URL、文件类型限制、最大上传文件大小等。 - **创建上传按钮**:使用JavaScript代码创建一个隐藏的Flash按钮,并将其绑定到SwfUpload实例。 - **监听事件**:...
在jQuery的`$(document).ready`函数中,通过`$("#vinEdit").vinSWFUpload()`来初始化插件,配置上传的相关参数。例如: ```javascript $(function() { var path = "<%=path%>/uiwidget/vinSwfUpload-1.2/"; var ...
1. **初始化SWFUpload** 在HTML页面中,我们需要一个隐藏的Flash对象来承载SWFUpload实例。然后在JavaScript代码中,通过`new SWFUpload()`来创建实例,配置项包括上传URL、文件类型限制、文件大小限制等。 2. **...
本项目是struts2和swfupload结合,实现单个文件上传、上传后预览(index.jsp),和批量上传(multiple.jsp),里面都有代码注释和一个整理的说明文档(SWFUpload说明文档),讲的非常非常详细,都是本人亲自整理。...