- Description:
- Source:
表单/自定义页面字段相关方法
Methods
(static) activateTabItems(context, tabFieldId)
- Description:
- 激活Tab组件中所有Tab项,此方法用于解决在表单上使用Tab组件时嵌套在Tab内的组件会报错,
且无法通过JS API获取组件实例。
一般在 didMount 中调用此函数即可。
- Source:
Example
export function didMount() {
activateTabItems(this, "tabsLayout_lhzy2spv");
}
Parameters:
| Name |
Type |
Description |
context |
Object
|
this上下文 |
tabFieldId |
string
|
TAB组件唯一标识符 |
(static) fieldToString(value, fieldType) → {string}
- Description:
- Source:
Example
// 日期字段
const date = this.$("dateField_lrh5sl2w").getValue(); // 1704067200000
fieldToString(date, getFieldTypeById("dateField_lrh5sl2w")); // "2024-01-01"
// 人员字段
const employee = this.$("dateField_lrh5sl2w").getValue(); // [{ name: "张三", value: "1343242225778381" }, { name: "李四", value: "1343242225778382" }]
fieldToString(date, getFieldTypeById("employeeField_lrh6iy5m")); // "[张三,李四]"
Parameters:
| Name |
Type |
Description |
value |
any
|
字段值 |
fieldType |
FieldType
|
字段类型 |
Returns:
字符串
-
Type
-
string
(static) fieldValueDiff(fieldType, newVal, oldVal) → {module:Field~FieldValueDiff}
- Description:
- Source:
Example
// [{ name: "张三", value: "1343242225778381" }, { name: "李四", value: "1343242225778382" }]
const employeeA = this.$("employeeField_lrh5sl2v").getValue();
// [{ name: "张三", value: "1343242225778381" }, { name: "王二", value: "1298349283929102" }]
const employeeB = this.$("employeeField_lrhbdj3c").getValue();
const fieldType = getFieldTypeById("employeeField_lrh5sl2v"); // employee
fieldValueDiff(fieldType, employeeA, employeeB);
// {
// isEqual: false, new: [{ name: "张三", value: "1343242225778381" }, { name: "李四", value: "1343242225778382" }],
// old: [{ name: "张三", value: "1343242225778381" }, { name: "王二", value: "1298349283929102" }],
// diff: {
// added: [{ name: "李四", value: "1343242225778382" }],
// removed: [{ name: "王二", value: "1298349283929102" }]
// }
// }
Parameters:
| Name |
Type |
Description |
fieldType |
string
|
字段类型,可通过getFieldTypeById获取 |
newVal |
any
|
新字段值 |
oldVal |
any
|
旧字段值 |
Returns:
描述两个值的差异对象
-
Type
-
module:Field~FieldValueDiff
(static) fieldValueEqualSingle(fieldType, valA, valB) → {boolean}
- Description:
- 判断两个字段单值是否相等,如果字段数据类型为数组,需要传入单个数组元素
- Source:
Example
const employeeA = this.$("employeeField_lrh5sl2v").getValue();
const employeeB = this.$("employeeField_lrhbdj3c").getValue();
const fieldType = getFieldTypeById("employeeField_lrh5sl2v"); // employee
fieldValueEqualSingle(fieldType, employeeA[0], employeeB[0]); // true or false
Parameters:
| Name |
Type |
Description |
fieldType |
string
|
字段类型,可通过getFieldTypeById获取 |
valA |
any
|
字段值A |
valB |
any
|
字段值B |
Returns:
两个值是否相等
-
Type
-
boolean
- Description:
- Source:
Example
const associationForm = generateAssociationFormFieldData(
"APP_xxxxxx",
"FORM-xxxxxx",
"receipt",
[{ isntanceId: "FINST-xxxxxx", title: "标题", subTitle: "副标题" }]
);
this.$("associationFormField_lrh5sl2u").setValue(associationForm);
Parameters:
| Name |
Type |
Description |
appType |
string
|
应用ID |
formUuid |
string
|
表单ID |
formType |
"receipt"
|
"process"
|
单据类型,receipt-表单,process-流程 |
instances |
Array.<AssociationFormInstance>
|
关联表单实例信息数组 |
(static) generateDptFieldData(id, name) → {object}
- Description:
- 生成部门字段数据,可直接赋值给部门组件
⚠️如果传数组作为参数,ID和名称的顺序必须一一对应。
🤯通过数据源获取到的表单数据,部门字段的值就是部门ID和部门名称分开的两个数组,
可以直接将其传入来生成可赋值给部门组件的部门字段数据。
- Source:
Example
const dpt = generateDptFieldData("047126", "财务部");
const dpt = generateDptFieldData(["047126", "048374"], ["财务部", "人事部"]);
// 结合数据源使用
getFormData(this, "form", "FINST-xxxxxx").then(formData => {
const ids = formData.departmentSelectField_lbbyyrcy_id;
const names = formData.departmentSelectField_lbbyyrcy;
const dpt = generateDptFieldData(ids, names);
this.$("departmentSelectField_lbbxxrcz").setValue(dpt);
});
Parameters:
| Name |
Type |
Description |
id |
string
|
number
|
Array.<string>
|
Array.<number>
|
部门ID,接受单个ID或者ID数组 |
name |
string
|
Array.<string>
|
部门名称,接受单个名称字符串或者名称数组 |
Returns:
部门字段数据
-
Type
-
object
(static) generateEmployeeFieldData(id, name) → {object|Array.<object>}
- Description:
- 生成员工字段数据,可直接赋值给员工组件
⚠️如果传数组作为参数,ID和姓名的顺序必须一一对应。
🤯通过数据源获取到的表单数据,员工字段的值就是员工ID和员工姓名分开的两个数组,
可以直接将其传入来生成可赋值给员工组件的员工字段数据。
- Source:
Example
const employee = generateEmployeeFieldData("1343242225778381", "张三");
const employee = generateEmployeeFieldData(["1343242225778381", "1343242225778382"], ["张三", "李四"]);
// 结合数据源使用
getFormData(this, "form", "FINST-xxxxxx").then(formData => {
const ids = formData.employeeField_lm1cl4dk_id;
const names = formData.employeeField_lm1cl4dk;
const employee = generateEmployeeFieldData(ids, names);
this.$("employeeField_lm2ckef9").setValue(employee);
});
Parameters:
| Name |
Type |
Description |
id |
string
|
Array.<string>
|
员工ID,接受单个ID字符串或者ID数组 |
name |
string
|
Array.<string>
|
员工姓名,接受单个字符串或者字符串数组 |
Returns:
员工字段数据
-
Type
-
object
|
Array.<object>
(static) getFieldDataTypeById(fieldId, multiple) → {string}
- Description:
- Source:
Example
getFieldDataTypeById("textField_lbd7nz2d"); // string
getFieldDataTypeById("employeeField_lm1cl4dk"); // object
getFieldDataTypeById("employeeField_lm1cl4dk", true); // array
Parameters:
| Name |
Type |
Default |
Description |
fieldId |
string
|
|
字段唯一标识 |
multiple |
boolean
|
false
|
字段是否能多选,仅对人员字段有效 |
Returns:
字段数据类型
-
Type
-
string
- Description:
- Source:
Example
getFieldTypeId("textField_lbd7nz2d"); // text
getFieldTypeId("departmentSelectField_lbbyyrcy"); // departmentSelect
Parameters:
| Name |
Type |
Description |
fieldId |
string
|
字段唯一标识 |
Returns:
字段类型
-
Type
-
module:Field~FieldType
(static) mergeTo()
- Description:
- 将主表上的一些同类型字段值合并到另外一个字段
目前仅支持合并附件类型字段
- Source:
This:
(static) syncTo(changes)
- Description:
- Source:
This:
Example
// 此函数不应该在代码中显式调用,而应该设置为组件的OnChange事件回调
// 并在回调参数中配置要与此组件值保持同步的字段标识:
// {
// "target": "textField_xxxx"
// }
// 上面的回调参数表示将当前组件的值同步到textField_xxxx字段
Parameters:
| Name |
Type |
Description |
changes |
any
|
变更值 |
Type Definitions
ArrayDiff
- Description:
- Source:
Properties:
| Name |
Type |
Description |
added |
Array.<any>
|
新增的元素 |
removed |
Array.<any>
|
删除的元素 |
数组差异对象
Type:
- Description:
- Source:
Properties:
| Name |
Type |
Description |
instanceId |
string
|
实例ID |
title |
string
|
显示的标题 |
subTitle |
string
|
显示的副标题 |
关联表单实例
CallbackThis
- Source:
Properties:
| Name |
Type |
Description |
params |
T
|
开发者手动配置的回调参数 |
FieldType
- Description:
- Source:
字段类型
Type:
-
"text"
|
"textarea"
|
"number"
|
"rate"
|
"radio"
|
"checkbox"
|
"date"
|
"cascadeDate"
|
"employee"
|
"departmentSelect"
|
"select"
|
"multiSelect"
|
"cascadeSelect"
|
"associationForm"
|
"image"
|
"attachment"
|
"digitalSignature"
|
"countrySelect"
|
"address"
FieldValueDiff
- Description:
- Source:
Properties:
| Name |
Type |
Attributes |
Description |
isEqual |
boolean
|
|
两个值是否相等 |
new |
any
|
|
新字段值 |
old |
any
|
|
旧字段值 |
diff |
module:Field~ArrayDiff
|
<optional>
|
数组类型字段值差异对象 |
字段值差异对象
Type:
MergeToParams
- Source:
Properties:
| Name |
Type |
Description |
from |
string
|
Array.<string>
|
参与合并的字段标识 |
to |
string
|
目标字段标识,合并后的值赋值给此字段 |
type |
"attachment"
|
字段类型 |
SyncToParams
- Description:
- Source:
Properties:
| Name |
Type |
Description |
target |
string
|
Array.<string>
|
要同步的字段标识 |
syncTo方法回调参数
Type: