king
2022-04-26 5046d0d13dc6a8563b8e54e31913bc44cfa1072f
src/templates/zshare/editTable/index.jsx
@@ -3,7 +3,7 @@
import { is, fromJS } from 'immutable'
import { DndProvider, DragSource, DropTarget } from 'react-dnd'
import { Table, Input, InputNumber, Popconfirm, Form, Select, Radio, Cascader, notification, message, Modal, Typography } from 'antd'
import { CopyOutlined, EditOutlined, DeleteOutlined, SnippetsOutlined } from '@ant-design/icons'
import { CopyOutlined, EditOutlined, DeleteOutlined, SnippetsOutlined, SwapOutlined } from '@ant-design/icons'
import Utils from '@/utils/utils.js'
import ColorSketch from '@/mob/colorsketch'
@@ -12,6 +12,7 @@
import CusSwitch from './cusSwitch'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const MkEditIcon = asyncComponent(() => import('@/components/mkIcon'))
@@ -110,10 +111,12 @@
      )
    } else if (inputType === 'radio') {
      return (
        <Radio.Group>
        <Radio.Group style={{whiteSpace: 'nowrap'}}>
          {options.map((item, i) => (<Radio key={i} value={item.field || item.value}> {item.label || item.text} </Radio>))}
        </Radio.Group>
      )
    } else if (inputType === 'textarea') {
      return <Input.TextArea autoSize={true} placeholder=""/>
    } else {
      return <Input onPressEnter={() => this.getValue(form)}/>
    }
@@ -131,7 +134,7 @@
  renderCell = (form) => {
    const { getFieldDecorator } = form
    const { editing, dataIndex, title, record, children, className, required, inputType } = this.props
    const { editing, dataIndex, title, record, children, className, required, inputType, rules } = this.props
    return (
      <td className={className}>
@@ -142,7 +145,8 @@
                {
                  required: required,
                  message: ['number', 'text', 'input'].includes(inputType) ? `${eTDict['form.required.input']} ${title}!` : `${eTDict['form.required.select']} ${title}!`,
                }
                },
                ...rules
              ],
              initialValue: inputType === 'multiStr' ? (record[dataIndex] ? record[dataIndex].split(',') : []) : record[dataIndex],
            })(this.getInput(form))}
@@ -171,6 +175,7 @@
    data: [],
    editingKey: '',
    visible: false,
    editLineId: '',
    columns: []
  }
@@ -217,6 +222,7 @@
            <div className={'edit-operation-btn' + (editingKey !== '' ? ' disabled' : '')} style={{minWidth: '110px', whiteSpace: 'nowrap'}}>
              {actions.includes('edit') ? <span className="primary" onClick={() => {editingKey === '' && this.edit(record.uuid)}}><EditOutlined /></span> : null}
              {actions.includes('copy') ? <span className="copy" onClick={() => {editingKey === '' && this.copy(record)}}><CopyOutlined /></span> : null}
              {actions.includes('status') ? <span className="status" onClick={() => {editingKey === '' && this.handleStatus(record)}}><SwapOutlined /></span> : null}
              {actions.includes('del') && editingKey === '' ? <Popconfirm
                overlayClassName="popover-confirm"
                title={eTDict['model.query.delete']}
@@ -270,6 +276,21 @@
    }
  }
  componentDidMount () {
    MKEmitter.addListener('editLineId', this.getEditLineId)
  }
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('editLineId', this.getEditLineId)
  }
  getEditLineId = (id) => {
    this.setState({ editLineId: id })
  }
  isEditing = record => record.uuid === this.state.editingKey
  cancel = () => {
@@ -311,6 +332,11 @@
    }
    try {
      let srcid = localStorage.getItem(window.location.href.split('#')[0] + 'srcId')
      if (srcid) {
        msg.$srcId = srcid
      }
      msg = window.btoa(window.encodeURIComponent(JSON.stringify(msg)))
    } catch (e) {
      console.warn('Stringify Failure')
@@ -390,6 +416,22 @@
        })
      }
      message.success('粘贴成功。')
    })
  }
  handleStatus = (record) => {
    const { data } = this.state
    record.status = record.status === 'false' ? 'true' : 'false'
    let newData = data.map(item => {
      if (record.uuid === item.uuid) return record
      return item
    })
    this.setState({ data: newData }, () => {
      this.props.onChange(newData)
    })
  }
@@ -508,6 +550,7 @@
  render() {
    const { actions, indexShow } = this.props
    const { editLineId } = this.state
    let components = {
      body: {
@@ -534,6 +577,7 @@
          inputType: col.inputType,
          dataIndex: col.dataIndex,
          options: col.options || [],
          rules: col.rules || [],
          min: col.min || 0,
          max: col.max || 500,
          unlimit: col.unlimit,
@@ -570,7 +614,7 @@
              components={components}
              dataSource={data}
              columns={columns}
              rowClassName="editable-row"
              rowClassName={record => !editLineId || editLineId !== record.uuid ? 'editable-row' : 'editable-row active'}
              pagination={false}
              onRow={(record, index) => ({
                index,