Commit 8fa09bb3 by hfpp2012 yinsigan

重构代码

1 parent 5afb1e8b
...@@ -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>
) )
} }
......
...@@ -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>
......
...@@ -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);
......
...@@ -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() {
......
...@@ -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 headerStore { class ElementGroupStore {
@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()
...@@ -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()
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()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!