king
2023-04-27 6dd965723be9dc245105296198c25a80cfe51b54
src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -6,7 +6,6 @@
import moment from 'moment'
import Api from '@/api'
import options from '@/store/options.js'
import asyncComponent from '@/utils/asyncComponent'
import Utils, { getEditTableSql, getMark } from '@/utils/utils.js'
import MkIcon from '@/components/mk-icon'
@@ -15,7 +14,6 @@
import enUS from '@/locales/en-US/main.js'
import CusSwitch from './cusSwitch'
import Encrypts from '@/components/encrypts'
import '@/assets/css/table.scss'
import './index.scss'
const { Paragraph } = Typography
@@ -128,6 +126,9 @@
    const { col, record } = this.props
    if (id !== col.uuid + record.$$uuid) return
    if (col.ctrlField && col.ctrlValue.includes(record[col.ctrlField])) return
    this.focus()
  }
@@ -290,6 +291,11 @@
    if (!col) return (<td {...resProps} className={className} style={style}/>)
    let disabled = false
    if (col.ctrlField) {
      disabled = col.ctrlValue.includes(record[col.ctrlField])
    }
    let children = null
    if (col.type === 'text') {
      let content = ''
@@ -327,7 +333,7 @@
        }
      }
      if (col.editable === 'true') {
      if (col.editable === 'true' && !disabled) {
        if (editing) {
          if (!col.editType || col.editType === 'text') {
            return (<td className="editing_table_cell">
@@ -423,7 +429,7 @@
        }
      }
      if (col.editable === 'true') {
      if (col.editable === 'true' && !disabled) {
        if (editing) {
          return (<td className="editing_table_cell">
            <InputNumber id={col.uuid + record.$$uuid} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
@@ -508,7 +514,10 @@
        <CardCellComponent data={record} cards={config} elements={col.elements}/>
      )
    } else if (col.type === 'action') {
      style.padding = '0px 5px'
      style.padding = '0px'
      if (col.style) {
        style = {...style, ...col.style}
      }
      children = (
        <CardCellComponent data={record} cards={config} elements={col.elements}/>
      )
@@ -684,9 +693,14 @@
    let { col, config, record, style, className } = this.props
    const { err } = this.state
    let disabled = false
    if (col.ctrlField) {
      disabled = col.ctrlValue.includes(record[col.ctrlField])
    }
    let children = null
    if (col.type === 'text') {
      if (col.editable === 'true') {
      if (col.editable === 'true' && !disabled) {
        let _value = ''
        if (col.editField) {
          _value = record[col.editField] !== undefined ? record[col.editField] : ''
@@ -756,7 +770,7 @@
        children = content
      }
    } else if (col.type === 'number') {
      if (col.editable === 'true') {
      if (col.editable === 'true' && !disabled) {
        let _value = record[col.field] !== undefined ? record[col.field] : ''
        children = (<>
          <InputNumber id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress}/>
@@ -915,7 +929,7 @@
    pageIndex: 1,         // 初始页面索引
    pageSize: 10,         // 每页数据条数
    columns: null,        // 显示列
    fields: [],
    forms: [],
    pickup: false,        // 收起未选择项
    orderfields: {},      // 排序id与field转换
    loading: false,
@@ -931,47 +945,85 @@
    let _columns = []
    let deForms = []
    columns.forEach(item => {
      if (!initEditLine && item.editable === 'true') {
        initEditLine = item
      }
    let _forms = {}
      if (item.type === 'text' && item.editable === 'true' && item.editType === 'select' && item.resourceType === '1') {
        let _option = Utils.getSelectQueryOptions(item)
    let getColumns = (cols) => {
      return cols.map(item => {
        let cell = null
        if (item.type === 'colspan') {
          cell = { title: item.label, align: item.Align }
          cell.children = getColumns(item.subcols)
        } else {
          if (item.editable === 'true') {
            _forms[item.field] = item
            if (!initEditLine) {
              initEditLine = item
            }
        item.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
        item.arr_field = _option.field
            if (item.ctrlField) {
              item.ctrlValue = item.ctrlValue.split(',')
            }
          }
          if (item.type === 'text' && item.editable === 'true' && item.editType === 'select' && item.resourceType === '1') {
            let _option = Utils.getSelectQueryOptions(item)
            if (window.GLOB.debugger === true || window.debugger === true) {
              console.info(_option.sql)
            }
            item.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
            item.arr_field = _option.field
            deForms.push(item)
          }
          if (item.field) {
            orderfields[item.uuid] = item.field
          }
        deForms.push(item)
      }
      if (item.field) {
        orderfields[item.uuid] = item.field
      }
      let _item = {
        align: item.Align,
        dataIndex: item.uuid,
        title: item.label,
        sorter: item.field && item.IsSort === 'true',
        width: item.Width || 120,
        onCell: record => ({
          record,
          col: item,
          config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
        })
      }
      if (item.type !== 'action') {
        let _copy = fromJS(_item).toJS()
        _copy.sorter = false
        if (item.editable === 'true') {
          _copy.title = <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span>
          cell = {
            align: item.Align,
            dataIndex: item.uuid,
            title: item.label,
            sorter: !!(item.field && item.IsSort === 'true'),
            width: item.Width || 120,
            $type: item.type,
            onCell: record => ({
              record,
              col: item,
              config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
            })
          }
        }
        edColumns.push(_copy)
        return cell
      })
    }
    _columns = getColumns(columns)
    let forms = []
    fields.forEach(item => {
      if (item.field === setting.primaryKey) return
      if (_forms[item.field]) {
        forms.push({..._forms[item.field], datatype: item.datatype})
      } else {
        forms.push(item)
      }
      _columns.push(_item)
    })
    _columns.forEach(item => {
      if (item.$type === 'action') return
      let _copy = fromJS(item).toJS()
      _copy.sorter = false
      if (item.editable === 'true') {
        _copy.title = <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span>
      }
      edColumns.push(_copy)
    })
    if (setting.delable !== 'false' && setting.operType !== 'buoyMode') {
@@ -988,13 +1040,6 @@
      })
    }
    // if (setting.borderColor) { // 边框颜色
    //   let style = `#${setting.tableId} table, #${setting.tableId} tr, #${setting.tableId} th, #${setting.tableId} td {border-color: ${setting.borderColor}}`
    //   let ele = document.createElement('style')
    //   ele.innerHTML = style
    //   document.getElementsByTagName('head')[0].appendChild(ele)
    // }
    let size = (setting.pageSize || 10) + ''
    let pageOptions = ['10', '25', '50', '100', '500', '1000']
@@ -1004,6 +1049,7 @@
    }
    this.setState({
      forms,
      pageSize: setting.pageSize || 10,
      pageOptions,
      columns: _columns,
@@ -1030,12 +1076,6 @@
  }
  componentDidMount () {
    const { fields, setting } = this.props
    this.setState({
      fields: fields.filter(item => item.field !== setting.primaryKey),
    })
    MKEmitter.addListener('subLine', this.subLine)
    MKEmitter.addListener('nextLine', this.nextLine)
    MKEmitter.addListener('addRecord', this.addLine)
@@ -1108,11 +1148,6 @@
        localItems.push(`select '${item.uuid}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`)
      }
    })
    if (options.sysType !== 'local') {
      localItems = [...localItems, ...mainItems]
      mainItems = []
    }
    // 本地请求
    let param = {
@@ -1203,13 +1238,21 @@
      if (item.resourceType === '1' && result[item.uuid] && result[item.uuid].length > 0) {
        let options = []
        let _map = new Map()
        let all = false
        result[item.uuid].forEach(cell => {
          let _cell = {key: Utils.getuuid()}
          _cell.value = cell[item.valueField]
          _cell.label = cell[item.valueText]
          if (!_cell.label && _cell.label !== 0) return
          if (!_cell.label && _cell.label !== 0) {
            if (!all) {
              _cell.label = '全部'
              all = true
            } else {
              return
            }
          }
          if (_map.has(_cell.value)) return
          _map.set(_cell.value, 0)
@@ -1278,7 +1321,7 @@
  }
  subLine = (col, record) => {
    const { tableId, fields, edData } = this.state
    const { tableId, forms, edData } = this.state
    if (col && col.tableId !== tableId) return
@@ -1292,7 +1335,7 @@
    setTimeout(() => {
      let item = fromJS(record).toJS()
      let line = []
      fields.forEach(col => {
      forms.forEach(col => {
        if (col.editable !== 'true' || item.$deleted) {
          if (col.type === 'number') {
            item[col.field] = +item[col.field]
@@ -1349,7 +1392,7 @@
  }
  plusLine = () => {
    const { edData, fields, initEditLine } = this.state
    const { edData, forms, initEditLine } = this.state
    let item = {...edData[edData.length - 1]}
@@ -1357,7 +1400,7 @@
    item.$type = 'add'
    item.$Index = ''
    fields.forEach(col => {
    forms.forEach(col => {
      if (col.initval !== '$copy') {
        item[col.field] = col.initval
      }
@@ -1426,7 +1469,7 @@
  addLine = (id, record) => {
    const { BID } = this.props
    const { edData, fields, tableId } = this.state
    const { edData, forms, tableId } = this.state
    if (id) {
      if (id !== tableId) return
@@ -1440,7 +1483,7 @@
      item.$Index = ''
      item.$$BID = BID || ''
  
      fields.forEach(col => {
      forms.forEach(col => {
        if (col.initval !== '$copy') {
          item[col.field] = col.initval
        }
@@ -1473,7 +1516,7 @@
        item.$$BID = BID || ''
      }
  
      fields.forEach(col => {
      forms.forEach(col => {
        if (col.initval !== '$copy') {
          item[col.field] = col.initval
        }
@@ -1494,7 +1537,7 @@
  }
  checkData = () => {
    const { edData, fields } = this.state
    const { edData, forms } = this.state
    if (edData.length === 0) {
      notification.warning({
@@ -1508,7 +1551,7 @@
    let Index = 1
    let data = fromJS(edData).toJS().map(item => {
      let line = []
      fields.forEach(col => {
      forms.forEach(col => {
        if (col.editable !== 'true' || item.$deleted) {
          if (col.type === 'number') {
            item[col.field] = +item[col.field]
@@ -1573,7 +1616,7 @@
  submit = (data, type) => {
    const { submit, BID, setting } = this.props
    const { fields } = this.state
    const { forms } = this.state
    if (type !== 'simple' && (setting.commit === 'change' || setting.commit === 'simple')) {
      data = data.filter(item => !item.$origin)
@@ -1588,7 +1631,7 @@
      return
    }
    let result = getEditTableSql(submit, data, fields)
    let result = getEditTableSql(submit, data, forms)
    let param = {
      excel_in: result.lines,
@@ -1969,7 +2012,7 @@
        pageSizeOptions: pageOptions,
        showSizeChanger: true,
        total: this.props.total || 0,
        showTotal: (total, range) => `${range[0]}-${range[1]} ${this.state.dict['main.pagination.of']} ${total} ${this.state.dict['main.pagination.items']}`
        showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`
      }
    }
@@ -1988,9 +2031,9 @@
        </div> : null}
        <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}>
          {!submit.hasAction && pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">提交</Button> : null}
          <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} />
          {setting.switchable !== 'false' ? <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} /> : null}
        </div>
        <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}>
        <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} id={tableId}>
          <Table
            rowKey="$$uuid"
            components={components}