Commit 33cb78ef by dongshufeng

refactor(iesplan): slider and switch config support in para card

parent a79f7525
5,car1,500
1000001,源电压,Checkbox
1000002,A相有功634,Radio
1000003,A相无功634,TextField
1000004,B相有功634,Switch
5,car1,,
1000001,源电压,Checkbox,
1000002,A相有功634,Radio,
1000003,A相无功634,TextField,
1000004,B相有功634,Switch,
1000005,B相无功634,Slider,-100;100;10
1000006,C相有功634,Select,1;2;3;10;30
\ No newline at end of file
......@@ -145,3 +145,9 @@ pub fn build_tiles(xlsx_bytes: Vec<u8>) -> Option<Tiles> {
let tiles = Tiles { id: "".to_string(), class_str, style_str, with_box: true };
Some(tiles)
}
#[test]
fn test_parse() {
let general_para = create_parameters(include_bytes!("../general.csv"));
assert_eq!(general_para.points.len(), 6);
}
\ No newline at end of file
......@@ -163,6 +163,7 @@ impl ParaCard {
}
}
ParaType::Slider(lower, upper, step) => {
let current_v = self.floats.get(&i).cloned().unwrap_or(*lower).to_string();
let oninput = link.callback(move |e: InputEvent| {
let target = e.target().unwrap();
let input = target.dyn_into::<web_sys::HtmlInputElement>().unwrap();
......@@ -172,17 +173,22 @@ impl ParaCard {
<Field horizontal={true} label={label}>
<input class={"slider is-fullwidth"} type={"range"} orient={"horizontal"}
oninput={oninput} step={step.to_string()} min={lower.to_string()}
max={upper.to_string()} value={lower.to_string()}
max={upper.to_string()} value={current_v}
/>
</Field>
}
}
ParaType::Select(options) => {
let current_v = self.floats.get(&i).cloned().unwrap_or(0.0).to_string();
html! {
<Field horizontal={true} label={label}>
<Select update={link.callback(move |s| Msg::SetOption(i, s))} >
{for options.iter().map(|f| {
html! {<option value={f.to_string()}>{f.to_string()}</option>}
html! {
<option value={f.to_string()} selected={current_v == f.to_string()}>
{f.to_string()}
</option>
}
})}
<option value={"None"}>{"no_selection"}</option>
</Select>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论