一个公式组件,求思路

[复制链接]
查看: 3581   回复: 5

8

主题

3

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
20877
2023-8-3 19:01:06   显示全部楼层   阅读模式  
公司有要求二开发一个公式组件,具体就是:选两个表单上的组件。选操作符:加减乘除,选择的组件值变动时就根据操作符进行对两个值进行运算结果加到这个组件上。
主表子表都要实现。我现没有思路,谁能给我点思路应该怎么做呢?
我知道答案 回答被采纳将会获得400 威望 已有5人回答
回复

使用道具 举报

0

主题

3

回帖

459

积分

中级会员

Rank: 3Rank: 3

积分
459
2023-8-21 16:56:28   显示全部楼层  
同求思路
回复

使用道具 举报

0

主题

10

回帖

134

积分

注册会员

Rank: 2

积分
134
2024-5-17 10:08:41   显示全部楼层  
在字段的 onChange事件里 增加计算代码,emitFieldDataChange(newValue, oldValue) {
      this.emit$('field-value-changed', [newValue, oldValue]),
      this.broadcast("FieldWidget", "sync-field-value", [this.field.options.name, this.field.options.keyName, this.subFormName, this.subFormRowId, newValue, this.getObjectName()]),
      this.getFormRef().broadcast("FieldWidget", "calculate-formula", [newValue, this]),
      /* 必须用dispatch向指定父组件派发消息!! */
      this.dispatch('VFormRender', 'fieldChange',[this.field.options.name, newValue, oldValue, this.subFormName, this.subFormRowIndex])
    },


this.on$("calculate-formula", (e)=>{
        if (!!this.field.options.formulaEnabled && !!this.field.options.formula) {
            //console.log(e)
            const oChangeField = e[1];
            const t = this.field.options.name;
              //console.log(this.field.options.formula, o)
           // this.getFormRef().getWidgetRef.getWidgetRef
            let ret = calcExpression(this.field.options.formula,this.getFormRef(), this.getGlobalDsv(),this,oChangeField);
           // console.log(this.field.type)
           if(ret !== null){
            if(this.field.type=='number'){
              if(getDataType(ret) == "Number"){
                this.setValue(ret,true);
              }else if(getDataType(ret)==="String"){
                this.setValue(parseFloat(ret),true);
              }
            }else
            this.setValue(ret,true);
           }      
        }                 
    })
回复

使用道具 举报

0

主题

10

回帖

134

积分

注册会员

Rank: 2

积分
134
2024-5-17 10:32:35   显示全部楼层  
calcExpression 这个可以使用hot-formula-parser 来完成计算
回复

使用道具 举报

8

主题

3

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
20877
UNION (楼主)
2024-6-27 20:28:45   显示全部楼层  
本帖最后由 UNION 于 2024-6-27 20:30 编辑

。。。。。。。。。
回复

使用道具 举报

0

主题

8

回帖

8

积分

新手上路

Rank: 1

积分
8
QQ
2024-8-8 10:16:28   显示全部楼层  

你好,请问解决了嘛
回复

使用道具 举报

您需要登录后才可以回帖   登录 注册账号

高级模式