Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
sparrowzz
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
sgool
sparrowzz
Commits
313dce37
Commit
313dce37
authored
Oct 24, 2024
by
dongshufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(iesplan): radio is not ok
parent
33cb78ef
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
67 行增加
和
28 行删除
+67
-28
mems/examples/iesplan/general.csv
+1
-1
mems/examples/iesplan/src/lib.rs
+22
-6
mems/examples/iesplan/src/paracard.rs
+44
-21
没有找到文件。
mems/examples/iesplan/general.csv
查看文件 @
313dce37
5,car1,,
1000001,源电压,Checkbox,
1000002,A相有功634,Radio,
1000002,A相有功634,Radio,
name1:1.0;name2:3;name3:4
1000003,A相无功634,TextField,
1000004,B相有功634,Switch,
1000005,B相无功634,Slider,-100;100;10
...
...
mems/examples/iesplan/src/lib.rs
查看文件 @
313dce37
...
...
@@ -46,9 +46,9 @@ impl QueryWithId {
pub
enum
ParaType
{
// show expression, true expression, false expression
Checkbox
,
Radio
,
Switch
,
Select
(
Vec
<
f64
>
),
Radio
(
Vec
<
(
String
,
f64
)
>
),
Select
(
Vec
<
(
String
,
f64
)
>
),
// min, max, step
Slider
(
f64
,
f64
,
f64
),
TextField
,
...
...
@@ -81,7 +81,6 @@ pub fn create_parameters(content: &[u8]) -> Parameters {
let
para_type_s
=
csv_str
(
&
row
,
2
)
.unwrap
()
.to_uppercase
();
let
para_type
=
match
para_type_s
.as_str
()
{
"CHECKBOX"
=>
ParaType
::
Checkbox
,
"RADIO"
=>
ParaType
::
Radio
,
"SWITCH"
=>
ParaType
::
Switch
,
"TEXTFIELD"
=>
ParaType
::
TextField
,
"SLIDER"
=>
{
...
...
@@ -94,9 +93,13 @@ pub fn create_parameters(content: &[u8]) -> Parameters {
},
"SELECT"
=>
{
let
v
=
csv_str
(
&
row
,
3
)
.unwrap
();
let
floats
=
v
.split
(
";"
)
.map
(|
s
|
s
.parse
::
<
f64
>
()
.unwrap
())
.collect
();
ParaType
::
Select
(
floats
)
let
options
=
parse_options
(
v
);
ParaType
::
Select
(
options
)
}
"RADIO"
=>
{
let
v
=
csv_str
(
&
row
,
3
)
.unwrap
();
let
options
=
parse_options
(
v
);
ParaType
::
Radio
(
options
)
}
_
=>
ParaType
::
TextField
};
...
...
@@ -105,6 +108,19 @@ pub fn create_parameters(content: &[u8]) -> Parameters {
Parameters
{
id
,
name
,
labels
,
points
,
para_types
}
}
fn
parse_options
(
v
:
&
str
)
->
Vec
<
(
String
,
f64
)
>
{
let
options
=
v
.split
(
";"
)
.map
(|
s
|
{
let
options
:
Vec
<&
str
>
=
s
.split
(
":"
)
.collect
();
if
options
.len
()
==
2
{
(
options
[
0
]
.to_string
(),
options
[
1
]
.parse
::
<
f64
>
()
.unwrap
())
}
else
{
(
""
.to_string
(),
s
.parse
::
<
f64
>
()
.unwrap
())
}
})
.collect
();
options
}
pub
fn
build_tiles
(
xlsx_bytes
:
Vec
<
u8
>
)
->
Option
<
Tiles
>
{
let
(
m
,
n
,
merge_map
,
values
)
=
get_first_sheet_merged_cells
(
xlsx_bytes
)
?
;
let
mut
class_str
=
Vec
::
new
();
...
...
mems/examples/iesplan/src/paracard.rs
查看文件 @
313dce37
...
...
@@ -40,8 +40,7 @@ impl Component for ParaCard {
for
index
in
0
..
ctx
.props
()
.paras.points
.len
()
{
let
input_type
=
&
ctx
.props
()
.paras.para_types
[
index
];
if
ParaType
::
Checkbox
.eq
(
input_type
)
||
ParaType
::
Switch
.eq
(
input_type
)
||
ParaType
::
Radio
.eq
(
input_type
)
{
||
ParaType
::
Switch
.eq
(
input_type
)
{
bools
.insert
(
index
,
false
);
}
else
{
floats
.insert
(
index
,
0.0
);
...
...
@@ -85,6 +84,7 @@ impl Component for ParaCard {
self
.do_set_point
(
ctx
,
&
value
,
point_id
);
}
Msg
::
SetOption
(
i
,
value
)
=>
{
log
::
warn!
(
"========================= {i} {value}"
);
if
value
==
"None"
{
return
false
;
}
...
...
@@ -141,17 +141,6 @@ impl ParaCard {
<
/
Field
>
}
}
ParaType
::
Radio
=>
{
let
checked
=
self
.bools
.get
(
&
i
)
.cloned
()
.unwrap_or
(
false
);
html!
{
<
Field
horizontal
=
{
true
}
label
=
{
label
}
>
<
Radio
update
=
{
link
.callback
(
move
|
_
|
Msg
::
SetBool
(
i
,
!
checked
))}
checked_value
=
{
"selected"
}
value
=
{
if
checked
{
"selected"
}
else
{
"none"
}}
>
<
/
Radio
>
<
/
Field
>
}
}
ParaType
::
Switch
=>
{
let
checked
=
self
.bools
.get
(
&
i
)
.cloned
()
.unwrap_or
(
false
);
html!
{
...
...
@@ -179,22 +168,56 @@ impl ParaCard {
}
}
ParaType
::
Select
(
options
)
=>
{
let
current_v
=
self
.floats
.get
(
&
i
)
.cloned
()
.unwrap_or
(
0.0
)
.to_string
();
let
current_f
=
self
.floats
.get
(
&
i
)
.cloned
()
.unwrap_or
(
0.0
);
let
content
=
(
0
..
options
.len
())
.map
(|
i
|
{
let
(
name
,
f
)
=
&
options
[
i
];
let
to_show
=
if
name
.is_empty
()
{
f
.to_string
()
}
else
{
name
.clone
()
};
html!
{
<
option
value
=
{
f
.to_string
()}
selected
=
{
current_f
==
*
f
}
>
{
to_show
}
<
/
option
>
}
})
.collect
::
<
Html
>
();
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
()}
selected
=
{
current_v
==
f
.to_string
()}
>
{
f
.to_string
()}
<
/
option
>
}
})}
{
content
}
<
option
value
=
{
"None"
}
>
{
"no_selection"
}
<
/
option
>
<
/
Select
>
<
/
Field
>
}
}
ParaType
::
Radio
(
options
)
=>
{
let
current_f
=
self
.floats
.get
(
&
i
)
.cloned
()
.unwrap_or
(
0.0
);
let
content
=
(
0
..
options
.len
())
.map
(|
i
|
{
let
(
name
,
f
)
=
&
options
[
i
];
let
to_show
=
if
name
.is_empty
()
{
f
.to_string
()
}
else
{
name
.clone
()
};
let
checked_value
=
if
current_f
==
*
f
{
f
.to_string
()
}
else
{
current_f
.to_string
()
};
html!
{
<
Radio
update
=
{
link
.callback
(
move
|
s
|
Msg
::
SetOption
(
i
,
s
))}
checked_value
=
{
checked_value
}
value
=
{
f
.to_string
()}
>
<
span
>
{
to_show
}
<
/
span
>
<
/
Radio
>
}
})
.collect
::
<
Html
>
();
html!
{
<
Field
horizontal
=
{
true
}
label
=
{
label
}
>
<
div
class
=
"radios"
>
{
content
}
<
/
div
>
<
/
Field
>
}
}
ParaType
::
TextField
=>
{
let
name
=
format!
(
"tf_{}"
,
point_id
);
let
f
=
self
.floats
.get
(
&
i
)
.cloned
()
.unwrap_or
(
0.0
)
.to_string
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论