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 8fa09bb3
authored
May 26, 2017
by
hfpp2012 yinsigan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
重构代码
1 parent
5afb1e8b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
19 deletions
src/components/ElementGroup.js
src/components/Header.js
src/components/ModalRepoForm.js
src/containers/Spd.js
src/stores/ElementGroupStore.js
src/stores/HeaderStore.js
src/stores/ModalRepoFormStore.js
src/components/ElementGroup.js
View file @
8fa09bb
...
...
@@ -8,16 +8,20 @@ import { observer } from 'mobx-react'
@
observer
export
default
class
ElementGroup
extends
React
.
Component
{
cloneElement
(
element
)
{
this
.
props
.
ElementGroupStore
.
cloneElement
(
element
)
this
.
store
()
.
cloneElement
(
element
)
}
deleteElement
(
element
)
{
this
.
props
.
ElementGroupStore
.
deleteElement
(
element
)
this
.
store
()
.
deleteElement
(
element
)
}
// 返回element的index为-1, 删除最后一个元素
deleteLastElement
()
{
this
.
props
.
ElementGroupStore
.
deleteLastElement
()
this
.
store
().
deleteLastElement
()
}
store
()
{
return
this
.
props
.
ElementGroupStore
}
sidebar
()
{
...
...
@@ -27,13 +31,19 @@ export default class ElementGroup extends React.Component {
render
()
{
return
(
<
div
>
{
this
.
props
.
ElementGroupStore
.
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
}
/
>
)
}.
bind
(
this
))
}
{
this
.
store
().
elements
.
map
(
element
=>
(
<
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
}
/>
)
)}
<
/div
>
)
}
...
...
src/components/Header.js
View file @
8fa09bb
...
...
@@ -5,6 +5,10 @@ import { Link } from 'react-router-dom'
import
{
observer
}
from
'mobx-react'
import
autobind
from
'autobind-decorator'
import
ModalRepoFormModel
from
'../stores/ModalRepoFormStore'
const
ModalRepoFormStore
=
new
ModalRepoFormModel
()
@
autobind
@
observer
export
default
class
Header
extends
React
.
Component
{
...
...
@@ -40,7 +44,7 @@ export default class Header extends React.Component {
return
(
<
div
className
=
"text-left top-header"
>
<
ModalRepoForm
handleNewRepo
=
{
this
.
addRepo
}
/
>
<
ModalRepoForm
handleNewRepo
=
{
this
.
addRepo
}
ModalRepoFormStore
=
{
ModalRepoFormStore
}
/
>
<
div
className
=
'col-md-10'
>
{
result
}
<
/div
>
...
...
src/components/ModalRepoForm.js
View file @
8fa09bb
...
...
@@ -3,8 +3,10 @@ import { Modal, Button } from 'react-bootstrap'
import
EventEmitter
from
'../libs/eventEmitter'
import
$
from
'jquery'
import
autobind
from
'autobind-decorator'
import
{
observer
}
from
'mobx-react'
@
autobind
@
observer
export
default
class
ModalRepoForm
extends
React
.
Component
{
constructor
(
props
){
super
(
props
);
...
...
src/containers/Spd.js
View file @
8fa09bb
...
...
@@ -3,12 +3,8 @@ import ElementGroup from '../components/ElementGroup'
import
Header
from
'../components/Header'
import
AlertContainer
from
'react-alert'
import
EventEmitter
from
'../libs/eventEmitter'
import
headerModel
from
'../stores/HeaderStore'
const
headerStore
=
new
headerModel
()
import
ElementGroupModel
from
'../stores/ElementGroupStore'
const
ElementGroupStore
=
new
ElementGroupModel
()
import
headerStore
from
'../stores/HeaderStore'
import
ElementGroupStore
from
'../stores/ElementGroupStore'
export
default
class
Spd
extends
React
.
Component
{
componentDidMount
()
{
...
...
src/stores/ElementGroupStore.js
View file @
8fa09bb
...
...
@@ -2,7 +2,7 @@ import { observable, useStrict, action } from 'mobx'
useStrict
(
true
)
export
default
class
header
Store
{
class
ElementGroup
Store
{
@
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'
},
...
...
@@ -21,3 +21,5 @@ export default class headerStore {
this
.
elements
.
pop
()
}
}
export
default
new
ElementGroupStore
()
src/stores/HeaderStore.js
View file @
8fa09bb
...
...
@@ -3,7 +3,7 @@ import $ from 'jquery'
useStrict
(
true
)
export
default
class
headerStore
{
class
headerStore
{
@
observable
data
=
[]
@
observable
loading
=
true
@
observable
error
=
null
...
...
@@ -28,3 +28,5 @@ export default class headerStore {
})
}
}
export
default
new
headerStore
()
src/stores/ModalRepoFormStore.js
0 → 100644
View file @
8fa09bb
import
{
observable
,
useStrict
,
action
}
from
'mobx'
useStrict
(
true
)
class
ModalRepoFormStore
{
@
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
()
}
}
export
default
new
ModalRepoFormStore
()
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