Appearance
表达式相关
概述
织信提供在脚本中调用表达式中方法的能力,支持的表达式有:
| 类别 | 描述 | 说明 |
|---|---|---|
| Array | 集合 | 数组集合相关函数 |
| Date | 日期 | 日期运算相关函数 |
| Encode | 字符编码 | 字符串编解码相关函数 |
| Math | 数字 | 数学运算 |
| Misc | 其他 | 其他工具函数 |
| String | 字符串 | 字符串相关函数 |
| User | 用户 | 当前系统下的用户相关操作函数 |
| Context | 上下文 | 上下文相关函数。上下文表示在执行过程中的环境参数 |
| Record | 数据表记录 | 数据表相关函数 |
| T | 国际化 | 国际化相关函数 |
Array
数组集合相关函数,调用方式为informat.Array.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| of | ...item: Object | Array<Object> | 将多个元素转化为数组 | informat.Array.of('x', 2, 3) // ["x",2,3] |
| toList | item: Object | Array<Object> | 将元素转化为数组,数组则clone | informat.Array.toList('x') // ["x"] |
| join | array: Array, separator: String | String | 按分隔符拼接数组内容 | informat.Array.join([1,2,3], '-') // "1-2-3" |
| length | list: Array | Integer | 返回数组长度,null返回0 | informat.Array.length([1,2,3]) // 3 |
| get | list: Array|Map, key: Integer|String | Object | 获取集合中指定位置的元素 | informat.Array.get([{name:'张三'}], 0) // {name:'张三'} |
| set | list: Array|Map, key: String|Integer, value: Object | Array|Map | 设置集合中的元素值 | informat.Array.set({name:'张三'}, 'name', '李四') |
| add | list: Array, item: Object | Array | 向数组尾部添加元素 | informat.Array.add([1,2], 3) // [1,2,3] |
| remove | list: Array|Map, item: Object|String | Array|Map | 移除集合中的元素(仅第一个匹配项) | informat.Array.remove([1,2,3], 2) // [1,3] |
| removeAll | list: Array|Map, item: Object|String|Array | Array|Map | 移除集合中的所有匹配元素 | informat.Array.removeAll([1,2,2,3], 2) // [1,3] |
| isEmpty | list: Array|Map | Boolean | 判断集合是否为空 | informat.Array.isEmpty([]) // true |
| isNotEmpty | list: Array|Map | Boolean | 判断集合是否不为空 | informat.Array.isNotEmpty([1]) // true |
| contains | list: Array|Map, item: Object | Boolean | 判断集合是否包含指定元素 | informat.Array.contains([1,2,3], 2) // true |
| containsAny | list1: Array, list2: Array | Boolean | 判断list1是否包含list2中任意元素 | informat.Array.containsAny([1,2],[2,3]) // true |
| containsAll | list1: Array, list2: Array | Boolean | 判断list1是否包含list2中所有元素 | informat.Array.containsAll([1,2,3],[1,2]) // true |
| map | list: Array, key: String | Array | 返回数组中每个元素指定属性的列表 | informat.Array.map([{name:'张三'}], 'name') // ["张三"] |
| props | list: Array, props: Array<String> | Array | 返回元素指定属性组成的新对象列表 | informat.Array.props([{name:'张三'}], ['name']) // [{name:'张三'}] |
| transform | list: Array, mapping: Map<String,String> | Array | 按映射关系转换对象属性 | informat.Array.transform([{name:'张三'}], {name:'userName'}) |
| concat | list1: Array, list2: Array | Array | 拼接两个数组 | informat.Array.concat([1,2],[3,4]) // [1,2,3,4] |
| sort | list: Array, key: String | Array | 按指定属性排序数组 | informat.Array.sort([{age:20},{age:18}], 'age') |
| distinct | list: Array | Array | 去除数组中的重复项 | informat.Array.distinct([1,2,2,3]) // [1,2,3] |
| reverse | list: Array | Array | 反转数组顺序 | informat.Array.reverse([1,2,3]) // [3,2,1] |
| repeat | count: Integer, element: Object | Array | 生成重复元素的数组 | informat.Array.repeat(3, 'a') // ["a","a","a"] |
| sublist | list: Array, fromIndex: Integer, toIndex: Integer | Array | 返回数组的子集 | informat.Array.sublist([1,2,3,4], 1, 2) // [2,3] |
| filter | list: Array, key: String, value: Object | Array | 过滤数组中指定属性值的元素 | informat.Array.filter([{a:1},{a:2}], "a", 2) // [{a:2}] |
| shift | list: Array | Object | 移除并返回数组头部元素 | informat.Array.shift([1,2,3]) // 1 |
| pop | list: Array | Object | 移除并返回数组尾部元素 | informat.Array.pop([1,2,3]) // 3 |
| sum | list: Array | Double | 对数字数组求和 | informat.Array.sum([1,2,3]) // 6.0 |
| avg | list: Array | Double | 对数字数组求平均值 | informat.Array.avg([1,2,3]) // 2.0 |
| max | list: Array | Double | 求数字数组最大值 | informat.Array.max([1,2,3]) // 3.0 |
| min | list: Array | Double | 求数字数组最小值 | informat.Array.min([1,2,3]) // 1.0 |
| first | list: Array | Object | 返回数组第一个元素 | informat.Array.first([1,2,3]) // 1 |
| last | list: Array | Object | 返回数组最后一个元素 | informat.Array.last([1,2,3]) // 3 |
Date
日期运算相关函数,调用方式为informat.Date.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| sysdate | 无参数 | Date | 返回当前日期和时间 | informat.Date.sysdate() // Date对象 |
| now | 无参数 | Long | 返回当前时间的UNIX时间戳 | informat.Date.now() // 1668483800328 |
| newDate | year, month, day, hour, minute, second, millisecond (均为Integer,可选) | Date | 返回指定的日期,参数可选 | informat.Date.newDate(2025, 0, 3) // 2025-01-03 00:00:00,000 |
| dateSet | d: Date或Long, type: String, value: Integer | Date | 将日期中指定部分设置为值 | informat.Date.dateSet(date, 'year', 2024) // 设置年份为2024 |
| dateAdd | d: Date或Long, type: String, diff: Integer | Date | 计算日期按类型加上差值后的日期 | informat.Date.dateAdd(date, 'year', 1) // 加1年 |
| datePart | d: Date或Long, type: String | Integer | 返回日期中指定部分的值 | informat.Date.datePart(date, 'year') // 返回年份 |
| dateBefore | d1: Date或Long, d2: Date或Long | Boolean | 判定d1是否在d2之前 | informat.Date.dateBefore(date1, date2) // true/false |
| dateAfter | d1: Date或Long, d2: Date或Long | Boolean | 判定d1是否在d2之后 | informat.Date.dateAfter(date1, date2) // true/false |
| dateDiff | d1: Date或Long, d2: Date或Long | Integer | 计算两个日期之间的天数差值 | informat.Date.dateDiff(date1, date2) // 相差天数 |
| monthDiff | d1: Date或Long, d2: Date或Long | Integer | 计算两个日期之间的月份数差值 | informat.Date.monthDiff(date1, date2) // 相差月数 |
| weekDiff | d1: Date或Long, d2: Date或Long | Integer | 计算两个日期之间的周差值 | informat.Date.weekDiff(date1, date2) // 相差周数 |
| quarterDiff | d1: Date或Long, d2: Date或Long | Integer | 计算两个日期之间的季度差值 | informat.Date.quarterDiff(date1, date2) // 相差季度数 |
特殊说明
month的值范围
| 月份 | 值 |
|---|---|
| 1月 | 0 |
| 2月 | 1 |
| 3月 | 2 |
| 4月 | 3 |
| 5月 | 4 |
| 6月 | 5 |
| 7月 | 6 |
| 8月 | 7 |
| 9月 | 8 |
| 10月 | 9 |
| 11月 | 10 |
| 12月 | 11 |
day_of_week的值范围
| 天 | 值 |
|---|---|
| 星期日 | 0 |
| 星期一 | 1 |
| 星期二 | 2 |
| 星期三 | 3 |
| 星期四 | 4 |
| 星期五 | 5 |
| 星期六 | 6 |
Encode
字符串编解码相关函数,调用方式为informat.Encode.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| md5 | s: String | String | 返回字符串的MD5哈希值 | informat.Encode.md5('123456') // e10adc3949ba59abbe56e057f20f883e |
| urlEncode | str: String | String | 将字符串进行URL编码 | informat.Encode.urlEncode('https://next.informat.cn') // https%3A%2F%2Fnext.informat.cn |
| urlDecode | str: String | String | 将字符串进行URL解码 | informat.Encode.urlDecode('https%3A%2F%2Fnext.informat.cn') // https://next.informat.cn |
Math
数学运算。它包括了一些数学函数,调用方式为informat.Math.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| abs | x: Integer或Double | Integer或Double | 返回数字的绝对值 | informat.Math.abs(-100.3) // 100.3 |
| pow | d1: Integer或Double, d2: Integer或Double | Double | 返回d1的d2次方 | informat.Math.pow(2, 3) // 8.0 |
| ceil | x: Double | Double | 返回大于或等于x的最小整数 | informat.Math.ceil(2.2) // 3.0 |
| floor | x: Double | Double | 返回小于或等于x的最大整数 | informat.Math.floor(2.2) // 2.0 |
| random | 无参数 | Double | 返回0到1之间的随机数 | informat.Math.random() // 0.6260832016946124 |
| sqrt | x: Double | Double | 返回x的平方根 | informat.Math.sqrt(4) // 2.0 |
| round | n: Double, digits: Integer | Double | 返回数字按指定位数四舍五入的值 | informat.Math.round(3.1415926, 2) // 3.14 |
Misc
工具函数,调用方式为informat.Misc.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| jsonStringify | obj: Object | String | 将对象转换为JSON字符串 | informat.Misc.jsonStringify({a:1}) // "{\"a\":1}" |
| jsonParse | str: String | Object | 将JSON字符串转换为对象 | informat.Misc.jsonParse('{"a":1}') // {a:1} |
| parseFloat | str: String | Double | 将字符串转换为小数 | informat.Misc.parseFloat("3.14") // 3.14 |
| parseInt | str: String | Integer | 将字符串转换为整数 | informat.Misc.parseInt("3.14") // 3 |
| timestampToDate | timestamp: Integer | Date | 将UNIX时间戳转换为日期 | informat.Misc.timestampToDate(1667232000000) |
| dateToTimestamp | date: Date | Integer | 将日期转换为UNIX时间戳 | informat.Misc.dateToTimestamp(new Date()) |
| formatDate | date: Date, fmt: String | String | 按格式格式化日期 | informat.Misc.formatDate(date, 'yyyy-MM-dd') |
| parseDate | str: String, fmt: String | Date | 按格式解析日期字符串 | informat.Misc.parseDate('2022-11-01', 'yyyy-MM-dd') |
| host | 无参数 | String | 返回系统首页地址 | informat.Misc.host() // https://next.informat.cn/ |
| pinyin | str: String | String | 返回字符串的中文拼音 | informat.Misc.pinyin('你好') // "ni hao" |
| shortPinyin | str: String | String | 返回拼音首字母 | informat.Misc.shortPinyin('你好') // "nh" |
| expectNotNull | obj: Object, message: String | Object | 判空,为空则抛异常 | informat.Misc.expectNotNull(obj, '不能为空') |
| expectFirst | array: Array, message: String | Object | 返回数组第一个元素 | informat.Misc.expectFirst([1,2], '空数组') // 1 |
| expectLast | array: Array, message: String | Object | 返回数组最后一个元素 | informat.Misc.expectLast([1,2], '空数组') // 2 |
| invokeScript | script: String, func: String, ...args: Object | Object | 调用脚本中的函数 | informat.Misc.invokeScript('test.js', 'add', 1, 2) |
| invokeAutomatic | automaticId: String, ...args: Object | Object | 调用自动化程序 | informat.Misc.invokeAutomatic('test', 1, 2) |
| httpGet | url: String | String | 通过GET方式访问URL | informat.Misc.httpGet('https://example.com') |
| prop | object: Object, key: String | Object | 获取对象属性值 | informat.Misc.prop({a:1}, 'a') // 1 |
| props | object: Object, props: Array<String> | Object | 获取多个属性组成新对象 | informat.Misc.props({a:1,b:2}, ['a']) |
| transform | object: Object, mapping: Map<String,String> | Object | 按映射关系转换对象属性 | informat.Misc.transform({name:'张三'}, {name:'userName'}) |
| appId | 无参数 | String | 获取所在应用的ID | informat.Misc.appId() |
| getAppIdByKey | key: String | String | 通过应用标识符查询应用ID | informat.Misc.getAppIdByKey('appKey') |
| attachmentURL | tableKey: String, fieldKey: String, value: String | String | 获取附件访问链接 | informat.Misc.attachmentURL('staff','photo','1.png') |
| appResURL | appResId: String | String | 获取应用资源库资源地址 | informat.Misc.appResURL('image.jpg') |
| websiteResURL | moduleKey: String, filePath: String | String | 获取网站模块资源地址 | informat.Misc.websiteResURL('module','logo.png') |
| barcodeURL | value: String, format: String | String | 返回条码图片BASE64值 | informat.Misc.barcodeURL('12345','CODE128') |
| qrcodeURL | value: String, width: Integer | String | 返回二维码图片BASE64值 | informat.Misc.qrcodeURL('text', 300) |
| eval | str: String, context: Object | Object | 执行表达式引擎替换模板 | informat.Misc.eval('${name}', {name:'test'}) |
| safesql | sql: String, params: Array<Object> | String | 生成安全的完整SQL | informat.Misc.safesql('select ?', ['test']) |
| uuid16 | 无参数 | String | 生成16位UUID字符串 | informat.Misc.uuid16() // "lqjfw3xaglp38tru" |
| uuid32 | 无参数 | String | 生成32位UUID字符串 | informat.Misc.uuid32() // "rigzv6usysisu2gmkash6hdg526y10b5" |
| newObject | 无参数 | Object | 构建空对象 | informat.Misc.newObject() // {} |
| recordSql | sql: String, parameters: Array<Object> | Array<Object> | 执行SQL查询数据表记录 | informat.Misc.recordSql('select * from table', []) |
String
字符串相关函数,调用方式为informat.String.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| upper | s: String | String | 将字符串所有字母转为大写 | informat.String.upper('abc') // "ABC" |
| lower | s: String | String | 将字符串所有字母转为小写 | informat.String.lower('ABC') // "abc" |
| concat | s1: String, s2: String | String | 将两个字符串合并 | informat.String.concat('a','b') // "ab" |
| lpad | s1: String, len: Integer, s2: String | String | 在字符串开始处填充字符 | informat.String.lpad('ABC',6,'0') // "000ABC" |
| rpad | s1: String, len: Integer, s2: String | String | 在字符串结尾处填充字符 | informat.String.rpad('ABC',6,'0') // "ABC000" |
| trim | s: String | String | 移除字符串左右空白字符 | informat.String.trim(' abc ') // "abc" |
| replace | s: String, s1: String, s2: String | String | 替换字符串中第一次出现的子串 | informat.String.replace('abca','a','_') // "_bca" |
| replaceAll | s: String, s1: String, s2: String | String | 替换字符串中所有出现的子串 | informat.String.replaceAll('abca','a','_') // "_bc_" |
| substr | s: String, start: Integer, len: Integer | String | 从指定位置截取指定长度子串 | informat.String.substr('abcd',1,2) // "bc" |
| substring | s: String, start: Integer, end: Integer | String | 截取从开始到结束位置的子串 | informat.String.substring('abcd',0,2) // "ab" |
| indexOf | s: String, s2: String | Integer | 获取子串首次出现的位置 | informat.String.indexOf('abcd','a') // 0 |
| lastIndexOf | s: String, s2: String | Integer | 获取子串最后出现的位置 | informat.String.lastIndexOf('abcad','a') // 3 |
| contains | s: String, s2: String | Boolean | 判断是否包含子串 | informat.String.contains('abcd','a') // true |
| length | s: String | Integer | 获取字符串长度 | informat.String.length('abcd') // 4 |
| startsWith | s: String, s2: String | Boolean | 判断是否以子串开头 | informat.String.startsWith('abcd','a') // true |
| endsWith | s: String, s2: String | Boolean | 判断是否以子串结尾 | informat.String.endsWith('abcd','d') // true |
| match | regex: String, input: String | Boolean | 使用正则表达式验证字符串 | informat.String.match('^[a-z]+','abcd') // true |
| isEmpty | s: String | Boolean | 判断字符串是否为空(去除首尾空格) | informat.String.isEmpty(' ') // true |
| isNotEmpty | s: String | Boolean | 判断字符串是否不为空(去除首尾空格) | informat.String.isNotEmpty('a') // true |
| html2text | s: String | String | 将HTML内容转换为文本(XSS过滤) | informat.String.html2text('<div>test</div>') // "test" |
User
当前系统下的用户相关操作函数,调用方式为informat.User.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| usersWithRole | roleIdList: Array<String> | Array<String> | 返回拥有指定角色中任意一个角色的用户列表 | informat.User.usersWithRole(['admin']) // [user1, user2, user3] |
| usersWithDepartment | departmentIdList: Array<String> | Array<String> | 返回属于指定部门的用户列表 | informat.User.usersWithDepartment(['yanfabu']) |
| superiorUsers | userId: String | Array<String> | 返回用户的直接上级列表 | informat.User.superiorUsers('user1') // [user2, user3] |
| superiorUsersWithLevel | userId: String, level: Integer | Array<String> | 返回用户的连续上级列表(指定层级) | informat.User.superiorUsersWithLevel(Context.userId(), 1) |
| subordinateUsers | userId: String | Array<String> | 返回用户的直接下属列表 | informat.User.subordinateUsers('user1') // [user2, user3] |
| subordinateUsersWithLevel | userId: String, level: Integer | Array<String> | 返回用户的连续下属列表(指定层级) | informat.User.subordinateUsersWithLevel('user1', 2) // [user2, user3] |
| leaderOfDept | departmentId: String | Array<String> | 返回单个部门负责人列表 | informat.User.leaderOfDept('dept1') // [user2, user3] |
| leaderOfDeptWithLevel | departmentId: String, level: Integer | Array<String> | 返回连续上级部门负责人列表 | informat.User.leaderOfDeptWithLevel('yanfabu', 1) |
| leaderOfDeptList | departmentIdList: Array<String> | Array<String> | 返回多个部门的负责人列表 | informat.User.leaderOfDeptList(['dept1', 'dept2']) // [user2, user3, user4] |
| parentOfDept | departmentId: String | String | 返回部门的直接父部门ID | informat.User.parentOfDept('dept1') // dept2 |
| parentOfDeptList | departmentId: String | Array<String> | 返回部门的所有父部门ID列表 | informat.User.parentOfDept('dept1') // ['dept2', 'dept3'] |
| childrenOfDept | departmentId: String | Array<String> | 返回单个部门所有下级部门列表(递归) | informat.User.childrenOfDept('dept1') // [dept2, dept3] |
| childrenOfDeptList | departmentList: Array<String> | Array<String> | 返回多个部门的所有下级部门列表 | informat.User.childrenOfDeptList(['dept1', 'dept2']) // [dept2, dept3] |
| directChildrenOfDept | departmentId: String | Array<String> | 返回直接下级部门列表 | informat.User.directChildrenOfDept('dept1') // [dept2] |
| user | userId: String | User | 返回用户信息对象 | informat.User.user(Context.userId()) |
| userInfo | userId: String | UserInfo | 返回用户详细信息对象 | informat.User.userInfo(Context.userId()) |
| deptList | departmentIdList: Array<String> | Array<Dept> | 返回部门信息对象列表 | informat.User.deptList(['dept1', 'dept2']) |
| dept | deptId: String | Dept | 返回部门信息对象 | informat.User.dept('dept1') |
Context
上下文相关函数。上下文表示在执行过程中的环境参数,调用方式为informat.Context.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| userId | 无参数 | String | 返回当前操作用户ID | informat.Context.userId() // "ek5veueb6c9zg" |
| appId | 无参数 | String | 返回当前应用ID | informat.Context.appId() |
| appEnvProp | propKey: String | String | 返回应用环境变量值 | informat.Context.appEnvProp('payURL') // "http://dev-demo.com/pay" |
| httpHeaders | 无参数 | Object | 返回当前HTTP请求头信息 | informat.Context.httpHeaders() // {headers: {...}} |
| clipboardType | 无参数 | String | 返回应用剪切板数据类型 | informat.Context.clipboardType() // "test" |
| clipboardData | 无参数 | Object | 返回应用剪切板存储数据 | informat.Context.clipboardData() |
| weworkAccessToken | 无参数 | String | 返回企业微信AccessToken | informat.Context.weworkAccessToken() |
| dingtalkAccessToken | 无参数 | String | 返回钉钉AccessToken | informat.Context.dingtalkAccessToken() |
| feishuAccessToken | 无参数 | String | 返回飞书应用AccessToken | informat.Context.feishuAccessToken() |
| feishuTenantAccessToken | 无参数 | String | 返回飞书租户AccessToken | informat.Context.feishuTenantAccessToken() |
| requestIp | 无参数 | String | 返回当前请求IP地址 | informat.Context.requestIp() // "192.168.1.1" |
| hasAppPerm | permKey: String | Boolean | 判断用户是否有应用权限 | informat.Context.hasAppPerm('admin') // true |
| hasModulePerm | moduleKey: String, permKey: String | Boolean | 判断用户是否有模块权限 | informat.Context.hasModulePerm('crm', 'read') // true |
Record
数据表相关函数,调用方式为informat.Record.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| getById | tableId: String, recordId: String | Object | 根据ID查询数据表记录信息 | informat.Record.getById('order', 'z2koxrkxtp854') // {amount:11, name:'测试采购单', id:'z2koxrkxtp854'} |
| getFieldValue | tableId: String, recordId: String, fieldId: String | Object | 获取数据表记录的字段值 | informat.Record.getFieldValue('order','z2koxrkxtp854','amount') // 11 |
| getByField | tableId: String, fieldId: String, opt: String, value: Object | Array<Record> | 根据单个字段过滤记录列表 | informat.Record.getByField('order', 'amount', 'eq', 11) // [{amount:11, name:'测试采购单', id:'z2koxrkxtp854'}] |
| getByFields | tableId: String, conditions: Array | Array<Record> | 根据多个字段过滤记录列表 | informat.Record.getByFields('tab', [{fieldId:'text', opt:'eq', value:'13'}]) // [{amount:11, text:'13', id:'z2koxrkxtp854'}] |
| getRecordOptionName | tableId: String, fieldId: String, value: String | String | 返回单个选项值的名称 | informat.Record.getRecordOptionName('order', 'type', 'a') // "选项1" |
| getRecordOptionNames | tableId: String, fieldId: String, valueList: Array<String>, join: String | String | 返回多个选项值的名称并拼接 | informat.Record.getRecordOptionNames('order', 'type', ['a','b'], ',') // "选项1,选项2" |
| getRecordOptions | tableId: String, fieldId: String | Array<Option> | 返回选项值列表 | informat.Record.getRecordOptions('order', 'type') // [{id:'a',name:'选项1'},{id:'b',name:'选项2'}] |
| getRelationList | tableId: String, fieldId: String, recordId: String | Array<Record> | 返回关联列表字段的值 | informat.Record.getRelationList('order','orderDetail','z2koxrkxtp854') |
T
国际化相关函数,调用方式为informat.T.方法
| 方法 | 传参 | 返回值 | 说明 | 示例 |
|---|---|---|---|---|
| locale | 无参数 | String | 获取当前使用语言 | informat.T.locale() // "zh-CN" |
| t | key: String, args: Object/Array | String | 通过翻译标识符和参数进行翻译 | informat.T.t('welcome.message') // "欢迎" |
| tWithLocale | locale: String, key: String, args: Object/Array | String | 通过指定语言进行翻译 | informat.T.tWithLocale('en-US', 'welcome.message') // "Welcome" |

