菜单
一、流程提交前验证事件
需求:流程点击提交前,需要进行一些数据判断,例如子表遍历判断控制。下面提供一个例子,某些公司要求加班的时间不能少于1个小时,否则无法提交。
checkCustomize = function(){
var issubmit=true;
var rowindex = WfForm.getDetailAllRowIndexStr("detail_1").split(",");//获取明细表1行标示
jQuery.each(rowindex,function(index,p_index){
var fplx = WfForm.getFieldValue("field8963_"+p_index);
if(fplx<1){
issubmit = false;
WfForm.showMessage("第"+(index+1)+"行加班时长小于1小时,不符合考勤制度,不可以提交",2,8);
}
});
return issubmit;
}
扩展学习:太多if else if 在代码阅读上并不美观。可参考javacript的switch例子
二、Switch:
需求一:根据不同条件进行相应的操作。可使用switch(true)
switch (true){
case asd>=1 && asd<=2:
console.log(11)
x="1";
break;
case asd>=3 && asd<=4:
x="2";
console.log(22)
break;
default:
x="3";
break;
}
需求二:根据某个变量,进行相应的操作。
let fruit = "苹果";
switch (fruit) {
case "苹果":
case "梨子":
case "香蕉":
console.log("这是一种水果");
break;
case "胡萝卜":
case "土豆":
console.log("这是一种蔬菜");
break;
default:
console.log("未知类型");
}
三、泛微流程提交前数据校验
需求:例如电子发票要求源文件上传,则需要判断发票的录入方式,如果是电子发票的话,只允许邮箱或文件录入的方式。根据以上switch是可以达到要求,但在扩充上没能很多达到松耦合的概念。我们可以通过定义常量,通过数组的indexOf方式来判断是否存在?下面是新的提交校验事件和数组判定例子
WfForm.registerCheckEvent(WfForm.OPER_SUBMITCONFIRM, function(callback){
var i,fply,fplx,x,y;
var str1 = ["增值税电子专用发票","增值税电子普通发票"];
var str2 = ["邮箱","文件录入"];
var StageFlag = 0;
console.log("aa");
var rowindex = WfForm.getDetailAllRowIndexStr("detail_1").split(",");//获取明细表1行标示
jQuery.each(rowindex,function(index,p_index){
fplx = WfForm.getFieldValue("field8321_"+p_index);
fply = WfForm.getSelectShowName("field13701_"+p_index);
x=str1.indexOf(fplx);
y=str2.indexOf(fply);
if(x>=0&&y<0){
WfForm.showMessage("第"+(index+1)+"行电子发票来源不是邮箱或文件录入,不可以提交",2,8);
StageFlag = 1;
return;
}
});
console.log("bb");
if(StageFlag==1){
return;
}
callback();
});
四、泛微OA如何赋值附件字段
由于泛微OA并未提供附件赋值的功能,因此可以通过字段赋值并调用保存接口执行
需求:在明细表的附件列增加“批量填充按钮”,点击按钮后实现附件批量填充
注意:此需求有几个开发功能点
- React新增按钮,并绑定一个onclick事件
- 获取该行的附件,和需要覆盖行的附件,注意防止重复追加和保留原附件
第一步:在列表上追加批量填充按钮
const rowIndexStr = WfForm.getDetailAllRowIndexStr("detail_1");
const fieldPrefix = "field13492_";
rowIndexStr.split(",").map(index => {
WfForm.afterFieldComp(fieldPrefix + index, React.createElement("button", {
onClick: () => fillFile(index,rowIndexStr),
className: "ant-btn ant-btn-primary",
type: "button",
children: "附件批量填充"
}));
});
第二步:编写批量填充的函数
function fillFile(rowIndex,detailLineNum){
var FFile = WfForm.getFieldValue("field13492_"+rowIndex);
var CurrentPurType = WfForm.getFieldValue("field13481_"+rowIndex);
if(CurrentPurType==4){
WfForm.showConfirm("线上平台无须上传合同", function(){
});
return;
}
var rowItem = rowIndex*1+1;
if(detailLineNum !=""){
detailLineNum = detailLineNum.split(",");
DLength = detailLineNum.length;
if(rowItem<DLength){
console.log(rowIndex+"==="+DLength);
for(var ii=rowItem;rowItem<=DLength;rowItem++){
var PurType = WfForm.getFieldValue("field13481_"+rowItem);
//console.log(PurType);
if(PurType==""||PurType==4){
continue;
}
var FileItem = WfForm.getFieldValue("field13492_" + rowItem);
var FileContent = FFile.split(",");
if(FileItem!=""){
FileItem.split(",").forEach(function(item) {
// 在这里处理每个分割后的元素
if (!FileContent.includes(item)) {
FileContent.push(item);
}
});
}
//console.log("第"+(rowItem*1+1)+"行,附件内容:"+FileContent.join(","))
//WfForm.changeFieldValue("#field13492_"+rowItem, {value:FileContent});
$("#field13492_" + rowItem).val(FileContent.join(","));
}
}
}
WfForm.doRightBtnEvent("BTN_WFSAVE");
}
五、附件联动
// 全局变量
let enable = true;
let nodeid = null;
let workflowId = null;
// 更新后的配置信息数组,支持一个nodeId下多个fileFieldid与linkfileFieldid的对应
const configInfo = [
{
workflowId: 87,
nodeId: 461,
fields: [
{ fileFieldid: 'field9140', linkfileFieldid: 'field9297' },
]
},
{
workflowId: 146,
nodeId: 832,
fields: [
{ fileFieldid: 'field11483', linkfileFieldid: 'field11882' },
{ fileFieldid: 'field11482', linkfileFieldid: 'field11883' },
]
}
];
// 设置节点ID对应的配置信息
function getConfigsForNodeId(nodeId) {
console.log("进入了获取联动信息函数");
const config = configInfo.find(item => item.nodeId === nodeId);
console.log(config);
return config ? config.fields : [];
}
// 使用ID调用API
async function callApiWithId(id) {
const options = {
url: '/api/doc/save/getAccListForEdit',
method: 'GET',
params: { id },
type: 'json',
deep: true,
checkCode: false
};
const ApiResponse = await window.weaJs.callApi(options);
return ApiResponse;
}
// 检查条件是否满足
const checkConditions = () => {
const { hash } = window.location;
if (!hash.startsWith('#/main/workflow/req') || !WfForm) return false;
const baseInfo = WfForm.getBaseInfo();
({ nodeid } = baseInfo);
const isNodeIdAllowed = configInfo.some(item => item.nodeId === nodeid);
return isNodeIdAllowed;
};
// 覆写 WeaUpload 组件
ecodeSDK.overwritePropsFnQueueMapSet('WeaUpload', {
fn: async (newProps) => {
if (!enable || !checkConditions()) return;
console.log("条件已满足!");
const fieldConfigs = getConfigsForNodeId(nodeid);
fieldConfigs.forEach(config => {
const { fileFieldid, linkfileFieldid } = config;
async function processIds(idArray) {
const fileLinkdatas = [];
for (const id of idArray) {
const ApiResponse = await callApiWithId(parseInt(id, 10));
console.log("请求 id 的 API:", id);
console.log("ApiResponse:", JSON.stringify(ApiResponse));
if (ApiResponse.dataList && ApiResponse.dataList.length > 0) {
const dataListItem = ApiResponse.dataList[0];
const fileData = {
fileExtendName: dataListItem.fileExtendName,
fileid: dataListItem.id,
filelink: dataListItem.filelink,
filename: dataListItem.filename,
filesize: dataListItem.filesize,
imgSrc: "/images/filetypeicons/txt_wev8.png",
loadlink: dataListItem.loadlink,
showLoad: true,
showDelete: true,
isImg: false,
imagefileid: dataListItem.fileid,
secretLevel: "4",
secretLevelValidity: "",
secretLevelValidityValue: "",
};
fileLinkdatas.push(fileData);
}
}
console.log("构建后的 fileLinkdatas:", fileLinkdatas);
return Promise.resolve(fileLinkdatas);
}
async function startProcessing(idArray, value) {
const fileLinkdatas = await processIds(idArray);
console.log("processIds 执行完毕,开始设置字段值");
const fileFieldValueObj = {
"value": value,
"specialobj": {
"filedatas": fileLinkdatas,
"showBatchLoad": false
}
};
console.log("构建的 fileFieldValueObj:", fileFieldValueObj);
WfForm.changeFieldValue(fileFieldid, fileFieldValueObj);
}
console.log("linkfileFieldid:", linkfileFieldid);
WfForm.bindFieldChangeEvent(linkfileFieldid, function (obj, id, value) {
console.log("字段变化触发 startProcessing 调用,值为:", value);
var idArray = value.split(',');
startProcessing(idArray, value);
});
});
},
order: 1,
desc: '附件联动功能 V3'
});