泛微OA二次开发SDK使用记录
目标:特定字段实现级联操作
1.SDK说明
proxyFieldContentComp: function(fieldid,fn)
接口参数说明
参数 | 参数类型 | 必须 | 说明 |
---|---|---|---|
field | String | 是 | 主表/明细表字段ID,格式$fieldid$ |
fn | Function | 是 | 代理的函数,此函数必须有返回值,返回自定义渲染的组件 |
代理的函数参数说明
参数 | 参数类型 | 必须 | 说明 |
---|---|---|---|
info | JSON | 是 | 字段基础信息,包括字段值、字段属性等等 |
compFn | Function | 是 | 代理前原字段组件函数,可通过此函数获取原组件 |
2.代码块例子
WfForm.proxyFieldContentComp("111", function(info, compFn) {
console.log("字段id:", info.fieldid);
console.log("明细行号:", info.rowIndex);
console.log("字段只读必填属性:", info.viewAttr);
console.log("字段值:", info.fieldValue);
// 定义级联组件的选项
const options = [
{
value: 'zhejiang',
label: '浙江',
children: [
{
value: 'hangzhou',
label: '杭州',
children: [
{
value: 'xihu',
label: '西湖',
},
],
},
],
},
{
value: 'jiangsu',
label: '江苏',
children: [
{
value: 'nanjing',
label: '南京',
children: [
{
value: 'zhonghuamen',
label: '中华门',
},
],
},
],
},
];
// 级联组件的变化事件
function onChange(value) {
console.log("选中的值:", value);
// 可以将选中的值同步到表单字段
WfForm.changeFieldValue(info.fieldid, {
value: value.join("/"), // 将级联值合并为字符串
});
}
// 返回自定义渲染的级联组件
return React.createElement(antd.Cascader, {
options: options,
onChange: onChange,
placeholder: "请选择地区",
});
});
// 如果此接口调用在代码块、custompage等(非模块加载前调用),需强制渲染字段一次
WfForm.forceRenderField("field111");