|
3 | 3 | @{ |
4 | 4 | Layout = null; |
5 | 5 | } |
6 | | -<html lang="en"> |
| 6 | +<html> |
7 | 7 | <head> |
8 | 8 | <meta charset="UTF-8" /> |
9 | 9 | </head> |
10 | 10 | <body> |
11 | 11 | 编译ToolGood.Algorithm.WebAssembly项目,生成文件夹下的wwwroot文件夹中的_framework文件夹中就是生成的WebAssembly和相关文件 |
12 | 12 | <br /> |
13 | | - 我们运行前端项目. 由于Blazor会生成blat、dll等不被Web服务器默认接受的文件类型,所以请确保在Web服务器上为如下格式的文件配置MimeType:.pdb、.blat、.dat、.dll、.json、.wasm、.woff、.woff2。 |
14 | | - |
15 | | - |
| 13 | + 我们运行前端项目. 由于Blazor会生成blat、dll等不被Web服务器默认接受的文件类型,所以请确保在Web服务器上为如下格式的文件配置MimeType:.gz、.dat、.wasm |
| 14 | + |
| 15 | + |
16 | 16 | <pre> |
| 17 | +AreaUnitType = new class { |
| 18 | + constructor() { |
| 19 | + this.MM2 = 11; |
| 20 | + this.CM2 = 12; |
| 21 | + this.DM2 = 13; |
| 22 | + this.M2 = 14; |
| 23 | + this.KM2 = 15; |
| 24 | + } |
| 25 | + }(); |
| 26 | + DistanceUnitType = new class { |
| 27 | + constructor() { |
| 28 | + this.MM = 1; |
| 29 | + this.CM = 2; |
| 30 | + this.DM = 3; |
| 31 | + this.M = 4; |
| 32 | + this.KM = 5; |
| 33 | + } |
| 34 | + }(); |
| 35 | + MassUnitType = new class { |
| 36 | + constructor() { |
| 37 | + this.G = 31; |
| 38 | + this.KG = 32; |
| 39 | + this.T = 33; |
| 40 | + } |
| 41 | + }(); |
| 42 | + VolumeUnitType = new class { |
| 43 | + constructor() { |
| 44 | + this.MM3 = 21; |
| 45 | + this.CM3 = 22; |
| 46 | + this.DM3 = 23; |
| 47 | + this.M3 = 24; |
| 48 | + this.KM3 = 25; |
| 49 | + } |
| 50 | + }(); |
| 51 | + AlgorithmEngine = new class { |
| 52 | + constructor() { |
| 53 | + this.UseExcelIndex = true; |
| 54 | + this.UseTempDict = false; |
| 55 | + this.UseLocalTime = false; |
| 56 | + this.DistanceUnit = DistanceUnitType.M; |
| 57 | + this.AreaUnit = AreaUnitType.M2; |
| 58 | + this.VolumeUnit = VolumeUnitType.M3; |
| 59 | + this.MassUnit = MassUnitType.KG; |
| 60 | + this.IgnoreCase = false; |
| 61 | + } |
| 62 | + |
| 63 | + createOption = function () { |
| 64 | + var data = { |
| 65 | + UseExcelIndex: this.UseExcelIndex, |
| 66 | + UseTempDict: this.UseTempDict, |
| 67 | + UseLocalTime: this.UseLocalTime, |
| 68 | + DistanceUnit: this.DistanceUnit, |
| 69 | + AreaUnit: this.AreaUnit, |
| 70 | + VolumeUnit: this.VolumeUnit, |
| 71 | + MassUnit: this.MassUnit, |
| 72 | + IgnoreCase: this.IgnoreCase, |
| 73 | + } |
| 74 | + return JSON.stringify(data); |
| 75 | + } |
| 76 | + |
| 77 | + TryEvaluateString = async function (exp, def, data) { |
| 78 | + return await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluateString', exp, def, data, this.createOption()); |
| 79 | + } |
| 80 | + TryEvaluateNumber = async function (exp, def, data) { |
| 81 | + return await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluateNumber', exp, def, data, this.createOption()); |
| 82 | + } |
| 83 | + TryEvaluateBool = async function (exp, def, data) { |
| 84 | + return await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluateBool', exp, def, data, this.createOption()); |
| 85 | + } |
| 86 | + TryEvaluateDateTime = async function (exp, def, data) { |
| 87 | + return await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluateDateTime', exp, def, data, this.createOption()); |
| 88 | + } |
| 89 | + }(); |
| 90 | + |
| 91 | + |
17 | 92 | window.onload = async function () { |
18 | 93 | await Blazor.start(); |
19 | | - constr = await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluate', '1+1'); |
20 | | - alert(constr); |
| 94 | + r = await AlgorithmEngine.TryEvaluateString("'S' & 1", "") |
| 95 | + alert("'S' & 1 =>" + r); |
| 96 | + r = await AlgorithmEngine.TryEvaluateNumber("1+2", 0) |
| 97 | + alert("1+2 =>" + r); |
| 98 | + r = await AlgorithmEngine.TryEvaluateBool("1=1", false) |
| 99 | + alert("1=1 =>" + r); |
| 100 | + r = await AlgorithmEngine.TryEvaluateDateTime("date(2014,1,2)", '2024-01-11') |
| 101 | + alert('date(2014,1,2) =>' + r); |
21 | 102 | }; |
22 | 103 | </pre> |
23 | 104 | </body> |
24 | 105 | <script src="_framework/blazor.webassembly.js" autostart="false"></script> |
25 | 106 | <script> |
| 107 | + AreaUnitType = new class { |
| 108 | + constructor() { |
| 109 | + this.MM2 = 11; |
| 110 | + this.CM2 = 12; |
| 111 | + this.DM2 = 13; |
| 112 | + this.M2 = 14; |
| 113 | + this.KM2 = 15; |
| 114 | + } |
| 115 | + }(); |
| 116 | + DistanceUnitType = new class { |
| 117 | + constructor() { |
| 118 | + this.MM = 1; |
| 119 | + this.CM = 2; |
| 120 | + this.DM = 3; |
| 121 | + this.M = 4; |
| 122 | + this.KM = 5; |
| 123 | + } |
| 124 | + }(); |
| 125 | + MassUnitType = new class { |
| 126 | + constructor() { |
| 127 | + this.G = 31; |
| 128 | + this.KG = 32; |
| 129 | + this.T = 33; |
| 130 | + } |
| 131 | + }(); |
| 132 | + VolumeUnitType = new class { |
| 133 | + constructor() { |
| 134 | + this.MM3 = 21; |
| 135 | + this.CM3 = 22; |
| 136 | + this.DM3 = 23; |
| 137 | + this.M3 = 24; |
| 138 | + this.KM3 = 25; |
| 139 | + } |
| 140 | + }(); |
| 141 | + AlgorithmEngine = new class { |
| 142 | + constructor() { |
| 143 | + this.UseExcelIndex = true; |
| 144 | + this.UseTempDict = false; |
| 145 | + this.UseLocalTime = false; |
| 146 | + this.DistanceUnit = DistanceUnitType.M; |
| 147 | + this.AreaUnit = AreaUnitType.M2; |
| 148 | + this.VolumeUnit = VolumeUnitType.M3; |
| 149 | + this.MassUnit = MassUnitType.KG; |
| 150 | + this.IgnoreCase = false; |
| 151 | + } |
| 152 | +
|
| 153 | + createOption = function () { |
| 154 | + var data = { |
| 155 | + UseExcelIndex: this.UseExcelIndex, |
| 156 | + UseTempDict: this.UseTempDict, |
| 157 | + UseLocalTime: this.UseLocalTime, |
| 158 | + DistanceUnit: this.DistanceUnit, |
| 159 | + AreaUnit: this.AreaUnit, |
| 160 | + VolumeUnit: this.VolumeUnit, |
| 161 | + MassUnit: this.MassUnit, |
| 162 | + IgnoreCase: this.IgnoreCase, |
| 163 | + } |
| 164 | + return JSON.stringify(data); |
| 165 | + } |
| 166 | +
|
| 167 | + TryEvaluateString = async function (exp, def, data) { |
| 168 | + return await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluateString', exp, def, data, this.createOption()); |
| 169 | + } |
| 170 | + TryEvaluateNumber = async function (exp, def, data) { |
| 171 | + return await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluateNumber', exp, def, data, this.createOption()); |
| 172 | + } |
| 173 | + TryEvaluateBool = async function (exp, def, data) { |
| 174 | + return await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluateBool', exp, def, data, this.createOption()); |
| 175 | + } |
| 176 | + TryEvaluateDateTime = async function (exp, def, data) { |
| 177 | + return await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluateDateTime', exp, def, data, this.createOption()); |
| 178 | + } |
| 179 | + }(); |
| 180 | +
|
| 181 | +
|
26 | 182 | window.onload = async function () { |
27 | 183 | await Blazor.start(); |
28 | | - constr = await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluate', '1+1'); |
29 | | - alert(constr); |
| 184 | + r = await AlgorithmEngine.TryEvaluateString("'S' & 1", "") |
| 185 | + alert("'S' & 1 =>" + r); |
| 186 | + r = await AlgorithmEngine.TryEvaluateNumber("1+2", 0) |
| 187 | + alert("1+2 =>" + r); |
| 188 | + r = await AlgorithmEngine.TryEvaluateBool("1=1", false) |
| 189 | + alert("1=1 =>" + r); |
| 190 | + r = await AlgorithmEngine.TryEvaluateDateTime("date(2014,1,2)", '2024-01-11') |
| 191 | + alert('date(2014,1,2) =>' + r); |
30 | 192 | }; |
31 | 193 | </script> |
32 | 194 | </html> |
0 commit comments