npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@suplink/tf-script-util

v0.9.6

Published

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

Downloads

4

Readme

概述

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

目录

使用说明

安装

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|DELETE等 | | 否 | | 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挂载