king
2023-08-25 49d445742b2915742656a292faebf576fef30bdd
2023-08-25
3个文件已修改
273 ■■■■■ 已修改文件
src/menu/components/chart/antv-bar/chartcompile/formconfig.jsx 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/templates/sharecomponent/fieldscomponent/index.jsx 107 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/templates/sharecomponent/tablecomponent/index.jsx 164 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/menu/components/chart/antv-bar/chartcompile/formconfig.jsx
@@ -41,8 +41,6 @@
    }
  }
  console.log(card)
  return [
    {
      type: 'text',
src/templates/sharecomponent/fieldscomponent/index.jsx
@@ -3,6 +3,7 @@
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'
@@ -11,8 +12,8 @@
class FieldsComponent extends Component {
  static propTpyes = {
    type: PropTypes.string,          // 搜索条件添加、显示列添加
    config: PropTypes.object,        // 容器Id
    type: PropTypes.string,
    config: PropTypes.object,
    updatefield: PropTypes.func
  }
@@ -23,10 +24,8 @@
    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: '请选择表名!',
@@ -35,9 +34,101 @@
      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 _decimal = 0
                let _length = 50
                if (/^nvarchar/.test(_type)) {
                  try { // 存在max
                    _length = +_type.match(/\d+/)[0] || 50
                  } catch (e) {
                    _length = 2048
                  }
                  _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'
                }
                return {
                  field: item.FieldName || '',
                  label: item.FieldDec,
                  type: _type,
                  datatype: _type,
                  decimal: _decimal,
                  length: _length,
                  $datatype: item.FieldType.toLowerCase()
                }
              })
            }
            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)
      })
@@ -281,7 +372,7 @@
    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"
src/templates/sharecomponent/tablecomponent/index.jsx
@@ -23,7 +23,6 @@
  state = {
    tables: [],          // 系统表
    tableFields: [],     // 已选表字段集
    selectedTables: [],  // 已选表
  }
@@ -39,8 +38,6 @@
    this.setState({
      selectedTables: tables
    }, () => {
      this.gettableFields()
    })
  }
@@ -96,163 +93,28 @@
    })
  }
  gettableFields = () => {
    let deffers = this.state.selectedTables.map((item, i) => {
      return new Promise(resolve => {
        let param = {func: 'sPC_Get_FieldName', TBName: item.TbName}
        if (window.GLOB.cloudServiceApi) { // 且存在云端地址
          param.rduri = window.GLOB.cloudServiceApi
          param.userid = sessionStorage.getItem('CloudUserID') || ''
          param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
        }
        setTimeout(() => {
          Api.getSystemCacheConfig(param).then(res => {
            res.TBName = item.TbName
            resolve(res)
          })
        }, (i + 1) * 100)
      })
    })
    Promise.all(deffers).then(response => {
      let _columns = []
      response.forEach(res => {
        if (res.status) {
          let tabmsg = {
            tableName: res.TBName,
            columns: res.FDName.map(item => {
              let _type = item.FieldType.toLowerCase()
              let _decimal = 0
              let _length = 50
              if (/^nvarchar/.test(_type)) {
                try { // 存在max
                  _length = +_type.match(/\d+/)[0] || 50
                } catch (e) {
                  _length = 2048
                }
                _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'
              }
              return {
                field: item.FieldName || '',
                label: item.FieldDec,
                type: _type,
                datatype: _type,
                decimal: _decimal,
                length: _length,
                $datatype: item.FieldType.toLowerCase()
              }
            })
          }
          _columns.push(tabmsg)
        } else {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          })
        }
      })
      this.setState({
        tableFields: _columns
      })
      window.GLOB.tableFields = _columns
    })
  }
  /**
   * @description 添加表名
   */
  onTableChange = (value) => {
    const { config } = this.props
    const { tables, tableFields, selectedTables } = this.state
    const { tables, selectedTables } = this.state
    let _table = tables.filter(item => item.TbName === value)[0]
    let isSelected = !!selectedTables.filter(cell => cell.TbName === value)[0]
    if (!isSelected) {
      let _tables = [...selectedTables, _table]
      window.GLOB.publicTables = _tables
    if (selectedTables.findIndex(cell => cell.TbName === value) > -1) return
      this.setState({
        selectedTables: _tables
      })
    let _tables = [...selectedTables, _table]
      let _config = {...config, tables: _tables}
      Api.getCloudConfig({func: 'sPC_Get_FieldName', TBName: value}).then(res => {
        if (res.status) {
          let tabmsg = {
            tableName: _table.TbName,
            columns: res.FDName.map(item => {
              let _type = item.FieldType.toLowerCase()
              let _decimal = 0
              let _length = 50
    window.GLOB.publicTables = _tables
              if (/^nvarchar/.test(_type)) {
                try { // 存在max
                  _length = +_type.match(/\d+/)[0] || 50
                } catch (e) {
                  _length = 2048
                }
                _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'
              }
    this.setState({
      selectedTables: _tables
    })
              return {
                field: item.FieldName,
                label: item.FieldDec,
                type: _type,
                datatype: _type,
                decimal: _decimal,
                length: _length,
                $datatype: item.FieldType.toLowerCase()
              }
            })
          }
          let _columns = [...tableFields, tabmsg]
          this.setState({
            tableFields: _columns
          })
          window.GLOB.tableFields = _columns
          this.props.updatetable(_config)
        } else {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          })
        }
      })
    }
    let _config = {...config, tables: _tables}
    this.props.updatetable(_config)
  }
  /**
@@ -260,19 +122,15 @@
   */
  deleteTable = (table) => {
    const { config } = this.props
    const { selectedTables, tableFields } = this.state
    const { selectedTables } = this.state
    let _tables = selectedTables.filter(item => item.TbName !== table.TbName)
    let _fields = tableFields.filter(item => item.tableName !== table.TbName)
    window.GLOB.publicTables = _tables
    this.setState({
      selectedTables: _tables,
      tableFields: _fields
    })
    window.GLOB.tableFields = _fields
    this.props.updatetable({...config, tables: _tables})
  }