Skip to content

Commit 20d813e

Browse files
author
linzhijun
committed
修改
1 parent dfbe889 commit 20d813e

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

csharp/ToolGood.Algorithm2.WebTest/Pages/Index.cshtml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
AreaUnitType = new class { constructor() { this.MM2 = 11; this.CM2 = 12; this.DM2 = 13; this.M2 = 14; this.KM2 = 15; } }();
1919
VolumeUnitType = new class { constructor() { this.MM3 = 21; this.CM3 = 22; this.DM3 = 23; this.M3 = 24; this.KM3 = 25; } }();
2020
MassUnitType = new class { constructor() { this.G = 31; this.KG = 32; this.T = 33; } }();
21-
AlgorithmEngine = new class {
21+
AlgorithmEngine = class {
2222
constructor() {
2323
this.UseExcelIndex = true;
2424
this.UseTempDict = false;
@@ -33,17 +33,25 @@
3333
TryEvaluateNumber = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateNumber', exp, def, data, JSON.stringify(this)); }
3434
TryEvaluateBool = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateBool', exp, def, data, JSON.stringify(this)); }
3535
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+
};
3744

3845
window.onload = async function () {
3946
await Blazor.start();
40-
r = AlgorithmEngine.TryEvaluateString("'S' & 1", "")
47+
var ae = new AlgorithmEngine();
48+
r = ae.TryEvaluate("'S' & 1", "")
4149
alert("'S' & 1 =>" + r);
42-
r = AlgorithmEngine.TryEvaluateNumber("1+2", 0)
50+
r = ae.TryEvaluate("1+2", 0)
4351
alert("1+2 =>" + r);
44-
r = AlgorithmEngine.TryEvaluateBool("1=1", false)
52+
r = ae.TryEvaluate("1=1", false)
4553
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())
4755
alert('date(2014,1,2) =>' + r);
4856
};
4957
</pre>
@@ -54,7 +62,7 @@
5462
AreaUnitType = new class { constructor() { this.MM2 = 11; this.CM2 = 12; this.DM2 = 13; this.M2 = 14; this.KM2 = 15; } }();
5563
VolumeUnitType = new class { constructor() { this.MM3 = 21; this.CM3 = 22; this.DM3 = 23; this.M3 = 24; this.KM3 = 25; } }();
5664
MassUnitType = new class { constructor() { this.G = 31; this.KG = 32; this.T = 33; } }();
57-
AlgorithmEngine = new class {
65+
AlgorithmEngine = class {
5866
constructor() {
5967
this.UseExcelIndex = true;
6068
this.UseTempDict = false;
@@ -69,17 +77,25 @@
6977
TryEvaluateNumber = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateNumber', exp, def, data, JSON.stringify(this)); }
7078
TryEvaluateBool = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateBool', exp, def, data, JSON.stringify(this)); }
7179
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+
};
7388
7489
window.onload = async function () {
7590
await Blazor.start();
76-
r = AlgorithmEngine.TryEvaluateString("'S' & 1", "")
91+
var ae = new AlgorithmEngine();
92+
r = ae.TryEvaluate("'S' & 1", "")
7793
alert("'S' & 1 =>" + r);
78-
r = AlgorithmEngine.TryEvaluateNumber("1+2", 0)
94+
r = ae.TryEvaluate("1+2", 0)
7995
alert("1+2 =>" + r);
80-
r = AlgorithmEngine.TryEvaluateBool("1=1", false)
96+
r = ae.TryEvaluate("1=1", false)
8197
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())
8399
alert('date(2014,1,2) =>' + r);
84100
};
85101
</script>

0 commit comments

Comments
 (0)