af-mobile-client-vue3 1.2.31 → 1.2.33

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