• 沒有找到結果。

action 定义脚本的输入输出方法,以及调用脚本的方法。

buffer 操作二进制缓存区,例如将缓冲区内容转换为字符串。

setup 对系统对象Standard Object的增、删、改、查。

db 对自定义对象Customer Object的增、删、改、查。

sql 执行sql语句,目前只支持执行select查询语句。

bo 对Business Object的增、删、改、查。

meta 操作object的元数据,例如获取字段名称、获取字段长度。

http http或者https操作。

iconv 将字符串转为GBK、GB18030、GB2132或ISO8859_1编码格式,或 者解码字符串。

crypto 加密操作,包含对哈希、HMAC、加密、解密、签名及验证的封 装。

decimal 将从http请求或从数据库中查询出来的number类型值,转换成 Decimal类型,并能进行加、减、乘、除等数学运算。

excel 操作Excel文件,例如生成Excel文件。

text 操作文本,例如将文本转换为二进制。

xml 操作XML文件,例如读取XML文件内容。

uuid 生成全局唯一标识。

3-51 定义入参

3-52 定义出参

3. 定义方法以及使用的对象。

3-53 定义方法及使用对象

4. 进行数据库操作。

3-54 数据库相关操作

具体我们通过解读以下脚本样例,了解1个脚本的总体结构框架、编写要求。

样例脚本:

import * as decimal from 'decimal';

@action.object({type: "param"}) export class ActionInput {

@action.param({type: 'String', required: true, label: 'your name', description: 'please input your name'}) name: string;

@action.param({type: 'Number', required: true, min: 1, max: 100, message: 'age must during [1, 100]'}) age: decimal.Decimal;

@action.param({type: 'Date', pattern: 'yyyy-MM-dd'}) birthday: Date;

@action.param({type: 'String', isCollection: true}) schools: string[];

@action.param({type: 'Boolean'}) married: boolean;

@action.param({type: 'MyObject'}) obj: MyObject;

}

@action.object({type: "param"}) export class MyObject {

@action.param({type: 'String'}) something: string;

@action.param({type: 'Number'}) otherthing: decimal.Decimal;

}

@action.object({type: "param"}) export class ActionOutput {

@action.param({type: 'String', isCollection: true}) greets: string[];

}

@action.object({type: "method"}) export class ActionDemo {

@action.method({ label: 'greeting something', description: 'greeting something.', input: 'ActionInput', output: 'ActionOutput' })

public greet(inarg: ActionInput): ActionOutput { console.log('name = ', inarg.name);

import * as decimal from 'decimal';

除了平台预置标准库,您还可以声明对其他自定义模块的引用。例如已经提前开 发了一个脚本circle,您可以用如下方式加载它。

import * as circle from './circle';

2. 定义输入、输出变量。

脚本可以有多个输入、输出参数,也可以没有。所有的输入或输出参数必须封装 在一个class中,作为实例成员。

本例中,脚本有6个输入参数,被封装为ActionInput。每个参数都必须定义其参 数类型,同时还可以定义是否必填、标签、最大值、最小值等可选属性。

@action.object({type: "param"}) export class ActionInput {

@action.param({type: 'String', required: true, label: 'your name', description: 'please input your name'})

name: string;

@action.param({type: 'Number', required: true, min: 1, max: 100, message: 'age must during [1, 100]'})

age: decimal.Decimal;

@action.param({type: 'Date', pattern: 'yyyy-MM-dd'}) birthday: Date;

@action.param({type: 'String', isCollection: true}) schools: string[];

@action.param({type: 'Boolean'}) married: boolean;

@action.param({type: 'MyObject'}) obj: MyObject;

}

因为第6个输入参数“obj”的参数类型为自定义对象,所以还需要给出

“MyObject”的定义。

@action.object({type: "param"}) export class MyObject {

@action.param({type: 'String'}) something: string;

@action.param({type: 'Number'}) otherthing: decimal.Decimal;

}

脚本有1个输出参数,被封装为ActionOutput。

@action.object({type: "param"}) export class ActionOutput {

@action.param({type: 'String', isCollection: true}) greets: string[];

}

3. 定义方法。

样例中,ActionDemo是外部调用的class,使用export导出。ActionDemo定义了 一个action method,使用action.method装饰,表明调用脚本时从此方法入口。

greet是class的实例方法,其输入、输出参数就是前面定义的ActionInput和 ActionOutput。

在一个脚本文件里面,action.method只能使用一次。

@action.object({type: "method"}) export class ActionDemo {

@action.method({ label: 'greeting something', description: 'greeting something.', input:

'ActionInput', output: 'ActionOutput' })

public greet(inarg: ActionInput): ActionOutput { console.log('name = ', inarg.name);

相關文件