king
2022-10-22 03a22ec6f9ad7303d10b4c65bb5bc6fa5cbd448a
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,7 +55,7 @@
        subtype: card.subtype,
        setting: { interType: 'system' },
        wrap: { bordered: 'true', tableType: 'checkbox', show: 'true' },
        style: { marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' },
        style: {},
        headerStyle: { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' },
        columns: [],
        cols: [
@@ -105,7 +107,6 @@
      item.cols = item.cols.filter(a => !a.origin)
      delete item.isNew
      this.setState({card: item}, () => { MKEmitter.emit('revert') })
    }
  }
@@ -148,6 +149,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 => {
@@ -307,6 +312,64 @@
    this.updateComponent({...card, wrap: res})
  }
  updatecolumn = (config) => {
    config.columns = []
    config.absFields = []
    config.cols.forEach(col => {
      if (!col.field) return
      if (['text', 'picture', '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']
@@ -328,7 +391,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>
    )
  }