| | |
| | | }) |
| | | } |
| | | |
| | | queryField = (type) => { |
| | | const {selectedTables, tableFields, config} = this.state |
| | | // 判断是否已选择表名 |
| | | if (selectedTables.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请选择表名!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | // 表字段集转为map数据 |
| | | let columns = new Map() |
| | | tableFields.forEach(table => { |
| | | table.columns.forEach(column => { |
| | | columns.set(column.field, column) |
| | | }) |
| | | }) |
| | | |
| | | if (type === 'search') { |
| | | // 添加搜索条件,字段集中存在搜索条件字段,使用搜索条件对象替换字段集,设置数据类型 |
| | | config.search.forEach(item => { |
| | | if (columns.has(item.field)) { |
| | | let _datatype = columns.get(item.field).datatype |
| | | columns.set(item.field, {...item, selected: true, datatype: _datatype}) |
| | | } |
| | | }) |
| | | } else if (type === 'columns') { |
| | | // 添加显示列,字段集中存在显示列字段,使用显示列对象替换字段集,设置数据类型 |
| | | config.columns.forEach(item => { |
| | | if (columns.has(item.field)) { |
| | | let _datatype = columns.get(item.field).datatype |
| | | columns.set(item.field, {...item, selected: true, datatype: _datatype}) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // 显示字段集弹窗 |
| | | this.setState({ |
| | | addType: type, |
| | | tableVisible: true, |
| | | fields: [...columns.values()] |
| | | }) |
| | | } |
| | | |
| | | addFieldSubmit = () => { |
| | | // 字段集为空,关闭弹窗 |
| | | if (!this.state.fields || this.state.fields.length === 0) { |
| | | this.setState({ |
| | | tableVisible: false, |
| | | addType: '' |
| | | }) |
| | | } |
| | | |
| | | const {addType, config} = this.state |
| | | |
| | | // 获取已选字段集合 |
| | | let cards = this.refs.searchcard.state.selectCards |
| | | let columnsMap = new Map() |
| | | cards.forEach(card => { |
| | | columnsMap.set(card.field, card) |
| | | }) |
| | | |
| | | let items = [] |
| | | if (addType === 'search') { |
| | | config.search.forEach(item => { |
| | | if (columnsMap.has(item.field)) { |
| | | let cell = columnsMap.get(item.field) |
| | | |
| | | if (cell.selected && cell.type === item.type) { // 数据未修改 |
| | | items.push(item) |
| | | } else if (cell.selected) { // 数据类型修改 |
| | | if (cell.type === 'select') { |
| | | item.match = '=' |
| | | } else if (cell.type === 'daterange') { |
| | | item.match = 'between' |
| | | } else { |
| | | cell.type = 'text' |
| | | item.match = 'like' |
| | | } |
| | | |
| | | item.type = cell.type |
| | | item.initval = '' |
| | | items.push(item) |
| | | } |
| | | columnsMap.delete(item.field) |
| | | } else if (!item.origin) { |
| | | items.push(item) |
| | | } |
| | | }) |
| | | |
| | | let _columns = [...columnsMap.values()] |
| | | |
| | | _columns.forEach(item => { |
| | | if (item.selected) { |
| | | let _match = '' |
| | | if (item.type === 'select') { |
| | | _match = '=' |
| | | } else if (item.type === 'daterange') { |
| | | _match = 'between' |
| | | } else { |
| | | item.type = 'text' |
| | | _match = 'like' |
| | | } |
| | | |
| | | let newcard = { |
| | | uuid: Utils.getuuid(), |
| | | label: item.label, |
| | | field: item.field, |
| | | initval: '', |
| | | type: item.type, |
| | | resourceType: '0', |
| | | setAll: 'false', |
| | | options: [], |
| | | dataSource: '', |
| | | linkField: '', |
| | | valueField: '', |
| | | valueText: '', |
| | | orderBy: '', |
| | | orderType: 'asc', |
| | | match: _match, |
| | | display: 'dropdown' |
| | | } |
| | | |
| | | items.push(newcard) |
| | | } |
| | | }) |
| | | } else { |
| | | config.columns.forEach(item => { |
| | | if (columnsMap.has(item.field)) { |
| | | let cell = columnsMap.get(item.field) |
| | | |
| | | if (cell.selected) { |
| | | items.push(item) |
| | | } |
| | | columnsMap.delete(item.field) |
| | | } else if (!item.origin) { |
| | | items.push(item) |
| | | } |
| | | }) |
| | | |
| | | let _columns = [...columnsMap.values()] |
| | | |
| | | _columns.forEach(item => { |
| | | if (item.selected) { |
| | | let newcard = { |
| | | uuid: Utils.getuuid(), |
| | | Align: 'left', |
| | | label: item.label, |
| | | field: item.field, |
| | | Hide: 'false', |
| | | IsSort: item.type === 'picture' ? 'false' : 'true', |
| | | type: item.type, |
| | | Width: 120 |
| | | } |
| | | |
| | | items.push(newcard) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | this.setState({ |
| | | config: {...config, [addType]: items} |
| | | }) |
| | | |
| | | notification.success({ |
| | | top: 92, |
| | | message: '操作成功', |
| | | duration: 2 |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 添加表名 |
| | | */ |
| | | onTableChange = (value) => { |
| | | const { config } = this.props |
| | | const { tables, tableFields, selectedTables } = this.state |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 删除表名 |
| | | */ |
| | | deleteTable = (table) => { |
| | | const { config } = this.props |
| | | const {selectedTables, tableFields} = this.state |
| | |
| | | }) |
| | | |
| | | this.props.updatetable({...config, tables: _tables}, _fields) |
| | | } |
| | | |
| | | changeSetting = () => { |
| | | this.setState({ |
| | | settingVisible: true |
| | | }) |
| | | } |
| | | |
| | | render() { |