2.18.2 • Published 5 years ago

@shuyun-ep-team/loyalty-lp4-components v2.18.2

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

企业版忠诚度LP4组件库

发布

node scripts/publish.js

表达式编辑器

Usage

import ExpressionEditor from '@shuyun-ep-team/loyalty-lp4-components/editor';

const customHints: ICustomHint[] = [
  /**
   * 基础版配置
   */
  {
    text: '自定义模板',
    value: `1 + 1 > 2`
  },
  /**
   * 可自定义命中逻辑的配置
   */
  {
    text: 'custom template',
    value: '{{C}} {{A}} {{B}} {{D}}',
    test(input: string) {
      return !!input.trim() && 'custom template'.includes(input);
    }
  },

  /**
   * 可自定义命中逻辑
   * 可自定义显示文本
   */
  {
    text: 'custom template',
    value: '{{C}} {{A}} {{B}} {{D}}',
    test(input: string) {
      return !!input.trim() && 'custom template'.includes(input);
    },
    render($li, input: string) {
      $li.innerHTML = highlight('custom template', input, 'cm-hint-matched-keyword');
    },
  }
  ];

<ExpressionEditor
    fqn={this.fqn}
    value="1 + 2 == 3"
    disabled={false}
    placeholder="忠诚度LP4高级表达式"
    errorMessage="表达式解析错误"
    onChange={this.onEditorValueChange}
    functions={['SUM', 'AVG', 'COUNT']}
    declarations={['Date', 'Time', 'DateTime']}
    customHints={customHints}
    operatorReplacements={[code: '&&', name: '且']}
    customProperties={[
      { id: 1, name: '姓名', dataType: 'String' },
      { id: 2, name: '年龄', dataType: 'Integer', disabled: true },
      { id: 3, name: '生日', dataType: 'DateTime' }
    ]}
    onRef={editor => this.editor = editor}
/>
// 预览模式
import ExpressionPreview from '@shuyun-ep-team/loyalty-lp4-components/editor/preview';

<ExpressionPreview
    fqn={this.fqn}
    value="1 + 2 == 3"
    functions={['SUM', 'AVG', 'COUNT']}
    declarations={['Date', 'Time', 'DateTime']}
    operatorReplacements={[code: '&&', name: '且']}
    customProperties={[
      { id: 1, name: '姓名', dataType: 'String' },
      { id: 2, name: '年龄', dataType: 'Integer', disabled: true },
      { id: 3, name: '生日', dataType: 'DateTime' }
    ]}
/>

表达式类型推导

Usage

import ExpressionInference, { getCustomProperies, getSpecialTokens } from '@shuyun-ep-team/loyalty-lp4-components/ast';

const input = '{3} > DateTime("2019-01-17T06:57:58.390Z")';
const config = {
  functions: ['SUM', 'AVG', 'COUNT'],
  declarations: ['Date', 'Time', 'DateTime'],
  customProperties: [
    { id: 1, name: '姓名', dataType: 'String' },
    { id: 2, name: '年龄', dataType: 'Integer', disabled: true },
    { id: 3, name: '生日', dataType: 'DateTime' }
  ]
};

// 推断表达式返回的数据类型
console.log(ExpressionInference(input, config)); // Boolean

// 获取表达式中被使用的属性(已废弃,不建议使用)
console.log(getCustomProperies(input, config)); // [{ id: 3, name: '生日', dataType: 'DateTime' }


// 获取表达式中用到的特殊属性集合(仅做模式匹配),例如 自定义属性
const {
  customProperties, // 自定义属性
  pointAccounts, // 积分账户
  gradeHierarchies // 等级体系
} = getSpecialTokens(input, config);
2.18.2

5 years ago

2.18.1

6 years ago

2.18.0

6 years ago

2.17.1

6 years ago

2.16.4

6 years ago

2.16.3

6 years ago

2.16.2

6 years ago

2.16.1

6 years ago

2.16.0

6 years ago

2.15.0

6 years ago

2.14.3

6 years ago

2.14.2

6 years ago

2.14.1

6 years ago

2.14.0

6 years ago

2.13.0

6 years ago

2.12.0

6 years ago

2.11.0

6 years ago

2.10.0

6 years ago

2.9.1

6 years ago

2.9.0

6 years ago

2.8.0

6 years ago

2.7.3

6 years ago

2.7.2

6 years ago

2.7.1

6 years ago

2.7.0

6 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.5

6 years ago

2.5.4

6 years ago

2.5.3

6 years ago

2.5.2

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.4.3

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.0

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

1.9.4

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.9.3

6 years ago

1.9.2

6 years ago

1.9.1

6 years ago

1.9.0

6 years ago

1.8.0

6 years ago

1.7.6

6 years ago

1.7.5

6 years ago

1.7.4

6 years ago

1.7.3

6 years ago

1.7.2

6 years ago

1.7.1

6 years ago

1.7.0

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago