123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- var upload;
- var fileIdArray = "";
- var update_flag = "0";//附件操作权限标示,0:编辑 1:查询
- //设置默认的上传文件格式
- var filetypes="*.mp4;*.wmv;*.zip;*.rar;*.jpg;*.jpeg;*.gif;*.png;*.txt;*.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx;*.pdf";
- //设置默认的文件大小
- var file_size_limit="10240000";
- //设置默认文件数量
- var file_upload_limit="10";
- //设置默认上传文件队列数
- var file_queue_limit="10";
- function fileUpload() {
- upload = new SWFUpload(
- {
- // 提交路径
- upload_url : prjContextPath+ "/fileUploadAction!fileUpload.action",
- file_post_name : "file",
- // 向后台传递额外的参数
- // post_params: {"id":"11111"},
- // 下面自己按照字面意思理解
- file_size_limit : file_size_limit, // 100MB 文件最大上限
- file_types : filetypes,
- file_types_description : "请选取需要上传的文件,格式如下:",
- file_upload_limit : file_upload_limit,// 上传最大文件数
- file_queue_limit : file_queue_limit,// 最大队列数
- // 事件处理
- file_dialog_start_handler : fileDialogStart,
- file_queued_handler : fileQueued,
- file_queue_error_handler : fileQueueError,
- file_dialog_complete_handler : fileDialogComplete,
- upload_start_handler : uploadStart,
- upload_progress_handler : uploadProgress,
- upload_error_handler : uploadError,
- // 上传成功后执行方法:fileObj可获取file.id、file.name、file.size等;server_data为后台传递参数。
- upload_success_handler : function myUploadSuccess(fileObj,
- server_data) {
- fileIdArray+=(server_data+",");
- try {
- var progress = new FileProgress(fileObj,
- this.customSettings.progressTarget);
- progress.setComplete();
- var fileSize = fileObj.size;
- var i = 0;
- while (fileSize > 1024 && i < 2) {
- fileSize = fileSize / 1024;
- i++;
- }
- var sizeDW;
- if (i == 0)
- sizeDW = "B";
- else if (i == 1)
- sizeDW = "K";
- else if (i == 2)
- sizeDW = "M";
- progress.setStatus(toDecimal2(fileSize) + sizeDW+ " 上传完成");
- progress.toggleCancel(false);
- var filelist = document.getElementById("progressContainer"+ fileObj.id);
- filelist.style.paddingLeft = "50px";
- filelist.style.background = "#F0F5FF url('"+ prjContextPath + "/swfUpload/file-icon/"+ fileObj.type.replace('.', '')+ ".png') no-repeat 5px 5px";
- // 删除附件按钮
- var deleteObject = document.createElement("a");
- deleteObject.className = "myProgressBt";
- deleteObject.href = "javascript:void(0);";
- deleteObject.appendChild(document.createTextNode("删除"));
- deleteObject.onclick = function() {
- //删除方法,server_data为后台返回的文件id或业务id
- this.parentNode.parentNode.style.display = 'none';
- var idObj = document.getElementById("arrId"+ fileObj.id);
- idObj.parentNode.removeChild(idObj);
- delFile(server_data);
- }
- filelist.appendChild(deleteObject);
- // action 返回的附件ID
- var idObj = document.createElement("input");
- idObj.setAttribute("type", "hidden");
- idObj.setAttribute("name", "arrId");
- idObj.setAttribute("value", server_data);
- idObj.setAttribute("id", "arrId" + fileObj.id);
- filelist.appendChild(idObj);
- var clearObj = document.createElement("div");
- clearObj.className = "clear";
- filelist.appendChild(clearObj);
- } catch (ex) {
- this.debug(ex);
- }
- },
-
- upload_complete_handler : uploadComplete,
-
- // 按钮的处理
- button_image_url : prjContextPath+ "/swfUpload/images/XPButtonUploadText_61x22.png",
- button_placeholder_id : "spanButtonPlaceholder1",
- button_width : 100,
- button_height : 26,
- // Flash Settings
- flash_url : prjContextPath + "/swfUpload/swfupload.swf",
- custom_settings : {
- progressTarget : "fsUploadProgress1",
- cancelButtonId : "btnCancel1"
- },
- // Debug Settings
- debug : false
- });
- if('1'==update_flag)
- $("#div_del").remove() ;
- }
- /*文件删除*/
- function delFile(server_data) {
- if (confirm("真的要删除此附件吗?删除后此附件将被删除并且无法恢复!")){
- $("#fileView"+server_data).remove();
- $.post(prjContextPath + "/fileUploadAction!delteFolder.action", {
- fileIdArray : server_data
- });
- }
- }
- /*文件显示回调函数开始*/
- var fileList=[];
- //备课及听评课需要,存储附件的主键ID
- var fileidLst=[];
- function callBackFunQueryFile(json){
- if(json!=null && json.data!=null){
- for (var i = 0; i < json.data.length; i++) {
-
- var pData=json.data[i];
- fileList.push(pData.fileid);
- //获取文件id
- fileIdArray+= pData.fileid+',';
- //获取json返回的路径和文件名,下载使用,此处下载需修改tomcat编码为utf-8,在server.xml中修改URIEncoding="utf-8"
- var f_path=pData.filepath+"/"+pData.fileLSMC;
- //文件下载目录
- var downpath=filepath+f_path;
- //文件回显
- var queryFile = '<div class="progressWrapper" id="fileView'+pData.fileid+'" style="filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);"><div class="progressContainer blue" id='+pData.fileid+' FP_TIMER="null">';
- queryFile+= '<div class="progressName" id='+pData.fileid+'>'+pData.filename+' ';
- if("0"==update_flag)
- queryFile += "<a href='#' onclick = 'delFile("+pData.fileid+")'>删除</a> <span>|</span> ";
- queryFile+= '<a href="'+downpath+'" target="_blank">下载</a></div></div></div>';
- $("#fsUploadProgress1").append(queryFile);
- //显示文件类型
- var fileView = document.getElementById('fileView'+pData.fileid);
- fileView.style.paddingLeft="50px";
- fileView.style.background="#F0F5FF url('"+prjContextPath+"/swfUpload/file-icon/"+pData.fileType.replace('.','')+".png') no-repeat 10px 10px";
- }
- }
- }
- /*文件显示回调函数开始*/
- function callBackFunQueryFile_sel(json){
- $("#mytr").hide();
- if(json!=null && json.data!=null){
- for (var i = 0; i < json.data.length; i++) {
-
- var pData=json.data[i];
- //获取文件id
- fileIdArray+= pData.fileid+',';
- //获取json返回的路径和文件名,下载使用,此处下载需修改tomcat编码为utf-8,在server.xml中修改URIEncoding="utf-8"
- var f_path=pData.filepath+"/"+pData.fileLSMC;
- //文件下载目录
- var downpath=filepath+f_path;
- //文件回显
-
-
-
- var queryFile = '<div class="progressWrapper" id="fileView'+pData.fileid+'" style="filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);"><div class="progressContainer blue" id='+pData.fileid+' FP_TIMER="null">';
- queryFile+= '<div class="progressName" id='+pData.fileid+'>'+pData.filename+' ';
- if("0"==update_flag)
- queryFile += " ";
- queryFile+= '<a href="'+downpath+'" target="_blank">下载</a></div></div></div>';
- $("#fsUploadProgress1").append(queryFile);
- //显示文件类型
- var fileView = document.getElementById('fileView'+pData.fileid);
- fileView.style.paddingLeft="50px";
- fileView.style.background="#F0F5FF url('"+prjContextPath+"/swfUpload/file-icon/"+pData.fileType.replace('.','')+".png') no-repeat 10px 10px";
- }
- }
- }
- /*文件显示回调函数结束*/
- // 制保留2位小数,如:2,会在2后面补上00.即2.00
- function toDecimal2(x) {
- var f = parseFloat(x);
- if (isNaN(f)) {
- return false;
- }
- var f = Math.round(x * 100) / 100;
- var s = f.toString();
- var rs = s.indexOf('.');
- if (rs < 0) {
- rs = s.length;
- s += '.';
- }
- while (s.length <= rs + 2) {
- s += '0';
- }
- return s;
- }
|