king
2022-08-26 665b7b5866f726030ec0335834c2ba80060c86e8
src/templates/sharecomponent/tablecomponent/index.jsx
@@ -1,13 +1,13 @@
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'
import { queryTableSql } from '@/utils/option.js'
import './index.scss'
@@ -22,12 +22,9 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    tables: [],          // 系统表
    tableFields: [],    // 已选表字段集
    tableFields: [],     // 已选表字段集
    selectedTables: [],  // 已选表
    searchlist: null,    // 搜索条件集
    visible: false       // 模态框控制
  }
  /**
@@ -59,11 +56,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 +84,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)
        })
@@ -100,7 +110,7 @@
              if (/^nvarchar/.test(_type)) {
                try { // 存在max
                  _length = +_type.match(/\d+/)[0] || 50
                } catch {
                } catch (e) {
                  _length = 2048
                }
                _type = 'text'
@@ -119,12 +129,13 @@
              }
  
              return {
                field: item.FieldName,
                field: item.FieldName || '',
                label: item.FieldDec,
                type: _type,
                datatype: _type,
                decimal: _decimal,
                length: _length,
                $datatype: item.FieldType.toLowerCase()
              }
            })
          }
@@ -141,8 +152,7 @@
      this.setState({
        tableFields: _columns
      })
      this.props.updatetable(this.props.config, _columns)
      window.GLOB.tableFields = _columns
    })
  }
@@ -170,8 +180,13 @@
              let _type = item.FieldType.toLowerCase()
              let _decimal = 0
              let _length = 50
              if (/^nvarchar/.test(_type)) {
                _length = +_type.match(/\d+/)[0] || 50
                try { // 存在max
                  _length = +_type.match(/\d+/)[0] || 50
                } catch (e) {
                  _length = 2048
                }
                _type = 'text'
              } else if (/^int/.test(_type)) {
                _type = 'number'
@@ -193,15 +208,21 @@
                type: _type,
                datatype: _type,
                decimal: _decimal,
                length: _length
                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,
@@ -228,7 +249,9 @@
      tableFields: _fields
    })
    this.props.updatetable({...config, tables: _tables}, _fields)
    window.GLOB.tableFields = _fields
    this.props.updatetable({...config, tables: _tables})
  }
  /**
@@ -242,16 +265,16 @@
  render() {
    const { containerId } = this.props
    const { dict, tables, selectedTables } = this.state
    const { tables, selectedTables } = this.state
    return (
      <div className="model-table-tablemanage-view">
      <div className="model-tablename-manage-view">
        {/* 表名添加 */}
        <div className="ant-col ant-form-item-label">
          <label>
            <Tooltip placement="topLeft" title={dict['model.tooltip.table.guide']}>
              <Icon type="question-circle" />
              {dict['header.menu.table.add']}
            <Tooltip placement="topLeft" title="此处可以添加页面配置相关的常用表,可通过工具栏中的添加按钮,可批量添加表格相关字段。">
              <QuestionCircleOutlined className="mk-form-tip" />
              表名
            </Tooltip>
          </label>
        </div>
@@ -260,17 +283,18 @@
          className="tables"
          style={{ width: '100%' }}
          optionFilterProp="children"
          value={dict['header.menu.table.placeholder']}
          onChange={this.onTableChange}
          value="请选择表名"
          onSelect={this.onTableChange}
          dropdownClassName="mk-tables"
          showArrow={false}
          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
            return option.props.children[0].toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
              option.props.children[2].toLowerCase().indexOf(input.toLowerCase()) >= 0
          }}
        > 
          {tables.map((table, index) => (
            <Option key={index} title={table.TbName} value={table.TbName}>{table.Remark}</Option>
            <Option key={index} title={table.TbName} value={table.TbName}>{table.Remark}<br/>{table.TbName}</Option>
          ))}
        </Select>
        {selectedTables.length > 0 && <List
@@ -279,8 +303,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)}/>
            <div className="bottom-mask"></div>
            <CloseOutlined onClick={() => this.deleteTable(item)}/>
          </List.Item>}
        />}
      </div>