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
Show 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'
...
@@ -8,16 +8,20 @@ import { observer } from 'mobx-react'
@
observer
@
observer
export
default
class
ElementGroup
extends
React
.
Component
{
export
default
class
ElementGroup
extends
React
.
Component
{
cloneElement
(
element
)
{
cloneElement
(
element
)
{
this
.
props
.
ElementGroupStore
.
cloneElement
(
element
)
this
.
store
()
.
cloneElement
(
element
)
}
}
deleteElement
(
element
)
{
deleteElement
(
element
)
{
this
.
props
.
ElementGroupStore
.
deleteElement
(
element
)
this
.
store
()
.
deleteElement
(
element
)
}
}
// 返回element的index为-1, 删除最后一个元素
// 返回element的index为-1, 删除最后一个元素
deleteLastElement
()
{
deleteLastElement
()
{
this
.
props
.
ElementGroupStore
.
deleteLastElement
()
this
.
store
().
deleteLastElement
()
}
store
()
{
return
this
.
props
.
ElementGroupStore
}
}
sidebar
()
{
sidebar
()
{
...
@@ -27,13 +31,19 @@ export default class ElementGroup extends React.Component {
...
@@ -27,13 +31,19 @@ export default class ElementGroup extends React.Component {
render
()
{
render
()
{
return
(
return
(
<
div
>
<
div
>
{
{
this
.
store
().
elements
.
map
(
element
=>
this
.
props
.
ElementGroupStore
.
elements
.
map
(
function
(
element
)
{
(
<
Element
return
(
meta_element
=
{
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
}
/
>
key
=
{
"key_"
+
element
.
id
}
)
id
=
{
element
.
id
}
}.
bind
(
this
))
name
=
{
element
.
name
}
}
initialPos
=
{
element
.
initialPos
}
target_type
=
{
element
.
target_type
}
handleCloneElement
=
{
this
.
cloneElement
}
handleDeleteElement
=
{
this
.
deleteElement
}
handleDeleteLastElement
=
{
this
.
deleteLastElement
}
/>
)
)}
<
/div
>
<
/div
>
)
)
}
}
...
...
src/components/Header.js
View file @
8fa09bb
...
@@ -5,6 +5,10 @@ import { Link } from 'react-router-dom'
...
@@ -5,6 +5,10 @@ import { Link } from 'react-router-dom'
import
{
observer
}
from
'mobx-react'
import
{
observer
}
from
'mobx-react'
import
autobind
from
'autobind-decorator'
import
autobind
from
'autobind-decorator'
import
ModalRepoFormModel
from
'../stores/ModalRepoFormStore'
const
ModalRepoFormStore
=
new
ModalRepoFormModel
()
@
autobind
@
autobind
@
observer
@
observer
export
default
class
Header
extends
React
.
Component
{
export
default
class
Header
extends
React
.
Component
{
...
@@ -40,7 +44,7 @@ export default class Header extends React.Component {
...
@@ -40,7 +44,7 @@ export default class Header extends React.Component {
return
(
return
(
<
div
className
=
"text-left top-header"
>
<
div
className
=
"text-left top-header"
>
<
ModalRepoForm
handleNewRepo
=
{
this
.
addRepo
}
/
>
<
ModalRepoForm
handleNewRepo
=
{
this
.
addRepo
}
ModalRepoFormStore
=
{
ModalRepoFormStore
}
/
>
<
div
className
=
'col-md-10'
>
<
div
className
=
'col-md-10'
>
{
result
}
{
result
}
<
/div
>
<
/div
>
...
...
src/components/ModalRepoForm.js
View file @
8fa09bb
...
@@ -3,8 +3,10 @@ import { Modal, Button } from 'react-bootstrap'
...
@@ -3,8 +3,10 @@ import { Modal, Button } from 'react-bootstrap'
import
EventEmitter
from
'../libs/eventEmitter'
import
EventEmitter
from
'../libs/eventEmitter'
import
$
from
'jquery'
import
$
from
'jquery'
import
autobind
from
'autobind-decorator'
import
autobind
from
'autobind-decorator'
import
{
observer
}
from
'mobx-react'
@
autobind
@
autobind
@
observer
export
default
class
ModalRepoForm
extends
React
.
Component
{
export
default
class
ModalRepoForm
extends
React
.
Component
{
constructor
(
props
){
constructor
(
props
){
super
(
props
);
super
(
props
);
...
...
src/containers/Spd.js
View file @
8fa09bb
...
@@ -3,12 +3,8 @@ import ElementGroup from '../components/ElementGroup'
...
@@ -3,12 +3,8 @@ import ElementGroup from '../components/ElementGroup'
import
Header
from
'../components/Header'
import
Header
from
'../components/Header'
import
AlertContainer
from
'react-alert'
import
AlertContainer
from
'react-alert'
import
EventEmitter
from
'../libs/eventEmitter'
import
EventEmitter
from
'../libs/eventEmitter'
import
headerStore
from
'../stores/HeaderStore'
import
headerModel
from
'../stores/HeaderStore'
import
ElementGroupStore
from
'../stores/ElementGroupStore'
const
headerStore
=
new
headerModel
()
import
ElementGroupModel
from
'../stores/ElementGroupStore'
const
ElementGroupStore
=
new
ElementGroupModel
()
export
default
class
Spd
extends
React
.
Component
{
export
default
class
Spd
extends
React
.
Component
{
componentDidMount
()
{
componentDidMount
()
{
...
...
src/stores/ElementGroupStore.js
View file @
8fa09bb
...
@@ -2,7 +2,7 @@ import { observable, useStrict, action } from 'mobx'
...
@@ -2,7 +2,7 @@ import { observable, useStrict, action } from 'mobx'
useStrict
(
true
)
useStrict
(
true
)
export
default
class
header
Store
{
class
ElementGroup
Store
{
@
observable
elements
=
[
@
observable
elements
=
[
{
id
:
1
,
name
:
"药库"
,
initialPos
:
{
x
:
80
,
y
:
70
},
target_type
:
'RegionalDesign::Repo'
},
{
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
:
2
,
name
:
"药架"
,
initialPos
:
{
x
:
80
,
y
:
70
+
60
},
target_type
:
'RegionalDesign::DrugRepo'
},
...
@@ -21,3 +21,5 @@ export default class headerStore {
...
@@ -21,3 +21,5 @@ export default class headerStore {
this
.
elements
.
pop
()
this
.
elements
.
pop
()
}
}
}
}
export
default
new
ElementGroupStore
()
src/stores/HeaderStore.js
View file @
8fa09bb
...
@@ -3,7 +3,7 @@ import $ from 'jquery'
...
@@ -3,7 +3,7 @@ import $ from 'jquery'
useStrict
(
true
)
useStrict
(
true
)
export
default
class
headerStore
{
class
headerStore
{
@
observable
data
=
[]
@
observable
data
=
[]
@
observable
loading
=
true
@
observable
loading
=
true
@
observable
error
=
null
@
observable
error
=
null
...
@@ -28,3 +28,5 @@ export default class headerStore {
...
@@ -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