Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
hfpp2012
/
react-spd
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5afb1e8b
authored
May 26, 2017
by
hfpp2012 yinsigan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix ElementGroup mobx
1 parent
54785816
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
20 deletions
src/components/ElementGroup.js
src/containers/Spd.js
src/stores/ElementGroupStore.js
src/components/ElementGroup.js
View file @
5afb1e8
...
...
@@ -2,35 +2,22 @@ import React from 'react'
import
Element
from
'./Element'
import
ReactAddonsUpdate
from
'react-addons-update'
import
autobind
from
'autobind-decorator'
import
{
observer
}
from
'mobx-react'
@
autobind
@
observer
export
default
class
ElementGroup
extends
React
.
Component
{
constructor
(
props
){
super
(
props
);
this
.
state
=
{
elements
:
[
{
id
:
1
,
name
:
"药库"
,
initialPos
:
{
x
:
80
,
y
:
70
},
target_type
:
'RegionalDesign::Repo'
},
{
id
:
2
,
name
:
"药架"
,
initialPos
:
{
x
:
80
,
y
:
70
+
60
},
target_type
:
'RegionalDesign::DrugRepo'
},
{
id
:
3
,
name
:
"药架格"
,
initialPos
:
{
x
:
80
,
y
:
70
+
60
*
2
},
target_type
:
'RegionalDesign::DrugBrandreth'
}
]
};
}
cloneElement
(
element
)
{
const
elements
=
ReactAddonsUpdate
(
this
.
state
.
elements
,
{
$push
:
[
element
]
})
this
.
setState
({
elements
:
elements
})
this
.
props
.
ElementGroupStore
.
cloneElement
(
element
)
}
deleteElement
(
element
)
{
const
index
=
this
.
state
.
elements
.
indexOf
(
element
)
const
elements
=
ReactAddonsUpdate
(
this
.
state
.
elements
,
{
$splice
:
[[
index
,
1
]]
})
this
.
setState
({
elements
:
elements
})
this
.
props
.
ElementGroupStore
.
deleteElement
(
element
)
}
// 返回element的index为-1, 删除最后一个元素
deleteLastElement
()
{
const
elements
=
ReactAddonsUpdate
(
this
.
state
.
elements
,
{
$splice
:
[[
-
1
,
1
]]
})
this
.
setState
({
elements
:
elements
})
this
.
props
.
ElementGroupStore
.
deleteLastElement
()
}
sidebar
()
{
...
...
@@ -41,7 +28,7 @@ export default class ElementGroup extends React.Component {
return
(
<
div
>
{
this
.
stat
e
.
elements
.
map
(
function
(
element
)
{
this
.
props
.
ElementGroupStor
e
.
elements
.
map
(
function
(
element
)
{
return
(
<
Element
meta_element
=
{
element
}
key
=
{
"key_"
+
element
.
id
}
id
=
{
element
.
id
}
name
=
{
element
.
name
}
initialPos
=
{
element
.
initialPos
}
target_type
=
{
element
.
target_type
}
handleCloneElement
=
{
this
.
cloneElement
}
handleDeleteElement
=
{
this
.
deleteElement
}
handleDeleteLastElement
=
{
this
.
deleteLastElement
}
/
>
)
...
...
src/containers/Spd.js
View file @
5afb1e8
...
...
@@ -7,6 +7,9 @@ import EventEmitter from '../libs/eventEmitter'
import
headerModel
from
'../stores/HeaderStore'
const
headerStore
=
new
headerModel
()
import
ElementGroupModel
from
'../stores/ElementGroupStore'
const
ElementGroupStore
=
new
ElementGroupModel
()
export
default
class
Spd
extends
React
.
Component
{
componentDidMount
()
{
EventEmitter
.
subscribe
(
'alert'
,
function
(
info
){
...
...
@@ -46,7 +49,7 @@ export default class Spd extends React.Component {
<
div
className
=
"row"
>
<
div
className
=
"col-md-2 sidebar"
id
=
'sidebar'
>
<
h3
className
=
'sidebar-header'
>
元件
<
/h3
>
<
ElementGroup
/>
<
ElementGroup
ElementGroupStore
=
{
ElementGroupStore
}
/
>
<
/div
>
<
div
id
=
"dropzone"
className
=
"col-md-10 dropzone"
>
{
this
.
props
.
children
}
...
...
src/stores/ElementGroupStore.js
0 → 100644
View file @
5afb1e8
import
{
observable
,
useStrict
,
action
}
from
'mobx'
useStrict
(
true
)
export
default
class
headerStore
{
@
observable
elements
=
[
{
id
:
1
,
name
:
"药库"
,
initialPos
:
{
x
:
80
,
y
:
70
},
target_type
:
'RegionalDesign::Repo'
},
{
id
:
2
,
name
:
"药架"
,
initialPos
:
{
x
:
80
,
y
:
70
+
60
},
target_type
:
'RegionalDesign::DrugRepo'
},
{
id
:
3
,
name
:
"药架格"
,
initialPos
:
{
x
:
80
,
y
:
70
+
60
*
2
},
target_type
:
'RegionalDesign::DrugBrandreth'
}
]
@
action
cloneElement
(
element
)
{
this
.
elements
.
push
(
element
)
}
@
action
deleteElement
(
element
)
{
this
.
elements
.
remove
(
element
)
}
@
action
deleteLastElement
()
{
this
.
elements
.
pop
()
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment