fix: 🐛 解决小程序环境没有 window, 而 rax 出码中却默认在 __$eval 中用到 window 的问题

-- 解决方法: 将这个 __$$eval 的错误处理的默认行为搞成配置化的, 支持从外面传入...
This commit is contained in:
Clarence-pan 2022-04-10 20:29:41 +08:00 committed by Clarence Pan
parent 2bb8efb6ee
commit ce531aeb45
35 changed files with 576 additions and 361 deletions

View File

@ -280,6 +280,8 @@ export class ProjectBuilder implements IProjectBuilder {
postProcessors: this.postProcessors,
contextData: {
inStrictMode: this.inStrictMode,
tolerateEvalErrors: true,
evalErrorsHandler: '',
...this.extraContextData,
},
...options,

View File

@ -62,6 +62,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
const ir = next.ir as IContainerInfo;
const rootScope = Scope.createRootScope();
const { tolerateEvalErrors = true, evalErrorsHandler = '' } = next.contextData;
// Rax 构建到小程序的时候,不能给组件起起别名,得直接引用,故这里将所有的别名替换掉
// 先收集下所有的 alias 的映射
@ -86,7 +87,9 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
// 3. 通过 this.xxx 能拿到的东西太多了,而且自定义的 methods 可能会无意间破坏 Rax 框架或小程序框架在页面 this 上的东东
const customHandlers: HandlerSet<string> = {
expression(input: JSExpression, scope: IScope) {
return transformJsExpr(generateExpression(input, scope), scope);
return transformJsExpr(generateExpression(input, scope), scope, {
dontWrapEval: !tolerateEvalErrors,
});
},
function(input, scope: IScope) {
return transformThis2Context(input.value || 'null', scope);
@ -138,17 +141,14 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
type: ChunkType.STRING,
fileType: cfg.fileType,
name: COMMON_CHUNK_NAME.CustomContent,
content: `
content: [
tolerateEvalErrors &&
`
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
} catch (error) {
${evalErrorsHandler}
}
}
@ -156,16 +156,57 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
`,
`
function __$$createChildContext(oldContext, ext) {
return Object.assign({}, oldContext, ext);
}
`,
]
.filter(Boolean)
.join('\n'),
linkAfter: [COMMON_CHUNK_NAME.FileExport],
});
return next;
function generateRaxLoopCtrl(
nodeItem: NodeSchema,
scope: IScope,
config?: NodeGeneratorConfig,
next?: NodePlugin,
): CodePiece[] {
if (nodeItem.loop) {
const loopItemName = nodeItem.loopArgs?.[0] || 'item';
const loopIndexName = nodeItem.loopArgs?.[1] || 'index';
const subScope = scope.createSubScope([loopItemName, loopIndexName]);
const pieces: CodePiece[] = next ? next(nodeItem, subScope, config) : [];
const loopDataExpr = tolerateEvalErrors
? `__$$evalArray(() => (${transformThis2Context(
generateCompositeType(nodeItem.loop, scope, { handlers: config?.handlers }),
scope,
)}))`
: `(${transformThis2Context(
generateCompositeType(nodeItem.loop, scope, { handlers: config?.handlers }),
scope,
)})`;
pieces.unshift({
value: `${loopDataExpr}.map((${loopItemName}, ${loopIndexName}) => ((__$$context) => (`,
type: PIECE_TYPE.BEFORE,
});
pieces.push({
value: `))(__$$createChildContext(__$$context, { ${loopItemName}, ${loopIndexName} })))`,
type: PIECE_TYPE.AFTER,
});
return pieces;
}
return next ? next(nodeItem, scope, config) : [];
}
};
return plugin;
@ -189,39 +230,6 @@ function isImportAliasDefineChunk(chunk: ICodeChunk): chunk is ICodeChunk & {
);
}
function generateRaxLoopCtrl(
nodeItem: NodeSchema,
scope: IScope,
config?: NodeGeneratorConfig,
next?: NodePlugin,
): CodePiece[] {
if (nodeItem.loop) {
const loopItemName = nodeItem.loopArgs?.[0] || 'item';
const loopIndexName = nodeItem.loopArgs?.[1] || 'index';
const subScope = scope.createSubScope([loopItemName, loopIndexName]);
const pieces: CodePiece[] = next ? next(nodeItem, subScope, config) : [];
const loopDataExpr = `__$$evalArray(() => (${transformThis2Context(
generateCompositeType(nodeItem.loop, scope, { handlers: config?.handlers }),
scope,
)}))`;
pieces.unshift({
value: `${loopDataExpr}.map((${loopItemName}, ${loopIndexName}) => ((__$$context) => (`,
type: PIECE_TYPE.BEFORE,
});
pieces.push({
value: `))(__$$createChildContext(__$$context, { ${loopItemName}, ${loopIndexName} })))`,
type: PIECE_TYPE.AFTER,
});
return pieces;
}
return next ? next(nodeItem, scope, config) : [];
}
function generateNodeAttrForRax(
this: { cfg: PluginConfig },
attrData: { attrName: string; attrValue: CompositeValue },

View File

@ -42,12 +42,14 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
...pre,
};
const { tolerateEvalErrors = true, evalErrorsHandler = '' } = next.contextData;
// 这里会将内部的一些子上下文的访问(this.xxx)转换为 __$$context.xxx 的形式
// 与 Rax 所不同的是,这里不会将最顶层的 this 转换掉
const customHandlers: HandlerSet<string> = {
expression(input: JSExpression, scope: IScope) {
return transformJsExpr(generateExpression(input, scope), scope, {
dontWrapEval: true,
dontWrapEval: !tolerateEvalErrors,
dontTransformThis2ContextAtRootScope: true,
});
},
@ -111,7 +113,23 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
type: ChunkType.STRING,
fileType: cfg.fileType,
name: COMMON_CHUNK_NAME.CustomContent,
content: `
content: [
tolerateEvalErrors &&
`
function __$$eval(expr) {
try {
return expr();
} catch (error) {
${evalErrorsHandler}
}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
`,
`
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,
@ -121,6 +139,9 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
return childContext;
}
`,
]
.filter(Boolean)
.join('\n'),
linkAfter: [COMMON_CHUNK_NAME.FileExport],
});
return next;

View File

@ -1,4 +1,4 @@
import { IProjectBuilder } from '../types';
import { IProjectBuilder, IProjectBuilderOptions } from '../types';
import { createProjectBuilder } from '../generator/ProjectBuilder';
@ -22,15 +22,14 @@ import icejs from '../plugins/project/framework/icejs';
import { prettier } from '../postprocessor';
export type IceJsProjectBuilderOptions = {
inStrictMode?: boolean;
};
export interface IceJsProjectBuilderOptions extends IProjectBuilderOptions {}
export default function createIceJsProjectBuilder(
options?: IceJsProjectBuilderOptions,
): IProjectBuilder {
return createProjectBuilder({
inStrictMode: options?.inStrictMode,
extraContextData: { ...options },
template: icejs.template,
plugins: {
components: [

View File

@ -1,4 +1,4 @@
import { IProjectBuilder } from '../types';
import { IProjectBuilder, IProjectBuilderOptions } from '../types';
import { createProjectBuilder } from '../generator/ProjectBuilder';
@ -22,8 +22,14 @@ import raxApp from '../plugins/project/framework/rax';
import { prettier } from '../postprocessor';
import { RaxFrameworkOptions } from '../plugins/project/framework/rax/types/RaxFrameworkOptions';
export default function createRaxProjectBuilder(options?: RaxFrameworkOptions): IProjectBuilder {
export interface RaxProjectBuilderOptions extends IProjectBuilderOptions, RaxFrameworkOptions {}
export default function createRaxProjectBuilder(
options?: RaxProjectBuilderOptions,
): IProjectBuilder {
return createProjectBuilder({
inStrictMode: options?.inStrictMode,
extraContextData: { ...options },
template: raxApp.template,
plugins: {
components: [

View File

@ -63,10 +63,7 @@ export interface ICodeStruct extends IBaseCodeStruct {
}
/** 上下文数据,用来在插件之间共享一些数据 */
export interface IContextData {
/** 是否处于严格模式 */
inStrictMode?: boolean;
export interface IContextData extends IProjectBuilderOptions {
/** 是否使用了 Ref 的 API (this.$/this.$$) */
useRefApi?: boolean;
@ -139,6 +136,33 @@ export interface IProjectPlugins {
[slotName: string]: BuilderComponentPlugin[];
}
export interface IProjectBuilderOptions {
/** 是否处于严格模式(默认: 否) */
inStrictMode?: boolean;
/**
* JSExpression
* true
* : 如果容忍异常 try-catch
* catch CustomEvent
*/
tolerateEvalErrors?: boolean;
/**
*
* 默认:
*
* window.dispatchEvent(new CustomEvent('lowcode-eval-error', { error, expr }))
*
*
*
* :
* - error: 异常信息
* - expr: 求值的表达式
*/
evalErrorsHandler?: string;
}
export interface IProjectBuilder {
generateProject: (schema: ProjectSchema | string) => Promise<ResultDir>;
}

View File

@ -129,13 +129,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -336,13 +336,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -138,13 +138,7 @@ export default Detail$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -138,13 +138,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -141,13 +141,7 @@ export default List$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -133,13 +133,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -135,13 +135,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -141,13 +141,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -135,13 +135,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -141,13 +141,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -144,13 +144,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -146,13 +146,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -158,13 +158,7 @@ export default Aaaa$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -149,13 +149,7 @@ export default Home$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -160,13 +160,7 @@ export default Example$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (err) {
try {
if (window.handleEvalError) {
window.handleEvalError('Failed to evaluate: ', expr, err);
}
} catch (e) {}
}
} catch (error) {}
}
function __$$evalArray(expr) {

View File

@ -131,7 +131,7 @@ class Test$$Page extends React.Component {
return (
<div ref={this._refsManager.linkRef("outterView")} autoLoading={true}>
<Form
labelCol={this.state.colNum}
labelCol={__$$eval(() => this.state.colNum)}
style={{}}
ref={this._refsManager.linkRef("testForm")}
>
@ -154,9 +154,9 @@ class Test$$Page extends React.Component {
<Button.Group>
{["a", "b", "c"].map((item, index) =>
((__$$context) =>
!!(index >= 1) && (
!!__$$eval(() => index >= 1) && (
<Button type="primary" style={{ margin: "0 5px 0 5px" }}>
{item}
{__$$eval(() => item)}
</Button>
))(__$$createChildContext(__$$context, { item, index }))
)}
@ -170,6 +170,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -87,6 +87,17 @@ class Aaaa$$Page extends React.Component {
export default Aaaa$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -43,12 +43,12 @@ class Test$$Page extends React.Component {
return (
<div ref={this._refsManager.linkRef("outterView")} autoLoading={true}>
<Form
labelCol={this.state.colNum}
labelCol={__$$eval(() => this.state.colNum)}
style={{}}
ref={this._refsManager.linkRef("testForm")}
>
<Form.Item
label={this.i18n("i18n-jwg27yo4")}
label={__$$eval(() => this.i18n("i18n-jwg27yo4"))}
name="name"
initValue="李雷"
>
@ -92,6 +92,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -45,7 +45,7 @@ class Test$$Page extends React.Component {
const { state } = __$$context;
return (
<div>
<Super title={this.state.title} />
<Super title={__$$eval(() => this.state.title)} />
<SuperSub />
<SuperOther />
<Button />
@ -62,6 +62,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -190,7 +190,7 @@ class Test$$Page extends React.Component {
flex={true}
>
<AliSearchTable
dataSource={this.state.users.data}
dataSource={__$$eval(() => this.state.users.data)}
rowKey="workid"
columns={[
{ title: "花名", dataIndex: "cname" },
@ -265,6 +265,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -152,7 +152,7 @@ class Test$$Page extends React.Component {
width: "400px",
display: "inline-block",
}}
options={this.state.gateways}
options={__$$eval(() => this.state.gateways)}
mode="single"
defaultValue={["auto-edd-uniproxy"]}
labelInValue={true}
@ -220,7 +220,7 @@ class Test$$Page extends React.Component {
</Button>
<Modal
title="创建发布单"
visible={this.state.modalVisible}
visible={__$$eval(() => this.state.modalVisible)}
footer=""
__events={{
eventDataList: [
@ -317,7 +317,7 @@ class Test$$Page extends React.Component {
</Modal>
<AliAutoSearchTableDefault
rowKey="key"
dataSource={this.state.records}
dataSource={__$$eval(() => this.state.records)}
columns={[
{
title: "发布名称",
@ -342,7 +342,7 @@ class Test$$Page extends React.Component {
},
{ title: "发布时间", dataIndex: "publish_id" },
]}
actions={this.actions || []}
actions={__$$eval(() => this.actions || [])}
getActions={function () {
return this.getActions.apply(
this,
@ -362,6 +362,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -131,7 +131,7 @@ class Test$$Page extends React.Component {
return (
<div ref={this._refsManager.linkRef("outterView")} autoLoading={true}>
<Form
labelCol={this.state.colNum}
labelCol={__$$eval(() => this.state.colNum)}
style={{}}
ref={this._refsManager.linkRef("testForm")}
>
@ -156,7 +156,7 @@ class Test$$Page extends React.Component {
((__$$context) =>
!!false && (
<Button type="primary" style={{ margin: "0 5px 0 5px" }}>
{item}
{__$$eval(() => item)}
</Button>
))(__$$createChildContext(__$$context, { item, index }))
)}
@ -170,6 +170,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -200,7 +200,7 @@ class Test$$Page extends React.Component {
>
<Modal
title="是否修改"
visible={this.state.isModifyDialogVisible}
visible={__$$eval(() => this.state.isModifyDialogVisible)}
okText="确认"
okType=""
forceRender={false}
@ -293,13 +293,13 @@ class Test$$Page extends React.Component {
flex={true}
style={{ marginBottom: "24px" }}
>
<Steps current={this.state.currentStep}>
<Steps current={__$$eval(() => this.state.currentStep)}>
<Steps.Step title="版本申请" description="" />
<Steps.Step title="机器配置" subTitle="" description="" />
<Steps.Step title="项目审批" description="" />
</Steps>
</NextP>
{!!(this.state.currentStep === 0) && (
{!!__$$eval(() => this.state.currentStep === 0) && (
<NextP
wrap={false}
type="body2"
@ -347,7 +347,9 @@ class Test$$Page extends React.Component {
{ name: "onValuesChange", disabled: true },
],
}}
initialValues={this.state.customerProjectInfo}
initialValues={__$$eval(
() => this.state.customerProjectInfo
)}
onValuesChange={function () {
this.onValuesChange.apply(
this,
@ -391,10 +393,11 @@ class Test$$Page extends React.Component {
{ label: "UI定制", value: "4", disabled: false },
]}
style={{ width: "600px" }}
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
/>
</Form.Item>
<Form.Item
@ -409,11 +412,12 @@ class Test$$Page extends React.Component {
>
<Select
style={{ width: "600px" }}
options={this.state.versionLinesArray}
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
options={__$$eval(() => this.state.versionLinesArray)}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
placeholder="请选择版本线"
/>
</Form.Item>
@ -442,10 +446,11 @@ class Test$$Page extends React.Component {
<Input
placeholder="公司简称-产品名称-版本类型"
style={{ width: "600px" }}
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
/>
</Form.Item>
<Form.Item
@ -462,10 +467,11 @@ class Test$$Page extends React.Component {
>
<DatePicker
style={{ width: "600px" }}
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
/>
</Form.Item>
<Form.Item
@ -484,10 +490,11 @@ class Test$$Page extends React.Component {
value={3}
style={{ width: "600px" }}
placeholder="单位(台)使用该版本的机器数量+预计出货量,请如实填写"
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
min={0}
size="middle"
/>
@ -543,7 +550,7 @@ class Test$$Page extends React.Component {
</Form>
</NextP>
)}
{!!(this.state.currentStep === 1) && (
{!!__$$eval(() => this.state.currentStep === 1) && (
<NextP
wrap={false}
type="body2"
@ -592,7 +599,9 @@ class Test$$Page extends React.Component {
{ name: "onValuesChange", disabled: true },
],
}}
initialValues={this.state.customerProjectInfo}
initialValues={__$$eval(
() => this.state.customerProjectInfo
)}
onValuesChange={function () {
this.onValuesChange.apply(
this,
@ -614,11 +623,12 @@ class Test$$Page extends React.Component {
>
<Select
style={{ width: "600px" }}
options={this.state.projectModalsArray}
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
options={__$$eval(() => this.state.projectModalsArray)}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
placeholder="请选择设备类型"
/>
</Form.Item>
@ -638,10 +648,11 @@ class Test$$Page extends React.Component {
value={3}
style={{ width: "600px" }}
placeholder="例如1280"
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
min={0}
/>
</Form.Item>
@ -661,10 +672,11 @@ class Test$$Page extends React.Component {
value={3}
style={{ width: "600px" }}
placeholder="例如720"
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
min={0}
/>
</Form.Item>
@ -684,10 +696,11 @@ class Test$$Page extends React.Component {
value={3}
style={{ width: "600px" }}
placeholder="请输入尺寸"
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
min={0}
/>
</Form.Item>
@ -703,10 +716,11 @@ class Test$$Page extends React.Component {
value={3}
style={{ width: "600px" }}
placeholder="UI定制项目必填"
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
min={0}
/>
</Form.Item>
@ -727,10 +741,11 @@ class Test$$Page extends React.Component {
<Input
placeholder="请输入芯片名称"
style={{ width: "600px" }}
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
/>
</Form.Item>
<Form.Item
@ -749,10 +764,11 @@ class Test$$Page extends React.Component {
value={3}
style={{ width: "600px" }}
placeholder="请输入芯片核数"
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
defaultValue=""
min={0}
/>
@ -767,11 +783,12 @@ class Test$$Page extends React.Component {
>
<Select
style={{ width: "600px" }}
options={this.state.instructionsArray}
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
options={__$$eval(() => this.state.instructionsArray)}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
/>
</Form.Item>
<Form.Item
@ -788,11 +805,12 @@ class Test$$Page extends React.Component {
>
<Select
style={{ width: "600px" }}
options={this.state.osVersionsArray}
disabled={
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
}
options={__$$eval(() => this.state.osVersionsArray)}
disabled={__$$eval(
() =>
this.state.customerProjectInfo.id > 0 &&
!this.state.isModifyStatus
)}
placeholder="请选择系统版本"
/>
</Form.Item>
@ -829,11 +847,12 @@ class Test$$Page extends React.Component {
type="primary"
htmlType="submit"
style={{ float: "right", marginLeft: "20px" }}
loading={
this.state.LOADING_ADD_OR_UPDATE_CUSTOMER_PROJECT
}
loading={__$$eval(
() =>
this.state.LOADING_ADD_OR_UPDATE_CUSTOMER_PROJECT
)}
>
{this.state.secondCommitText}
{__$$eval(() => this.state.secondCommitText)}
</Button>
<Button
type="primary"
@ -862,7 +881,7 @@ class Test$$Page extends React.Component {
</Form>
</NextP>
)}
{!!(this.state.currentStep === 2) && (
{!!__$$eval(() => this.state.currentStep === 2) && (
<NextP
wrap={false}
type="body2"
@ -925,7 +944,7 @@ class Test$$Page extends React.Component {
style={{ width: "200px" }}
/>
<Steps.Step
title={this.state.thirdAuditText}
title={__$$eval(() => this.state.thirdAuditText)}
subTitle=""
description=""
style={{ width: "200px" }}
@ -982,9 +1001,11 @@ class Test$$Page extends React.Component {
);
}.bind(this)}
>
{this.state.thirdButtonText}
{__$$eval(() => this.state.thirdButtonText)}
</Button>
{!!(this.state.customerProjectInfo.status > 2) && (
{!!__$$eval(
() => this.state.customerProjectInfo.status > 2
) && (
<Button
type="primary"
htmlType="submit"
@ -1023,6 +1044,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -72,7 +72,7 @@ class Example$$Page extends React.Component {
return (
<div>
<Table
dataSource={this.dataSourceMap["userList"]}
dataSource={__$$eval(() => this.dataSourceMap["userList"])}
columns={[
{ dataIndex: "name", title: "姓名" },
{ dataIndex: "age", title: "年龄" },
@ -85,6 +85,17 @@ class Example$$Page extends React.Component {
export default Example$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -75,13 +75,13 @@ class Index$$Page extends React.Component {
return (
<div>
<div>
{this.dataSourceMap.todos.data.map((item, index) =>
{__$$eval(() => this.dataSourceMap.todos.data).map((item, index) =>
((__$$context) => (
<div>
<Switch
checkedChildren="开"
unCheckedChildren="关"
checked={item.done}
checked={__$$eval(() => item.done)}
/>
</div>
))(__$$createChildContext(__$$context, { item, index }))
@ -94,6 +94,17 @@ class Index$$Page extends React.Component {
export default Index$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -192,7 +192,7 @@ class Test$$Page extends React.Component {
>
<Modal
title="查看结果"
visible={this.state.resultVisible}
visible={__$$eval(() => this.state.resultVisible)}
footer={
<Button
type="primary"
@ -238,12 +238,13 @@ class Test$$Page extends React.Component {
width="720px"
centered={true}
>
{this.state.results.map((item, index) =>
{__$$eval(() => this.state.results).map((item, index) =>
((__$$context) => (
<AliAutoDivDefault style={{ width: "100%" }}>
{!!(
__$$context.state.results &&
__$$context.state.results.length > 0
{!!__$$eval(
() =>
__$$context.state.results &&
__$$context.state.results.length > 0
) && (
<AliAutoDivDefault
style={{
@ -277,16 +278,22 @@ class Test$$Page extends React.Component {
</AliAutoDivDefault>
)}
<Typography.Text>
{__$$context.formatResult(item)}
{__$$eval(() => __$$context.formatResult(item))}
</Typography.Text>
{!!item.download_link && (
<Typography.Link href={item.download_link} target="_blank">
{!!__$$eval(() => item.download_link) && (
<Typography.Link
href={__$$eval(() => item.download_link)}
target="_blank"
>
{" "}
- 点击下载
</Typography.Link>
)}
{!!item.release_notes && (
<Typography.Link href={item.release_notes} target="_blank">
{!!__$$eval(() => item.release_notes) && (
<Typography.Link
href={__$$eval(() => item.release_notes)}
target="_blank"
>
{" "}
- 跳转发布节点
</Typography.Link>
@ -365,7 +372,7 @@ class Test$$Page extends React.Component {
<Form.Item label="项目名称/渠道号" name="channel_id">
<Select
style={{ width: "280px" }}
options={this.state.projects}
options={__$$eval(() => this.state.projects)}
showArrow={true}
tokenSeparators={[]}
showSearch={true}
@ -412,13 +419,14 @@ class Test$$Page extends React.Component {
flex={true}
>
<ConfigProvider locale="zh-CN">
{!!(
!this.state.isSearch ||
(this.state.isSearch && this.state.pkgs.length > 0)
{!!__$$eval(
() =>
!this.state.isSearch ||
(this.state.isSearch && this.state.pkgs.length > 0)
) && (
<AliAutoSearchTableDefault
rowKey="key"
dataSource={this.state.pkgs}
dataSource={__$$eval(() => this.state.pkgs)}
columns={[
{
title: "ID",
@ -433,14 +441,13 @@ class Test$$Page extends React.Component {
width: 142,
render: (text, record, index) =>
((__$$context) =>
text
.split(",")
.map((item, index) =>
__$$eval(() => text.split(",")).map(
(item, index) =>
((__$$context) => (
<Typography.Text
style={{ display: "block" }}
>
{item}
{__$$eval(() => item)}
</Typography.Text>
))(
__$$createChildContext(__$$context, {
@ -448,7 +455,7 @@ class Test$$Page extends React.Component {
index,
})
)
))(
))(
__$$createChildContext(__$$context, {
text,
record,
@ -463,26 +470,32 @@ class Test$$Page extends React.Component {
render: (text, record, index) =>
((__$$context) => (
<Tooltip
title={(text || []).map((item, index) =>
((__$$context) => (
<Typography.Text
style={{
display: "block",
color: "#FFFFFF",
}}
>
{item.channelId + " / " + item.version}
</Typography.Text>
))(
__$$createChildContext(__$$context, {
item,
index,
})
)
title={__$$eval(() => text || []).map(
(item, index) =>
((__$$context) => (
<Typography.Text
style={{
display: "block",
color: "#FFFFFF",
}}
>
{__$$eval(
() =>
item.channelId +
" / " +
item.version
)}
</Typography.Text>
))(
__$$createChildContext(__$$context, {
item,
index,
})
)
)}
>
<Typography.Text>
{text[0].version}
{__$$eval(() => text[0].version)}
</Typography.Text>
</Tooltip>
))(
@ -506,9 +519,9 @@ class Test$$Page extends React.Component {
render: (text, record, index) =>
((__$$context) => [
<Typography.Text>
{__$$context.statusDesc[text]}
{__$$eval(() => __$$context.statusDesc[text])}
</Typography.Text>,
!!(text === 2) && (
!!__$$eval(() => text === 2) && (
<Icon
type="SyncOutlined"
size={16}
@ -552,12 +565,15 @@ class Test$$Page extends React.Component {
dataIndex: "jenkins_link",
render: (text, record, index) =>
((__$$context) => [
!!text && (
<Typography.Link href={text} target="_blank">
!!__$$eval(() => text) && (
<Typography.Link
href={__$$eval(() => text)}
target="_blank"
>
查看
</Typography.Link>
),
!!!text && (
!!__$$eval(() => !text) && (
<Typography.Text>暂无</Typography.Text>
),
])(
@ -575,7 +591,7 @@ class Test$$Page extends React.Component {
width: 120,
render: (text, record, index) =>
((__$$context) => [
!!text && (
!!__$$eval(() => text) && (
<Typography.Link
href="http://rivermap.alibaba.net/dashboard/testExecute"
target="_blank"
@ -583,7 +599,7 @@ class Test$$Page extends React.Component {
查看
</Typography.Link>
),
!!!text && (
!!__$$eval(() => !text) && (
<Typography.Text>暂无</Typography.Text>
),
])(
@ -668,7 +684,7 @@ class Test$$Page extends React.Component {
);
}.bind(__$$context)}
ghost={false}
href={text}
href={__$$eval(() => text)}
>
查看
</Button>
@ -740,7 +756,7 @@ class Test$$Page extends React.Component {
]}
actions={[]}
pagination={{
total: this.state.total,
total: __$$eval(() => this.state.total),
defaultPageSize: 8,
onPageChange: function () {
return this.onPageChange.apply(
@ -766,9 +782,9 @@ class Test$$Page extends React.Component {
align="left"
flex={true}
>
{!!(this.state.pkgs.length < 1 && this.state.isSearch) && (
<Empty description="暂无数据" />
)}
{!!__$$eval(
() => this.state.pkgs.length < 1 && this.state.isSearch
) && <Empty description="暂无数据" />}
</NextP>
</NextBlockCell>
</NextBlock>
@ -780,6 +796,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -218,7 +218,7 @@ class Test$$Page extends React.Component {
>
<Modal
title="查看结果"
visible={this.state.resultVisible}
visible={__$$eval(() => this.state.resultVisible)}
footer={
<Button
type="primary"
@ -269,7 +269,9 @@ class Test$$Page extends React.Component {
maskClosable={true}
>
<AliAutoDivDefault style={{ width: "100%" }}>
{!!(this.state.results && this.state.results.length > 0) && (
{!!__$$eval(
() => this.state.results && this.state.results.length > 0
) && (
<AliAutoDivDefault
style={{
width: "100%",
@ -301,20 +303,26 @@ class Test$$Page extends React.Component {
</Button>
</AliAutoDivDefault>
)}
{this.state.results.map((item, index) =>
{__$$eval(() => this.state.results).map((item, index) =>
((__$$context) => (
<AliAutoDivDefault style={{ width: "100%", marginTop: "10px" }}>
<Typography.Text>
{__$$context.formatResult(item)}
{__$$eval(() => __$$context.formatResult(item))}
</Typography.Text>
{!!item.download_link && (
<Typography.Link href={item.download_link} target="_blank">
{!!__$$eval(() => item.download_link) && (
<Typography.Link
href={__$$eval(() => item.download_link)}
target="_blank"
>
{" "}
- 点击下载
</Typography.Link>
)}
{!!item.release_notes && (
<Typography.Link href={item.release_notes} target="_blank">
{!!__$$eval(() => item.release_notes) && (
<Typography.Link
href={__$$eval(() => item.release_notes)}
target="_blank"
>
{" "}
- 跳转发布节点
</Typography.Link>
@ -378,7 +386,7 @@ class Test$$Page extends React.Component {
preserve={true}
scrollToFirstError={true}
size="middle"
values={this.state.searchValues}
values={__$$eval(() => this.state.searchValues)}
>
<Form.Item
label="项目名称/渠道号"
@ -388,7 +396,7 @@ class Test$$Page extends React.Component {
>
<Select
style={{ width: "320px" }}
options={this.state.projects}
options={__$$eval(() => this.state.projects)}
showArrow={false}
tokenSeparators={[]}
showSearch={true}
@ -454,14 +462,16 @@ class Test$$Page extends React.Component {
<Form.Item label="构建人" name="user_id">
<Select
style={{ width: "210px" }}
options={this.state.userOptions}
options={__$$eval(() => this.state.userOptions)}
showSearch={true}
defaultActiveFirstOption={false}
size="middle"
bordered={true}
filterOption={true}
optionFilterProp="label"
notFoundContent={this.userNotFoundContent}
notFoundContent={__$$eval(
() => this.userNotFoundContent
)}
showArrow={false}
placeholder="请输入构建人"
__events={{
@ -568,13 +578,14 @@ class Test$$Page extends React.Component {
align="left"
flex={true}
>
{!!(
!this.state.isSearch ||
(this.state.isSearch && this.state.pkgs.length > 0)
{!!__$$eval(
() =>
!this.state.isSearch ||
(this.state.isSearch && this.state.pkgs.length > 0)
) && (
<AliAutoSearchTableDefault
rowKey="key"
dataSource={this.state.pkgs}
dataSource={__$$eval(() => this.state.pkgs)}
columns={[
{ title: "ID", dataIndex: "id", key: "name", width: 80 },
{
@ -584,20 +595,18 @@ class Test$$Page extends React.Component {
width: 142,
render: (text, record, index) =>
((__$$context) =>
text
.split(",")
.map((item, index) =>
((__$$context) => (
<Typography.Text style={{ display: "block" }}>
{item}
</Typography.Text>
))(
__$$createChildContext(__$$context, {
item,
index,
})
)
__$$eval(() => text.split(",")).map((item, index) =>
((__$$context) => (
<Typography.Text style={{ display: "block" }}>
{__$$eval(() => item)}
</Typography.Text>
))(
__$$createChildContext(__$$context, {
item,
index,
})
)
))(
__$$createChildContext(__$$context, {
text,
record,
@ -612,26 +621,30 @@ class Test$$Page extends React.Component {
render: (text, record, index) =>
((__$$context) => (
<Tooltip
title={(text || []).map((item, index) =>
((__$$context) => (
<Typography.Text
style={{
display: "block",
color: "#FFFFFF",
}}
>
{item.channelId + " / " + item.version}
</Typography.Text>
))(
__$$createChildContext(__$$context, {
item,
index,
})
)
title={__$$eval(() => text || []).map(
(item, index) =>
((__$$context) => (
<Typography.Text
style={{
display: "block",
color: "#FFFFFF",
}}
>
{__$$eval(
() =>
item.channelId + " / " + item.version
)}
</Typography.Text>
))(
__$$createChildContext(__$$context, {
item,
index,
})
)
)}
>
<Typography.Text>
{text[0].version}
{__$$eval(() => text[0].version)}
</Typography.Text>
</Tooltip>
))(
@ -655,9 +668,9 @@ class Test$$Page extends React.Component {
render: (text, record, index) =>
((__$$context) => [
<Typography.Text>
{__$$context.statusDesc[text]}
{__$$eval(() => __$$context.statusDesc[text])}
</Typography.Text>,
!!(text === 2) && (
!!__$$eval(() => text === 2) && (
<Icon
type="SyncOutlined"
size={16}
@ -701,12 +714,17 @@ class Test$$Page extends React.Component {
dataIndex: "jenkins_link",
render: (text, record, index) =>
((__$$context) => [
!!text && (
<Typography.Link href={text} target="_blank">
!!__$$eval(() => text) && (
<Typography.Link
href={__$$eval(() => text)}
target="_blank"
>
查看
</Typography.Link>
),
!!!text && <Typography.Text>暂无</Typography.Text>,
!!__$$eval(() => !text) && (
<Typography.Text>暂无</Typography.Text>
),
])(
__$$createChildContext(__$$context, {
text,
@ -722,7 +740,7 @@ class Test$$Page extends React.Component {
width: 120,
render: (text, record, index) =>
((__$$context) => [
!!text && (
!!__$$eval(() => text) && (
<Typography.Link
href="http://rivermap.alibaba.net/dashboard/testExecute"
target="_blank"
@ -730,7 +748,9 @@ class Test$$Page extends React.Component {
查看
</Typography.Link>
),
!!!text && <Typography.Text>暂无</Typography.Text>,
!!__$$eval(() => !text) && (
<Typography.Text>暂无</Typography.Text>
),
])(
__$$createChildContext(__$$context, {
text,
@ -813,7 +833,7 @@ class Test$$Page extends React.Component {
);
}.bind(__$$context)}
ghost={false}
href={text}
href={__$$eval(() => text)}
>
查看
</Button>
@ -885,7 +905,7 @@ class Test$$Page extends React.Component {
]}
actions={[]}
pagination={{
total: this.state.total,
total: __$$eval(() => this.state.total),
defaultPageSize: 10,
onPageChange: function () {
return this.onPageChange.apply(
@ -917,9 +937,9 @@ class Test$$Page extends React.Component {
align="left"
flex={true}
>
{!!(this.state.pkgs.length < 1 && this.state.isSearch) && (
<Empty description="暂无数据" />
)}
{!!__$$eval(
() => this.state.pkgs.length < 1 && this.state.isSearch
) && <Empty description="暂无数据" />}
</NextP>
</NextBlockCell>
</NextBlock>
@ -931,6 +951,17 @@ class Test$$Page extends React.Component {
export default Test$$Page;
function __$$eval(expr) {
try {
return expr();
} catch (error) {}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,

View File

@ -35,7 +35,7 @@ function exportProject(
) {
const schemaJsonStr = fs.readFileSync(importPath, { encoding: 'utf8' });
const schema = { ...JSON.parse(schemaJsonStr), ...mergeSchema };
const builder = CodeGenerator.solutions.icejs();
const builder = CodeGenerator.solutions.icejs({ tolerateEvalErrors: false });
return builder.generateProject(schema).then(async (result) => {
const publisher = createDiskPublisher();

View File

@ -7,7 +7,7 @@ Object {
"content": "
const __$$context = this._context || this;
const { state } = __$$context;
return (this.state.otherThings).map((item, index) => ((__$$context) => (!!(__$$context.state.something) && (<Page><Text>Hello world!</Text></Page>)))(__$$createChildContext(__$$context, { item, index })));
return (__$$eval(() => (this.state.otherThings))).map((item, index) => ((__$$context) => (!!(__$$eval(() => (__$$context.state.something))) && (<Page><Text>Hello world!</Text></Page>)))(__$$createChildContext(__$$context, { item, index })));
",
"fileType": "jsx",
"linkAfter": Array [
@ -19,6 +19,20 @@ Object {
},
Object {
"content": "
function __$$eval(expr) {
try {
return expr();
} catch (error) {
}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,
@ -68,7 +82,7 @@ Object {
"content": "
const __$$context = this._context || this;
const { state } = __$$context;
return !!(this.state.something) && (<Page><Text>Hello world!</Text></Page>);
return !!(__$$eval(() => (this.state.something))) && (<Page><Text>Hello world!</Text></Page>);
",
"fileType": "jsx",
"linkAfter": Array [
@ -80,6 +94,20 @@ Object {
},
Object {
"content": "
function __$$eval(expr) {
try {
return expr();
} catch (error) {
}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,
@ -137,6 +165,20 @@ Object {
},
Object {
"content": "
function __$$eval(expr) {
try {
return expr();
} catch (error) {
}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,
@ -191,6 +233,20 @@ Object {
},
Object {
"content": "
function __$$eval(expr) {
try {
return expr();
} catch (error) {
}
}
function __$$evalArray(expr) {
const res = __$$eval(expr);
return Array.isArray(res) ? res : [];
}
function __$$createChildContext(oldContext, ext) {
const childContext = {
...oldContext,