vue2-client 1.11.4 → 1.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/package.json +1 -1
  2. package/src/base-client/components/common/CitySelect/CitySelect.vue +366 -342
  3. package/src/base-client/components/common/Upload/Upload.vue +322 -322
  4. package/src/base-client/components/common/XDescriptions/XDescriptionsGroup.vue +61 -51
  5. package/src/base-client/components/common/XDescriptions/demo.vue +10 -9
  6. package/src/base-client/components/common/XFormGroup/demo.vue +3 -10
  7. package/src/base-client/components/common/XFormTable/demo.vue +60 -60
  8. package/src/components/STable/index.js +426 -426
  9. package/src/expression/ExpressionRunner.ts +28 -0
  10. package/src/expression/TestExpression.ts +509 -0
  11. package/src/expression/core/Delegate.ts +114 -0
  12. package/src/expression/core/Expression.ts +1295 -0
  13. package/src/expression/core/Program.ts +950 -0
  14. package/src/expression/core/Token.ts +29 -0
  15. package/src/expression/enums/ExpressionType.ts +81 -0
  16. package/src/expression/enums/TokenType.ts +13 -0
  17. package/src/expression/exception/BreakWayException.ts +2 -0
  18. package/src/expression/exception/ContinueWayException.ts +2 -0
  19. package/src/expression/exception/ExpressionException.ts +28 -0
  20. package/src/expression/exception/ReturnWayException.ts +14 -0
  21. package/src/expression/exception/ServiceException.ts +22 -0
  22. package/src/expression/instances/JSONArray.ts +48 -0
  23. package/src/expression/instances/JSONObject.ts +109 -0
  24. package/src/expression/instances/LogicConsole.ts +32 -0
  25. package/src/router/async/router.map.js +3 -2
  26. package/src/utils/indexedDB.js +234 -234
@@ -0,0 +1,28 @@
1
+ import Program from './core/Program'
2
+ import Delegate from './core/Delegate'
3
+ import JSONObject from "./instances/JSONObject";
4
+
5
+ export default class ExpressionRunner {
6
+ /**
7
+ * Runs an expression with parameters
8
+ *
9
+ * @param source Expression source
10
+ * @param params Expression parameters
11
+ * @returns The result of the expression
12
+ */
13
+ public static run(source: string, params: JSONObject): any {
14
+ const delegate: Delegate = this.getDelegate(source);
15
+ return delegate.invoke(params);
16
+ }
17
+
18
+ /**
19
+ * Gets the delegate for the expression
20
+ *
21
+ * @param source Expression source
22
+ * @returns A delegate to invoke
23
+ */
24
+ public static getDelegate(source: string): Delegate {
25
+ // Parse the source and return a delegate
26
+ return new Program(source).parse();
27
+ }
28
+ }
@@ -0,0 +1,509 @@
1
+ import ExpressionRunner from './ExpressionRunner'
2
+ import Program from "./core/Program";
3
+ import JSONObject from "./instances/JSONObject";
4
+ import LogicConsole from "./instances/LogicConsole";
5
+
6
+ console.debug("1.========testValidate========")
7
+ testValidate()
8
+ console.debug("2.========testAssert========")
9
+ testAssert()
10
+ console.debug("3.========testTry========")
11
+ testTry()
12
+ console.debug("4.========testPropertyType========")
13
+ testPropertyType()
14
+ console.debug("5.========testJSONArrayIndex========")
15
+ testJSONArrayIndex()
16
+ console.debug("6.========testArrayIndex========")
17
+ testArrayIndex()
18
+ console.debug("7.========testCompare========")
19
+ testCompare()
20
+ console.debug("8.========testJSONObject========")
21
+ testJSONObject()
22
+ console.debug("9.========testJSONArray========")
23
+ testJSONArray()
24
+ console.debug("10.========testFunctionCall========")
25
+ testFunctionCall()
26
+ console.debug("11.========testMath========")
27
+ testMath()
28
+ console.debug("12.========testString========")
29
+ testString()
30
+ console.debug("13.========testCondition========")
31
+ testCondition()
32
+ console.debug("14.========testThrow========")
33
+ testThrow()
34
+ console.debug("15.========testJSONArrayLoop========")
35
+ testJSONArrayLoop()
36
+ console.debug("16.========testJSONObjectLoop========")
37
+ testJSONObjectLoop()
38
+ console.debug("17.========testIntLoop========")
39
+ testIntLoop()
40
+ console.debug("18.========testContinueAndBreak========")
41
+ testContinueAndBreak()
42
+ console.debug("19.========testComment========")
43
+ testComment()
44
+ console.debug("20.========testReturn========")
45
+ testReturn()
46
+ console.debug("21.========testLambda========")
47
+ testLambda()
48
+
49
+ /**
50
+ * validate
51
+ */
52
+ function testValidate () {
53
+ const expression = `
54
+ validate {
55
+ model: {
56
+ required: true,
57
+ },
58
+ visible: {
59
+ default: 1 + 1,
60
+ },
61
+ isAep: {
62
+ default: 3
63
+ },
64
+ testJson: {
65
+ required: true,
66
+ items: {
67
+ userid: {
68
+ required: true
69
+ }
70
+ }
71
+ },
72
+ testGroup: {
73
+ mode: "atLeastOne",
74
+ fields: [
75
+ "test1",
76
+ "test2"
77
+ ]
78
+ }
79
+ },
80
+ data.isAep == 3 :(
81
+ log.info(123)
82
+ ),null,
83
+ log.info(data)
84
+ `
85
+ const data = {
86
+ model: 'a',
87
+ test1: 'b',
88
+ isAep: null,
89
+ testJson: {
90
+ userid: {}
91
+ }
92
+ }
93
+ runExpression(expression, data)
94
+ }
95
+
96
+ /**
97
+ * assert
98
+ */
99
+ function testAssert () {
100
+ const expression = `
101
+ c = 1,
102
+ assert c == 1,
103
+ log.debug("ok"),
104
+ a = 1 + c,
105
+ assert a == 2,
106
+ log.debug("ok2")`
107
+ runExpression(expression);
108
+ }
109
+
110
+ /**
111
+ * try
112
+ */
113
+ function testTry () {
114
+ const expression = `
115
+ a = 0,
116
+ log.debug(a),
117
+ try {
118
+ assert c == 2
119
+ } catch (WebException e) {
120
+ log.debug(e),
121
+ a = 1 + 1
122
+ } catch (Exception e) {
123
+ log.debug(e),
124
+ a = 1 + 2
125
+ },
126
+ log.debug(a)
127
+ `
128
+ runExpression(expression)
129
+ }
130
+
131
+ /**
132
+ * property
133
+ */
134
+ function testPropertyType() {
135
+ const expression = `
136
+ a = 1,
137
+ b = 2.0,
138
+ c = {
139
+ d: 1,
140
+ e: {
141
+ str: "123",
142
+ 你好: "中国"
143
+ }
144
+ },
145
+ c.a = 1,
146
+ log.debug(c.e.你好),
147
+ log.debug(c["e"].str),
148
+ e = c.d,
149
+ f = "123",
150
+ g = [],
151
+ 名称 = "123=>",
152
+ log.debug(data.testArray[0]),
153
+ return 名称
154
+ `
155
+ const data = {
156
+ testArray: "zhang|b|c".split("\|")
157
+ }
158
+ runExpression(expression, data)
159
+ }
160
+
161
+ /**
162
+ * JSONArray index
163
+ */
164
+ function testJSONArrayIndex() {
165
+ const expression = `
166
+ a = [1,2,3,4,5],
167
+ return a[4]
168
+ `;
169
+ runExpression(expression)
170
+ }
171
+
172
+ /**
173
+ * array index
174
+ */
175
+ function testArrayIndex() {
176
+ const expression = `
177
+ return data.a[4]
178
+ `;
179
+ const data = {
180
+ a: [1,2,3,4,5]
181
+ }
182
+ runExpression(expression, data)
183
+ }
184
+
185
+ function testCompare() {
186
+ const expression = `
187
+ a = 0,
188
+ a >= 0 :(
189
+ a = a + 1,
190
+ b = 1,
191
+ a == b :(
192
+ c = 3.0,
193
+ a < c :(
194
+ a + 2,
195
+ a <= c :(
196
+ strA = $a$,
197
+ strB = $b$,
198
+ strC = $c$,
199
+ strA < strB && strA != strC :(
200
+ return $ok$
201
+ ),null
202
+ ),null
203
+ ),null
204
+ ),null
205
+ ),null
206
+ `;
207
+ runExpression(expression)
208
+ }
209
+
210
+ /**
211
+ * JSONObject
212
+ */
213
+ function testJSONObject() {
214
+ const expression = `
215
+ datas = {
216
+ name: "张三",
217
+ 年龄: 15,
218
+ },
219
+ datas
220
+ `
221
+ runExpression(expression)
222
+ }
223
+
224
+ /**
225
+ * JSONArray
226
+ */
227
+ function testJSONArray() {
228
+ const expression = `
229
+ datas = ["a","b","c"],
230
+ datas
231
+ `
232
+ runExpression(expression)
233
+ }
234
+
235
+ /**
236
+ * function call
237
+ */
238
+ function testFunctionCall() {
239
+ const expression = `
240
+ log.debug("test is ok")
241
+ `
242
+ runExpression(expression)
243
+ }
244
+
245
+ /**
246
+ * math
247
+ */
248
+ function testMath() {
249
+ const expression = `
250
+ a = 1,
251
+ b = 2,
252
+ c = a + b,
253
+ c = c - 1,
254
+ d = 5 * 8,
255
+ e = d / 10,
256
+ e = e % 2,
257
+ c
258
+ `
259
+ runExpression(expression)
260
+ }
261
+
262
+ /**
263
+ * string
264
+ */
265
+ function testString() {
266
+ const expression = `
267
+ test1 = {}.toString(),
268
+ log.debug(test1),
269
+ a = $part1$,
270
+ log.debug(a),
271
+ b = "part2",
272
+ log.debug(b),
273
+ c = "{a}:{b}",
274
+ log.debug(c),
275
+ d = "{name}:张三",
276
+ log.debug(d),
277
+ e = "\\{name\\}:张三",
278
+ log.debug(e),
279
+ f = "\\"123\\"",
280
+ log.debug(f),
281
+ g = "\\$15.7",
282
+ log.debug(g),
283
+ h = $\\$15.7$,
284
+ log.debug(h),
285
+ i = "http:\\\\www.baidu.com",
286
+ log.debug(i),
287
+ j = $http://www.baidu.com$,
288
+ log.debug(j)
289
+ `
290
+ runExpression(expression)
291
+ }
292
+
293
+ /**
294
+ * condition
295
+ */
296
+ function testCondition() {
297
+ const expression = `
298
+ 1 != 1 :(
299
+ throw "异常"
300
+ ),null,
301
+ 1 + 1 != 2 :(
302
+ throw "异常"
303
+ ),null,
304
+ !(2 > 3) && !(3 > 2):(
305
+ throw "异常"
306
+ ),null,
307
+ 2 > 3 :(
308
+ throw "异常"
309
+ ),null,
310
+ !(3 > 2) :(
311
+ throw "异常"
312
+ ),null,
313
+ y = 1 > 0,
314
+ !y && 1 > 0 :(
315
+ throw "异常"
316
+ ),null
317
+ `
318
+ const data = {
319
+ type: "1"
320
+ }
321
+ runExpression(expression, data)
322
+ }
323
+
324
+ /**
325
+ * throw
326
+ */
327
+ function testThrow() {
328
+ const expression = `
329
+ data.type == 2 :(
330
+ throw "error",
331
+ log.debug(result)
332
+ ),null
333
+ `
334
+ const data = {
335
+ type: "1"
336
+ }
337
+ runExpression(expression, data)
338
+ }
339
+
340
+ /**
341
+ * JSONArray loop
342
+ */
343
+ function testJSONArrayLoop() {
344
+ const expression = `
345
+ log.debug("test-JSONArray"),
346
+ datas = [1,2,3,4,5],
347
+ datas.each(
348
+ log.debug(\${row}\$)
349
+ ),
350
+ log.debug("test-Set"),
351
+ data.testSet.each(
352
+ log.debug(\${row}\$)
353
+ ),
354
+ log.debug("test-Array"),
355
+ data.testArray.each(
356
+ log.debug(\${row}\$)
357
+ )
358
+ `
359
+ const data = {
360
+ testSet: [1, 2, 3, 4, 5],
361
+ testArray: 'a|b|c'.split('\|')
362
+ }
363
+ runExpression(expression, data)
364
+ }
365
+
366
+ /**
367
+ * JSONObject loop
368
+ */
369
+ function testJSONObjectLoop() {
370
+ const expression = `
371
+ log.debug("test-JSONObject"),
372
+ datas = {name: 1, age: 2},
373
+ datas.each(
374
+ log.debug(\${rowKey}:{row}$)
375
+ ),
376
+ log.debug("test-Map"),
377
+ data.testMap.each(
378
+ log.debug(\${rowKey}:{row}$)
379
+ )
380
+ `
381
+ const data = {
382
+ testMap: {
383
+ name: "xxx",
384
+ age: 18,
385
+ gender: "男"
386
+ }
387
+ }
388
+ runExpression(expression, data)
389
+ }
390
+
391
+ /**
392
+ * int loop
393
+ */
394
+ function testIntLoop() {
395
+ const expression = `
396
+ a = 5,
397
+ a.each(
398
+ log.debug(row)
399
+ ),
400
+ (0,5).each(
401
+ log.debug(row)
402
+ ),
403
+ null
404
+ `
405
+ runExpression(expression)
406
+ }
407
+
408
+ /**
409
+ * continue and break
410
+ */
411
+ function testContinueAndBreak() {
412
+ const expression = `
413
+ datas = [1,2,3,4,5,6,7],
414
+ datas.each(
415
+ row == 3 :(
416
+ continue
417
+ ),row == 5:(
418
+ break
419
+ ),
420
+ log.debug(row)
421
+ )
422
+ `
423
+ runExpression(expression)
424
+ }
425
+
426
+ /**
427
+ * comment
428
+ */
429
+ function testComment () {
430
+ const expression = `
431
+ $//排序单表查询
432
+ select {items}
433
+ from {tablename}
434
+ where {condition}
435
+ order by {orderitem}
436
+ `
437
+ runExpression(expression)
438
+ }
439
+
440
+ /**
441
+ * return
442
+ */
443
+ function testReturn () {
444
+ const expression = `
445
+ data.type == 1 :(
446
+ return "123",
447
+ log.debug(123)
448
+ ),(
449
+ return 2
450
+ ),
451
+ log.debug(123)
452
+ `
453
+ const data = {
454
+ type: 1
455
+ }
456
+ runExpression(expression, data)
457
+ }
458
+
459
+ /**
460
+ * lambda
461
+ */
462
+ function testLambda () {
463
+ const expression = `
464
+ log.debug("进入外层逻辑,参数:{data}"),
465
+ age = 13,
466
+ // 声明一个lambda块
467
+ lambdaObj = (data) => {
468
+ index = 1,
469
+ log.debug("进入lambda了"),
470
+ log.debug("传入lambda块的参数:{data}"),
471
+ log.debug("外层的只读参数:{age}"),
472
+ return "执行lambda完成"
473
+ },
474
+ log.debug("age参数:{age}"),
475
+ result = lambdaObj.apply({
476
+ name: "江超"
477
+ }),
478
+ result = lambdaObj.apply({
479
+ name: "大神"
480
+ }),
481
+ log.debug("result:{result}"),
482
+ return {
483
+ func: lambdaObj
484
+ }
485
+ `
486
+ const data = {
487
+ type: 1
488
+ }
489
+ runExpression(expression, data)
490
+ }
491
+
492
+ function runExpression (expression: string, data?: any) {
493
+ const program = new Program(expression)
494
+ const d = program.parse()
495
+ const params = {};
496
+ if (data == null) {
497
+ data = {}
498
+ }
499
+ params['data'] = data
500
+ params['log'] = new LogicConsole()
501
+ params['b'] = 5
502
+ try {
503
+ const result = d.invoke(new JSONObject(params))
504
+ console.log(result)
505
+ return result
506
+ } catch (e) {
507
+ throw e
508
+ }
509
+ }
@@ -0,0 +1,114 @@
1
+ import Expression from './Expression'
2
+ import ExpressionType from '../enums/ExpressionType'
3
+ import ReturnWayException from "../exception/ReturnWayException"
4
+ import JSONObject from "../instances/JSONObject"
5
+
6
+ export default class Delegate {
7
+ private exp: Expression;
8
+ private source: string;
9
+ private lambdaOutProps: string[] = [];
10
+ private objectNames: JSONObject;
11
+
12
+ constructor(exp: Expression, source: string, objectNames?: JSONObject) {
13
+ this.exp = exp;
14
+ this.source = source;
15
+ if (objectNames) {
16
+ this.objectNames = objectNames;
17
+ } else {
18
+ this.objectNames = new JSONObject();
19
+ }
20
+ }
21
+
22
+ // 执行程序,执行前,参数必须实例化
23
+ invoke(params?: JSONObject): any {
24
+ if (params == null) {
25
+ params = new JSONObject();
26
+ }
27
+ // 把初始参数给参数表
28
+ this.objectNames = params;
29
+ // 沿根Expression节点遍历,把delegate传递下去
30
+ this.putDelegate(this.exp);
31
+ // 调用exp的执行过程
32
+ try {
33
+ return this.exp.invoke();
34
+ } catch (returnWay) {
35
+ if (returnWay instanceof ReturnWayException) {
36
+ return returnWay.getReturnObject();
37
+ }
38
+ throw returnWay;
39
+ }
40
+ }
41
+
42
+ // 沿根节点递归,传递delegate的过程
43
+ private putDelegate(parent: Expression): void {
44
+ for (const child of parent.children) {
45
+ // 有些节点会放空的子节点
46
+ if (child == null) {
47
+ continue;
48
+ }
49
+ // try特殊处理
50
+ if (child.type === ExpressionType.Try) {
51
+ const exps: Expression[] = child.value as Expression[];
52
+ if (exps[0] != null) {
53
+ exps[0].setDelegate(this);
54
+ this.putDelegate(exps[0]);
55
+ }
56
+ if (exps[1] != null) {
57
+ exps[1].setDelegate(this);
58
+ this.putDelegate(exps[1]);
59
+ }
60
+ }
61
+ child.setDelegate(this);
62
+ this.putDelegate(child);
63
+ }
64
+ }
65
+
66
+ // 获取表达式
67
+ getExp(): Expression {
68
+ return this.exp;
69
+ }
70
+
71
+ // 获取对象值存储
72
+ getObjectNames(): JSONObject {
73
+ return this.objectNames;
74
+ }
75
+
76
+ // 获取lambda外层参数名
77
+ getLambdaOutProps(): string[] {
78
+ return this.lambdaOutProps;
79
+ }
80
+
81
+ // 存储对象值
82
+ put(key: string, value: any): void {
83
+ this.objectNames.put(key, value);
84
+ }
85
+
86
+ // 获取对象值
87
+ get(key: string): any {
88
+ return this.objectNames.get(key);
89
+ }
90
+
91
+ // 检查是否包含某个键
92
+ containsKey(key: string): boolean {
93
+ return this.objectNames.has(key);
94
+ }
95
+
96
+ // 获取源代码
97
+ getSource(): string {
98
+ return this.source;
99
+ }
100
+
101
+ // 使用参数调用
102
+ apply(params?: JSONObject): any {
103
+ if (params === null) {
104
+ params = new JSONObject();
105
+ }
106
+ const map = this.objectNames;
107
+ if (this.lambdaOutProps.length === 0) {
108
+ this.lambdaOutProps.push(...map.keySet());
109
+ }
110
+ const lambdaMap = new JSONObject(map)
111
+ lambdaMap.put("data", params);
112
+ return this.invoke(lambdaMap);
113
+ }
114
+ }