| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { fromJS } from 'immutable' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, Empty, notification } from 'antd' |
| | | |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | |
| | | import './index.scss' |
| | | |
| | | // **悲观者往往正确,乐观者往往成功 |
| | | class FieldsComponent extends Component { |
| | | static propTpyes = { |
| | | type: PropTypes.string, // 搜索条件添加、显示列添加 |
| | |
| | | } |
| | | |
| | | state = { |
| | | dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS, |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | fields: [], // 字段集 |
| | | tableVisible: false, // 模态框控制 |
| | | } |
| | |
| | | queryField = () => { |
| | | const { type, config, tableFields } = this.props |
| | | // 判断是否已选择表名 |
| | | if (!config.tables || config.tables.length === 0) { |
| | | if (!tableFields || tableFields.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请选择表名!', |
| | |
| | | }) |
| | | } 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}) |
| | | } |
| | | }) |
| | | } else if (type === 'fields') { |
| | | config.columns.forEach(item => { |
| | | if (columns.has(item.field)) { |
| | | let _datatype = columns.get(item.field).datatype |
| | |
| | | resourceType: '0', |
| | | setAll: 'false', |
| | | options: [], |
| | | dataSource: '', |
| | | linkField: '', |
| | | valueField: '', |
| | | valueText: '', |
| | | orderBy: '', |
| | | orderType: 'asc', |
| | | match: _match, |
| | | display: 'dropdown' |
| | |
| | | Width: 120 |
| | | } |
| | | |
| | | if (item.type === 'number') { |
| | | newcard.decimal = item.decimal |
| | | } else { |
| | | newcard.fieldlength = item.length || 50 |
| | | } |
| | | |
| | | items.push(newcard) |
| | | } |
| | | }) |
| | | } else if (type === 'fields') { |
| | | 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 { |
| | | items.push(item) |
| | | } |
| | | }) |
| | | |
| | | let _columns = [...columnsMap.values()] |
| | | |
| | | _columns.forEach(item => { |
| | | if (item.selected) { |
| | | let newcard = { |
| | | uuid: Utils.getuuid(), |
| | | label: item.label, |
| | | field: item.field, |
| | | datatype: item.type === 'number' ? 'Decimal(18,0)' : 'Nvarchar(50)' |
| | | } |
| | | |
| | | items.push(newcard) |
| | | } |
| | | }) |
| | |
| | | |
| | | if (type === 'search') { |
| | | _config = {...this.props.config, search: items} |
| | | |
| | | this.props.updatefield(_config) |
| | | |
| | | notification.success({ |
| | | top: 92, |
| | | message: '操作成功', |
| | | duration: 2 |
| | | }) |
| | | } else if (type === 'columns') { |
| | | _config = {...this.props.config, columns: items} |
| | | } |
| | | |
| | | if (_config) { |
| | | this.props.updatefield(_config) |
| | | |
| | | notification.success({ |
| | | top: 92, |
| | | message: '操作成功', |
| | | duration: 2 |
| | | }) |
| | | } else if (type === 'fields') { |
| | | this.props.updatefield(items) |
| | | |
| | | notification.success({ |
| | | top: 92, |
| | |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | /** |
| | | * @description 组件销毁,清除state更新 |
| | | */ |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { type } = this.props |
| | | const { dict, fields } = this.state |
| | | |
| | | let label = '' |
| | | if (type === 'search') { |
| | | label = dict['header.menu.search.add'] |
| | | } else if (type === 'columns') { |
| | | label = dict['header.menu.column.add'] |
| | | } |
| | | |
| | | return ( |
| | | <div> |
| | | <Button type="primary" block onClick={this.queryField}>{label}</Button> |
| | | <div className="quickly-add"> |
| | | <Button type="primary" block onClick={this.queryField}>{dict['model.batchAdd']}</Button> |
| | | {/* 根据字段名添加显示列及搜索条件 */} |
| | | <Modal |
| | | wrapClassName="model-table-fieldmanage-modal" |
| | |
| | | width={'65vw'} |
| | | maskClosable={false} |
| | | style={{minWidth: '900px', maxWidth: '1200px'}} |
| | | cancelText={dict['header.close']} |
| | | cancelText={dict['model.close']} |
| | | onOk={this.addFieldSubmit} |
| | | onCancel={() => { // 取消添加 |
| | | this.setState({ |