UNPKG

app-base-web

Version:
58 lines (56 loc) 1.72 kB
import React from 'react'; import { Select } from 'antd'; import dic from '../util-dic'; const Option = Select.Option; // const url= "CfgDictionary/getByType"; //value必须转换为字符串 export default class Dic extends React.Component { constructor(props) { super(props); this.state = { hasNullVal: this.props.hasNullVal === false ? false : true, nullValue: this.props.nullValue || "", nullText: this.props.nullText || "请选择", data: [] } // this.initData(); } // async initData(){ // if(this.props.sync){ // let rs= await axios.post(url,this.props.params); // this.setState({data:rs.data}); // } // } init() { var me = this; const rows = []; this.state.hasNullVal && rows.push(<Option key="-1" value={this.state.nullValue}>{this.state.nullText}</Option>); let data; // if(this.props.sync){ // data=this.state.data; // }else{ if (this.props.params.subType) { data = dic.list(this.props.params.app, this.props.params.type, this.props.params.subType); } else { data = dic.list(this.props.params.app, this.props.params.type); } // } if (!data) return rows; var len = data.length; for (let i = 0; i < len; i++) { let item = data[i]; let value = item.value; let text = item.zh_CN; rows.push(<Option key={value} title={text}>{text}</Option>); }; return rows; } render() { let _showSearch = this.props.showSearch == false ? false : true; return ( <Select className="app-dic" {...this.props} virtual={false} showSearch={_showSearch} optionFilterProp="title"> {this.init()} </Select> ); } }