var UploadManager = { Uploader: [] }; function preLoad() { if (!this.support.loading) { return false; } } function loadFailed() { alert("加载上传控件时发生异常,请刷新页面或联系管理员"); } function fileQueueError(file, errorCode, message) { try { var errorName = ""; if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) { errorName = "你选择了太多的文件."; } if (errorName !== "") { alert(errorName); return; } switch (errorCode) { case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: alert("您选择了0字节的文件,请检查文件"); break; case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: alert(file.name + "超出规定的文件大小"); break; case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: alert("不允许的文件类型"); break; default: alert(message); break; } } catch (ex) { this.debug(ex); } } function fileDialogComplete(numFilesSelected, numFilesQueued) { try { if (numFilesQueued > 0) { var containerId = '#divFileProgressContainer_' + UploadManager.Uploader[this.movieName].Id; jQuery(containerId).html(' '); UploadManager.Uploader[this.movieName].UploadedFilePaths = ''; UploadManager.Uploader[this.movieName].UploadedFileIds = ''; UploadManager.Uploader[this.movieName].UploadedFileSizes = ''; UploadManager.Uploader[this.movieName].UploadedFileThumbPath = ''; if (this.customSettings.renderType == 'Simple') { this.setButtonText('正在上传'); var _pdc = new progressBarControler('uploadContainer_' + UploadManager.Uploader[this.movieName].Id); this.customSettings.visableAddress = jQuery('#uploadContainer_' + UploadManager.Uploader[this.movieName].Id).find('input').is(':visible'); if (!this.customSettings.visableAddress) { jQuery(containerId).hide(); } var loadingIcon = jQuery('#uploadContainer_' + UploadManager.Uploader[this.movieName].Id + ' .uploadloadingIcons'); if (loadingIcon.length > 0) { loadingIcon.css("display", "inline"); } this.startUpload(); _pdc.startUpload(); } else { //clear progress // 按照顺序存放上传文件 UploadManager.Uploader[this.movieName].LocalFileArray = new Array(); var currentStats = this.getStats(); var max = numFilesSelected; if (currentStats) { if (currentStats.files_queued) { max = currentStats.files_queued + currentStats.successful_uploads + currentStats.in_progress + currentStats.upload_errors + currentStats.upload_cancelled + currentStats.queue_errors; } else { max = currentStats.successful_uploads + currentStats.in_progress + currentStats.upload_errors + currentStats.upload_cancelled + currentStats.queue_errors; } } var start = 0; for (var i = start; i < max; i++) { var file = this.getQueueFile(i); // alert(file.toString()); if (file&&( file.filestatus == SWFUpload.FILE_STATUS.QUEUED || file.filestatus == SWFUpload.FILE_STATUS.IN_PROGRESS)) { progress = new FileProgress(file, this.customSettings.upload_target, this); } } } } } catch (ex) { this.debug(ex); } } function uploadProgress(file, bytesLoaded) { try { var percent = Math.ceil((bytesLoaded / file.size) * 100); var progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setProgress(percent); if (percent === 100) { progress.toggleCancel(false, this); } else { progress.toggleCancel(true, this); } } catch (ex) { this.debug(ex); } } function uploadSuccess(file, serverData) { try { serverData = eval('(' + serverData + ')'); if (serverData.Result == 'Success') { this.customSettings.Result = 'Success'; var recordid = serverData.Id; if (UploadManager.Uploader[this.movieName].EnableFileServer && UploadManager.Uploader[this.movieName].AddRecord) { recordid = AddUploadedFileRecord(serverData.Path, serverData.Size); } if (this.settings.button_action == SWFUpload.BUTTON_ACTION.SELECT_FILE) { UploadManager.Uploader[this.movieName].UploadedFilePaths = serverData.Path; UploadManager.Uploader[this.movieName].UploadedFileIds = recordid; UploadManager.Uploader[this.movieName].UploadedFileSizes = serverData.Size; UploadManager.Uploader[this.movieName].UploadedFileThumbPath = serverData.Thumbpath; } else { UploadManager.Uploader[this.movieName].UploadedFilePaths = UploadManager.Uploader[this.movieName].UploadedFilePaths.Concate(serverData.Path, ','); UploadManager.Uploader[this.movieName].UploadedFileIds = UploadManager.Uploader[this.movieName].UploadedFileIds.Concate(recordid, ','); UploadManager.Uploader[this.movieName].UploadedFileSizes = UploadManager.Uploader[this.movieName].UploadedFileSizes.Concate(serverData.Size, ','); if (serverData.Thumbpath) { UploadManager.Uploader[this.movieName].UploadedFileThumbPath = UploadManager.Uploader[this.movieName].UploadedFileThumbPath.Concate(serverData.Thumbpath, ','); } } if (UploadManager.Uploader[this.movieName].LocalFileArray) { UploadManager.Uploader[this.movieName].LocalFileArray[file.index] = serverData.Path; var uploadFiles = ""; for (var x in UploadManager.Uploader[this.movieName].LocalFileArray) { uploadFiles = uploadFiles.Concate(UploadManager.Uploader[this.movieName].LocalFileArray[x], ','); } jQuery('#' + UploadManager.Uploader[this.movieName].Id).val(uploadFiles); } else { jQuery('#' + UploadManager.Uploader[this.movieName].Id).val(UploadManager.Uploader[this.movieName].UploadedFilePaths); } var progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setSuccess(); progress.toggleCancel(false); } else { this.customSettings.Result = 'Error'; window.alert(serverData.Message); var progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setError(); progress.toggleCancel(false); this.cancelQueue(); return false; } } catch (ex) { this.debug(ex); } } String.prototype.Concate = function (str, sign) { if (sign == undefined || sign == '' || sign == ' ') { return this + str; } if (this != '' && this != ' ') { return this + sign + str; } return this + str; } function uploadError(file, errorCode, message) { var progress; try { switch (errorCode) { case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: try { progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setCancelled(); // progress.setStatus("Cancelled"); // progress.toggleCancel(false); } catch (ex1) { this.debug(ex1); } break; case SWFUpload.UPLOAD_ERROR.IO_ERROR: try { progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setError(); alert("文件上传失败!IO异常"); } catch (ex2) { this.debug(ex2); } break; case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED: try { progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setError(); alert("上传的文件类型不符合服务器要求。"); } catch (ex2) { this.debug(ex2); } break; case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: try { progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setError(); alert("文件大小或个数超出合法范围"); } catch (ex2) { this.debug(ex2); } break; case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: try { progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setError(); alert("文件上传失败"); } catch (ex2) { this.debug(ex2); } break; case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED: try { progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setCancelled(); // progress.setStatus("Stopped"); // progress.toggleCancel(true); } catch (ex2) { this.debug(ex2); } case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: try { progress = new FileProgress(file, this.customSettings.upload_target, this); progress.setError(); alert(file.name + "超出允许上传的大小"); } catch (ex2) { this.debug(ex2); } break; default: alert(message); break; } } catch (ex3) { this.debug(ex3); } } function CancelFileUpload(swfu, fileId) { swfu.cancelUpload(fileId); } function StartUpload(swfu) { if (swfu != undefined) { swfu.startUpload(); } return false; } /* ****************************************** * FileProgress Object * Control object for displaying file info * ****************************************** */ function FileProgress(file, targetID, swfu) { // if (file.filestatus != SWFUpload.FILE_STATUS.QUEUED || file.filestatus != SWFUpload.FILE_STATUS.IN_PROGRESS) { // progress = new FileProgress(file, this.customSettings.upload_target, this); // } this.fileProgressID = "divFileProgress_" + swfu.movieName; this.fileId = file.id; this.SWF = swfu; if (this.SWF.customSettings.renderType == 'Popup') { this.fileProgressID = file.id + '_' + this.fileProgressID; } this.Id = UploadManager.Uploader[swfu.movieName].Id; this.fileProgressWrapper = document.getElementById(this.fileProgressID); if (!this.fileProgressWrapper) { this.fileProgressWrapper = document.createElement("div"); this.fileProgressWrapper.className = "progressWrapper"; this.fileProgressWrapper.id = this.fileProgressID; this.fileProgressElement = document.createElement("div"); this.fileProgressElement.className = "progressContainer"; this.fileProgressElement.style.width = '0%'; //+ 文件信息容器 this.fileInfoContainer = document.createElement("div"); this.fileInfoContainer.className = "fileInfoContainer"; //设置文件名 var progressText = document.createElement("div"); progressText.className = "progressName"; progressText.appendChild(document.createTextNode(cutString(file.name, 16))); var status = swfu.getStats(); var currFileTotal = status.successful_uploads + 1; if (swfu.customSettings.renderType == 'Popup') { var chkbox = $(""); //+ loading图标 var uploadingIcon = document.createElement("img"); uploadingIcon.src = 'WebResource.axd?d=47mmRNjgLucnhWJYHYTr40G6Ih28ihDZaKkuUOJRgPqFtHSlGfToYlRncOD6g0djkWa5Ym2al2qYrgPTnw_QIDZyucadap1aNEluesmMjZnJWY-ngnmcRTe7oO-yq1JCf1YQ2t2Ic9IAEvlRDszZdZRNoLoKNmYvJZhwX4CCjS1JgkfhlWjtGs__5v6OS4SuWf5hcA2&t=636630993609442064'; uploadingIcon.alt = "loading"; uploadingIcon.className = "uploading"; //取消按钮 var progressCancel = document.createElement("a"); progressCancel.className = "progressCancel"; progressCancel.href = "javascript:CancelFileUpload(swfu_" + this.Id + ",'" + file.id + "');"; progressCancel.style.backgroundImage = 'url(WebResource.axd?d=o4L4Z230y9XiTQGQJyrdxQZEzRFPStpygErv5_4jdwykXo7Eu1vXh9alblEJtjEk17H2X-k5B92oUDDRNP1W-rdkhg0kEq09xeENqKd_vuu4v9q6PE6wprAcvMYnXJirLbQoA1E8MXx2ix_qu2C7wuaEnprHSr6hmArge4zDrcI1-1IiJyetwo6mxOCTdDRlkvF_Yw2&t=636630993609442064)'; progressCancel.appendChild(document.createTextNode(" ")); //剩余时间 var progressLefttime = document.createElement("div"); progressLefttime.className = "progress_filesize"; progressLefttime.innerHTML = SWFUpload.speed.formatBytes(file.size); this.fileInfoContainer.appendChild(chkbox[0]); this.fileInfoContainer.appendChild(uploadingIcon); this.fileInfoContainer.appendChild(progressCancel); this.fileInfoContainer.appendChild(progressLefttime); } //NOTE: 百分比 var progressPercentage = document.createElement("div"); progressPercentage.className = "progressPercentage"; progressPercentage.innerHTML = '0%'; this.fileInfoContainer.appendChild(progressText); this.fileInfoContainer.appendChild(progressPercentage); this.fileProgressWrapper.appendChild(this.fileProgressElement); this.fileProgressWrapper.appendChild(this.fileInfoContainer); document.getElementById(targetID).appendChild(this.fileProgressWrapper); this.progressFile = file; } else { this.fileProgressElement = this.fileProgressWrapper.firstChild; this.fileInfoContainer = this.fileProgressWrapper.childNodes[1]; this.progressFile = file; } } FileProgress.prototype.setProgress = function (percentage) { if (percentage > 100) { percentage = 100; } this.fileProgressElement.style.width = percentage + "%"; var status = this.SWF.getStats(); var currFileTotal = status.successful_uploads; if (this.SWF.customSettings.renderType == 'Popup') { this.fileInfoContainer.childNodes[5].innerHTML = percentage + "%"; jQuery('#upload_currentspeed_' + this.Id).text(SWFUpload.speed.formatBPS(this.progressFile.currentSpeed)); this.fileInfoContainer.childNodes[1].src = 'WebResource.axd?d=oD5Rv7wJgHj0GZDrdNLAlHoEF96FrC0j6pmri63c4bZyg-HfhjE4IZ5JgH07UA2Z57b1KRjlTQ8jnvMGbajiTSFbJpFNJfNKv2ScE92WCe77pgMqJRgnZxBRKRD4Utq2C_l9AqW6OapYqommoFwMWTgV61Rb8nLnCiS0HA9S_aoOTARr6k83dK9vp58AHiW1ELBQ_Q2&t=636630993609442064'; } if (this.SWF.customSettings.renderType == 'Simple') { this.fileInfoContainer.childNodes[1].innerHTML = percentage + "%"; } // if () { // //this.fileInfoContainer.childNodes[2].firstChild.nodeValue = currFileTotal + '/' + UploadManager.Uploader[this.SWF.movieName].FileTotal + '(' + SWFUpload.speed.formatBPS(this.progressFile.currentSpeed) + ")"; // //this.fileInfoContainer.childNodes[4].innerHTML = SWFUpload.speed.formatTime(this.progressFile.timeRemaining); // } //this.fileInfoContainer.childNodes[ }; FileProgress.prototype.setComplete = function () { if (this.SWF.customSettings.renderType == 'Popup') { jQuery('#uploadContainerFacia_' + this.Id + ' img').attr('src', 'WebResource.axd?d=UOn_i9QTSUT5SWUyZArtu2fGGkNn2Luv8pDOgMBMWVkvLR-PZGljrFcuaPLPBd7fL0Epetij0DCBNiW1T1CJqKGDRB5qy25dVRKH2CaL4gboKZtKyV48RR0QE4P2tpXItv2kWd4znNgLdPkAgIlI69EZN-Jqc5unGThk8g_j9poavrvPqKXRjVLBylDDgen5B6Rw8sOi53IXakPx4EdNGxeQ4gQ1&t=636630993609442064'); jQuery('#upload_currentspeed_' + this.Id).text("上传完毕"); } if (this.SWF.customSettings.renderType == 'Simple') { // this.fileInfoContainer.childNodes[0].src = 'WebResource.axd?d=UOn_i9QTSUT5SWUyZArtu2fGGkNn2Luv8pDOgMBMWVkvLR-PZGljrFcuaPLPBd7fL0Epetij0DCBNiW1T1CJqKGDRB5qy25dVRKH2CaL4gboKZtKyV48RR0QE4P2tpXItv2kWd4znNgLdPkAgIlI69EZN-Jqc5unGThk8g_j9poavrvPqKXRjVLBylDDgen5B6Rw8sOi53IXakPx4EdNGxeQ4gQ1&t=636630993609442064'; //this.fileInfoContainer.childNodes[2].firstChild.nodeValue = '上传完毕'; this.fileInfoContainer.childNodes[1].innerHTML = ''; if (jQuery != undefined) { //jQuery('#' + this.fileProgressID).slideUp(5000); var _pdc = new progressBarControler('uploadContainer_' + this.Id); _pdc.completeUpload(this.SWF); }; } jQuery(this.fileInfoContainer.childNodes[2]).hide(); }; FileProgress.prototype.setError = function () { if (this.SWF.customSettings.renderType == 'Simple') { jQuery('.fileInfoContainer_' + UploadManager.Uploader[this.SWF.movieName].Id).html(''); // this.fileInfoContainer.childNodes[0].src = 'WebResource.axd?d=o4L4Z230y9XiTQGQJyrdxQZEzRFPStpygErv5_4jdwykXo7Eu1vXh9alblEJtjEk17H2X-k5B92oUDDRNP1W-rdkhg0kEq09xeENqKd_vuu4v9q6PE6wprAcvMYnXJirLbQoA1E8MXx2ix_qu2C7wuaEnprHSr6hmArge4zDrcI1-1IiJyetwo6mxOCTdDRlkvF_Yw2&t=636630993609442064'; this.SWF.cancelQueue(); var _pdc = new progressBarControler('uploadContainer_' + this.Id); _pdc.completeUpload(this.SWF); } else { this.fileProgressElement.style.backgroundColor = '#F7A7C1'; jQuery(this.fileInfoContainer.childNodes[2]).hide(); this.fileInfoContainer.childNodes[1].src = 'WebResource.axd?d=o4L4Z230y9XiTQGQJyrdxQZEzRFPStpygErv5_4jdwykXo7Eu1vXh9alblEJtjEk17H2X-k5B92oUDDRNP1W-rdkhg0kEq09xeENqKd_vuu4v9q6PE6wprAcvMYnXJirLbQoA1E8MXx2ix_qu2C7wuaEnprHSr6hmArge4zDrcI1-1IiJyetwo6mxOCTdDRlkvF_Yw2&t=636630993609442064'; } }; FileProgress.prototype.setCancelled = function () { if (this.SWF.customSettings.renderType == 'Popup') { jQuery('#' + this.fileProgressID).hide(); } CancelFileUpload(this.SWF, this.fileId); // this.fileProgressElement.className = "progressContainer"; // this.fileProgressElement.childNodes[3].className = "progressBarError"; // this.fileProgressElement.childNodes[3].style.width = ""; }; FileProgress.prototype.setStatus = function (status) { // this.fileProgressElement.childNodes[2].innerHTML = status; }; FileProgress.prototype.setSuccess = function () { if (this.SWF.customSettings.renderType == "Popup") { jQuery(this.fileInfoContainer.childNodes[2]).hide(); this.fileInfoContainer.childNodes[1].src = 'WebResource.axd?d=UOn_i9QTSUT5SWUyZArtu2fGGkNn2Luv8pDOgMBMWVkvLR-PZGljrFcuaPLPBd7fL0Epetij0DCBNiW1T1CJqKGDRB5qy25dVRKH2CaL4gboKZtKyV48RR0QE4P2tpXItv2kWd4znNgLdPkAgIlI69EZN-Jqc5unGThk8g_j9poavrvPqKXRjVLBylDDgen5B6Rw8sOi53IXakPx4EdNGxeQ4gQ1&t=636630993609442064'; } } FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) { }; function cutString(str, len) { if (str.length * 2 <= len) { return str; } var strlen = 0; var s = ""; for (var i = 0; i < str.length; i++) { s = s + str.charAt(i); if (str.charCodeAt(i) > 128) { strlen = strlen + 2; if (strlen >= len) { return s.substring(0, s.length - 1) + "..."; } } else { strlen = strlen + 1; if (strlen >= len) { return s.substring(0, s.length - 2) + "..."; } } } return s; } progressBarControler = function (pbc) { this.progressContainer = document.getElementById(pbc); this.addressMessage = jQuery(this.progressContainer).find('input'); } progressBarControler.prototype.startUpload = function () { this.addressMessage.hide(); } progressBarControler.prototype.completeUpload = function (swfuloader) { this.progressBar = jQuery(this.progressContainer).find('.progressWrapper'); this.progressBar.hide(); if (swfuloader.customSettings.visableAddress) { this.addressMessage.show(); } swfuloader.setButtonText('选择文件'); }