@lcap/asl
Version:
NetEase Application Specific Language
53 lines (49 loc) • 1.27 kB
text/typescript
import { immutable } from '../../decorators';
import { ExpressionNode, LOGIC_TYPE } from '../LogicItem';
import { DestinationParam } from './DestinationParam';
/**
* 跳转页面
* @TODO: 当前类目前主要用于生成文档
*/
export class Destination extends ExpressionNode {
/**
* 逻辑节点类型
*/
()
public readonly type: LOGIC_TYPE = LOGIC_TYPE.Destination;
/**
* 页面路径
*/
()
public readonly page: string = undefined;
/**
* URL
*/
()
public readonly url: string = undefined;
/**
* Code
*/
()
public readonly code: string = undefined;
/**
* 跳转页面参数
*/
()
public readonly params: Array<DestinationParam> = [];
/**
* 生成 JS 脚本
*/
toScript() {
const params = this.params
.filter((param) => param.pageParamKey && param.pageParamKeyValue)
.map((param) => param.toScript());
let result = this.code;
if (params.length) {
result = '`' + `${this.code}?${params.join('&')}` + '`';
} else {
result = '`' + `${result}` + '`';
}
return result.replace(/"/g, "'");
}
}