king
2023-10-03 6196360e5821d8bc13f38bae137f850cff033851
src/menu/datasource/verifycard/index.jsx
@@ -2,7 +2,7 @@
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, Tabs, Popconfirm, notification, Modal, Typography, Spin, message, Button, Input } from 'antd'
import { StopOutlined, CheckCircleOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined, SnippetsOutlined } from '@ant-design/icons'
import { StopOutlined, CheckCircleOutlined, TableOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined, SnippetsOutlined } from '@ant-design/icons'
import moment from 'moment'
import md5 from 'md5'
@@ -40,6 +40,7 @@
    subColumns: [],
    activeKey: 'setting',
    loading: false,
    colLoading: false,
    searchKey: '',
    initsql: '',          // sql验证时变量声明及赋值
    usefulfields: '',
@@ -214,6 +215,27 @@
    columns.reverse()
    subColumns.reverse()
    columns.forEach(col => {
      if (!col.datatype) return
      if (/^nvarchar/.test(col.datatype)) {
        col.datatype = col.datatype.replace(/^nvarchar/, 'Nvarchar')
      } else if (/^decimal/.test(col.datatype)) {
        col.datatype = col.datatype.replace(/^decimal/, 'Decimal')
      } else if (/^int/.test(col.datatype)) {
        col.datatype = col.datatype.replace(/^int/, 'Int')
      }
    })
    subColumns.forEach(col => {
      if (!col.datatype) return
      if (/^nvarchar/.test(col.datatype)) {
        col.datatype = col.datatype.replace(/^nvarchar/, 'Nvarchar')
      } else if (/^decimal/.test(col.datatype)) {
        col.datatype = col.datatype.replace(/^decimal/, 'Decimal')
      } else if (/^int/.test(col.datatype)) {
        col.datatype = col.datatype.replace(/^int/, 'Int')
      }
    })
    this.setState({
      scripts,
@@ -504,7 +526,6 @@
    let arr_field = columns.map(col => col.field).join(',')
    let _search = joinMainSearchkey(searches)
    _search = _search ? 'where ' + _search : ''
    if (setting.dataresource) {
      let _dataresource = setting.dataresource
@@ -607,7 +628,7 @@
  sqlverify = (resolve, reject, type, testScripts) => {
    const { config } = this.props
    const { columns, setting, scripts, searches, debugId } = this.state
    const { columns, setting, scripts, searches, debugId, subColumns } = this.state
    let _scripts = scripts.filter(item => item.status !== 'false')
@@ -630,7 +651,11 @@
    }
    if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) {
      let r = SettingUtils.getDebugSql(setting, _scripts, columns, searches, config.type)
      let _columns = columns
      if (config.subtype === 'dualdatacard') {
        _columns = [...columns, ...subColumns]
      }
      let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.type)
      let _debugId = md5(r.sql)
@@ -840,11 +865,25 @@
    const { columns } = this.state
    let m = []
    let n = []
    let s = []
    columns.forEach(col => {
      m.push(`${col.field} ${col.datatype}`)
      n.push(col.field)
      m.unshift(`${col.field} ${col.datatype}`)
      n.unshift(col.field)
      if (/decimal|int/ig.test(col.datatype)) {
        s.unshift(`${Math.round(Math.random() * 10)} as ${col.field}`)
      } else if (/datetime/.test(col.datatype)) {
        s.unshift(`'${moment().format('YYYY-MM-DD HH:mm:ss')}' as ${col.field}`)
      } else if (/date/.test(col.datatype)) {
        s.unshift(`'${moment().format('YYYY-MM-DD')}' as ${col.field}`)
      } else {
        s.unshift(`'${col.label}' as ${col.field}`)
      }
    })
    if (window.debugger) {
      console.info('select ' + s.join(', '))
    }
    let oInput = document.createElement('input')
    oInput.value = `/*${m.join(',')}*/
@@ -921,6 +960,49 @@
    })
  }
  updateColumns = (tableName) => {
    const { config } = this.props
    const { colLoading, columns } = this.state
    if (colLoading || columns.length > 0) return
    if (config.subtype === 'basetable') return
    let param = {func: 'sPC_Get_FieldName', TBName: tableName}
    if (window.GLOB.cloudServiceApi) { // 且存在云端地址
      param.rduri = window.GLOB.cloudServiceApi
      param.userid = sessionStorage.getItem('CloudUserID') || ''
      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
    }
    this.setState({colLoading: true})
    Api.getSystemCacheConfig(param).then(result => {
      this.setState({colLoading: false})
      if (!result.status) return
      let fields = []
      result.FDName.forEach(item => {
        if (item.f_type !== 0) return
        if (/nvarchar|int|decimal/ig.test(item.FieldType) || item.FieldType === 'date' || item.FieldType === 'datetime') {
          fields.unshift({
            uuid: Utils.getuuid(),
            label: item.FieldDec,
            field: item.FieldName,
            datatype: item.FieldType.toLowerCase()
          })
        }
      })
      if (fields.length === 0) return
      this.setState({columns: fields})
    }, () => {
      this.setState({colLoading: false})
    })
  }
  /**
   * @description 组件销毁,清除state更新
   */
@@ -951,6 +1033,7 @@
              setting={setting}
              scripts={scripts}
              updateStatus={this.updateStatus}
              updateColumns={this.updateColumns}
              addProcess={this.addProcess}
              wrappedComponentRef={(inst) => this.settingForm = inst}
            /> : null}
@@ -968,7 +1051,15 @@
              updatefield={this.updatefields}
            />
            <EditTable actions={['edit', 'move', 'copy', 'del', 'clear']} searchKey={searchKey} type="datasourcefield" wrappedComponentRef={(inst) => this.datasource = inst} data={columns} columns={colColumns} onChange={(columns) => this.setState({columns})}/>
          </TabPane> : null}
          </TabPane> : <TabPane tab={
            <span>
              字段集<TableOutlined style={{marginLeft: '5px', fontSize: '12px'}} />
              {columns.length ? <span className="count-tip">{columns.length}</span> : null}
            </span>
          } key="columns">
            <div className="base-table-columns"></div>
            <EditTable actions={[]} searchKey={searchKey} type="datasourcefield" data={columns} columns={colColumns}/>
          </TabPane>}
          {config.subtype === 'dualdatacard' ? <TabPane tab={
            <span>
              子表字段集