king
2022-11-21 f6626b05f1275cc2f8ca77f773d4f6a6af1b0a89
src/menu/components/table/base-table/index.jsx
@@ -6,6 +6,7 @@
import asyncComponent from '@/utils/asyncComponent'
import asyncIconComponent from '@/utils/asyncIconComponent'
import { getTables } from '@/utils/utils-custom.js'
import MKEmitter from '@/utils/events.js'
import getWrapForm from './options'
import Utils from '@/utils/utils.js'
@@ -38,6 +39,7 @@
      let _card = {
        uuid: card.uuid,
        type: card.type,
        name: card.name || '',
        format: 'array',    // 组件属性 - 数据格式
        pageable: true,     // 组件属性 - 是否可分页
        switchable: true,   // 组件属性 - 数据是否可切换
@@ -53,8 +55,8 @@
        subtype: card.subtype,
        setting: { interType: 'system' },
        wrap: { bordered: 'true', tableType: 'checkbox', show: 'true' },
        style: { marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' },
        headerStyle: { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' },
        style: {},
        headerStyle: {},
        columns: [],
        cols: [
          { origin: true, uuid: Utils.getuuid(), Align: 'left', label: 'label1', field: '', Hide: 'false', type: 'text', Width: 120 },
@@ -63,6 +65,10 @@
        ],
        scripts: [],
        isNew: true
      }
      if (card.name === '主表') {
        _card.setting.supModule = ['empty']
      }
      this.updateComponent(_card)
@@ -76,7 +82,6 @@
  }
  componentDidMount () {
    MKEmitter.addListener('submitModal', this.handleSave)
    MKEmitter.addListener('completeSave', this.completeSave)
  }
@@ -91,7 +96,6 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('submitModal', this.handleSave)
    MKEmitter.removeListener('completeSave', this.completeSave)
  }
@@ -105,7 +109,6 @@
      item.cols = item.cols.filter(a => !a.origin)
      delete item.isNew
      this.setState({card: item}, () => { MKEmitter.emit('revert') })
    }
  }
@@ -148,6 +151,10 @@
        card.errors.push({ level: 0, detail: '主键已失效!'})
      } else if (!card.setting.supModule) {
        card.errors.push({ level: 0, detail: '未设置上级组件!'})
      }
      if (card.errors.length === 0) {
        card.$tables = getTables(card)
      }
      card.action.forEach(cell => {
@@ -257,26 +264,6 @@
    }
  }
  handleSave = (_cards, btn, modal) => {
    let card = fromJS(this.state.card).toJS()
    if (card.uuid !== _cards.uuid) return
    let _index = card.action.findIndex(cell => cell.uuid === btn.uuid)
    if (_index === -1) return
    card.action = card.action.map(cell => {
      if (cell.uuid === btn.uuid) {
        cell.modal = modal
      }
      return cell
    })
    this.updateComponent(card)
  }
  getWrapForms = () => {
    const { wrap, action, columns, cols } = this.state.card
@@ -307,6 +294,64 @@
    this.updateComponent({...card, wrap: res})
  }
  updatecolumn = (config) => {
    config.columns = []
    config.absFields = []
    config.cols.forEach(col => {
      if (!col.field) return
      if (['text', 'picture', 'video', 'textarea'].includes(col.type)) {
        config.columns.push({
          datatype: `Nvarchar(${col.fieldlength || 50})`,
          field: col.field,
          fieldlength: col.fieldlength || 50,
          label: col.label,
          type: 'text',
          uuid: col.uuid
        })
      } else if (col.type === 'link') {
        config.columns.push({
          datatype: `Nvarchar(${col.fieldlength || 50})`,
          field: col.field,
          fieldlength: col.fieldlength || 50,
          label: col.label,
          type: 'text',
          uuid: col.uuid
        })
        if (col.nameField) {
          config.columns.push({
            datatype: `Nvarchar(${col.fieldlength || 50})`,
            field: col.nameField,
            fieldlength: col.fieldlength || 50,
            label: col.label + '(名称)',
            type: 'text',
            uuid: col.uuid + 'name'
          })
        }
      } else if (col.type === 'number') {
        config.columns.push({
          datatype: `Decimal(18,${col.decimal || 0})`,
          field: col.field,
          decimal: col.decimal || 0,
          label: col.label,
          type: 'number',
          uuid: col.uuid
        })
        if (col.format === 'abs') {
          config.absFields.push(col.field)
        }
      }
    })
    if (config.absFields.length) {
      config.absFields = Array.from(new Set(config.absFields))
    } else {
      config.absFields = null
    }
    this.updateComponent(config)
  }
  render() {
    const { card } = this.state
    let options = ['action', 'search', 'form', 'cols']
@@ -318,7 +363,7 @@
            <NormalForm title="表格设置" width={800} update={this.updateWrap} getForms={this.getWrapForms}>
              <EditOutlined style={{color: '#1890ff'}} title="编辑"/>
            </NormalForm>
            <CopyComponent type="normaltable" card={card}/>
            <CopyComponent type="basetable" card={card}/>
            <PasteComponent config={card} options={options} updateConfig={this.updateComponent} />
            <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/>
            <SettingComponent config={card} updateConfig={this.updateComponent} />
@@ -328,7 +373,7 @@
        </Popover>
        <SearchComponent config={card} updatesearch={this.updateComponent}/>
        <ActionComponent config={card} setSubConfig={this.setSubConfig} updateaction={this.updateComponent}/>
        <ColumnComponent config={card} updatecolumn={this.updateComponent}/>
        <ColumnComponent config={card} updatecolumn={this.updatecolumn}/>
      </div>
    )
  }