@suplink/tf-script-util
TypeScript icon, indicating that this package has built-in type declarations

0.9.6 • Public • Published

概述

本包为天坊跨平台运行期使用,为基础应用和领域应用提供天坊核心脚本能力。

目录

使用说明

安装

npm i @suplink/tf-script-util

初始化

全域变量

  • 通过tf.mount挂载全域变量并初始化window.scriptUtil对象。

用户信息

  • 通过tf.mount将用户信息userSessionInfo写入本地,包含userId、username、staffCode、staffName等信息。

url适配器

  • 通过tf.mount初始化链接适配器-urlAdopter,确保天坊地址兼容当前应用平台。

Window/Document TS类型

  • 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等功能使用。

平台应用实现

需实现如下组件/功能以确保脚本完整可用。

message

  • 涉及window.scriptUtil的showMessage和copy功能,TS类型为antd的message,如需要则在平台应用层面实现并通过tf.mount挂载进来。

CommonModal

  • 涉及showModal和renderModal功能,TS类型为antd的Modal,如需要则在平台应用层面实现并通过tf.mount挂载进来。

notification

  • 涉及window.scriptUtil的jsError功能,TS类型为antd的notification,如需要则在平台应用层面实现并通过tf.mount挂载进来。

常用脚本

Alert

提示框

参数

参数 类型 含义 默认 必须
message string 消息
callback function 确认回调提示

案例

window.scriptUtil.Alert('消息', () => {
    console.log('确认回调');
})

reload

刷新页面

参数

参数 类型 含义 默认 必须
time number 刷新延迟 50

案例

window.scriptUtil.reload();

registerDatalink

注册数据连接

参数

参数 类型 含义 默认 必须
data object HT数据

getDatalink

获取数据连接

参数

参数 类型 含义 默认 必须
id string HT数据连接ID

request

接口请求

参数

参数 类型 含义 默认 必须
url string 请求地址
options object 请求配置
options.headers object 请求头配置
options.body object 请求体配置
options.method string 请求方式, POST PUT GET
options.fetchType string 请求类型, file等

案例

window.scriptUtil.request('xxx');

refreshWorkflow

刷新页面所有元素

executeScriptService

获取对象模型数据

// == 2.7版本
window.scriptUtil.executeScriptService({
    objName: 'obj',
    serviceName: 's'
});

// == 3.0版本
window.scriptUtil.executeScriptService({
    templateNamespace: 't',
    templateName: 't1',
    instanceName: 'obj',
    serviceNamespace: 'ns',
    serviceName: 's'
});

getSessionUserInfo

获取本地用户信息

const userSessionInfo = window.scriptUtil.getSessionUserInfo();
console.log(userSessionInfo);

getUserInfo

获取用户信息

window.scriptUtil.getUserInfo((user) => {
    console.log(user);
});

registerReactDom

注册组件实例至dynamicImportWidget对象

参数

参数 类型 含义 默认 必须
instance object 类组件实例
options object 配置
options.itemskey string 组件key,与widgetIndex二选一作为dynamicImportWidget的key
options.widgetIndex string 组件id,与itemskey二选一作为dynamicImportWidget的key

logoutReactDom

注销组件实例,即从dynamicImportWidget对象删除对应组件实例

参数

参数 类型 含义 默认 必须
options object 配置
options.itemskey string 组件key,与widgetIndex二选一作为dynamicImportWidget的key
options.widgetIndex string 组件id,与itemskey二选一作为dynamicImportWidget的key

getRegisterReactDom

从dynamicImportWidget对象中获取组件实例

参数

参数 类型 含义 默认 必须
componentId string 组件ID,为itemskey或widgetIndex

handleReactDom

执行组件实例的相应方法

参数

参数 类型 含义 默认 必须
componentId string 组件ID,为itemskey或widgetIndex
value any 执行方法时的入参
funcName string 执行方法名 setValue

setReactDomValue

设置对应组件实例的值,本质是调用对应组件实例的setValue方法

参数

参数 类型 含义 默认 必须
componentId string 组件ID,为itemskey或widgetIndex
value any 组件值

getReactDomValue

获取对应组件实例的值,本质是调用对应组件实例的getValue方法

参数

参数 类型 含义 默认 必须
componentId string 组件ID,为itemskey或widgetIndex

setFormData

设置表单数据对象

参数

参数 类型 含义 默认 必须
data object 表单数据对象

getFormData

获取表单数据对象

参数

参数 类型 含义 默认 必须
formIds string[] 表单选项ID数组

closeCurrentPage

关闭当前窗口

openPage

打开页面

参数

参数 类型 含义 默认 必须
url string 页面地址
method string 打开方式 _blank
feature string 打开特性
openConfig object 打开配置
openConfig.isCenter object 是否居中打开
openConfig.width object 打开页面宽度 400
openConfig.height object 打开页面高度 400

setUuid

本地添加uuid

getUuid

获取本地uuid

emptyUuid

清空本地uuid

triggerEvent

触发事件脚本

参数

参数 类型 含义 默认 必须
config object 配置
config.action string 全局事件名,onGetWorkFlowData/onRejectWorkFlowData/onUploadComplete等
config.actions object[] 事件配置数组
config.actions[].action string 事件名
config.actions[].script string 事件脚本
cb function 触发后回调

moment

三方库moment.js的对象实例,文档见momentjs

isEmptyObject

判断传入的对象是否为空

isInArray

判断值是否在数组内

参数

参数 类型 含义 默认 必须
arr any[] 数组
value any

regRexGroup

常用正则表达式

参数

参数 类型 含义 默认 必须
type string/regExp 正则类型或表达式,类型有none-空字符, mobilePhone-手机号,telephone-电话号码,
zipCode-邮政编码,idCard-身份证,number-数字,email-邮箱,ip-ip地址

valueCheck

正则验证

参数

参数 类型 含义 默认 必须
value string 待验证的值
type string/regExp 正则类型或表达式,同regRexGroup none
isRequired string 是否必须,yes-必须,no-非必须 yes

isVaild

批量校验组件实例,本质是调用组件实例的getValid方法

参数

参数 类型 含义 默认 必须
ctrlIds string[] 组件ID列表

showMessage

消息提示弹窗,需平台应用通过tf.mount方法挂载如message组件

参数

参数 类型 含义 默认 必须
msg string 提示内容
type string 提示类型,success-成功,error-失败,warning-警告 success

getDictionary

获取字典

showModal

显示弹窗,需要平台应用实现CommonModal并通过tf.mount挂载

Readme

Keywords

Package Sidebar

Install

npm i @suplink/tf-script-util

Weekly Downloads

0

Version

0.9.6

License

ISC

Unpacked Size

972 kB

Total Files

272

Last publish

Collaborators

  • suplinks