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
d36aaa61
Commit
d36aaa61
authored
Oct 23, 2024
by
dongshufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(iesplan): make sett points work
parent
25df8a88
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
210 行增加
和
52 行删除
+210
-52
Cargo.lock
+39
-38
eig-domain/src/lib.rs
+15
-0
mems/examples/iesplan/Cargo.toml
+1
-0
mems/examples/iesplan/general.csv
+5
-3
mems/examples/iesplan/src/lib.rs
+25
-3
mems/examples/iesplan/src/paracard.rs
+125
-8
没有找到文件。
Cargo.lock
查看文件 @
d36aaa61
...
@@ -43,9 +43,9 @@ dependencies = [
...
@@ -43,9 +43,9 @@ dependencies = [
[[package]]
[[package]]
name = "anyhow"
name = "anyhow"
version = "1.0.9
0
"
version = "1.0.9
1
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95
"
checksum = "
c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8
"
[[package]]
[[package]]
name = "anymap2"
name = "anymap2"
...
@@ -181,9 +181,9 @@ dependencies = [
...
@@ -181,9 +181,9 @@ dependencies = [
[[package]]
[[package]]
name = "cc"
name = "cc"
version = "1.1.3
0
"
version = "1.1.3
1
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945
"
checksum = "
c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f
"
dependencies = [
dependencies = [
"shlex",
"shlex",
]
]
...
@@ -370,7 +370,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611"
...
@@ -370,7 +370,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -390,7 +390,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
...
@@ -390,7 +390,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
"unicode-xid",
"unicode-xid",
]
]
...
@@ -402,7 +402,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
...
@@ -402,7 +402,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -677,7 +677,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
...
@@ -677,7 +677,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -1090,7 +1090,7 @@ dependencies = [
...
@@ -1090,7 +1090,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro-crate",
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -1178,6 +1178,7 @@ dependencies = [
...
@@ -1178,6 +1178,7 @@ dependencies = [
"bytes",
"bytes",
"csv",
"csv",
"eig-domain",
"eig-domain",
"eig-expr",
"getrandom",
"getrandom",
"gloo-file 0.3.0",
"gloo-file 0.3.0",
"gloo-utils 0.2.0",
"gloo-utils 0.2.0",
...
@@ -1222,7 +1223,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
...
@@ -1222,7 +1223,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9311685eb9a34808bbb0608ad2fcab9ae216266beca5848613e95553ac914e3b"
checksum = "9311685eb9a34808bbb0608ad2fcab9ae216266beca5848613e95553ac914e3b"
dependencies = [
dependencies = [
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -1363,7 +1364,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc"
...
@@ -1363,7 +1364,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -1558,7 +1559,7 @@ checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8"
...
@@ -1558,7 +1559,7 @@ checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -1611,12 +1612,12 @@ dependencies = [
...
@@ -1611,12 +1612,12 @@ dependencies = [
[[package]]
[[package]]
name = "prettyplease"
name = "prettyplease"
version = "0.2.2
2
"
version = "0.2.2
4
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba
"
checksum = "
910d41a655dac3b764f1ade94821093d3610248694320cd072303a8eedcf221d
"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -1655,9 +1656,9 @@ dependencies = [
...
@@ -1655,9 +1656,9 @@ dependencies = [
[[package]]
[[package]]
name = "proc-macro2"
name = "proc-macro2"
version = "1.0.8
8
"
version = "1.0.8
9
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9
"
checksum = "
f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e
"
dependencies = [
dependencies = [
"unicode-ident",
"unicode-ident",
]
]
...
@@ -1868,9 +1869,9 @@ dependencies = [
...
@@ -1868,9 +1869,9 @@ dependencies = [
[[package]]
[[package]]
name = "serde"
name = "serde"
version = "1.0.21
0
"
version = "1.0.21
3
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a
"
checksum = "
3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1
"
dependencies = [
dependencies = [
"serde_derive",
"serde_derive",
]
]
...
@@ -1909,20 +1910,20 @@ dependencies = [
...
@@ -1909,20 +1910,20 @@ dependencies = [
[[package]]
[[package]]
name = "serde_derive"
name = "serde_derive"
version = "1.0.21
0
"
version = "1.0.21
3
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f
"
checksum = "
7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5
"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
name = "serde_json"
name = "serde_json"
version = "1.0.13
1
"
version = "1.0.13
2
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
67d42a0bd4ac281beff598909bb56a86acaf979b84483e1c79c10dcaf98f8cf
3"
checksum = "
d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db0
3"
dependencies = [
dependencies = [
"itoa",
"itoa",
"memchr",
"memchr",
...
@@ -1995,9 +1996,9 @@ dependencies = [
...
@@ -1995,9 +1996,9 @@ dependencies = [
[[package]]
[[package]]
name = "syn"
name = "syn"
version = "2.0.
79
"
version = "2.0.
82
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8
9132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590
"
checksum = "8
3540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021
"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
...
@@ -2019,29 +2020,29 @@ dependencies = [
...
@@ -2019,29 +2020,29 @@ dependencies = [
[[package]]
[[package]]
name = "thiserror"
name = "thiserror"
version = "1.0.6
4
"
version = "1.0.6
5
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84
"
checksum = "
5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5
"
dependencies = [
dependencies = [
"thiserror-impl",
"thiserror-impl",
]
]
[[package]]
[[package]]
name = "thiserror-impl"
name = "thiserror-impl"
version = "1.0.6
4
"
version = "1.0.6
5
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3
"
checksum = "
ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602
"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
name = "tokio"
name = "tokio"
version = "1.4
0
.0"
version = "1.4
1
.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998
"
checksum = "
145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb
"
dependencies = [
dependencies = [
"backtrace",
"backtrace",
"pin-project-lite",
"pin-project-lite",
...
@@ -2094,7 +2095,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
...
@@ -2094,7 +2095,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
@@ -2158,7 +2159,7 @@ dependencies = [
...
@@ -2158,7 +2159,7 @@ dependencies = [
"once_cell",
"once_cell",
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
"wasm-bindgen-shared",
"wasm-bindgen-shared",
]
]
...
@@ -2192,7 +2193,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
...
@@ -2192,7 +2193,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
dependencies = [
dependencies = [
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
"wasm-bindgen-backend",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
"wasm-bindgen-shared",
]
]
...
@@ -2440,11 +2441,11 @@ checksum = "02fd8ca5166d69e59f796500a2ce432ff751edecbbb308ca59fd3fe4d0343de2"
...
@@ -2440,11 +2441,11 @@ checksum = "02fd8ca5166d69e59f796500a2ce432ff751edecbbb308ca59fd3fe4d0343de2"
dependencies = [
dependencies = [
"boolinator",
"boolinator",
"once_cell",
"once_cell",
"prettyplease 0.2.2
2
",
"prettyplease 0.2.2
4
",
"proc-macro-error",
"proc-macro-error",
"proc-macro2",
"proc-macro2",
"quote",
"quote",
"syn 2.0.
79
",
"syn 2.0.
82
",
]
]
[[package]]
[[package]]
...
...
eig-domain/src/lib.rs
查看文件 @
d36aaa61
...
@@ -289,6 +289,21 @@ pub struct SetFloatValue {
...
@@ -289,6 +289,21 @@ pub struct SetFloatValue {
pub
timestamp
:
u64
,
pub
timestamp
:
u64
,
}
}
/**
* @api {公式型指令数据} /SetPointValue SetPointValue
* @apiGroup A_Object
* @apiSuccess {u64} sender_id sender_id
* @apiSuccess {u64} point_id point_id
* @apiSuccess {expr} command command
* @apiSuccess {u64} timestamp timestamp
*/
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
pub
struct
SetPointValue
{
pub
sender_id
:
u64
,
pub
point_id
:
u64
,
pub
command
:
Expr
,
pub
timestamp
:
u64
,
}
fn
deserialize_enum_or_unknown
<
'de
,
E
:
EnumFull
,
D
:
serde
::
Deserializer
<
'de
>>
(
fn
deserialize_enum_or_unknown
<
'de
,
E
:
EnumFull
,
D
:
serde
::
Deserializer
<
'de
>>
(
d
:
D
,
d
:
D
,
...
...
mems/examples/iesplan/Cargo.toml
查看文件 @
d36aaa61
...
@@ -27,6 +27,7 @@ protobuf = { version = "3.7", features = ["with-bytes"] }
...
@@ -27,6 +27,7 @@ protobuf = { version = "3.7", features = ["with-bytes"] }
csv
=
"1.3"
csv
=
"1.3"
yew-bulma
=
{
git
=
"https://github.com/shufengdong/yew-bulma.git"
}
yew-bulma
=
{
git
=
"https://github.com/shufengdong/yew-bulma.git"
}
eig-domain
=
{
path
=
"../../../eig-domain"
}
eig-domain
=
{
path
=
"../../../eig-domain"
}
eig-expr
=
{
path
=
"../../../eig-expr"
}
# web-sys and js-sys
# web-sys and js-sys
js-sys
=
"0.3"
js-sys
=
"0.3"
[dependencies.web-sys]
[dependencies.web-sys]
...
...
mems/examples/iesplan/general.csv
查看文件 @
d36aaa61
1,car1,500
5,car1,500
100001,name1,Checkbox
1000001,源电压,Checkbox
100002,name2,Checkbox
1000002,A相有功634,Radio
1000003,A相无功634,TextField
1000004,B相有功634,Switch
mems/examples/iesplan/src/lib.rs
查看文件 @
d36aaa61
use
crate
::
startpage
::
StartPage
;
use
crate
::
startpage
::
StartPage
;
use
eig_domain
::
excel
::
get_first_sheet_merged_cells
;
use
eig_domain
::
excel
::
get_first_sheet_merged_cells
;
use
eig_domain
::{
csv_string
,
csv_u64
,
csv_usize
};
use
eig_domain
::{
csv_str
,
csv_string
,
csv_u64
,
csv_usize
,
SetPointValue
};
use
serde
::{
Deserialize
,
Serialize
};
use
wasm_bindgen
::
prelude
::
*
;
use
wasm_bindgen
::
prelude
::
*
;
use
web_sys
::
Element
;
use
web_sys
::
{
Element
,
Headers
}
;
use
yew_bulma
::
layout
::
tiles
::
Tiles
;
use
yew_bulma
::
layout
::
tiles
::
Tiles
;
pub
mod
startpage
;
pub
mod
startpage
;
mod
paracard
;
mod
paracard
;
...
@@ -12,6 +13,17 @@ pub fn create_view(e: Element) {
...
@@ -12,6 +13,17 @@ pub fn create_view(e: Element) {
yew
::
Renderer
::
<
StartPage
>
::
with_root
(
e
)
.render
();
yew
::
Renderer
::
<
StartPage
>
::
with_root
(
e
)
.render
();
}
}
#[wasm_bindgen(raw_module
=
"/mems-view-bin-457c52177f3ff994.js"
)]
extern
"C"
{
pub
fn
get_headers
()
->
Headers
;
pub
fn
get_user_id
()
->
u16
;
}
#[derive(Serialize,
Deserialize,
Debug,
Clone)]
pub
struct
PointControl3
{
pub
commands
:
Vec
<
SetPointValue
>
,
}
#[derive(Clone,
Debug,
PartialEq)]
#[derive(Clone,
Debug,
PartialEq)]
pub
enum
ParaType
{
pub
enum
ParaType
{
// show expresion, true expression, false expression
// show expresion, true expression, false expression
...
@@ -47,7 +59,17 @@ pub fn create_parameters(content: &[u8]) -> Parameters {
...
@@ -47,7 +59,17 @@ pub fn create_parameters(content: &[u8]) -> Parameters {
let
row
=
record
.unwrap
();
let
row
=
record
.unwrap
();
points
.push
(
csv_u64
(
&
row
,
0
)
.unwrap
());
points
.push
(
csv_u64
(
&
row
,
0
)
.unwrap
());
labels
.push
(
csv_string
(
&
row
,
1
)
.unwrap
());
labels
.push
(
csv_string
(
&
row
,
1
)
.unwrap
());
para_types
.push
(
ParaType
::
Checkbox
);
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
,
// "SLIDE" => ParaType::Slider(),
// "SLIDE" => ParaType::Checkbox,
_
=>
ParaType
::
TextField
};
para_types
.push
(
para_type
);
}
}
Parameters
{
id
,
name
,
labels
,
points
,
para_types
}
Parameters
{
id
,
name
,
labels
,
points
,
para_types
}
}
}
...
...
mems/examples/iesplan/src/paracard.rs
查看文件 @
d36aaa61
use
std
::
collections
::
HashMap
;
use
wasm_bindgen
::
JsCast
;
use
wasm_bindgen
::
JsCast
;
use
web_sys
::
InputEvent
;
use
web_sys
::
InputEvent
;
use
yew
::
prelude
::
*
;
use
yew
::
prelude
::
*
;
use
yew_bulma
::
*
;
use
yew_bulma
::
*
;
use
crate
::{
ParaType
,
Parameters
};
use
yew_bulma
::
calendar
::
get_timestamp
;
use
eig_domain
::
SetPointValue
;
use
eig_expr
::{
Expr
,
Token
};
use
crate
::{
get_headers
,
get_user_id
,
ParaType
,
Parameters
,
PointControl3
};
pub
enum
Msg
{
pub
enum
Msg
{
SetBool
(
usize
,
bool
),
SetBool
(
usize
,
bool
),
SetString
(
usize
),
SetString
(
usize
),
SetOption
(
usize
,
String
),
SetOption
(
usize
,
String
),
None
,
}
}
#[derive(Clone,
Debug,
PartialEq,
Properties)]
#[derive(Clone,
Debug,
PartialEq,
Properties)]
pub
struct
Props
{
pub
struct
Props
{
pub
paras
:
Parameters
pub
paras
:
Parameters
,
}
}
pub
struct
ParaCard
{}
pub
struct
ParaCard
{
bools
:
HashMap
<
usize
,
bool
>
,
}
impl
Component
for
ParaCard
{
impl
Component
for
ParaCard
{
type
Message
=
Msg
;
type
Message
=
Msg
;
type
Properties
=
Props
;
type
Properties
=
Props
;
fn
create
(
_
:
&
Context
<
Self
>
)
->
Self
{
fn
create
(
ctx
:
&
Context
<
Self
>
)
->
Self
{
Self
{}
let
mut
bools
=
HashMap
::
new
();
for
index
in
0
..
ctx
.props
()
.paras.points
.len
()
{
let
input_type
=
&
ctx
.props
()
.paras.para_types
[
index
];
if
let
ParaType
::
Checkbox
=
input_type
{
bools
.insert
(
index
,
false
);
}
else
if
let
ParaType
::
Switch
=
input_type
{
bools
.insert
(
index
,
false
);
}
else
if
let
ParaType
::
Radio
=
input_type
{
bools
.insert
(
index
,
false
);
}
}
Self
{
bools
}
}
fn
update
(
&
mut
self
,
ctx
:
&
Context
<
Self
>
,
msg
:
Self
::
Message
)
->
bool
{
match
msg
{
Msg
::
SetBool
(
i
,
b
)
=>
{
let
point_id
=
&
ctx
.props
()
.paras.points
[
i
];
let
input_type
=
&
ctx
.props
()
.paras.para_types
[
i
];
let
v
=
if
ParaType
::
Checkbox
.eq
(
input_type
)
||
ParaType
::
Radio
.eq
(
input_type
)
||
ParaType
::
Switch
.eq
(
input_type
)
{
if
b
{
Some
(
Expr
::
from_vec
(
vec!
[
Token
::
Number
(
1.0
)]))
}
else
{
Some
(
Expr
::
from_vec
(
vec!
[
Token
::
Number
(
0.0
)]))
}
}
else
{
None
};
if
let
Some
(
expr
)
=
v
{
let
user_id
=
get_user_id
();
let
v
=
SetPointValue
{
point_id
:
*
point_id
,
sender_id
:
user_id
as
u64
,
command
:
expr
,
timestamp
:
get_timestamp
(),
};
self
.set_point
(
ctx
,
PointControl3
{
commands
:
vec!
[
v
]
});
}
if
let
Some
(
v
)
=
self
.bools
.get_mut
(
&
i
)
{
*
v
=
b
;
return
true
;
}
}
Msg
::
SetString
(
i
)
=>
{
let
point_id
=
&
ctx
.props
()
.paras.points
[
i
];
let
name
=
format!
(
"tf_{}"
,
point_id
);
let
value
=
get_input_value_by_name
(
&
name
);
if
let
Ok
(
expr
)
=
value
.parse
()
{
let
user_id
=
get_user_id
();
let
v
=
SetPointValue
{
point_id
:
*
point_id
,
sender_id
:
user_id
as
u64
,
command
:
expr
,
timestamp
:
get_timestamp
(),
};
self
.set_point
(
ctx
,
PointControl3
{
commands
:
vec!
[
v
]
});
}
else
{
alert
(
"Wrong input"
);
}
}
Msg
::
SetOption
(
i
,
value
)
=>
{
if
value
==
"None"
{
return
false
;
}
let
point_id
=
&
ctx
.props
()
.paras.points
[
i
];
if
let
Ok
(
expr
)
=
value
.parse
()
{
let
user_id
=
get_user_id
();
let
v
=
SetPointValue
{
point_id
:
*
point_id
,
sender_id
:
user_id
as
u64
,
command
:
expr
,
timestamp
:
get_timestamp
(),
};
self
.set_point
(
ctx
,
PointControl3
{
commands
:
vec!
[
v
]
});
}
else
{
alert
(
"Wrong input"
);
}
}
Msg
::
None
=>
{}
}
false
}
}
fn
view
(
&
self
,
ctx
:
&
Context
<
Self
>
)
->
Html
{
fn
view
(
&
self
,
ctx
:
&
Context
<
Self
>
)
->
Html
{
...
@@ -58,7 +147,7 @@ impl ParaCard {
...
@@ -58,7 +147,7 @@ impl ParaCard {
};
};
match
input_type
{
match
input_type
{
ParaType
::
Checkbox
=>
{
ParaType
::
Checkbox
=>
{
let
checked
=
true
;
let
checked
=
self
.bools
.get
(
&
i
)
.cloned
()
.unwrap_or
(
false
)
;
html!
{
html!
{
<
Field
horizontal
=
{
true
}
>
<
Field
horizontal
=
{
true
}
>
<
Checkbox
checked
=
{
checked
}
<
Checkbox
checked
=
{
checked
}
...
@@ -69,7 +158,7 @@ impl ParaCard {
...
@@ -69,7 +158,7 @@ impl ParaCard {
}
}
}
}
ParaType
::
Radio
=>
{
ParaType
::
Radio
=>
{
let
checked
=
true
;
let
checked
=
self
.bools
.get
(
&
i
)
.cloned
()
.unwrap_or
(
false
)
;
html!
{
html!
{
<
Field
horizontal
=
{
true
}
>
<
Field
horizontal
=
{
true
}
>
<
Radio
update
=
{
link
.callback
(
move
|
_
|
Msg
::
SetBool
(
i
,
!
checked
))}
<
Radio
update
=
{
link
.callback
(
move
|
_
|
Msg
::
SetBool
(
i
,
!
checked
))}
...
@@ -81,7 +170,7 @@ impl ParaCard {
...
@@ -81,7 +170,7 @@ impl ParaCard {
}
}
}
}
ParaType
::
Switch
=>
{
ParaType
::
Switch
=>
{
let
checked
=
true
;
let
checked
=
self
.bools
.get
(
&
i
)
.cloned
()
.unwrap_or
(
false
)
;
html!
{
html!
{
<
Field
horizontal
=
{
true
}
label
=
{
label
}
>
<
Field
horizontal
=
{
true
}
label
=
{
label
}
>
<
input
class
=
{
classes!
(
"mui-switch"
,
"mui-switch-animbg"
)}
type
=
"checkbox"
<
input
class
=
{
classes!
(
"mui-switch"
,
"mui-switch-animbg"
)}
type
=
"checkbox"
...
@@ -137,4 +226,31 @@ impl ParaCard {
...
@@ -137,4 +226,31 @@ impl ParaCard {
}
}
}
}
}
}
}
impl
ParaCard
{
fn
set_point
(
&
self
,
ctx
:
&
Context
<
Self
>
,
cmd
:
PointControl3
)
{
let
url
=
"/api/v1/controls_cbor/points_by_expr"
;
ctx
.link
()
.send_future
(
async
move
{
let
content
=
serde_cbor
::
to_vec
(
&
cmd
)
.unwrap
();
let
body
=
js_sys
::
Uint8Array
::
from
(
content
.as_ref
())
.dyn_into
()
.unwrap
();
match
async_ws_post_no_resp
(
url
,
&
get_headers
(),
Some
(
body
))
.await
{
Ok
(
b
)
=>
{
if
b
{
alert
(
"Success"
);
}
else
{
alert
(
"Fail"
);
}
}
Err
(
err
)
=>
{
if
err
.to_string
()
.eq
(
HEADER_TOKEN_INVALID
)
{
alert
(
&
format!
(
"Invalid header token for url: {url}"
));
}
else
if
err
.to_string
()
.eq
(
HEADER_PERMISSION_DENIED
)
{
alert
(
&
format!
(
"Permission denied for url: {}"
,
url
));
}
else
{}
}
}
Msg
::
None
});
}
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论