| | |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | | import options from '@/store/options.js' |
| | | import Utils from '@/utils/utils.js' |
| | | import SettingForm from './settingform' |
| | | import { queryTableSql } from '@/utils/option.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | |
| | | class ReplaceField extends Component { |
| | |
| | | func: 'sPC_Get_SelectedList', |
| | | LText: queryTableSql, |
| | | obj_name: 'data', |
| | | arr_field: 'TbName,Remark' |
| | | arr_field: 'TbName,Remark', |
| | | exec_type: 'x' |
| | | } |
| | | |
| | | param.LText = Utils.formatOptions(param.LText) |
| | | param.LText = Utils.formatOptions(param.LText, 'x') |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.secretkey = Utils.encrypt('', param.timestamp) |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 云端数据验证 |
| | | |
| | | if (options.cloudServiceApi) { // 且存在云端地址 |
| | | param.rduri = options.cloudServiceApi |
| | | if (window.GLOB.cloudServiceApi) { // 且存在云端地址 |
| | | param.rduri = window.GLOB.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } |
| | |
| | | |
| | | if (res.resource === 'custom') { |
| | | if (res.reType === 'name') { |
| | | let map = {[res.label.toLowerCase()]: { |
| | | FieldDec: res.label, |
| | | FieldName: res.field, |
| | | let map = {[res.field.toLowerCase()]: { |
| | | FieldDec: res.field, |
| | | FieldName: res.label, |
| | | datatype: '' |
| | | }} |
| | | |
| | |
| | | } |
| | | } else { |
| | | let param = {func: 'sPC_Get_FieldName', TBName: res.table} |
| | | if (options.cloudServiceApi) { // 且存在云端地址 |
| | | param.rduri = options.cloudServiceApi |
| | | if (window.GLOB.cloudServiceApi) { // 且存在云端地址 |
| | | param.rduri = window.GLOB.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } |
| | |
| | | if (item.cols) { |
| | | let _update = (cols) => { |
| | | return cols.map(col => { |
| | | if (col.type === 'action' && col.elements) { |
| | | if (col.type === 'custom' && col.elements) { |
| | | col.elements = col.elements.map(m => { |
| | | if (m.modal && m.modal.fields) { |
| | | m.modal.fields = m.modal.fields.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | | col.field = map[col.field.toLowerCase()].FieldName |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | if (m.verify && m.verify.columns) { |
| | | m.verify.columns = m.verify.columns.map(col => { |
| | | if (col.Column && map[col.Column.toLowerCase()]) { |
| | | col.Column = map[col.Column.toLowerCase()].FieldName |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | if (m.config && m.config.components) { |
| | | m.config.components = _replace(m.config.components) |
| | | } |
| | | |
| | | return m |
| | | }) |
| | | } else if (col.type === 'custom' && col.elements) { |
| | | col.elements = col.elements.map(m => { |
| | | if (m.datatype === 'dynamic' && map[m.field.toLowerCase()]) { |
| | | m.field = map[m.field.toLowerCase()].FieldName |
| | | if (m.eleType === 'button') { |
| | | if (m.modal && m.modal.fields) { |
| | | m.modal.fields = m.modal.fields.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | | col.field = map[col.field.toLowerCase()].FieldName |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | if (m.verify && m.verify.columns) { |
| | | m.verify.columns = m.verify.columns.map(col => { |
| | | if (col.Column && map[col.Column.toLowerCase()]) { |
| | | col.Column = map[col.Column.toLowerCase()].FieldName |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | if (m.config && m.config.components) { |
| | | m.config.components = _replace(m.config.components) |
| | | } |
| | | } else { |
| | | if (m.datatype === 'dynamic' && map[m.field.toLowerCase()]) { |
| | | m.field = map[m.field.toLowerCase()].FieldName |
| | | } |
| | | } |
| | | |
| | | return m |
| | |
| | | } |
| | | |
| | | config.components = _replace(config.components) |
| | | } else if (type === 'table') { |
| | | config.columns = config.columns.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | | col.field = map[col.field.toLowerCase()].FieldName |
| | | } |
| | | return col |
| | | }) |
| | | // } else if (type === 'table') { |
| | | // config.columns = config.columns.map(col => { |
| | | // if (col.field && map[col.field.toLowerCase()]) { |
| | | // col.field = map[col.field.toLowerCase()].FieldName |
| | | // } |
| | | // return col |
| | | // }) |
| | | |
| | | config.search = config.search.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | | col.field = map[col.field.toLowerCase()].FieldName |
| | | } |
| | | if (col.datefield && map[col.datefield.toLowerCase()]) { |
| | | col.datefield = map[col.datefield.toLowerCase()].FieldName |
| | | } |
| | | return col |
| | | }) |
| | | // config.search = config.search.map(col => { |
| | | // if (col.field && map[col.field.toLowerCase()]) { |
| | | // col.field = map[col.field.toLowerCase()].FieldName |
| | | // } |
| | | // if (col.datefield && map[col.datefield.toLowerCase()]) { |
| | | // col.datefield = map[col.datefield.toLowerCase()].FieldName |
| | | // } |
| | | // return col |
| | | // }) |
| | | |
| | | config.action = config.action.map(m => { |
| | | if (m.verify && m.verify.columns) { |
| | | m.verify.columns = m.verify.columns.map(col => { |
| | | if (col.Column && map[col.Column.toLowerCase()]) { |
| | | col.Column = map[col.Column.toLowerCase()].FieldName |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | return m |
| | | }) |
| | | // config.action = config.action.map(m => { |
| | | // if (m.verify && m.verify.columns) { |
| | | // m.verify.columns = m.verify.columns.map(col => { |
| | | // if (col.Column && map[col.Column.toLowerCase()]) { |
| | | // col.Column = map[col.Column.toLowerCase()].FieldName |
| | | // } |
| | | // return col |
| | | // }) |
| | | // } |
| | | // return m |
| | | // }) |
| | | } else if (type === 'form') { |
| | | config.fields = config.fields.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | |
| | | duration: 3 |
| | | }) |
| | | this.props.updateConfig(config) |
| | | |
| | | setTimeout(() => { |
| | | MKEmitter.emit('revert') |
| | | }, 300) |
| | | } |
| | | |
| | | // 依据字段替换名称 |
| | |
| | | if (item.cols) { |
| | | let _update = (cols) => { |
| | | return cols.map(col => { |
| | | if (col.type === 'action' && col.elements) { |
| | | if (col.type === 'custom' && col.elements) { |
| | | col.elements = col.elements.map(m => { |
| | | if (m.modal && m.modal.fields) { |
| | | m.modal.fields = m.modal.fields.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | | col.label = map[col.field.toLowerCase()].FieldDec |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | if (m.verify && m.verify.columns) { |
| | | m.verify.columns = m.verify.columns.map(col => { |
| | | if (col.Column && map[col.Column.toLowerCase()]) { |
| | | col.Text = map[col.Column.toLowerCase()].FieldDec |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | if (m.config && m.config.components) { |
| | | m.config.components = _replace(m.config.components) |
| | | if (m.eleType === 'button') { |
| | | if (m.modal && m.modal.fields) { |
| | | m.modal.fields = m.modal.fields.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | | col.label = map[col.field.toLowerCase()].FieldDec |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | if (m.verify && m.verify.columns) { |
| | | m.verify.columns = m.verify.columns.map(col => { |
| | | if (col.Column && map[col.Column.toLowerCase()]) { |
| | | col.Text = map[col.Column.toLowerCase()].FieldDec |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | if (m.config && m.config.components) { |
| | | m.config.components = _replace(m.config.components) |
| | | } |
| | | } |
| | | |
| | | return m |
| | |
| | | } |
| | | |
| | | config.components = _replace(config.components) |
| | | } else if (type === 'table') { |
| | | config.columns = config.columns.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | | col.label = map[col.field.toLowerCase()].FieldDec |
| | | } |
| | | return col |
| | | }) |
| | | // } else if (type === 'table') { |
| | | // config.columns = config.columns.map(col => { |
| | | // if (col.field && map[col.field.toLowerCase()]) { |
| | | // col.label = map[col.field.toLowerCase()].FieldDec |
| | | // } |
| | | // return col |
| | | // }) |
| | | |
| | | config.search = config.search.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | | col.label = map[col.field.toLowerCase()].FieldDec |
| | | } |
| | | return col |
| | | }) |
| | | // config.search = config.search.map(col => { |
| | | // if (col.field && map[col.field.toLowerCase()]) { |
| | | // col.label = map[col.field.toLowerCase()].FieldDec |
| | | // } |
| | | // return col |
| | | // }) |
| | | |
| | | config.action = config.action.map(m => { |
| | | if (m.verify && m.verify.columns) { |
| | | m.verify.columns = m.verify.columns.map(col => { |
| | | if (col.Column && map[col.Column.toLowerCase()]) { |
| | | col.Text = map[col.Column.toLowerCase()].FieldDec |
| | | } |
| | | return col |
| | | }) |
| | | } |
| | | return m |
| | | }) |
| | | // config.action = config.action.map(m => { |
| | | // if (m.verify && m.verify.columns) { |
| | | // m.verify.columns = m.verify.columns.map(col => { |
| | | // if (col.Column && map[col.Column.toLowerCase()]) { |
| | | // col.Text = map[col.Column.toLowerCase()].FieldDec |
| | | // } |
| | | // return col |
| | | // }) |
| | | // } |
| | | // return m |
| | | // }) |
| | | } else if (type === 'form') { |
| | | config.fields = config.fields.map(col => { |
| | | if (col.field && map[col.field.toLowerCase()]) { |
| | |
| | | duration: 3 |
| | | }) |
| | | this.props.updateConfig(config) |
| | | setTimeout(() => { |
| | | MKEmitter.emit('revert') |
| | | }, 500) |
| | | } |
| | | |
| | | render() { |
| | | const { visible, loadingTable, tables, confirming } = this.state |
| | | |
| | | return ( |
| | | <div className="mk-replace-field" style={{display: 'inline-block'}}> |
| | | <> |
| | | <Button className="mk-border-yellow" icon="swap" loading={loadingTable} onClick={this.trigger}>字段替换</Button> |
| | | <Modal |
| | | title="字段替换" |
| | |
| | | > |
| | | <SettingForm tables={tables} wrappedComponentRef={(inst) => this.settingRef = inst}/> |
| | | </Modal> |
| | | </div> |
| | | </> |
| | | ) |
| | | } |
| | | } |