修复:模块设计器中初始化参数时,如果值类型为浮点数,那么就正确的设置为number

pull/2216/MERGE
ChenX 1 year ago
parent e534a756e5
commit 44c426a3c4

@ -249,7 +249,7 @@ export default class TemplateParamList extends React.Component<ITemplateParamLis
let dist = distRes.Distance;
const store = this.props.store;
store.params[store.currentParamIndex].value = dist.toFixed(2);
store.Template.Params[store.currentParamIndex].value = dist.toFixed(2);
store.Template.Params[store.currentParamIndex].value = parseFloat(dist.toFixed(2));
await store.Template.UpdateTemplateTree();
}
};

@ -1,5 +1,6 @@
import { ITreeNode } from "@blueprintjs/core";
import { observable, toJS } from "mobx";
import { safeEval } from "../../Common/eval";
import { Singleton } from "../../Common/Singleton";
import { FixedNotZero } from "../../Common/Utils";
import { TemplateParam } from "../../DatabaseServices/Template/Param/TemplateParam";
@ -71,10 +72,13 @@ export class TempalteEditorStore extends Singleton implements IConfigStore
tempPar.name = par.name;
this.Template.Params.push(tempPar);
}
tempPar.value = par.value;
tempPar.expr = par.expr;
tempPar.description = par.description;
tempPar.type = par.type ?? TemplateParamType.Float;
if (tempPar.type === TemplateParamType.Float)
tempPar.value = (typeof par.value === "string" ? safeEval(par.value) : par.value) || 0;
else
tempPar.value = par.value;
}
}, "修改模板参数");
@ -88,22 +92,4 @@ export class TempalteEditorStore extends Singleton implements IConfigStore
newConfig.option = toJS(this.params);
return newConfig;
}
async WriteParamsToTemplate()
{
for (let par of this.params)
{
let tempPar = this.Template.GetParam(par.name);
if (!tempPar)
{
tempPar = new TemplateParam();
this.Template.Params.push(tempPar);
}
tempPar.value = par.value;
tempPar.description = par.description;
tempPar.expr = par.expr;
tempPar.type = par.type ?? TemplateParamType.Float;
}
await this.Template.UpdateTemplateTree();
}
}

Loading…
Cancel
Save