1 | # 企业版忠诚度LP4组件库
|
2 |
|
3 | ## 发布
|
4 | ```bash
|
5 | node scripts/publish.js
|
6 | ```
|
7 |
|
8 | ## 表达式编辑器
|
9 | ### Usage
|
10 | ```javascript
|
11 | import ExpressionEditor from '@shuyun-ep-team/loyalty-lp4-components/editor';
|
12 |
|
13 | const customHints: ICustomHint[] = [
|
14 | /**
|
15 | * 基础版配置
|
16 | */
|
17 | {
|
18 | text: '自定义模板',
|
19 | value: `1 + 1 > 2`
|
20 | },
|
21 | /**
|
22 | * 可自定义命中逻辑的配置
|
23 | */
|
24 | {
|
25 | text: 'custom template',
|
26 | value: '{{C}} {{A}} {{B}} {{D}}',
|
27 | test(input: string) {
|
28 | return !!input.trim() && 'custom template'.includes(input);
|
29 | }
|
30 | },
|
31 |
|
32 | /**
|
33 | * 可自定义命中逻辑
|
34 | * 可自定义显示文本
|
35 | */
|
36 | {
|
37 | text: 'custom template',
|
38 | value: '{{C}} {{A}} {{B}} {{D}}',
|
39 | test(input: string) {
|
40 | return !!input.trim() && 'custom template'.includes(input);
|
41 | },
|
42 | render($li, input: string) {
|
43 | $li.innerHTML = highlight('custom template', input, 'cm-hint-matched-keyword');
|
44 | },
|
45 | }
|
46 | ];
|
47 |
|
48 | <ExpressionEditor
|
49 | fqn={this.fqn}
|
50 | value="1 + 2 == 3"
|
51 | disabled={false}
|
52 | placeholder="忠诚度LP4高级表达式"
|
53 | errorMessage="表达式解析错误"
|
54 | onChange={this.onEditorValueChange}
|
55 | functions={['SUM', 'AVG', 'COUNT']}
|
56 | declarations={['Date', 'Time', 'DateTime']}
|
57 | customHints={customHints}
|
58 | operatorReplacements={[code: '&&', name: '且']}
|
59 | customProperties={[
|
60 | { id: 1, name: '姓名', dataType: 'String' },
|
61 | { id: 2, name: '年龄', dataType: 'Integer', disabled: true },
|
62 | { id: 3, name: '生日', dataType: 'DateTime' }
|
63 | ]}
|
64 | onRef={editor => this.editor = editor}
|
65 | />
|
66 | ```
|
67 |
|
68 | ```javascript
|
69 | // 预览模式
|
70 | import ExpressionPreview from '@shuyun-ep-team/loyalty-lp4-components/editor/preview';
|
71 |
|
72 | <ExpressionPreview
|
73 | fqn={this.fqn}
|
74 | value="1 + 2 == 3"
|
75 | functions={['SUM', 'AVG', 'COUNT']}
|
76 | declarations={['Date', 'Time', 'DateTime']}
|
77 | operatorReplacements={[code: '&&', name: '且']}
|
78 | customProperties={[
|
79 | { id: 1, name: '姓名', dataType: 'String' },
|
80 | { id: 2, name: '年龄', dataType: 'Integer', disabled: true },
|
81 | { id: 3, name: '生日', dataType: 'DateTime' }
|
82 | ]}
|
83 | />
|
84 | ```
|
85 |
|
86 | ## 表达式类型推导
|
87 | ### Usage
|
88 | ```javascript
|
89 | import ExpressionInference, { getCustomProperies, getSpecialTokens } from '@shuyun-ep-team/loyalty-lp4-components/ast';
|
90 |
|
91 | const input = '{3} > DateTime("2019-01-17T06:57:58.390Z")';
|
92 | const config = {
|
93 | functions: ['SUM', 'AVG', 'COUNT'],
|
94 | declarations: ['Date', 'Time', 'DateTime'],
|
95 | customProperties: [
|
96 | { id: 1, name: '姓名', dataType: 'String' },
|
97 | { id: 2, name: '年龄', dataType: 'Integer', disabled: true },
|
98 | { id: 3, name: '生日', dataType: 'DateTime' }
|
99 | ]
|
100 | };
|
101 |
|
102 | // 推断表达式返回的数据类型
|
103 | console.log(ExpressionInference(input, config)); // Boolean
|
104 |
|
105 | // 获取表达式中被使用的属性(已废弃,不建议使用)
|
106 | console.log(getCustomProperies(input, config)); // [{ id: 3, name: '生日', dataType: 'DateTime' }
|
107 |
|
108 |
|
109 | // 获取表达式中用到的特殊属性集合(仅做模式匹配),例如 自定义属性
|
110 | const {
|
111 | customProperties, // 自定义属性
|
112 | pointAccounts, // 积分账户
|
113 | gradeHierarchies // 等级体系
|
114 | } = getSpecialTokens(input, config);
|
115 |
|
116 | ```
|