我很含蓄, 什么也没有留下!

平台现有能力-hooks-数据重复性检查

智驱平台2025-5-12 13:57 阅读 36 评论 0 热度 1

需求背景
 ISV目前在使用低代码开发时,经常有一些前端校验的业务功能,以前大多数只能高代码定制实现,现在平台提供了hooks能力(前面简单的js脚本)就可以实现,下面是其中关于hooks能力中的数据重复性校验的功能使用样例

实现方式

数据重复性检查校验

1、同步规则重复性检查只有表格可用(检查当前字段是否有重复数据-当前展示数据)


 //id为表格id 
var table = component.getComponentById("e0a94d0a-0b42-fe51-d1fa-93fea2717391") 
var valuesum = 0
 for (var i = 0; i < table.getAllRowData().length; i++) { 
 //获取的product_no为当前添加校验栏位的字段 
 var tablevalue = table.getAllRowData()[i].value.product_no; 
 if (value === tablevalue) { valuesum++ }
 } 
if (valuesum > 1) { 
 component.getControl().setErrors({ repeat: { key: 'repeat', type: 'error', errorMessage: '数据重复', }, }) 
}

2、异步规则表单、表格都可使用(检查该字段数据是否有重复数据-接口中所有数据)



// 获取编号值 
const novalue = parentData.contract_no
 // 请求esp请求入参---请求contract_no字段
 const parameter = { "zh_contract": [ { "contract_no": novalue } ] } 
// 发送esp请求
 options.utils.espApi.getEspByActionId({
 actionId: "dtdapp.zh.contract.list.get", parameter, }).subscribe((res) => { 
 // 打印接口返回结果
 console.log('res', res)
 if(res.data.zh_contract.length > 0){ 
 component.getControl().setErrors({ customInvalid: { key: 'customInvalid', type: 'error', errorMessage: '编号重复', }, }); } 
}, () => { });

路过

雷人

握手

鲜花

评论

您需要登录后才可以发表言论 登录立即注册
facelist
  • 200帖子
  • 0关注
  • 0粉丝
  • 关注公众号
Copyright © 2025 鼎捷数智股份有限公司 版权所有 All Rights Reserved. Powered by Discuz! X5.0
关灯
即将开放
返回顶部
返回顶部