Commit 1800ba88 by hfpp2012 yinsigan

router hash history push

1 parent 93d82e96
import React from 'react' import React from 'react'
import Move from '../libs/move' import Move from '../libs/move'
import EventEmitter from '../libs/eventEmitter' import EventEmitter from '../libs/eventEmitter'
import { hashHistory } from 'react-router'
export default class Element extends React.Component { export default class Element extends React.Component {
static get getDefaultProps() { static get getDefaultProps() {
...@@ -241,7 +240,7 @@ export default class Element extends React.Component { ...@@ -241,7 +240,7 @@ export default class Element extends React.Component {
const childrenObjectType = this.props.childrenObjectType const childrenObjectType = this.props.childrenObjectType
const url = `/regional_design/${this.props.id}?object=${childrenObjectType}` const url = `/regional_design/${this.props.id}?object=${childrenObjectType}`
if (childrenObjectType != 'drug_brandreth_grid') { if (childrenObjectType != 'drug_brandreth_grid') {
hashHistory.push(url) this.props.hashHistory.push(url)
} }
} }
......
...@@ -10,9 +10,11 @@ export default class ModalRepoForm extends React.Component { ...@@ -10,9 +10,11 @@ export default class ModalRepoForm extends React.Component {
this.state = { this.state = {
showModal: false, name: '' showModal: false, name: ''
}; };
this.init_state = this.state;
this.close = this.close.bind(this); this.close = this.close.bind(this);
this.open = this.open.bind(this); this.open = this.open.bind(this);
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
this.save = this.save.bind(this);
} }
close() { close() {
...@@ -36,7 +38,7 @@ export default class ModalRepoForm extends React.Component { ...@@ -36,7 +38,7 @@ export default class ModalRepoForm extends React.Component {
e.preventDefault() e.preventDefault()
$.post('/regional_design/repos.json', { repo: this.state }, function(data) { $.post('/regional_design/repos.json', { repo: this.state }, function(data) {
this.props.handleNewRepo(data) this.props.handleNewRepo(data)
this.setState(this.getInitialState()) this.setState(this.init_state)
EventEmitter.dispatch('alert', '操作成功') EventEmitter.dispatch('alert', '操作成功')
}.bind(this), 'JSON') }.bind(this), 'JSON')
} }
......
...@@ -11,6 +11,7 @@ export default class RegionalDesign extends React.Component { ...@@ -11,6 +11,7 @@ export default class RegionalDesign extends React.Component {
this.state = { this.state = {
data: null, loading: true, error: null, object_name: '', object_type: '', children_object_type: '' data: null, loading: true, error: null, object_name: '', object_type: '', children_object_type: ''
}; };
this.init_state = this.state;
this.addElement = this.addElement.bind(this); this.addElement = this.addElement.bind(this);
this.updateElement = this.updateElement.bind(this); this.updateElement = this.updateElement.bind(this);
this.addElement = this.addElement.bind(this); this.addElement = this.addElement.bind(this);
...@@ -34,11 +35,12 @@ export default class RegionalDesign extends React.Component { ...@@ -34,11 +35,12 @@ export default class RegionalDesign extends React.Component {
children_param_name: 'drug_brandreth_grid' children_param_name: 'drug_brandreth_grid'
} }
} }
return config[props.location.query.object][key] const search_str = props.location.search
return config[search_str.substring(search_str.indexOf("=") + 1)][key]
} }
componentDidMount() { componentDidMount() {
const url = this.getConfig(this.props, 'object_url') + '/' + this.props.params.id + '.json' const url = this.getConfig(this.props, 'object_url') + '/' + this.props.match.params.id + '.json'
this.getJSON(url) this.getJSON(url)
EventEmitter.subscribe('moveDropZone', function(element){ EventEmitter.subscribe('moveDropZone', function(element){
...@@ -59,7 +61,7 @@ export default class RegionalDesign extends React.Component { ...@@ -59,7 +61,7 @@ export default class RegionalDesign extends React.Component {
name: element.name, name: element.name,
pos_x: element.initialPos.x, pos_x: element.initialPos.x,
pos_y: element.initialPos.y, pos_y: element.initialPos.y,
parent_id: this.props.params.id parent_id: this.props.match.params.id
} }
const url = this.getConfig(this.props, 'children_object_url') + '.json' const url = this.getConfig(this.props, 'children_object_url') + '.json'
...@@ -95,8 +97,8 @@ export default class RegionalDesign extends React.Component { ...@@ -95,8 +97,8 @@ export default class RegionalDesign extends React.Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
this.setState(this.getInitialState) this.setState(this.init_state)
const url = this.getConfig(nextProps, 'object_url') + '/' + nextProps.params.id + '.json' const url = this.getConfig(nextProps, 'object_url') + '/' + nextProps.match.params.id + '.json'
this.getJSON(url) this.getJSON(url)
} }
...@@ -118,7 +120,7 @@ export default class RegionalDesign extends React.Component { ...@@ -118,7 +120,7 @@ export default class RegionalDesign extends React.Component {
else { else {
const data = this.state.data.map(function(element) { const data = this.state.data.map(function(element) {
return ( return (
<Element childrenObjectType={ this.state.children_object_type } isDropZoneChild={ true } key={ element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } /> <Element hashHistory={ this.props.history } childrenObjectType={ this.state.children_object_type } isDropZoneChild={ true } key={ element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } />
) )
}.bind(this)) }.bind(this))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!