king
2021-11-12 0c84df247914f893ef5e41d57a422e10a2dc814c
src/templates/sharecomponent/tablecomponent/index.jsx
@@ -1,10 +1,12 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Icon, Tooltip, Select, List, notification } from 'antd'
import { Tooltip, Select, List, notification } from 'antd'
import { QuestionCircleOutlined, CloseOutlined } from '@ant-design/icons'
import moment from 'moment'
import Api from '@/api'
import options from '@/store/options.js'
import Utils from '@/utils/utils.js'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
@@ -14,7 +16,6 @@
const { Option } = Select
// **悲观者往往正确,乐观者往往成功
class TablesComponent extends Component {
  static propTpyes = {
    config: PropTypes.object,        // 容器Id
@@ -23,12 +24,10 @@
  }
  state = {
    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    tables: [],          // 系统表
    tableFields: [],    // 已选表字段集
    tableFields: [],     // 已选表字段集
    selectedTables: [],  // 已选表
    searchlist: null,    // 搜索条件集
    visible: false       // 模态框控制
  }
  /**
@@ -60,10 +59,17 @@
    }
    param.LText = Utils.formatOptions(param.LText)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 云端数据验证
    Api.getSystemConfig(param).then(res => {
    if (options.cloudServiceApi) { // 且存在云端地址
      param.rduri = options.cloudServiceApi
      param.userid = sessionStorage.getItem('CloudUserID') || ''
      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
    }
    Api.getSystemCacheConfig(param).then(res => {
      if (res.status) {
        this.setState({
          tables: res.data
@@ -81,7 +87,14 @@
  gettableFields = () => {
    let deffers = this.state.selectedTables.map(item => {
      return new Promise(resolve => {
        Api.getSystemConfig({func: 'sPC_Get_FieldName', TBName: item.TbName}).then(res => {
        let param = {func: 'sPC_Get_FieldName', TBName: item.TbName}
        if (options.cloudServiceApi) { // 且存在云端地址
          param.rduri = options.cloudServiceApi
          param.userid = sessionStorage.getItem('CloudUserID') || ''
          param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
        }
        Api.getSystemCacheConfig(param).then(res => {
          res.TBName = item.TbName
          resolve(res)
        })
@@ -96,23 +109,19 @@
            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)
                if (_decimal > 4) {
                  _decimal = 4
                }
                _type = 'number'
              } else if (/^decimal/.test(_type)) {
                _decimal = _type.split(',')[1]
                _decimal = parseInt(_decimal)
                if (_decimal > 4) {
                  _decimal = 4
                }
                _type = 'number'
              } else if (/^datetime/.test(_type)) {
                _type = 'datetime'
@@ -123,11 +132,13 @@
              }
  
              return {
                field: item.FieldName,
                field: item.FieldName || '',
                label: item.FieldDec,
                type: _type,
                datatype: _type,
                decimal: _decimal
                decimal: _decimal,
                length: _length,
                $datatype: item.FieldType.toLowerCase()
              }
            })
          }
@@ -144,8 +155,7 @@
      this.setState({
        tableFields: _columns
      })
      this.props.updatetable(this.props.config, _columns)
      window.GLOB.tableFields = _columns
    })
  }
@@ -164,15 +174,22 @@
      })
      let _config = {...config, tables: [...selectedTables, _table]}
      Api.getSystemConfig({func: 'sPC_Get_FieldName', TBName: value}).then(res => {
        if (res.status) {
          let tabmsg = {
            tableName: _table.name,
            tableName: _table.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'
@@ -193,15 +210,22 @@
                label: item.FieldDec,
                type: _type,
                datatype: _type,
                decimal: _decimal
                decimal: _decimal,
                length: _length,
                $datatype: item.FieldType.toLowerCase()
              }
            })
          }
          let _columns = [...tableFields, tabmsg]
          this.setState({
            tableFields: [...tableFields, tabmsg]
            tableFields: _columns
          })
          this.props.updatetable(_config, [...tableFields, tabmsg])
          window.GLOB.tableFields = _columns
          this.props.updatetable(_config)
        } else {
          notification.warning({
            top: 92,
@@ -218,7 +242,7 @@
   */
  deleteTable = (table) => {
    const { config } = this.props
    const {selectedTables, tableFields} = this.state
    const { selectedTables, tableFields } = this.state
    let _tables = selectedTables.filter(item => item.TbName !== table.TbName)
    let _fields = tableFields.filter(item => item.tableName !== table.TbName)
@@ -228,7 +252,9 @@
      tableFields: _fields
    })
    this.props.updatetable({...config, tables: _tables}, _fields)
    window.GLOB.tableFields = _fields
    this.props.updatetable({...config, tables: _tables})
  }
  /**
@@ -250,7 +276,7 @@
        <div className="ant-col ant-form-item-label">
          <label>
            <Tooltip placement="topLeft" title={dict['model.tooltip.table.guide']}>
              <Icon type="question-circle" />
              <QuestionCircleOutlined className="mk-form-tip" />
              {dict['header.menu.table.add']}
            </Tooltip>
          </label>
@@ -263,7 +289,7 @@
          value={dict['header.menu.table.placeholder']}
          onChange={this.onTableChange}
          showArrow={false}
          getPopupContainer={() => document.getElementById(containerId)}
          getPopupContainer={() => containerId ? document.getElementById(containerId) : document.body}
          filterOption={(input, option) => {
            return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
              option.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
@@ -279,7 +305,7 @@
          dataSource={selectedTables}
          renderItem={(item, index) => <List.Item key={index} title={item.Remark + ' (' + item.TbName + ')'}>
            {item.Remark + ' (' + item.TbName + ')'}
            <Icon type="close" onClick={() => this.deleteTable(item)}/>
            <CloseOutlined onClick={() => this.deleteTable(item)}/>
            <div className="bottom-mask"></div>
          </List.Item>}
        />}