本包为天坊跨平台运行期使用,为基础应用和领域应用提供天坊核心脚本能力。
npm i @suplink/tf-script-util
- 通过tf.mount挂载全域变量并初始化window.scriptUtil对象。
- 通过tf.mount将用户信息userSessionInfo写入本地,包含userId、username、staffCode、staffName等信息。
- 通过tf.mount初始化链接适配器-urlAdopter,确保天坊地址兼容当前应用平台。
- Window全局变变量扩展WinConfig。
** 案例 **
import { WinConfig, DocConfig } from '@suplink/tf-script-util';
declare global {
interface Window extends WinConfig {
zhizhiRegisterHandler: any;
zhizhiDispatchAppEvent: any;
nodeTextTemp: any;
}
interface Document extends DocConfig {
}
}
需实现如下组件/功能以确保脚本完整可用
- 基础应用需实现运行期容器组件,并通过window.scriptUtil.registerReactDom方法将实例注入,并注册为previewWrapper。
容器需实现showWarning、setSpinLoading、closeSpinLoading、getFormData、updateForm、setModal、modalClose等功能,否则window.scriptUtil的Alert、showLoading、closeLoading、showModal、closeModal、showModalContent、getFormData、setFormData等功能将失效。
- 所有组件均可对外提供renderData、getFormItemId、setValue、getValue、getChooseOption、getValid等方法供window.scriptUtil使用。
- 表格组件需提供setObjectSource、getCurRow等方法供window.scriptUtil的renderTable、getEditRow等功能使用。
需实现如下组件/功能以确保脚本完整可用。
- 涉及window.scriptUtil的showMessage和copy功能,TS类型为antd的message,如需要则在平台应用层面实现并通过tf.mount挂载进来。
- 涉及showModal和renderModal功能,TS类型为antd的Modal,如需要则在平台应用层面实现并通过tf.mount挂载进来。
- 涉及window.scriptUtil的jsError功能,TS类型为antd的notification,如需要则在平台应用层面实现并通过tf.mount挂载进来。
提示框
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
message | string | 消息 | 是 | |
callback | function | 确认回调提示 | 否 |
案例
window.scriptUtil.Alert('消息', () => {
console.log('确认回调');
})
刷新页面
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
time | number | 刷新延迟 | 50 | 否 |
案例
window.scriptUtil.reload();
注册数据连接
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
data | object | HT数据 | 是 |
获取数据连接
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
id | string | HT数据连接ID | 是 |
接口请求
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
url | string | 请求地址 | 是 | |
options | object | 请求配置 | 否 | |
options.headers | object | 请求头配置 | 否 | |
options.body | object | 请求体配置 | 否 | |
options.method | string | 请求方式, POST | PUT | GET |
options.fetchType | string | 请求类型, file等 | 否 |
案例
window.scriptUtil.request('xxx');
刷新页面所有元素
获取对象模型数据
// == 2.7版本
window.scriptUtil.executeScriptService({
objName: 'obj',
serviceName: 's'
});
// == 3.0版本
window.scriptUtil.executeScriptService({
templateNamespace: 't',
templateName: 't1',
instanceName: 'obj',
serviceNamespace: 'ns',
serviceName: 's'
});
获取本地用户信息
const userSessionInfo = window.scriptUtil.getSessionUserInfo();
console.log(userSessionInfo);
获取用户信息
window.scriptUtil.getUserInfo((user) => {
console.log(user);
});
注册组件实例至dynamicImportWidget对象
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
instance | object | 类组件实例 | 是 | |
options | object | 配置 | 否 | |
options.itemskey | string | 组件key,与widgetIndex二选一作为dynamicImportWidget的key | 否 | |
options.widgetIndex | string | 组件id,与itemskey二选一作为dynamicImportWidget的key | 否 |
注销组件实例,即从dynamicImportWidget对象删除对应组件实例
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
options | object | 配置 | 否 | |
options.itemskey | string | 组件key,与widgetIndex二选一作为dynamicImportWidget的key | 否 | |
options.widgetIndex | string | 组件id,与itemskey二选一作为dynamicImportWidget的key | 否 |
从dynamicImportWidget对象中获取组件实例
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
componentId | string | 组件ID,为itemskey或widgetIndex | 否 |
执行组件实例的相应方法
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
componentId | string | 组件ID,为itemskey或widgetIndex | 否 | |
value | any | 执行方法时的入参 | 否 | |
funcName | string | 执行方法名 | setValue | 否 |
设置对应组件实例的值,本质是调用对应组件实例的setValue方法
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
componentId | string | 组件ID,为itemskey或widgetIndex | 否 | |
value | any | 组件值 | 否 |
获取对应组件实例的值,本质是调用对应组件实例的getValue方法
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
componentId | string | 组件ID,为itemskey或widgetIndex | 否 |
设置表单数据对象
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
data | object | 表单数据对象 | 否 |
获取表单数据对象
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
formIds | string[] | 表单选项ID数组 | 否 |
关闭当前窗口
打开页面
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
url | string | 页面地址 | 是 | |
method | string | 打开方式 | _blank | 否 |
feature | string | 打开特性 | 否 | |
openConfig | object | 打开配置 | 否 | |
openConfig.isCenter | object | 是否居中打开 | 否 | |
openConfig.width | object | 打开页面宽度 | 400 | 否 |
openConfig.height | object | 打开页面高度 | 400 | 否 |
本地添加uuid
获取本地uuid
清空本地uuid
触发事件脚本
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
config | object | 配置 | 否 | |
config.action | string | 全局事件名,onGetWorkFlowData/onRejectWorkFlowData/onUploadComplete等 | 否 | |
config.actions | object[] | 事件配置数组 | 否 | |
config.actions[].action | string | 事件名 | 否 | |
config.actions[].script | string | 事件脚本 | 否 | |
cb | function | 触发后回调 | 否 |
三方库moment.js的对象实例,文档见momentjs。
判断传入的对象是否为空
判断值是否在数组内
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
arr | any[] | 数组 | 否 | |
value | any | 值 | 否 |
常用正则表达式
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
type | string/regExp | 正则类型或表达式,类型有none-空字符, mobilePhone-手机号,telephone-电话号码, |
||
zipCode-邮政编码,idCard-身份证,number-数字,email-邮箱,ip-ip地址 | 否 |
正则验证
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
value | string | 待验证的值 | 否 | |
type | string/regExp | 正则类型或表达式,同regRexGroup | none | 否 |
isRequired | string | 是否必须,yes-必须,no-非必须 | yes | 否 |
批量校验组件实例,本质是调用组件实例的getValid方法
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
ctrlIds | string[] | 组件ID列表 | 否 |
消息提示弹窗,需平台应用通过tf.mount方法挂载如message组件
参数
参数 | 类型 | 含义 | 默认 | 必须 |
---|---|---|---|---|
msg | string | 提示内容 | 否 | |
type | string | 提示类型,success-成功,error-失败,warning-警告 | success | 否 |
获取字典
显示弹窗,需要平台应用实现CommonModal并通过tf.mount挂载