| | |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, Empty, notification } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | | import EditCard from './editcard' |
| | | |
| | |
| | | |
| | | class FieldsComponent extends Component { |
| | | static propTpyes = { |
| | | type: PropTypes.string, // 搜索条件添加、显示列添加 |
| | | config: PropTypes.object, // 容器Id |
| | | type: PropTypes.string, |
| | | config: PropTypes.object, |
| | | updatefield: PropTypes.func |
| | | } |
| | | |
| | |
| | | selectCards: [] |
| | | } |
| | | |
| | | queryField = () => { |
| | | const { type, config } = this.props |
| | | // 判断是否已选择表名 |
| | | if (!window.GLOB.tableFields || window.GLOB.tableFields.length === 0) { |
| | | checkField = () => { |
| | | if (!window.GLOB.publicTables || window.GLOB.publicTables.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请选择表名!', |
| | |
| | | return |
| | | } |
| | | |
| | | window.GLOB.tableFields = window.GLOB.tableFields || [] |
| | | |
| | | let index = 0 |
| | | |
| | | let deffers = window.GLOB.publicTables.map(item => { |
| | | let tb = window.GLOB.tableFields.filter(tab => tab.tableName === item.TbName)[0] |
| | | |
| | | if (tb) { |
| | | return Promise.resolve(fromJS(tb).toJS()) |
| | | } |
| | | |
| | | return new Promise(resolve => { |
| | | setTimeout(() => { |
| | | Api.getCloudConfig({func: 'sPC_Get_FieldName', TBName: item.TbName}).then(res => { |
| | | let tabmsg = { |
| | | status: res.status, |
| | | message: res.message, |
| | | tableName: item.TbName, |
| | | columns: [] |
| | | } |
| | | |
| | | if (res.FDName && res.FDName.length > 0) { |
| | | tabmsg.columns = res.FDName.map(item => { |
| | | let _type = item.FieldType.toLowerCase() |
| | | let _datatype = item.FieldType.toLowerCase() |
| | | let _decimal = 0 |
| | | let _length = 50 |
| | | if (/^nvarchar/.test(_type)) { |
| | | try { // 存在max |
| | | _length = +_type.match(/\d+/)[0] || 50 |
| | | } catch (e) { |
| | | _length = 4000 |
| | | } |
| | | _type = 'text' |
| | | } else if (/^int/.test(_type)) { |
| | | _type = 'number' |
| | | } else if (/^decimal/.test(_type)) { |
| | | _decimal = _type.split(',')[1] |
| | | _decimal = parseInt(_decimal) |
| | | _type = 'number' |
| | | } else if (/^datetime/.test(_type)) { |
| | | _type = 'datetime' |
| | | } else if (/^date/.test(_type)) { |
| | | _type = 'date' |
| | | } else { |
| | | _type = 'text' |
| | | } |
| | | |
| | | if (/^nvarchar/.test(_datatype)) { |
| | | _datatype = _datatype.replace(/^nvarchar/, 'Nvarchar') |
| | | } else if (/^decimal/.test(_datatype)) { |
| | | _datatype = _datatype.replace(/^decimal/, 'Decimal') |
| | | } else if (/^int/.test(_datatype)) { |
| | | _datatype = _datatype.replace(/^int/, 'Int') |
| | | } |
| | | |
| | | return { |
| | | field: item.FieldName || '', |
| | | label: item.FieldDec, |
| | | type: _type, |
| | | datatype: _type, |
| | | decimal: _decimal, |
| | | length: _length, |
| | | $datatype: _datatype |
| | | } |
| | | }) |
| | | } |
| | | |
| | | resolve(tabmsg) |
| | | }) |
| | | }, index * 50) |
| | | |
| | | index++ |
| | | }) |
| | | }) |
| | | Promise.all(deffers).then(response => { |
| | | let error = false |
| | | let _columns = response |
| | | |
| | | response.forEach(item => { |
| | | if (!item.status) { |
| | | error = item.message || '字段查询失败!' |
| | | } |
| | | }) |
| | | |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: error, |
| | | duration: 5 |
| | | }) |
| | | } else { |
| | | window.GLOB.tableFields = _columns |
| | | this.queryField(_columns) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | queryField = (tableFields) => { |
| | | const { type, config } = this.props |
| | | |
| | | // 表字段集转为map数据 |
| | | let columns = new Map() |
| | | window.GLOB.tableFields.forEach(table => { |
| | | tableFields.forEach(table => { |
| | | table.columns.forEach(column => { |
| | | columns.set(column.field.toLowerCase(), column) |
| | | }) |
| | |
| | | selectCards.forEach(item => { |
| | | let _match = '' |
| | | let initval = '' |
| | | if (item.type === 'select') { |
| | | let _type = item.type |
| | | if (item.type === 'date') { |
| | | _type = 'daterange' |
| | | } else if (item.type === 'select') { |
| | | _match = '=' |
| | | } else { |
| | | item.type = 'text' |
| | | _type = 'text' |
| | | _match = 'like' |
| | | } |
| | | |
| | |
| | | label: item.label, |
| | | field: item.field, |
| | | initval: initval, |
| | | type: item.type, |
| | | type: _type, |
| | | resourceType: '0', |
| | | options: [], |
| | | orderType: 'asc', |
| | |
| | | field: item.field, |
| | | Hide: 'false', |
| | | IsSort: 'true', |
| | | type: item.type, |
| | | type: item.type === 'number' ? 'number' : 'text', |
| | | Width: item.type === 'number' ? 80 : 120 |
| | | } |
| | | |
| | |
| | | newcard.decimal = item.decimal |
| | | } else { |
| | | newcard.fieldlength = item.length || 50 |
| | | } |
| | | |
| | | if (item.type === 'date') { |
| | | newcard.textFormat = 'YYYY-MM-DD' |
| | | } else if (item.type === 'datetime') { |
| | | newcard.textFormat = 'YYYY-MM-DD HH:mm:ss' |
| | | } |
| | | |
| | | items.push(newcard) |
| | |
| | | field: item.field, |
| | | datatype: _t |
| | | } |
| | | |
| | | items.unshift(newcard) |
| | | keys.push(item.field.toLowerCase()) |
| | | }) |
| | |
| | | required: 'true' |
| | | } |
| | | |
| | | if (item.type === 'text' && item.length >= 256) { |
| | | if (/^icon|images?$/ig.test(item.field)) { |
| | | newcard.type = 'fileupload' |
| | | newcard.fileType = 'picture-card' |
| | | newcard.fieldlength = item.length || 512 |
| | | newcard.maxSize = 1 |
| | | newcard.maxfile = 1 |
| | | } else if (item.type === 'text' && item.length >= 256) { |
| | | newcard.type = 'textarea' |
| | | newcard.required = 'false' |
| | | newcard.fieldlength = item.length |
| | |
| | | newcard.span = 24 |
| | | newcard.labelwidth = 16.2 |
| | | } |
| | | } else if (item.type === 'text') { |
| | | newcard.fieldlength = item.length || 50 |
| | | } |
| | | |
| | | items.push(newcard) |
| | |
| | | |
| | | return ( |
| | | <div className="quickly-add"> |
| | | <Button type="primary" block onClick={this.queryField}>{label}</Button> |
| | | <Button type="primary" block onClick={this.checkField}>{label}</Button> |
| | | {/* 根据字段名添加显示列及搜索条件 */} |
| | | <Modal |
| | | wrapClassName="model-table-fieldmanage-modal" |