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
489703d8
Commit
489703d8
authored
Oct 18, 2024
by
dongshufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(all): add iesplan example
parent
04eb97d7
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
172 行增加
和
82 行删除
+172
-82
Cargo.lock
+8
-70
eig-domain/src/lib.rs
+108
-1
mems/examples/iesplan/Cargo.toml
+18
-4
mems/examples/iesplan/general.csv
+6
-2
mems/examples/iesplan/src/lib.rs
+21
-2
mems/examples/iesplan/src/paracard.rs
+2
-1
mems/examples/iesplan/src/startpage.rs
+9
-2
没有找到文件。
Cargo.lock
查看文件 @
489703d8
...
...
@@ -144,15 +144,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "boolinator"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -310,15 +301,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "cpufeatures"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0"
dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -370,16 +352,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "csv"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -433,16 +405,6 @@ dependencies = [
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "displaydoc"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -759,16 +721,6 @@ dependencies = [
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -1234,12 +1186,10 @@ version = "0.1.0"
dependencies = [
"byteorder",
"bytes",
"chrono",
"cron",
"csv",
"eig-domain",
"getrandom",
"gloo-file 0.3.0",
"gloo-timers 0.3.0",
"gloo-utils 0.2.0",
"js-sys",
"log",
...
...
@@ -1248,7 +1198,6 @@ dependencies = [
"serde-wasm-bindgen 0.6.5",
"serde_cbor",
"serde_json",
"sha2",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
...
...
@@ -1323,9 +1272,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.16
0
"
version = "0.2.16
1
"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
f0b21006cd1874ae9e650973c565615676dc4a274c965bb0a73796dac838ce4f
"
checksum = "
8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1
"
[[package]]
name = "linux-raw-sys"
...
...
@@ -1666,9 +1615,9 @@ checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2"
[[package]]
name = "portable-atomic-util"
version = "0.2.
2
"
version = "0.2.
3
"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
fcdd8420072e66d54a407b3316991fe946ce3ab1083a7f575b2463866624704d
"
checksum = "
90a7d5beecc52a491b54d6dd05c7a45ba1801666a5baad9fdbfc6fef8d2d206c
"
dependencies = [
"portable-atomic",
]
...
...
@@ -1994,9 +1943,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.12
8
"
version = "1.0.12
9
"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6
ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8
"
checksum = "6
dbcf9b78a125ee667ae19388837dd12294b858d101fdd393cb9d5501ef09eb2
"
dependencies = [
"itoa",
"memchr",
...
...
@@ -2017,17 +1966,6 @@ dependencies = [
]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -2483,7 +2421,7 @@ dependencies = [
[[package]]
name = "yew-bulma"
version = "0.1.0"
source = "git+https://github.com/shufengdong/yew-bulma.git#2
6d4bab9e21144613448e0562c26ca09ce556cee
"
source = "git+https://github.com/shufengdong/yew-bulma.git#2
bd9d5ddc5c77c9797e427f488b3baa329abde66
"
dependencies = [
"bytes",
"chrono",
...
...
eig-domain/src/lib.rs
查看文件 @
489703d8
use
std
::
fmt
;
use
std
::
marker
::
PhantomData
;
use
csv
::
StringRecord
;
use
protobuf
::{
EnumFull
,
EnumOrUnknown
};
use
serde
::{
Deserialize
,
Serialize
};
...
...
@@ -332,3 +332,109 @@ fn deserialize_enum_or_unknown<'de, E: EnumFull, D: serde::Deserializer<'de>>(
d
.deserialize_any
(
DeserializeEnumVisitor
(
PhantomData
))
}
pub
fn
csv_str
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<&
str
>
{
Some
(
record
.get
(
col
)
?
.trim
())
}
pub
fn
csv_string
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
String
>
{
Some
(
record
.get
(
col
)
?
.trim
()
.to_string
())
}
pub
fn
csv_usize
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
usize
>
{
let
s
=
record
.get
(
col
)
?
.to_string
();
let
r
=
s
.parse
()
.ok
()
?
;
Some
(
r
)
}
pub
fn
csv_u8
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
u8
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
if
s
.starts_with
(
"0x"
)
{
u8
::
from_str_radix
(
s
.trim_start_matches
(
"0x"
),
16
)
.ok
()
?
}
else
{
s
.parse
()
.ok
()
?
};
Some
(
r
)
}
pub
fn
csv_u16
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
u16
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
if
s
.starts_with
(
"0x"
)
{
u16
::
from_str_radix
(
s
.trim_start_matches
(
"0x"
),
16
)
.ok
()
?
}
else
{
s
.parse
()
.ok
()
?
};
Some
(
r
)
}
pub
fn
csv_u32
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
u32
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
if
s
.starts_with
(
"0x"
)
{
u32
::
from_str_radix
(
s
.trim_start_matches
(
"0x"
),
16
)
.ok
()
?
}
else
{
s
.parse
()
.ok
()
?
};
Some
(
r
)
}
pub
fn
csv_u64
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
u64
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
if
s
.starts_with
(
"0x"
)
{
u64
::
from_str_radix
(
s
.trim_start_matches
(
"0x"
),
16
)
.ok
()
?
}
else
{
s
.parse
()
.ok
()
?
};
Some
(
r
)
}
pub
fn
csv_i8
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
i8
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
if
s
.starts_with
(
"0x"
)
{
i8
::
from_str_radix
(
s
.trim_start_matches
(
"0x"
),
16
)
.ok
()
?
}
else
{
s
.parse
()
.ok
()
?
};
Some
(
r
)
}
pub
fn
csv_i16
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
i16
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
if
s
.starts_with
(
"0x"
)
{
i16
::
from_str_radix
(
s
.trim_start_matches
(
"0x"
),
16
)
.ok
()
?
}
else
{
s
.parse
()
.ok
()
?
};
Some
(
r
)
}
pub
fn
csv_i32
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
i32
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
if
s
.starts_with
(
"0x"
)
{
i32
::
from_str_radix
(
s
.trim_start_matches
(
"0x"
),
16
)
.ok
()
?
}
else
{
s
.parse
()
.ok
()
?
};
Some
(
r
)
}
pub
fn
csv_i64
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
i64
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
if
s
.starts_with
(
"0x"
)
{
i64
::
from_str_radix
(
s
.trim_start_matches
(
"0x"
),
16
)
.ok
()
?
}
else
{
s
.parse
()
.ok
()
?
};
Some
(
r
)
}
pub
fn
csv_f64
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
f64
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
s
.parse
()
.ok
()
?
;
Some
(
r
)
}
pub
fn
csv_f32
(
record
:
&
StringRecord
,
col
:
usize
)
->
Option
<
f32
>
{
let
s
=
record
.get
(
col
)
?
.trim
();
let
r
=
s
.parse
()
.ok
()
?
;
Some
(
r
)
}
\ No newline at end of file
mems/examples/iesplan/Cargo.toml
查看文件 @
489703d8
...
...
@@ -22,12 +22,9 @@ yew = { version = "0.21", features = ["csr"] }
yew-agent
=
"0.2"
gloo-utils
=
"0.2"
gloo-file
=
"0.3"
gloo-timers
=
"0.3"
sha2
=
{
version
=
"0.10"
,
default-features
=
false
}
getrandom
=
{
version
=
"0.2"
,
features
=
["js"]
}
chrono
=
{
version
=
"0.4"
,
features
=
["wasmbind"]
}
protobuf
=
{
version
=
"3.7"
,
features
=
["with-bytes"]
}
c
ron
=
"0.12
"
c
sv
=
"1.3
"
yew-bulma
=
{
git
=
"https://github.com/shufengdong/yew-bulma.git"
}
eig-domain
=
{
path
=
"../../../eig-domain"
}
# web-sys and js-sys
...
...
@@ -35,3 +32,19 @@ js-sys = "0.3"
[dependencies.web-sys]
version
=
"0.3"
features
=
[
"FormData"
,
"File"
]
[profile.release]
# Tell `rustc` to optimize for small code size.
# 二进制文件会包含更少的代码
panic
=
'abort'
# 对所有代码库进行优化(优化更好,构建更慢)
codegen-units
=
1
# 优化大小(更加激进)
opt-level
=
0
# 优化大小
# opt-level = 's'
# 对整个程序进行链接时优化(link time optimization)
lto
=
true
[package.metadata.wasm-pack.profile.release]
wasm-opt
=
false
\ No newline at end of file
mems/examples/iesplan/general.csv
查看文件 @
489703d8
1
\ No newline at end of file
0,car1,500
100001,name1,Checkbox
100002,name2,Checkbox
100003,name3,Checkbox
100004,name4,Checkbox
100005,name5,Checkbox
mems/examples/iesplan/src/lib.rs
查看文件 @
489703d8
...
...
@@ -2,6 +2,7 @@ use wasm_bindgen::prelude::*;
use
web_sys
::
Element
;
use
crate
::
startpage
::
StartPage
;
use
yew_bulma
::
layout
::
tiles
::
Tiles
;
use
eig_domain
::{
csv_string
,
csv_u64
,
csv_usize
};
use
eig_domain
::
excel
::
get_first_sheet_merged_cells
;
pub
mod
startpage
;
mod
paracard
;
...
...
@@ -26,13 +27,31 @@ pub enum ParaType {
pub
struct
Parameters
{
id
:
usize
,
name
:
String
,
height
:
usize
,
labels
:
Vec
<
String
>
,
points
:
Vec
<
u64
>
,
para_types
:
Vec
<
ParaType
>
,
}
pub
fn
create_parameters
(
csv_bytes
:
&
[
u8
])
->
Option
<
Parameters
>
{
None
pub
fn
create_parameters
(
content
:
&
[
u8
])
->
Parameters
{
let
mut
rdr
=
csv
::
ReaderBuilder
::
new
()
.has_headers
(
false
)
.from_reader
(
content
);
let
mut
records
=
rdr
.records
();
let
record
=
records
.next
()
.unwrap
()
.unwrap
();
let
id
=
csv_usize
(
&
record
,
0
)
.unwrap
();
let
name
=
csv_string
(
&
record
,
1
)
.unwrap
();
let
height
=
csv_usize
(
&
record
,
2
)
.unwrap
();
let
mut
labels
=
Vec
::
new
();
let
mut
points
=
Vec
::
new
();
let
mut
para_types
=
Vec
::
new
();
for
record
in
records
{
let
row
=
record
.unwrap
();
points
.push
(
csv_u64
(
&
row
,
0
)
.unwrap
());
labels
.push
(
csv_string
(
&
row
,
1
)
.unwrap
());
para_types
.push
(
ParaType
::
Checkbox
);
}
Parameters
{
id
,
name
,
height
,
labels
,
points
,
para_types
}
}
pub
fn
build_tiles
(
xlsx_bytes
:
Vec
<
u8
>
)
->
Option
<
Tiles
>
{
...
...
mems/examples/iesplan/src/paracard.rs
查看文件 @
489703d8
...
...
@@ -30,8 +30,9 @@ impl Component for ParaCard {
let
input_html
=
(
0
..
paras
.points
.len
())
.map
(|
i
|
{
self
.create_input
(
ctx
,
i
)
})
.collect
::
<
Html
>
();
let
height
=
format!
(
"height:{}px"
,
paras
.height
);
html!
{
<
Card
>
<
Card
height
=
{
height
}
>
<
CardHeader
>
<
p
class
=
"card-header-title"
>
{
paras
.name
.clone
()}
...
...
mems/examples/iesplan/src/startpage.rs
查看文件 @
489703d8
...
...
@@ -4,13 +4,16 @@ use yew::prelude::*;
use
yew_bulma
::
layout
::
tiles
::
Tiles
;
use
yew_bulma
::
*
;
use
crate
::
build_tiles
;
use
crate
::{
build_tiles
,
create_parameters
,
Parameters
};
use
crate
::
paracard
::
ParaCard
;
pub
enum
Msg
{
start
,
}
pub
struct
StartPage
{
tiles
:
Tiles
,
general_para
:
Parameters
,
}
impl
Component
for
StartPage
{
...
...
@@ -19,7 +22,8 @@ impl Component for StartPage {
fn
create
(
_
:
&
Context
<
Self
>
)
->
Self
{
let
tiles
=
build_tiles
(
include_bytes!
(
"../layout.xlsx"
)
.to_vec
())
.unwrap
();
Self
{
tiles
}
let
general_para
=
create_parameters
(
include_bytes!
(
"../general.csv"
));
Self
{
tiles
,
general_para
}
}
fn
update
(
&
mut
self
,
_
:
&
Context
<
Self
>
,
msg
:
Self
::
Message
)
->
bool
{
...
...
@@ -39,6 +43,9 @@ impl Component for StartPage {
};
nodes
.insert
(
i
,
v
);
}
nodes
.insert
(
self
.general_para.id
,
html!
{
<
ParaCard
paras
=
{
self
.general_para
.clone
()}
/
>
});
self
.tiles
.create_html
(
nodes
)
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论