king
2024-04-22 fc8c8d714687a22f711d642d192bd4149f3b7e88
src/menu/datasource/verifycard/index.jsx
@@ -2,13 +2,13 @@
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'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import { formatSearch, joinMainSearchkey } from '@/utils/utils-custom.js'
import asyncComponent from '@/utils/asyncComponent'
import ColForm from './columnform'
import CustomScriptsForm from './customscript'
@@ -22,6 +22,7 @@
const { TabPane } = Tabs
const { Paragraph } = Typography
const { Search } = Input
const { confirm } = Modal
const CodeMirror = asyncComponent(() => import('@/templates/zshare/codemirror'))
const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
@@ -29,7 +30,8 @@
class VerifyCard extends Component {
  static propTpyes = {
    config: PropTypes.object,        // 组件配置信息
    config: PropTypes.object,
    updRecord: PropTypes.func
  }
  state = {
@@ -38,24 +40,27 @@
    subColumns: [],
    activeKey: 'setting',
    loading: false,
    colLoading: false,
    searchKey: '',
    initsql: '',          // sql验证时变量声明及赋值
    usefulfields: '',
    defaultsql: '',       // 默认Sql
    defaultSearch: '',
    systemScripts: [],
    median: {},
    visible: false,
    editLineId: '',
    pvisible: false,
    reload: false,
    script: null,
    scriptValue: '',
    cols: null,
    colColumns: [
      {
        title: '名称',
        dataIndex: 'label',
        inputType: 'input',
        editable: true,
        searchable: true,
        width: '28%'
      },
      {
@@ -64,6 +69,8 @@
        inputType: 'input',
        editable: true,
        unique: true,
        strict: true,
        searchable: true,
        copy: true,
        rules: [{
          pattern: /^[\u4E00-\u9FA50-9a-zA-Z_]*$/ig,
@@ -84,6 +91,7 @@
          { value: 'Nvarchar(512)', text: 'Nvarchar(512)' },
          { value: 'Nvarchar(1024)', text: 'Nvarchar(1024)' },
          { value: 'Nvarchar(2048)', text: 'Nvarchar(2048)' },
          { value: 'Nvarchar(4000)', text: 'Nvarchar(4000)' },
          { value: 'Nvarchar(max)', text: 'Nvarchar(max)' },
          { value: 'Int', text: 'Int' },
          { value: 'Decimal(18,0)', text: 'Decimal(18,0)' },
@@ -116,7 +124,7 @@
      {
        title: 'SQL',
        dataIndex: 'sql',
        width: '72%',
        width: '65%',
        render: (text) => {
          let title = text.match(/^\s*\/\*.+\*\//)
          title = title && title[0] ? title[0] : ''
@@ -131,9 +139,21 @@
        }
      },
      {
        title: '执行位置',
        dataIndex: 'position',
        width: '10%',
        render: (text, record) => {
          if (record.position === 'back') {
            return <span style={{color: '#1890ff'}}>后置</span>
          } else {
            return <span style={{color: '#26C281'}}>前置</span>
          }
        }
      },
      {
        title: '状态',
        dataIndex: 'status',
        width: '13%',
        width: '10%',
        render: (text, record) => record.status === 'false' ?
          (
            <div style={{color: '#ff4d4f'}}>
@@ -193,16 +213,32 @@
      })
    }
    let _search = this.formatSearch(search)
    _search = Utils.joinMainSearchkey(_search)
    _search = _search.replace(/@\$@/ig, '')
    _search = _search ? 'where ' + _search : ''
    let columns = config.columns ? fromJS(config.columns).toJS() : []
    let subColumns = config.subColumns ? fromJS(config.subColumns).toJS() : []
    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,
@@ -210,9 +246,9 @@
      subColumns: subColumns,
      setting: _setting,
      median: _setting,
      searches: search,
      defaultSearch: _search,
      searchKey: ''
      searches: formatSearch(search),
      searchKey: '',
      debugId: _setting.debugId || ''
    })
    this.getsysScript()
@@ -228,21 +264,21 @@
    let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from  s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort`
    _scriptSql = Utils.formatOptions(_scriptSql)
    _scriptSql = Utils.formatOptions(_scriptSql, 'x')
    let _sParam = {
      func: 'sPC_Get_SelectedList',
      LText: _scriptSql,
      obj_name: 'data',
      arr_field: 'funcname,longparam'
      arr_field: 'funcname,longparam',
      exec_type: 'x'
    }
    
    _sParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    _sParam.secretkey = Utils.encrypt(_sParam.LText, _sParam.timestamp)
    _sParam.secretkey = Utils.encrypt('', _sParam.timestamp)
    _sParam.open_key = Utils.encryptOpenKey(_sParam.secretkey, _sParam.timestamp) // 云端数据验证
    
    Api.getSystemConfig(_sParam).then(res => {
    Api.getCloudConfig(_sParam).then(res => {
      if (res.status) {
        let _scripts = res.data.map(item => {
          return {
@@ -357,6 +393,7 @@
    if (values.uuid) {
      scripts = scripts.map(item => {
        if (item.uuid === values.uuid) {
          values.$index = item.$index || ''
          return values
        } else {
          return item
@@ -367,7 +404,7 @@
    }
    return new Promise((resolve, reject) => {
      this.sqlverify(resolve, reject, false, scripts)
      this.sqlverify(resolve, reject, 'script', scripts)
    })
  }
@@ -408,15 +445,8 @@
          search = [...search, ...mainSearch]
        }
        let _search = this.formatSearch(search)
        _search = Utils.joinMainSearchkey(_search)
        _search = _search.replace(/@\$@/ig, '')
        _search = _search ? 'where ' + _search : ''
        this.setState({
          searches: search,
          defaultSearch: _search,
          searches: formatSearch(search),
          setting: res
        }, () => {
          this.sqlverify(() => { // 验证成功
@@ -431,7 +461,7 @@
              loading: false
            })
            this.getdefaultSql()
          }, true)
          }, 'change')
        })
      }, () => {
        this.setState({loading: false})
@@ -495,9 +525,11 @@
  }
  getdefaultSql = () => {
    const { columns, setting, defaultSearch } = this.state
    const { columns, setting, searches } = this.state
    let defaultsql = ''
    let arr_field = columns.map(col => col.field).join(',')
    let _search = joinMainSearchkey(searches)
    if (setting.dataresource) {
      let _dataresource = setting.dataresource
@@ -506,64 +538,15 @@
        _dataresource = '(' + _dataresource + ') tb'
      }
      defaultsql = `select top @pageSize@ ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${_dataresource} ${defaultSearch}) tmptable where rows > (@pageSize@ * (@pageIndex@ - 1)) order by tmptable.rows`
      defaultsql = `select top @pageSize@ ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${_dataresource} ${_search}) tmptable where rows > (@pageSize@ * (@pageIndex@ - 1)) order by tmptable.rows`
    }
    this.setState({defaultsql})
  }
  /**
   * @description 获取全部搜索条件
   * @param {Array} searches 搜索条件数组
   */
  formatSearch (searches) {
    if (!searches) return []
    let newsearches = []
    searches.forEach(search => {
      if (!search.field) return
      let item = {
        key: search.field,
        match: search.match,
        type: search.type,
        label: search.label,
        value: search.initval,
        required: search.required === 'true'
      }
      if (item.type === 'group') {
        item.key = search.datefield
        item.type = 'daterange'
        item.match = 'between'
        item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',')
        newsearches.push(item)
        return
      } else if (item.type === 'date') {
        item.value = moment().format('YYYY-MM-DD')
      } else if (item.type === 'datemonth') {
        item.value = moment().format('YYYY-MM')
      } else if (item.type === 'dateweek') {
        item.value = moment().format('YYYY-MM-DD')
      } else if (item.type === 'daterange') {
        item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',')
      } else if (item.type === 'range') {
      } else if (item.type === 'multiselect' || (item.type === 'checkcard' && search.multiple === 'true')) {
        item.type = 'multi'
        item.value = '@$@'
      } else {
        item.value = '@$@'
      }
      newsearches.push(item)
    })
    return newsearches
  }
  submitDataSource = () => {
    const { config, mainSearch } = this.props
    const { activeKey, setting, columns, subColumns, scripts } = this.state
    const { activeKey, setting, columns, subColumns, scripts, cols, median } = this.state
    if (config.subtype === 'dualdatacard') {
      let arr = columns.map(col => col.field.toLowerCase())
@@ -582,6 +565,42 @@
        })
        return Promise.reject()
      }
    } else if (config.subtype === 'editable') {
      let _arr = []
      columns.forEach(col => {
        let key = col.field.toLowerCase()
        if (['jskey', 'data_type', 'bid'].includes(key)) {
          _arr.push(col.field)
        }
      })
      if (_arr.length > 0) {
        notification.warning({
          top: 92,
          message: '字段集中不可使用' + _arr.join('、') + '!注:此字段为提交时的系统字段。',
          duration: 5
        })
        return Promise.reject()
      }
    }
    if (median.interType === 'system') {
      let _loading = false
      if (this.scriptsForm && this.scriptsForm.state.editItem) {
        _loading = true
      } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) {
        _loading = true
      }
      if (_loading) {
        notification.warning({
          top: 92,
          message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!',
          duration: 5
        })
        this.setState({activeKey: 'scripts'})
        return Promise.reject()
      }
    }
    return new Promise((resolve, reject) => {
@@ -593,18 +612,11 @@
            search = [...search, ...mainSearch]
          }
          let _search = this.formatSearch(search)
          _search = Utils.joinMainSearchkey(_search)
          _search = _search.replace(/@\$@/ig, '')
          _search = _search ? 'where ' + _search : ''
          this.setState({
            searches: search,
            defaultSearch: _search,
            searches: formatSearch(search),
            setting: res
          }, () => {
            this.sqlverify(() => { resolve({setting: res, columns, subColumns, scripts }) }, reject, false)
            this.sqlverify(() => { resolve({setting: res, columns, subColumns, scripts, cols }) }, reject, 'submit')
          })
        }, () => {
          reject()
@@ -619,7 +631,7 @@
          reject()
          return
        }
        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts }) }, reject, false)
        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit')
      } else if (activeKey === 'subcolumns') {
        if (this.subdatasource && this.subdatasource.state.editingKey) {
          notification.warning({
@@ -630,39 +642,23 @@
          reject()
          return
        }
        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts }) }, reject, false)
        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit')
      } else if (activeKey === 'scripts') {
        let _loading = false
        if (this.scriptsForm && this.scriptsForm.state.editItem) {
          _loading = true
        } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) {
          _loading = true
        }
        if (_loading) {
          notification.warning({
            top: 92,
            message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!',
            duration: 5
          })
          reject()
          return
        }
        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts }) }, reject, false)
        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit')
      }
    })
  }
  sqlverify = (resolve, reject, change = false, testScripts) => {
    const { columns, setting, scripts, searches, defaultSearch, debugId } = this.state
  sqlverify = (resolve, reject, type, testScripts) => {
    const { config } = this.props
    const { columns, setting, scripts, searches, debugId, subColumns } = this.state
    let _scripts = scripts.filter(item => item.status !== 'false')
    if (testScripts) {
      _scripts = testScripts.filter(item => item.status !== 'false')
    }
    if (!change && setting.interType === 'system' && setting.execute === 'false' && _scripts.length === 0) {
    if (type !== 'change' && setting.interType === 'system' && setting.execute === 'false' && _scripts.length === 0) {
      notification.warning({
        top: 92,
        message: '不执行默认sql时,请添加自定义脚本!',
@@ -672,16 +668,39 @@
      return
    }
    if (change && columns.length === 0) {
    if (type === 'change' && columns.length === 0) {
      reject()
      return
    }
    if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) {
      let timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      let r = SettingUtils.getDebugSql(setting, _scripts, columns, searches, defaultSearch, timestamp)
      let _columns = columns
      if (config.subtype === 'dualdatacard') {
        _columns = [...columns, ...subColumns]
      }
      let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.subtype)
      let _debugId = md5(r.sql)
      if (r.custompage && setting.laypage === 'true' && _columns.findIndex(col => col.field === 'mk_total') === -1) {
        if (config.subtype !== 'basetable') {
          Modal.warning({
            title: `数据源或自定义脚本中使用自定义分页排序时,请在字段集中添加 mk_total。`,
            okText: '知道了',
            onOk: () => {
              reject()
            }
          })
          return
        } else {
          notification.warning({
            top: 92,
            message: '数据源或自定义脚本中使用自定义分页排序时,请在显示列中添加 mk_total。',
            duration: 5
          })
        }
      }
      if (debugId === _debugId) {
        resolve()
@@ -696,50 +715,82 @@
        })
      }
      let param = {
        func: 's_debug_sql',
        exec_type: 'y',
        LText: r.sql
      }
      param.LText = Utils.formatOptions(param.LText)
      param.timestamp = timestamp
      param.secretkey = Utils.encrypt('', timestamp)
      let sumParam = null
      if (r.sumSql) {
        sumParam = {
          func: 's_debug_sql',
          exec_type: 'y',
          LText: r.sumSql
        }
        sumParam.LText = Utils.formatOptions(sumParam.LText)
        sumParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        sumParam.secretkey = Utils.encrypt('', sumParam.timestamp)
      }
      Api.genericInterface(param).then(result => {
        if (result.status) {
          if (sumParam) {
            Api.genericInterface(sumParam).then(res => {
              if (res.status) {
                this.setState({debugId: _debugId})
                resolve()
              } else {
                reject()
                Modal.error({
                  title: res.message
      Api.sDebug(r.sql).then(result => {
        if (result.status || result.ErrCode === '-2') {
          this.setState({debugId: _debugId}, () => {
            resolve()
          })
        } else {
          if (/列名\s*'[a-zA-Z0-9_-]+'\s*无效/.test(result.message)) {
            let tail = ''
            let type = ''
            if (setting.execute !== 'false' && setting.queryType !== 'statistics') {
              searches.forEach(item => {
                if (item.forbid) return
                item.key.split(',').forEach(field => {
                  if (new RegExp(`'${field}'`).test(result.message)) {
                    tail = field
                    type = '搜索条件'
                  }
                })
              })
            }
            if (!tail && setting.order) {
              let keys = setting.order.replace(/\s+(asc|desc)/ig, '').replace(/\s+/g, '')
              keys.split(',').forEach(field => {
                if (new RegExp(`'${field}'`).test(result.message)) {
                  tail = field
                  type = '排序'
                }
              })
            }
            if (!tail) {
              columns.forEach(item => {
                if (new RegExp(`'${item.field}'`).test(result.message)) {
                  tail = item.field
                  if (config.subtype === 'basetable') {
                    type = '显示列'
                  } else {
                    type = '字段集'
                  }
                }
              })
              if (!tail && config.subtype === 'dualdatacard') {
                subColumns.forEach(item => {
                  if (new RegExp(`'${item.field}'`).test(result.message)) {
                    tail = item.field
                    type = '子表字段集'
                  }
                })
              }
            }
            if (tail) {
              result.message = result.message.replace(/ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION。/, '')
              result.message = <>{result.message}<span style={{color: 'red'}}>注:{type}中存在字段{tail}</span></>
            }
          }
          if (type === 'submit') {
            Modal.confirm({
              title: result.message,
              okText: '知道了',
              cancelText: '强制保存',
              onOk: () => {
                reject()
              },
              onCancel() {
                resolve()
              }
            })
          } else {
            this.setState({debugId: _debugId})
            resolve()
            reject()
            Modal.error({
              title: result.message,
              okText: '知道了'
            })
          }
        } else {
          reject()
          Modal.error({
            title: result.message
          })
        }
      })
    } else {
@@ -760,7 +811,9 @@
      return
    }
    let editLineId = ''
    if (script) {
      editLineId = script.uuid
      _scripts = _scripts.map(item => {
        if (script.uuid === item.uuid) {
          item.sql = scriptValue
@@ -775,12 +828,13 @@
        status: 'true'
      }
      editLineId = _script.uuid
      _scripts.push(_script)
    }
    this.setState({loading: true})
    this.setState({loading: true, editLineId})
    this.sqlverify(() => {this.setState({scripts: _scripts, script: null, scriptValue: '', loading: false})}, () => {this.setState({loading: false})}, false, _scripts)
    this.sqlverify(() => {this.setState({scripts: _scripts, script: null, scriptValue: '', loading: false})}, () => {this.setState({loading: false})}, 'script', _scripts)
  }
  updatefields = (columns) => {
@@ -894,22 +948,65 @@
          this.setState({reload: false})
        })
      }
      this.props.updRecord({...res.data.setting})
    })
  }
  updateStatus = (res) => {
    this.setState({median: {...res}})
    this.props.updRecord({...res})
  }
  copyColumns = () => {
    const { columns } = this.state
    const { columns, setting } = this.state
    let m = []
    let n = []
    let s = []
    columns.forEach(col => {
      m.push(`${col.field}(${col.label})`)
      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(',')}*/
      ${n.join(',')}`
    oInput.value = `create table #${setting.tableName || 'tb'}
    (${m.join(',')},sort_id INT IDENTITY(1,1))
    insert into #${setting.tableName || 'tb'}
    (${n.join(',')})
    select ${n.join(',')}
    from ${setting.dataresource ? `(${setting.dataresource.replace(/\n/g, ' ')}) tb` : setting.tableName || 'tb'}
    order by @orderBy@
    declare @mk_total int
    set @mk_total = 0
    select @mk_total = count(1) from #${setting.tableName || 'tb'}
      declare @pageIndex_top int
      set @pageIndex_top=(@pageIndex@-1)*@pageSize@
      if @mk_total > @pageIndex@*@pageSize@
        delete #${setting.tableName || 'tb'} where sort_id > @pageIndex@*@pageSize@
      if @pageIndex_top > 0
        delete #${setting.tableName || 'tb'} where sort_id <= @pageIndex_top
    drop table #${setting.tableName || 'tb'}`
    document.body.appendChild(oInput)
    oInput.select()
    document.execCommand('Copy')
@@ -924,7 +1021,7 @@
    let n = []
    subColumns.forEach(col => {
      m.push(`${col.field}(${col.label})`)
      m.push(`${col.field} ${col.datatype}`)
      n.push(col.field)
    })
@@ -939,6 +1036,92 @@
    message.success('复制成功。')
  }
  addProcess = () => {
    const { config } = this.props
    const { columns } = this.state
    if (config.subtype === 'dualdatacard') return
    let fields = []
    let cols = []
    let _cols = columns.map(item => item.field.toLowerCase())
    if (!_cols.includes('remark_w')) {
      fields.push({ uuid: Utils.getuuid(), label: '备注', field: 'remark_w', datatype: 'Nvarchar(50)', fieldlength: 50, type: 'text' })
      cols.push({ uuid: Utils.getuuid(), Width: 120, label: '备注', field: 'remark_w', type: 'text', Hide: 'false', IsSort: 'false', fieldlength: 50 })
    }
    if (!_cols.includes('statusname_w')) {
      fields.push({ uuid: Utils.getuuid(), label: '状态', field: 'statusname_w', datatype: 'Nvarchar(50)', fieldlength: 50, type: 'text' })
      cols.push({ uuid: Utils.getuuid(), Width: 120, label: '状态', field: 'statusname_w', type: 'text', Hide: 'false', IsSort: 'false', fieldlength: 50 })
    }
    if (!_cols.includes('works_flow_param')) {
      fields.push({ uuid: Utils.getuuid(), label: '流程参数', field: 'works_flow_param', datatype: 'Nvarchar(512)', fieldlength: 512, type: 'text' })
      cols.push({ uuid: Utils.getuuid(), Width: 120, label: '流程参数', field: 'works_flow_param', type: 'text', Hide: 'true', IsSort: 'false', fieldlength: 512 })
    }
    if (fields.length === 0) return
    const that = this
    if (config.subtype !== 'basetable') {
      cols = null
    }
    confirm({
      content: cols ? '显示列中是否添加工作流字段?' : '字段集中是否添加工作流字段?',
      onOk() {
        that.setState({
          cols: cols,
          columns: [...fields, ...columns]
        })
      },
      onCancel() {}
    })
  }
  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更新
   */
@@ -950,7 +1133,7 @@
  render() {
    const { config } = this.props
    const { columns, subColumns, median, setting, scripts, colColumns, scriptsColumns, activeKey, loading, searches, defaultsql, visible, pvisible, reload, script, scriptValue, searchKey } = this.state
    const { columns, subColumns, median, setting, scripts, colColumns, scriptsColumns, activeKey, loading, searches, defaultsql, visible, pvisible, reload, script, scriptValue, searchKey, editLineId } = this.state
    return (
      <div className="model-data-source-wrap">
@@ -968,11 +1151,13 @@
              subColumns={subColumns}
              setting={setting}
              scripts={scripts}
              updateStatus={(res) => this.setState({median: {...res}})}
              updateStatus={this.updateStatus}
              updateColumns={this.updateColumns}
              addProcess={this.addProcess}
              wrappedComponentRef={(inst) => this.settingForm = inst}
            /> : null}
          </TabPane>
          {config.subtype !== 'basetable' ? <TabPane tab={
          {!['basetable', 'invoice', 'invTable'].includes(config.subtype) ? <TabPane tab={
            <span>
              字段集
              {columns.length ? <span className="count-tip">{columns.length}</span> : null}
@@ -985,7 +1170,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>
              子表字段集
@@ -1004,8 +1197,8 @@
            <span>
              自定义脚本
              {scripts.length ? <span className="count-tip">{scripts.length}</span> : null}
              {config.type !== 'interface' && activeKey === 'setting' ? <CopyOutlined title="复制数据源" className="mk-copy-datasource" onClick={(e) => {e.stopPropagation();this.copyDatasource()}}/> : null}
              {config.type !== 'interface' && activeKey === 'setting' ? <SnippetsOutlined title="导入数据源" className="mk-paste-datasource" onClick={(e) => {e.stopPropagation();this.setState({pvisible: true})}}/> : null}
              {activeKey === 'setting' ? <CopyOutlined title="复制数据源" className="mk-copy-datasource" onClick={(e) => {e.stopPropagation();this.copyDatasource()}}/> : null}
              {activeKey === 'setting' ? <SnippetsOutlined title="导入数据源" className="mk-paste-datasource" onClick={(e) => {e.stopPropagation();this.setState({pvisible: true})}}/> : null}
              {activeKey === 'columns' ? <CopyOutlined title="以逗号拼接形式复制字段" className="mk-copy-fields" onClick={(e) => {e.stopPropagation();this.copyColumns()}}/> : null}
              {activeKey === 'subcolumns' ? <CopyOutlined title="以逗号拼接形式复制字段" className="mk-copy-fields" onClick={(e) => {e.stopPropagation();this.copySubColumns()}}/> : null}
              {activeKey === 'subcolumns' || activeKey === 'columns' ? <span onClick={(e) => {e.stopPropagation()}}><Search className="mk-search-fields" defaultValue={searchKey} allowClear onSearch={(val, e) => {e.stopPropagation();this.setState({searchKey: val})}} /></span> : null}
@@ -1020,9 +1213,10 @@
                })
                return
              }
              this.setState({visible: true, script: null, scriptValue: ''})
              this.setState({visible: true, script: null, scriptValue: '', editLineId: ''})
            }}/> : null}
            <CustomScriptsForm
              type={config.type}
              setting={setting}
              searches={searches}
              defaultsql={defaultsql}
@@ -1031,6 +1225,7 @@
              systemScripts={this.state.systemScripts}
              scriptsChange={this.scriptsChange}
              scriptSubmit={this.scriptSubmit}
              addProcess={this.addProcess}
              wrappedComponentRef={(inst) => this.scriptsForm = inst}
            />
            <EditTable actions={['move']} data={scripts} columns={scriptsColumns} onChange={this.changeScripts}/>
@@ -1068,8 +1263,14 @@
                  </div>
                )
              } else {
                let sign = ''
                if (script && script.uuid === item.uuid) {
                  sign = 'active'
                } else if (editLineId === item.uuid) {
                  sign = 'edited'
                }
                return (
                  <div className={'script-item ' + (script && script.uuid === item.uuid ? 'active' : '') } key={item.uuid}>
                  <div className={'script-item ' + sign} key={item.uuid}>
                    <div style={{cursor: 'pointer'}} onClick={() => {
                      this.setState({script: item, scriptValue: item.sql})
                    }}>