bpmnjs如何创建ExtensionElements扩展属性与多实例MultiInstanceLoopCharacte

原作者链接

//例子:创建扩展属性用于存放表单权限数据
export default{
    data()
        return{
            prefix:'flowable',
            moddle:'',
            currentElement:'',//当前选中的节点element值(shape)
            modeling:'',
            propertiesForm:{
                signType:''//串行/并行的值
            }
        }
    },
    computed:{
        descriptorPrefix(){
            return this.prefix +':'
        }
    },
    methods:{
        async createFormRightExtensionElements(options){
            if(options &&  options.formRight){
                let formRightData = await this.moddle.create(this.descriptorPrefix+'Formright',{
                    name:'formright',
                    uri:'http://'+this.prefix+'.org/bpmn',
                    body:JSON.stringify(options.formRight)
                })
                this.createExtensionElements([formRightData], this.descriptorPrefix+'Formright')
            }
        },
        async createExtensionElements(propertiesValues, type, targetElement){
            let originExtensionItems = await this.deleteExtensionElement(type, targetElement)
            originExtensionItems = propertiesValues.length?originExtensionItems.concat(propertiesValues):originExtensionItems
            if(originExtensionItems.length){
                const extensionItems = await this.moddle.create(this.descriptorPrefix+"Properties",{
                    values:originExtensionItems,
                    uri:"http://"+this.prefix+".org/bpmn"
                })
                const extensions = await this.moddle.create('bpmn:ExtensionElements',{values:[extensionItems]})
                this.updateExtensionElements(extensions, targetElement)
            }
        },
        async deleteExtensionElement(type, targetElement){
            let allExtensions = await this.getAllExtensions(targetElement)
            allExtensions.forEach((item,index)=>{
                if(item.$type == type){
                    allExtensions.splice(index,1)
                }
            })
            return allExtensions
        },
        async getAllExtensions(targetElement){
            targetElement = targetElement?targetElement:this.currentElement
            let extensions = targetElement.businessObject.extensionElements
            return extensions?.values?.[0]?.values
        },
        updateExtensionElements(extensions,targetElement){
            targetElement = targetElement?targetElement:this.currentElement
            this.modeling.updateProperties(targetElement,{extensionElements:extensions});
        },
        //以上方法是创建扩展属性的过程,下面的方法是创建多实例的过程
        updateMultiInstanceLoopCharacteristics(bool){
            if(bool){
                let loopCharacteristics = this.moddle.create("bpmn:MultiInstanceLoopCharacteristics")
                loopCharacteristics.$attrs[this.descriptorPrefix+'collection'] = 'assigneeList'
                loopCharacteristics.$attrs[this.descriptorPrefix+'elementVariable'] = 'assignee'
                let isSequential = this.propertiesForm.signType == "1"? true : false //true为串行一个个完成才通过
                //串行和并行
                loopCharacteristics['isSequential'] = isSequential //设置是串行还是并行
                loopCharacteristics.$attrs['isSequential'] = isSequential //属性
                let taskCondition = isSequential?'${flowTaskMultiInstance.accessCondition(execution1)}' : '${flowTaskMultiInstance.accessCondition(execution2)}'
                let completionCondition = this.bpmnFactory.create("bpmn:FormalExpression",{body:taskCondition})
                //let completionCondition = this.bpmnFactory.create("bpmn:FormalExpression",{body:'${nrOfCompletedInstances == 1}'})//一个通过就行
                completionCondition.$parent = this.currentElement
                loopCharacteristics['completionCondition'] = completionCondition
                //loopCharacteristics['inputDataItem'] = inputDataItem
                //loopCharacteristics['loopCardinality'] = loopCardinality

                this.modeling.updateProperties(this.currentElement,{loopCharacteristics:loopCharacteristics});
            }else{
                this.currentElement && delete this.currentElement.businessObject.loopCharacteristics
            }
        },
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值