workflow自定义控件custom配置一例
一自定义包含iframe控件用于浏览pdf文件
表单初始化后加载脚本js写法
var frmStr = '<iframe id="custom1_frame" src="" scrolling="auto" frameborder="0" style="width:100%;height:99.2%;"></iframe>';
$('#custom1')[0].innerHTML=frmStr;
自定义控件显示文件的功能(jpg,pdf)
var t_cgpath = GetValue('fd_cgpath');
var tPath = "../dir_ath/file/"+t_cgpath;
$('#custom1_frame')[0].src=tPath;
图片和自定义控件切换显示功能
var t_cgpath = GetObject('grid1').GetSelected().cgpath;
if(t_cgpath && t_cgpath.indexOf('.jpg')!=-1){
var tPath = "../dir_ath/file/"+t_cgpath;
SetValue('image1',tPath);
GetObject('image1').Show();
GetObject('custom1').Hide();
}else{
var tPath = "../dir_ath/file/"+t_cgpath;
$('#custom1_frame')[0].src=tPath;
}
一自定义包含easy-filebox上传文件控件用于上传文件
表单加载脚本事件
var t_pid = GetUrlJson().pid;
t_pid = decodeURI(t_pid);
SetValue('vpath',t_pid);
//
var frmStr = '<input class="easyui-filebox" id="b_obj" name="b_obj" style="width:98%" ';
frmStr+='data-options="buttonText:\'选择要上传的文件\',prompt:\'选择文件\'" />';
$('#custom1')[0].innerHTML=frmStr;
//
var custom = GetObject('custom1');
custom.b_obj = new fileboxClass('b_obj','custom1');
custom.b_obj.init();
custom.b_obj.accept("*\/*");
//
custom.b_obj.onChange(function () {
var fileName = custom.b_obj.getValue();
//alert(fileName);
if (custom.b_obj && custom.b_obj.easyObj()[0]) {
//获取文件类型名称
var file_typename = fileName.substring(fileName.lastIndexOf('.'), fileName.length);
//计算文件大小
var fileSize = 0;
var file = custom.b_obj.file();
if (file) {
//获取文件名称
//fileName = file.name;
//如果文件大小大于1024字节X1024字节,则显示文件大小单位为MB,否则为KB
if (file.size > 1024 * 1024) {
fileSize = Math.round(file.size * 100 / (1024 * 1024)) / 100;
fileSize = fileSize.toString() + 'MB';
}
else {
fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
}
SetValue('filename','文件大小: '+ fileSize);
//
}
else {
SetValue('filename','文件大小: '+ fileSize);
}
}
});
保存上传文件的功能
注意:vpath,为textbox文本控件,必须为可读写操作,存储的是上传的目录路径值
后台./ADF/cform/fileToVDirHandler.ashx接收参数为固定指定的参数名为vpath
var vpath = GetValue('vpath');
var t_newdirname = GetValue('textbox1');
//
var rootPdir = "../dir_ath/file"+vpath;
var custom = GetObject('custom1');
var t = custom.b_obj.getValue();
if (t == null || t == "")
{
ShowAlert('请先选择要上传的附件');
return;
}
var c = custom.b_obj.fileCount();
if (c <= 0) {
ShowAlert('请先选择要上传的附件');
return;
}
if (t != "" && c <= 0) {
ShowAlert('选择附件类型不正确,请重新选择附件!');
return;
}
//判断文件大小验证
//计算文件大小
var FileMaxSize = 2048; //2G
var fileSize = 0;
var file = custom.b_obj.file();
if (file) {
//获取文件名称
//fileName = file.name;
//如果文件大小大于1024字节X1024字节,则显示文件大小单位为MB
if (file.size > 1024 * 1024) {
fileSize = Math.round(file.size * 100 / (1024 * 1024)) / 100;
if (fileSize > FileMaxSize) {
ShowAlert('文件超过' + FileMaxSize + 'MB,禁止上传!');
return;
}
fileSize = fileSize.toString() + 'MB';
}
}
var t_data = {};
AppendToJson(t_data, "vpath", vpath, true);
//上传保存图片
$('#WfCForm').form('submit', {
type: "post",
dataType: "json",
data: t_data,
url: "../ADF/cform/fileToVDirHandler.ashx",
success: function (r) {
//ShowAlert(r);
if (r != "F") {
//路径字符串 ../dir_ath/file/
//
parent.CloseForm();
//ShowAlert('保存成功');
}
else {
ShowAlert('保存未成功,请重新保存!');
}
},
error: function (msg) {
ShowAlert(msg.responseText);
}
});