/*
var renderToContainer = "id_attachment_table_container";//渲染到哪个div的id
var attachmentType="测试";//附件分类
var serialNo ="aaa";//流水号唯一标识
var isReadOnly = false;//是否只能下载,不能上传和删除附件
var width =1000;//上传列表宽度
var height = 500;//上传列表高度
var title ="测试附件上传";//列表标题
var border = false;//是否产生边框
new commonAttachmentFileUpload(renderToContainer,//渲染到哪个div的id
attachmentType,//附件分类
identifierOne,//流水号唯一标识
identifierTwo,//流水号唯一标识
identifierThree,//流水号唯一标识
identifierFour,//流水号唯一标识
isReadOnly,//是否只能下载,不能上传和删除附件
width,//上传列表宽度
height,//上传列表高度
title,//列表标题,
border//是否产生边框
);*/
//上传表单组件
var tenArr = [ "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" ];
function createAttachmentFileContainers() {
var uploadWindow = mini.get('id_uploadAttachmentFileWindow');
if (uploadWindow == undefined) {
var uploadAttachmentFileWindow_html = "";
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
![]()
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
![]()
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += ' | 上传进度: | |
';
uploadAttachmentFileWindow_html += ' | 存储进度: | |
';
uploadAttachmentFileWindow_html += '
';
uploadAttachmentFileWindow_html += '
';
jQuery(document.body).append(jQuery(uploadAttachmentFileWindow_html));
mini.parse(document.getElementById('id_uploadAttachmentFileWindow'));
mini.parse(document.getElementById('id_uploadAttachmentProcessFileWindow'));
}
}
//添加一行文件上传的位置
function addUploadLocation(obj){
var index = Number($(obj).attr("locationindex")) + Number(1);
document.getElementById("id_upload_location").innerHTML+='';
$(obj).attr("locationIndex",index);
}
//删除当前行文件上传的位置
function deleteUploadLocation(index){
document.getElementById("id_upload_location").removeChild(document.getElementById("div_" + index));
}
//批量上传文件
function __uploadActionSubmit() {
uploadAttachmentFileFormUploadSubmit(getRootPath() + '/attachmentfile/uploadAttachmentFiles.action');
}
function __uploadActionCancel() {
mini.get("id_uploadAttachmentFileWindow").hide();
}
// 批量文件下载
function batchUploadFiles(table, batchDownloadAttachmentFileTitle) {
var attchmentDetailIdStr = "";
var include_file_ids = "";
var checkedRowsData = table.getCheckedRowDatas();
var len = checkedRowsData.length;
if (len < 1) {
mini.alert("请选择要批量下载的资料!");
return;
} else {
for ( var i = 0; i < len; i++) {
include_file_ids = checkedRowsData[i]["attachmentFileUploadInfoDetailIds"].split("@@_@@").join(",");
if (include_file_ids) {
attchmentDetailIdStr += include_file_ids;
}
if ((i != (len - 1)) && (checkedRowsData[i + 1]["attachmentFileUploadInfoDetailIds"])) {
attchmentDetailIdStr += ",";
}
}
}
if ("" == attchmentDetailIdStr) {
mini.alert("请选择要批量下载的资料!");
return;
}
var tableBatchDownloadFormId = "id_table_batchDownloadForm";
var batchForm = document.getElementById(tableBatchDownloadFormId);
if (batchForm) {
document.body.removeChild(batchForm);
}
batchForm = document.createElement("form");
with (batchForm) {
action = getRootPath() + "/attachmentfile/downloadBatchAttachmentFiles.action?browserType=" + SysBrowser.getBrowser().toLowerCase();
target = table.name_exportExcelFormIFrame;
style.display = "none";
method = "post";
innerHTML = "" + "";
}
document.body.appendChild(batchForm);
batchForm.submit();
return false;
}
// attachmentFileDictListImplBeanName自定义实现 id_attachmentFileUnionKey
var globalAttachmentUploadOperCallBack = function(columnName, $me, isReadOnly) {
$me.setColumnRenderer(function(value, tableObj, columnName, columnIndex, rowData) {
var fileListUUIDStr = rowData["attachmentFileUploadInfoDetailIds"];
if (!fileListUUIDStr) {
return "暂无文档";
} else {
var splitStr = "@@_@@";
var fileUUIDListArr = fileListUUIDStr.split(splitStr);
var fileAdListArr = (rowData.attachmentFileUploadInfoDetailActivityDetailIds).split(splitStr);
var fileNameListArr = (rowData.attachmentFileUploadInfoDetailChineseFileNames).split(splitStr);
var fileTypeListArr = (rowData.attachmentFileUploadInfoDetailUploadTimes).split(splitStr);
var fileUploadUserListArr = (rowData.attachmentFileUploadInfoDetailUploadUsers).split(splitStr);
var fileSizeListArr = (rowData.attachmentFileUploadInfoDetailFileSizes).split(splitStr);
var renderHtml = "";
var tempValueArr = [];
for ( var i = 0; i < fileUUIDListArr.length; i++) {
var fileSizeFlag = "Kb";
var fileSize = parseFloat(fileSizeListArr[i]);
if (1024 * 1024 > fileSize) {
fileSize = decimal(parseFloat(fileSizeListArr[i]) / 1024, 2);
} else {
fileSize = decimal(parseFloat(fileSizeListArr[i]) / 1024 / 1024, 2);
fileSizeFlag = "Mb";
}
var tempValue = " ";
tempValue += "" + fileNameListArr[i] + " | ";
tempValue += "【上传日期:" + fileTypeListArr[i] + "】 | ";
tempValue += "【上传人:" + fileUploadUserListArr[i] + "】 | ";
tempValue += "【大小:" + fileSize + " " + fileSizeFlag + "】 | ";
// tempValue += "
";
// tempValue+="  ";
if (!isReadOnly) {
if (window.currentTaskActivityDetailId && (window.currentTaskActivityDetailId == fileAdListArr[i])) {
tempValue += " + "/images/icon_delete.gif) | ";
}
}
tempValueArr.push(tempValue);
}
renderHtml += tempValueArr.join("
");
renderHtml += "
";
return renderHtml;
}
}, columnName);
};
// unionkey
var tracywindyAttachmentFileUpload = function(config) {
var module = config.module;
if (!module) {
mini.alert("文件上传的模块名称不能为空!");
return;
}
var batchDownloadAttachmentFileTitle = config.batchDownloadAttachmentFileTitle || "";
var attachmentType = config.attachmentType, // 附件分类
identifierOne = config.identifierOne || "", // 流水号唯一标识
identifierTwo = config.identifierTwo || "", // 流水号唯一标识
identifierThree = config.identifierThree || "", // 流水号唯一标识
identifierFour = config.identifierFour || "", // 流水号唯一标识
identifierFive = config.identifierFive || "", //
identifierSix = config.identifierSix || "", //
identifierSeven = config.identifierSeven || "", //
identifierEight = config.identifierEight || "", //
identifierNine = config.identifierNine || "", //
identifierTen = config.identifierTen || "", //
isReadOnly = config.isReadOnly || window.isCompletedTask;// 是否只能下载,不能上传和删除附件
createAttachmentFileContainers();
var tableConfig = {
isCheck : (false == config.isCheck) ? false : true,
isRank : (false == config.isRank) ? false : true,
tools : [ {
html : '' + "批量下载文件" + '',
iconCls : 'icon-layers',
handler : function(table) {
batchUploadFiles(table, batchDownloadAttachmentFileTitle);
}
} ],
isAutoBreakContent : true,
isForceTools : true,
columns : [// { header:'检查附件标示',name:'isAttachmentChecked'},
{
name : 'attachmentFileDictId',
header : '文件编号',
hidden : true
}, {
name : 'attachmentFileDictFileName',
header : '文件名称',
width : 300
}, {
name : 'attachmentFileUploadInfoId',
header : '文件上传编号',
hidden : true
}, {
name : 'attachmentFileUploadInfoDetailIds',
header : '上传明细文件编号',
hidden : true
}, {
name : 'attachmentFileUploadInfoDetailChineseFileNames',
header : '上传明细文件显示名称',
hidden : true
}, {
name : 'attachmentFileUploadInfoDetailEncodeFileNames',
header : '上传明细文件加密名称',
hidden : true
}, {
name : 'attachmentFileUploadInfoDetailFileSizes',
header : '上传明细文件文件大小',
hidden : true
}, {
name : 'attachmentFileUploadInfoDetailUploadTimes',
header : '上传明细文件上传日期',
hidden : true
}, {
name : 'attachmentFileUploadInfoDetailRemarks',
header : '上传明细文件文件说明',
hidden : true
}, {
name : 'operOne',
header : '上载',
align : 'center',
width : 80,
renderer : function(value, tableObj, columnName, columnIndex, rowData) {
if (!identifierOne) {
return "关键字为空不能上载文件";
} else {
return "附件上传";
}
}
}, {
name : 'operTwo',
header : '上载文件清单'
} ],
loadMode : 'ajax',
url : getRootPath() + '/attachmentfile/getAttachmentFileTableData.action',
callBack : function() {
var fileDetailWidth = this.width - this.rankSize - this.checkSize - 450;
if (!config.isRank) {
fileDetailWidth += this.rankSize;
}
if (!config.isCheck) {
fileDetailWidth += this.checkSize;
}
this.tableDiv.style.overflowX = "hidden";
if (config.isReadOnly) {
fileDetailWidth += 80;
this.setColumnHidden(true, 'operOne');
}
this.setColumnWidth(fileDetailWidth, 'operTwo');
globalAttachmentUploadOperCallBack('operTwo', this, config.isReadOnly);
},
checkedKey : 'isAttachmentChecked',
completeCallBack : function() {
if (window.lazyLoadedObj) {
lazyLoadedObj["attachment"] = true;
}
},
params : {
attachmentFileDictListImplBeanName : config.attachmentFileDictListImplBeanName || "",
attachmentFileUnionKeyFieldMapping : config.unionKey || "",
module : module,
attachmentType : attachmentType,
identifierOne : identifierOne,
identifierTwo : identifierTwo,
identifierThree : identifierThree,
identifierFour : identifierFour,
identifierFive : identifierFive,
identifierSix : identifierSix,
identifierSeven : identifierSeven,
identifierEight : identifierEight,
identifierNine : identifierNine,
identifierTen : identifierTen
}
};
for ( var p in config) {
if ("params" == p) {
continue;
}
tableConfig[p] = config[p];
}
if (config.params) {
for ( var p in config.params) {
tableConfig["params"][p] = config.params[p];
}
}
var attachmentTable = new tracywindyTable(tableConfig);
return attachmentTable;
};
// 上传列表所需函数变量
var currentUploadAttachmentFileTableId = null;
// 重置上传表单
function resetFileUploadAttachmentFileForm() {
$("#id_attachmentFileDictId").val("");
$("#id_attachmentFileUploadInfoId").val("");
for ( var i = 0; i < tenArr.length; i++) {
var item = tenArr[i];
var identifierItem = ("identifier" + item);
$("#id_" + identifierItem).val("");
}
$("#id_uploadAttachmentFileWhich").html("");
$("#id_uploadAttachmentFileTime").html(getCurDateTime());
$("#id_uploadAttachmentFileRemark").val("");
}
// 提交上传表单
function uploadAttachmentFileFormUploadSubmit(newAction) {
isSuccessFlag = false;
$("#id_attachmentFileProcessKey").val(new Date().getTime() + "_" + GenerateGuid());
var uploadAttachmentFileForm = $("#id_uploadAttachmentFileForm")[0];
with (uploadAttachmentFileForm) {
action = newAction;
submit();
}
try {
mini.get("id_uploadAttachmentFileWindow").hide();
mini.get("id_uploadAttachmentProcessFileWindow").show();
$('#id_uploadAttachmentProcessFilePercent').progressbar({
width : 300,
value : 0
});
$('#id_uploadAttachmentProcessSaveFilePercent').progressbar({
width : 300,
value : 0
});
window.intervalAjaxFileProcess = setInterval("ajaxFileProcess()", window.constantLoopSeconds);
} catch (e) {
}
return false;
}
var isSuccessFlag = false;
function uploadAttachmentFileFormSubmit(newAction) {
isSuccessFlag = false;
mini.mask({
el : document.body,
cls : 'mini-mask-loading',
html : '数据加载中,请稍后...'
});
$("#id_attachmentFileProcessKey").val(new Date().getTime() + "_" + GenerateGuid());
var uploadAttachmentFileForm = $("#id_uploadAttachmentFileForm")[0];
with (uploadAttachmentFileForm) {
action = newAction;
submit();
}
mini.get("id_uploadAttachmentFileWindow").hide();
return false;
}
function ajaxFileProcess() {
var attachmentFileProcessKey = jQuery("#id_attachmentFileProcessKey").val();
ajaxRequest({
url : getRootPath() + "/attachmentfile/getAttachmentFileUploadedPercent.action?browserType=" + SysBrowser.getBrowser().toLowerCase(),
success : function(res) {
var fileProcess = JsonUtil.decode(res.responseText);
var filePercent = fileProcess.uploadedPercent;
var uploadedFinish = fileProcess.uploadedFinish;
// jQuery("#id_uploadAttachmentProcessFilePercent").val(filePercent);
if (!uploadedFinish) {
$('#id_uploadAttachmentProcessFilePercent').progressbar('setValue', parseFloat(filePercent));
if ((100 == parseFloat(filePercent))) {
// alert(uploadedFinish);
// jQuery("#id_uploadAttachmentProcessFileWindow").window("close");
// window.clearInterval(intervalAjaxFileProcess);
}
} else {
$('#id_uploadAttachmentProcessFilePercent').progressbar('setValue', parseFloat(100));
$('#id_uploadAttachmentProcessSaveFilePercent').progressbar('setValue', parseFloat(filePercent));
if ((100 == parseFloat(filePercent))) {
mini.get("id_uploadAttachmentProcessFileWindow").hide();
window.clearInterval(window.intervalAjaxFileProcess);
if (!isSuccessFlag) {
mini.mask({
el : document.body,
cls : 'mini-mask-loading',
html : '数据加载中,请稍后...'
});
}
}
}
},
params : {
attachmentFileProcessKey : attachmentFileProcessKey
}
});
}
// 上传附件
function addUploadFile(tableId, rowIndex, flag) {
currentUploadAttachmentFileTableId = tableId;
var attachmentTable = getTracywindyObject(tableId);
var rowData = attachmentTable.getRowDataAt(rowIndex);
resetFileUploadAttachmentFileForm();
if ("add" == flag) {
$("#id_attachmentFileDictId").val(rowData["attachmentFileDictId"]);
$("#id_attachmentFileUploadInfoId").val(rowData["attachmentFileUploadInfoId"]);
if (attachmentTable.unionKey) {
$("#id_attachmentFileUnionKey").val(rowData[attachmentTable.unionKey] || "");
}
for ( var i = 0; i < tenArr.length; i++) {
var item = tenArr[i];
var identifierItem = ("identifier" + item);
if (attachmentTable.params[identifierItem]) {
$("#id_" + identifierItem).val(attachmentTable.params[identifierItem]);
}
}
$("#id_attachmentFileModule").val(attachmentTable.params["module"]);
$("#id_uploadAttachmentFileWhich").html(rowData["attachmentFileDictFileName"]);
// $("#id_uploadAttachmentFileRemark").val("");
//$('#id_uploadAttachmentFileForm')[0].reset()
mini.get("id_uploadAttachmentFileWindow").show();
}
}
var constantLoopSeconds = 1000;
// 上传附件回调函数
function uploadAttachmentFileCallBack(msg) {
isSuccessFlag = true;
mini.alert(msg);
if (window.currentUploadAttachmentFileTableId) {
getTracywindyObject(window.currentUploadAttachmentFileTableId).reload();
}
try {
mini.get("id_uploadAttachmentProcessFileWindow").hide();
} catch (e) {
}
if (window.intervalAjaxFileProcess) {
window.clearInterval(window.intervalAjaxFileProcess);
}
setTimeout("if(window.intervalAjaxFileProcess){window.clearInterval(window.intervalAjaxFileProcess);}mini.unmask(document.body);", window.constantLoopSeconds);
mini.unmask(document.body);
}
//上传结果
function uploadAttachmentFileResultCallBack(msg){
isSuccessFlag = true;
mini.alert(msg);
if (window.currentUploadAttachmentFileTableId) {
getTracywindyObject(window.currentUploadAttachmentFileTableId).reload();
}
try {
mini.get("id_uploadAttachmentProcessFileWindow").hide();
} catch (e) {
}
mini.unmask(document.body);
}
// 下载附件
function downloadUploadFile(uploadAttachmentFileDetailId) {
mini.mask({
el : document.body,
cls : 'mini-mask-loading',
html : '数据加载中,请稍后...'
});
createAttachmentFileContainers();
var newAction = getRootPath() + "/attachmentfile/downloadAttachmentFile.action?browserType=" + SysBrowser.getBrowser().toLowerCase();
newAction += "&uploadAttachmentFileDetailId=" + uploadAttachmentFileDetailId;
uploadAttachmentFileFormSubmit(newAction);
mini.unmask(document.body);
}
// 删除附件
function removeUploadFile(tableId, uploadAttachmentFileDetailId) {
mini.confirm("确定删除该附件么?", "删除?", function(action) {
if (action == 'ok') {
mini.mask({
el : document.body,
cls : 'mini-mask-loading',
html : '数据加载中,请稍后...'
});
currentUploadAttachmentFileTableId = tableId;
var newAction = getRootPath() + "/attachmentfile/removeAttachmentFile.action";
newAction += "?uploadAttachmentFileDetailId=" + uploadAttachmentFileDetailId;
uploadAttachmentFileFormSubmit(newAction);
}
});
}
// 上传文件
function onUploadImgChange(sender) {
// 单纯只为了文件名
var filePath = sender.value;
var fileExt = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
if (!checkFileExt(fileExt)) {
mini.alert("不允许上传扩展名为《" + fileExt + "》的文件,请重新选择!");
return;
}
/*
* var objPreview = document.getElementById( 'preview' ); objPreviewFake =
* document.getElementById( 'preview_fake' ), objPreviewSizeFake =
* document.getElementById( 'preview_size_fake' ); var file = null; var
* fileSize = 0; if(!checkLocalFileType(fileExt)){
* mini.unmask(document.body); return; } try{ //先采用HTML5方法 if(typeof
* FileReader !== 'undefined'){ file = sender.files[0]; fileSize =
* file.fileSize || file.size; if(checkFileSize(fileSize)){ var reader = new
* FileReader(); reader.readAsDataURL(file); reader.onload = function(e){
* objPreview.src = this.result; }; } }else if( sender.files){
* //非IE,不支持HTML5方法 file = sender.files[0]; fileSize = file.fileSize;
* if(checkFileSize(fileSize)){ filePath = file.getAsDataURL();
* objPreview.src = filePath; }
*
* }else if( objPreviewFake.filters ){ if(!checkPicture(fileExt)){
* mini.unmask(document.body); return; } // IE7,IE8 在设置本地图片地址为 img.src
* 时出现莫名其妙的后果 //(相同环境有时能显示,有时不显示),因此只能用滤镜来解决 // IE7, IE8因安全性问题已无法直接通过
* input[file].value 获取完整的文件路径 sender.select(); var imgSrc =
* document.selection.createRange().text;
* //objPreviewFake.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src =
* imgSrc;
* //objPreviewSizeFake.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src =
* imgSrc; //autoSizePreview( objPreviewFake,objPreviewSizeFake.offsetWidth,
* objPreviewSizeFake.offsetHeight ); //objPreview.style.display = 'none';
* //读取图片文件大小 var sh = setInterval(function(){ var img =
* document.createElement("img"); img.src = imgSrc; fileSize = img.fileSize;
* if (fileSize > 0){ checkFileSize(fileSize); clearInterval(sh); } img =
* null; } ,1000); } } catch(e) { mini.unmask(document.body); //
* alert("调用后台方法"); }
*/
}
// 本地检测附件大小
function checkLocalFileType(ext) {
if (!ext.match(/.jpg|.jpeg|.gif|.png|.bmp|.txt|.doc|.docx|.xls|xlsx/i)) {
return false;
}
return true;
}
// 检测是否是图片
function checkPicture(ext) {
if (!ext.match(/.jpg|.jpeg|.gif|.png|.bmp/i)) {
return false;
}
return true;
}
// 检测文件类型
function checkFileExt(ext) {
/*
* if (!ext.match(/.jpg|.jpeg|.gif|.png|.bmp|.doc|.txt/i)) { return false; }
*/
return true;
}
// 检测文件大小
function checkFileSize(fileSize) {
mini.unmask(document.body);
/*
* if(fileSize > 1024*1024){ alert("您上传的文件大于1M,请重新选择!"); return false; }
*/
return true;
}
// 预览
function onPreviewLoad(sender) {
autoSizePreview(sender, sender.offsetWidth, sender.offsetHeight);
}
// 居中显示
function autoSizePreview(objPre, originalWidth, originalHeight) {
var zoomParam = clacImgZoomParam(300, 300, originalWidth, originalHeight);
objPre.style.width = zoomParam.width + 'px';
objPre.style.height = zoomParam.height + 'px';
objPre.style.marginTop = zoomParam.top + 'px';
objPre.style.marginLeft = zoomParam.left + 'px';
}
// 图像缩放
function clacImgZoomParam(maxWidth, maxHeight, width, height) {
var param = {
width : width,
height : height,
top : 0,
left : 0
};
if (width > maxWidth || height > maxHeight) {
rateWidth = width / maxWidth;
rateHeight = height / maxHeight;
if (rateWidth > rateHeight) {
param.width = maxWidth;
param.height = height / rateWidth;
} else {
param.width = width / rateHeight;
param.height = maxHeight;
}
}
param.left = (maxWidth - param.width) / 2;
param.top = (maxHeight - param.height) / 2;
return param;
}