This commit is contained in:
北海一刀 2021-11-11 18:58:36 +08:00
parent b837423b6b
commit c97bba9079
3 changed files with 35 additions and 47 deletions

View File

@ -9,26 +9,18 @@ import Menu from "../menu/main.js"
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
children :props.children
}
}
componentDidUpdate(prevProps,prevState){
if(prevState.children!=this.state.children)
{
console.log("更新")
} }
} }
render() { render() {
const {labelname,prop,labelwidth,myClassName} = this.props const {labelname,prop,labelwidth,myClassName} = this.props
console.log(222,this.state.children)
return ( return (
<div className ={ myClassName ? myClassName + " form-Item" :"form-Item"} > <div className ={ myClassName ? myClassName + " form-Item" :"form-Item"} >
<div className="form-label" style={{width: labelwidth ? labelwidth : "180px" }}> <div className="form-label" style={{width: labelwidth ? labelwidth : "180px" }}>
{labelname} {labelname}
</div> </div>
<div className="form-compontent"> <div className="form-compontent">
{this.state.children} {this.props.children}
</div> </div>
</div> </div>
) )

View File

@ -17,6 +17,10 @@ export default class form extends React.Component {
rules: props.rules rules: props.rules
} }
} }
componentWillReceiveProps(nextProps) {
this.setState({children: nextProps.children});
this.setState({model: nextProps.model});
}
componentDidMount() { componentDidMount() {
const dom = ReactDom.findDOMNode(this); const dom = ReactDom.findDOMNode(this);
let doms = dom.getElementsByClassName("form-Item"); let doms = dom.getElementsByClassName("form-Item");
@ -200,33 +204,6 @@ export default class form extends React.Component {
} }
// if (formItem_com.value == "") {
// if (rules_item[j].type == "required") {
// this.removeClasss(item);
// this.isRequired(formItem_com.value, o.className, item, rules_item[j].message);
// }
// } else {
// console.log("规则验证")
// if (rules_item[j].type == "regExp") {
// var regu = rules_item[j].reg;
// var re = new RegExp(regu);
// let s = formItem_com.value;
// if (re.test(s)) {
// console.log("满足")
// this.removeClasss(item)
// } else {
// console.log("不满足")
// this.isRequired(formItem_com.value, o.className, item, rules_item[j].message);
// }
// } else {
// this.removeClasss(item)
// }
// }
} }
} }
@ -236,7 +213,7 @@ export default class form extends React.Component {
render() { render() {
return ( < return ( <
div className = "form" > { div className = "form" > {
this.state.children this.props.children
} < } <
/div> /div>
) )

View File

@ -11,12 +11,13 @@ export default class adduserinfo extends React.Component{
super(props) super(props)
this.state={ this.state={
model:{ //数据模型不可少 model:{ //数据模型不可少
account:"",
phone:"",
pwd:"",
name:"", name:"",
type:"", post:"",
reseller:"", station:"",
return_id:"", },
date_time:""
}
} }
} }
@ -29,8 +30,26 @@ export default class adduserinfo extends React.Component{
onUploadChange(files){ onUploadChange(files){
console.log(files); console.log(files);
}; };
submit(){
this.refs.form1.validator() onChange (e) {
let model2 = {...this.model}
model2.station = e;
this.setState({
model:model2
});
};
cancel(){
console.log("取消")
let model2 = { //数据模型不可少
account:"",
phone:"",
pwd:"",
name:"",
post:"",
station:"",
}
this.setState({model:model2});
} }
render(){ render(){
const options = [ const options = [
@ -124,13 +143,13 @@ export default class adduserinfo extends React.Component{
<Select options={options} clearable placeholder="请选择岗位" popupWidth="360px" /> <Select options={options} clearable placeholder="请选择岗位" popupWidth="360px" />
</FormItem> </FormItem>
<FormItem prop="station" labelname="角色"> <FormItem prop="station" labelname="角色">
<Select options={options} clearable placeholder="请选择角色" popupWidth="360px" width="520px"/> <Select options={options} clearable placeholder="请选择角色" value={this.state.model.station} onChange={(e)=>{this.onChange(e)}} popupWidth="360px" width="520px"/>
</FormItem> </FormItem>
<div className="zent-form-actions"> <div className="zent-form-actions">
<Button type="primary" onClick={this.submit.bind(this)}> <Button type="primary" onClick={this.submit.bind(this)}>
提交 提交
</Button> </Button>
<Button type="normal" htmlType="reset"> <Button type="normal" htmlType="reset" onClick={this.cancel.bind(this)}>
取消 取消
</Button> </Button>
</div> </div>