|
18 | 18 | AreaUnitType = new class { constructor() { this.MM2 = 11; this.CM2 = 12; this.DM2 = 13; this.M2 = 14; this.KM2 = 15; } }(); |
19 | 19 | VolumeUnitType = new class { constructor() { this.MM3 = 21; this.CM3 = 22; this.DM3 = 23; this.M3 = 24; this.KM3 = 25; } }(); |
20 | 20 | MassUnitType = new class { constructor() { this.G = 31; this.KG = 32; this.T = 33; } }(); |
21 | | - AlgorithmEngine = new class { |
| 21 | + AlgorithmEngine = class { |
22 | 22 | constructor() { |
23 | 23 | this.UseExcelIndex = true; |
24 | 24 | this.UseTempDict = false; |
|
33 | 33 | TryEvaluateNumber = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateNumber', exp, def, data, JSON.stringify(this)); } |
34 | 34 | TryEvaluateBool = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateBool', exp, def, data, JSON.stringify(this)); } |
35 | 35 | TryEvaluateDateTime = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateDateTime', exp, def, data, JSON.stringify(this)); } |
36 | | - }(); |
| 36 | + TryEvaluate = function (exp, def, data) { |
| 37 | + if (def == null) { return this.TryEvaluateString(exp, def, data); } |
| 38 | + if (typeof def == "number") { return this.TryEvaluateNumber(exp, def, data); } |
| 39 | + if (typeof def == "boolean") { return this.TryEvaluateBool(exp, def, data); } |
| 40 | + if (typeof def == "object" && def instanceof Date) { return this.TryEvaluateDateTime(exp, def, data); } |
| 41 | + return this.TryEvaluateString(exp, def, data); |
| 42 | + } |
| 43 | + }; |
37 | 44 |
|
38 | 45 | window.onload = async function () { |
39 | 46 | await Blazor.start(); |
40 | | - r = AlgorithmEngine.TryEvaluateString("'S' & 1", "") |
| 47 | + var ae = new AlgorithmEngine(); |
| 48 | + r = ae.TryEvaluate("'S' & 1", "") |
41 | 49 | alert("'S' & 1 =>" + r); |
42 | | - r = AlgorithmEngine.TryEvaluateNumber("1+2", 0) |
| 50 | + r = ae.TryEvaluate("1+2", 0) |
43 | 51 | alert("1+2 =>" + r); |
44 | | - r = AlgorithmEngine.TryEvaluateBool("1=1", false) |
| 52 | + r = ae.TryEvaluate("1=1", false) |
45 | 53 | alert("1=1 =>" + r); |
46 | | - r = AlgorithmEngine.TryEvaluateDateTime("date(2014,1,2)", '2024-01-11') |
| 54 | + r = ae.TryEvaluate("date(2014,1,2)", new Date()) |
47 | 55 | alert('date(2014,1,2) =>' + r); |
48 | 56 | }; |
49 | 57 | </pre> |
|
54 | 62 | AreaUnitType = new class { constructor() { this.MM2 = 11; this.CM2 = 12; this.DM2 = 13; this.M2 = 14; this.KM2 = 15; } }(); |
55 | 63 | VolumeUnitType = new class { constructor() { this.MM3 = 21; this.CM3 = 22; this.DM3 = 23; this.M3 = 24; this.KM3 = 25; } }(); |
56 | 64 | MassUnitType = new class { constructor() { this.G = 31; this.KG = 32; this.T = 33; } }(); |
57 | | - AlgorithmEngine = new class { |
| 65 | + AlgorithmEngine = class { |
58 | 66 | constructor() { |
59 | 67 | this.UseExcelIndex = true; |
60 | 68 | this.UseTempDict = false; |
|
69 | 77 | TryEvaluateNumber = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateNumber', exp, def, data, JSON.stringify(this)); } |
70 | 78 | TryEvaluateBool = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateBool', exp, def, data, JSON.stringify(this)); } |
71 | 79 | TryEvaluateDateTime = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateDateTime', exp, def, data, JSON.stringify(this)); } |
72 | | - }(); |
| 80 | + TryEvaluate = function (exp, def, data) { |
| 81 | + if (def == null) { return this.TryEvaluateString(exp, def, data); } |
| 82 | + if (typeof def == "number") { return this.TryEvaluateNumber(exp, def, data); } |
| 83 | + if (typeof def == "boolean") { return this.TryEvaluateBool(exp, def, data); } |
| 84 | + if (typeof def == "object" && def instanceof Date) { return this.TryEvaluateDateTime(exp, def, data); } |
| 85 | + return this.TryEvaluateString(exp, def, data); |
| 86 | + } |
| 87 | + }; |
73 | 88 |
|
74 | 89 | window.onload = async function () { |
75 | 90 | await Blazor.start(); |
76 | | - r = AlgorithmEngine.TryEvaluateString("'S' & 1", "") |
| 91 | + var ae = new AlgorithmEngine(); |
| 92 | + r = ae.TryEvaluate("'S' & 1", "") |
77 | 93 | alert("'S' & 1 =>" + r); |
78 | | - r = AlgorithmEngine.TryEvaluateNumber("1+2", 0) |
| 94 | + r = ae.TryEvaluate("1+2", 0) |
79 | 95 | alert("1+2 =>" + r); |
80 | | - r = AlgorithmEngine.TryEvaluateBool("1=1", false) |
| 96 | + r = ae.TryEvaluate("1=1", false) |
81 | 97 | alert("1=1 =>" + r); |
82 | | - r = AlgorithmEngine.TryEvaluateDateTime("date(2014,1,2)", '2024-01-11') |
| 98 | + r = ae.TryEvaluate("date(2014,1,2)", new Date()) |
83 | 99 | alert('date(2014,1,2) =>' + r); |
84 | 100 | }; |
85 | 101 | </script> |
|
0 commit comments