king
2023-06-14 08cce3334a2dc81d690b518136b0aaea64e48b0b
src/templates/comtableconfig/updatetable/index.jsx
@@ -3,12 +3,14 @@
import { is, fromJS } from 'immutable'
import { Modal, Button, notification } from 'antd'
import { ArrowUpOutlined } from '@ant-design/icons'
// import moment from 'moment'
import moment from 'moment'
import md5 from 'md5'
import { colorTransform } from '@/utils/option.js'
// import Api from '@/api'
import { getTables } from '@/utils/utils-custom.js'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import './index.scss'
// import './index.scss'
const { confirm } = Modal
@@ -18,6 +20,8 @@
  }
  state = {}
  delButtons = []
  baseMsg = {}
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
@@ -49,72 +53,785 @@
  }
  execUpdate = (_resolve) => {
    const { config } = this.props
    const config = fromJS(this.props.config).toJS()
    this.delButtons = []
    this.baseMsg = {
      fstMenuId: config.fstMenuId,
      parentId: config.ParentId,
      MenuName: config.MenuName,
      MenuNo: config.MenuNo,
    }
    let _config = {
      version: 1.0,
      uuid: config.uuid,
      MenuID: config.uuid,
      fstMenuId: config.fstMenuId,
      parentId: config.ParentId,
      Template: 'BaseTable',
      easyCode: config.easyCode,
      enabled: false,
      MenuName: config.MenuName,
      MenuNo: config.MenuNo,
      OpenType: 'newtab',
      tables: config.tables || [],
      urlFields: config.urlFields || [],
      hidden: config.hidden,
      hidden: config.hidden || 'false',
      autoMatic: {},
      Remark: config.Remark,
      Remark: config.Remark || '',
      components: [],
      viewType: 'menu',
      style: { backgroundColor: '#ffffff', paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'},
    }
    let uuids = {}
    let formActions = []
    let popActions = []
    let errors = []
    let formTabs = []
    let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false', isMain: true}
    let tbl = this.getTable(config, uuids, errors, formActions, popActions, '主表')
    let oldtabs = {
      mainTable: mainTb.uuid
    }
    if (config.autoMatic && config.autoMatic.enable === 'true' && uuids[config.autoMatic.action]) {
      _config.autoMatic = {...config.autoMatic}
      _config.autoMatic.action = uuids[config.autoMatic.action]
    let tbl = this.getTable(config, mainTb, errors, formActions, formTabs, popActions, oldtabs)
    if (config.autoMatic && config.autoMatic.enable === 'true') {
      if (tbl.action.filter(item => item.uuid === config.autoMatic.action && (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print'))).length === 0) {
        _config.autoMatic = {enable: 'false'}
      } else {
        _config.autoMatic = {...config.autoMatic}
      }
    } else {
      _config.autoMatic = {enable: 'false'}
    }
    _config.components.push(tbl)
    let _tbs = []
    if (config.tabgroups && config.tabgroups.length > 0) {
      config.tabgroups.forEach(m => {
        if (!m.sublist || m.sublist.length === 0) return
        let tabs = {
          uuid: Utils.getuuid(),
          type: 'tabs',
          subtype: 'tabletabs',
          setting: {},
          style: {},
          subtabs: m.sublist.map(n => {
            let tab = { uuid: Utils.getuuid(), label: n.label, icon: n.icon, permission: 'false', components: [
              {
                uuid: Utils.getuuid(),
                linkTab: n.linkTab,
                name: n.label,
                useMSearch: n.searchPass === 'true' ? 'true' : 'false',
                supModule: n.supMenu || '',
                equalTab: n.equalTab && n.equalTab.length > 0 ? n.equalTab[0] : ''
              }
            ]}
            this.delButtons.push(n.linkTab)
            oldtabs[n.uuid] = tab.components[0].uuid
            _tbs.push(tab.components[0])
            return tab
          })
        }
        _config.components.push(tabs)
      })
    }
    console.log(config)
    console.log(_config)
    if (_tbs.length > 0) {
      let defers = _tbs.map((item, i) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            Api.getSystemConfig({
              func: 'sPC_Get_LongParam',
              MenuID: item.linkTab
            }).then(res => {
              if (res.status) {
                let _LongParam = ''
                if (res.LongParam) {
                  try {
                    _LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
                  } catch (e) {
                    console.warn('Parse Failure')
                    _LongParam = ''
                  }
                }
                if (_LongParam) {
                  _LongParam.uuid = item.linkTab
                  resolve(_LongParam)
                } else {
                  resolve({uuid: item.linkTab, $empty: true})
                }
              } else {
                notification.warning({
                  top: 92,
                  message: res.message,
                  duration: 5
                })
                resolve({uuid: item.linkTab, $empty: true})
              }
            })
          }, i * 50)
        })
      })
      Promise.all(defers).then(res => {
        let menus = {}
        res.forEach(item => {
          if (item && !item.$empty) {
            menus[item.uuid] = item
          }
        })
    setTimeout(() => {
      _resolve()
    }, 5000)
        _config.components = _config.components.map(item => {
          if (item.type === 'tabs') {
            item.subtabs = item.subtabs.map(tab => {
              tab.components[0] = this.getTable(menus[tab.components[0].linkTab], tab.components[0], errors, formActions, formTabs, popActions, oldtabs)
              return tab
            })
          }
          return item
        })
        this.setPopView(_resolve, _config, formActions, formTabs, popActions, errors)
      })
    } else {
      this.setPopView(_resolve, _config, formActions, formTabs, popActions, errors)
    }
  }
  getTable = (config, uuids, errors, formActions, popActions, name) => {
  setPopView = (_resolve, _config, formActions, formTabs, popActions, errors) => {
    if (popActions.length > 0) {
      let defers = popActions.map((item, i) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            Api.getSystemConfig({
              func: 'sPC_Get_LongParam',
              MenuID: item.linkTab
            }).then(res => {
              if (res.status) {
                let _LongParam = ''
                if (res.LongParam) {
                  try {
                    _LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
                  } catch (e) {
                    console.warn('Parse Failure')
                    _LongParam = ''
                  }
                }
                if (_LongParam) {
                  _LongParam.uuid = item.uuid
                  resolve(_LongParam)
                } else {
                  resolve({uuid: item.uuid, $empty: true})
                }
              } else {
                notification.warning({
                  top: 92,
                  message: res.message,
                  duration: 5
                })
                resolve({uuid: item.uuid, $empty: true})
              }
            })
          }, i * 50)
        })
      })
      Promise.all(defers).then(res => {
        let menus = {}
        res.forEach(item => {
          if (item && !item.$empty) {
            menus[item.uuid] = item
          }
        })
        _config.components.forEach(item => {
          if (item.type === 'tabs') {
            item.subtabs.forEach(tab => {
              tab.components[0].action.forEach(btn => {
                if (btn.OpenType === 'popview') {
                  if (menus[btn.uuid]) {
                    let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
                    btn.config = {
                      uuid: btn.uuid,
                      MenuID: btn.uuid,
                      ParentId: tab.components[0].uuid,
                      MenuName: btn.label,
                      tables: _config.tables || [],
                      Template: 'BaseTable',
                      components: [this.getTable(menus[btn.uuid], mainTb, errors, formActions, formTabs)],
                      viewType: 'popview',
                      style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
                    }
                    btn.config.enabled = this.setEnabled(btn.config)
                  } else {
                    errors.push(tab.label + '中按钮《' + btn.label + '》配置信息丢失')
                  }
                }
              })
              tab.components[0].cols.forEach(col => {
                if (col.type !== 'custom') return
                col.elements.forEach(btn => {
                  if (btn.eleType !== 'button') return
                  if (btn.OpenType === 'popview') {
                    if (menus[btn.uuid]) {
                      let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
                      btn.config = {
                        uuid: btn.uuid,
                        MenuID: btn.uuid,
                        ParentId: tab.components[0].uuid,
                        MenuName: btn.label,
                        tables: _config.tables || [],
                        Template: 'BaseTable',
                        components: [this.getTable(menus[btn.uuid], mainTb, errors, formActions, formTabs)],
                        viewType: 'popview',
                        style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
                      }
                      btn.config.enabled = this.setEnabled(btn.config)
                    } else {
                      errors.push(tab.label + '中按钮《' + btn.label + '》配置信息丢失')
                    }
                  }
                })
              })
            })
          } else {
            item.action.forEach(btn => {
              if (btn.OpenType === 'popview') {
                if (menus[btn.uuid]) {
                  let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
                  btn.config = {
                    uuid: btn.uuid,
                    MenuID: btn.uuid,
                    ParentId: item.uuid,
                    MenuName: btn.label,
                    tables: _config.tables || [],
                    Template: 'BaseTable',
                    components: [this.getTable(menus[btn.uuid], mainTb, errors, formActions, formTabs)],
                    viewType: 'popview',
                    style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
                  }
                  btn.config.enabled = this.setEnabled(btn.config)
                } else {
                  errors.push('主表中按钮《' + btn.label + '》配置信息丢失')
                }
              }
            })
            item.cols.forEach(col => {
              if (col.type !== 'custom') return
              col.elements.forEach(btn => {
                if (btn.eleType !== 'button') return
                if (btn.OpenType === 'popview') {
                  if (menus[btn.uuid]) {
                    let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false'}
                    btn.config = {
                      uuid: btn.uuid,
                      MenuID: btn.uuid,
                      ParentId: item.uuid,
                      MenuName: btn.label,
                      tables: _config.tables || [],
                      Template: 'BaseTable',
                      components: [this.getTable(menus[btn.uuid], mainTb, errors, formActions, formTabs)],
                      viewType: 'popview',
                      style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
                    }
                    btn.config.enabled = this.setEnabled(btn.config)
                  } else {
                    errors.push('主表中按钮《' + btn.label + '》配置信息丢失')
                  }
                }
              })
            })
          }
        })
        this.setPopForm(_resolve, _config, formActions, formTabs, errors)
      })
    } else {
      this.setPopForm(_resolve, _config, formActions, formTabs, errors)
    }
  }
  setEnabled = (config) => {
    let enabled = true
    config.components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          if (tab.components[0].errors.length > 0) {
            enabled = false
          }
        })
      } else {
        if (item.errors.length > 0) {
          enabled = false
        }
      }
    })
    return enabled
  }
  setPopForm = (_resolve, _config, formActions, formTabs, errors) => {
    if (formActions.length > 0) {
      let defers = formActions.map((item, i) => {
        return new Promise((resolve) => {
          setTimeout(() => {
            Api.getSystemConfig({
              func: 'sPC_Get_LongParam',
              MenuID: item.origin
            }).then(res => {
              if (res.status) {
                let _LongParam = ''
                if (res.LongParam) {
                  try {
                    _LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
                  } catch (e) {
                    console.warn('Parse Failure')
                    _LongParam = ''
                  }
                }
                if (_LongParam) {
                  _LongParam.uuid = item.uuid
                  resolve(_LongParam)
                } else {
                  resolve({uuid: item.uuid, $empty: true})
                }
              } else {
                notification.warning({
                  top: 92,
                  message: res.message,
                  duration: 5
                })
                resolve({uuid: item.uuid, $empty: true})
              }
            })
          }, i * 50)
        })
      })
      Promise.all(defers).then(res => {
        let menus = {}
        res.forEach(item => {
          if (item && !item.$empty) {
            menus[item.uuid] = item
          }
        })
        _config.components.forEach(item => {
          if (item.type === 'tabs') {
            item.subtabs.forEach(tab => {
              tab.components[0].action.forEach(btn => {
                if (btn.OpenType === 'popview' && btn.config && btn.config.components[0]) {
                  this.setTbForm(btn.config.components[0], menus, errors, tab.components[0].name + '-' + btn.label)
                } else if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
                  if (menus[btn.uuid]) {
                    btn.modal = {
                      setting: menus[btn.uuid].setting,
                      tables: [],
                      groups: [],
                      fields: menus[btn.uuid].fields || []
                    }
                  } else {
                    errors.push(tab.label + '中按钮《' + btn.label + '》配置信息丢失')
                  }
                }
              })
              tab.components[0].cols.forEach(col => {
                if (col.type !== 'custom') return
                col.elements.forEach(btn => {
                  if (btn.eleType !== 'button') return
                  if (btn.OpenType === 'popview' && btn.config && btn.config.components[0]) {
                    this.setTbForm(btn.config.components[0], menus, errors, tab.components[0].name + '-' + btn.label)
                  } else if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
                    if (menus[btn.uuid]) {
                      btn.modal = {
                        setting: menus[btn.uuid].setting,
                        tables: [],
                        groups: [],
                        fields: menus[btn.uuid].fields || []
                      }
                    } else {
                      errors.push(tab.label + '中按钮《' + btn.label + '》配置信息丢失')
                    }
                  }
                })
              })
            })
          } else {
            item.action.forEach(btn => {
              if (btn.OpenType === 'popview' && btn.config && btn.config.components[0]) {
                this.setTbForm(btn.config.components[0], menus, errors, item.name + '-' + btn.label)
              } else if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
                if (menus[btn.uuid]) {
                  btn.modal = {
                    setting: menus[btn.uuid].setting,
                    tables: [],
                    groups: [],
                    fields: menus[btn.uuid].fields || []
                  }
                } else {
                  errors.push('主表中按钮《' + btn.label + '》配置信息丢失')
                }
              }
            })
            item.cols.forEach(col => {
              if (col.type !== 'custom') return
              col.elements.forEach(btn => {
                if (btn.eleType !== 'button') return
                if (btn.OpenType === 'popview' && btn.config && btn.config.components[0]) {
                  this.setTbForm(btn.config.components[0], menus, errors, item.name + '-' + btn.label)
                } else if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
                  if (menus[btn.uuid]) {
                    btn.modal = {
                      setting: menus[btn.uuid].setting,
                      tables: [],
                      groups: [],
                      fields: menus[btn.uuid].fields || []
                    }
                  } else {
                    errors.push('主表中按钮《' + btn.label + '》配置信息丢失')
                  }
                }
              })
            })
          }
        })
        this.saveConfig(_resolve, _config, errors, formTabs)
      })
    } else {
      this.saveConfig(_resolve, _config, errors, formTabs)
    }
  }
  setTbForm = (item, menus, errors, name) => {
    item.action.forEach(btn => {
      if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
        if (menus[btn.uuid]) {
          btn.modal = {
            setting: menus[btn.uuid].setting,
            tables: [],
            groups: [],
            fields: menus[btn.uuid].fields || []
          }
        } else {
          errors.push(name + '中按钮《' + btn.label + '》配置信息丢失')
        }
      }
    })
    item.cols.forEach(col => {
      if (col.type !== 'custom') return
      col.elements.forEach(btn => {
        if (btn.eleType !== 'button') return
        if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
          if (menus[btn.uuid]) {
            btn.modal = {
              setting: menus[btn.uuid].setting,
              tables: [],
              groups: [],
              fields: menus[btn.uuid].fields || []
            }
          } else {
            errors.push(name + '中按钮《' + btn.label + '》配置信息丢失')
          }
        }
      })
    })
  }
  saveConfig = (_resolve, _config, errors, formTabs) => {
    let err = errors.join(';')
    let _this = this
    if (err) {
      _resolve()
      confirm({
        title: err + ',确定升级当前菜单吗?',
        content: '',
        onOk() {
          return new Promise(resolve => {
            _this.saveNewMenu(resolve, _config, formTabs)
          })
        },
        onCancel() {}
      })
    } else {
      this.saveNewMenu(_resolve, _config, formTabs)
    }
  }
  saveNewMenu = (_resolve, _config, formTabs) => {
    _config.components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          tab.components[0].action.forEach(btn => {
            if (btn.OpenType === 'popview' && btn.config) {
              btn.config.$tables = getTables(btn.config.components[0])
            }
          })
          tab.components[0].cols.forEach(col => {
            if (col.type !== 'custom') return
            col.elements.forEach(btn => {
              if (btn.eleType !== 'button') return
              if (btn.OpenType === 'popview' && btn.config) {
                btn.config.$tables = getTables(btn.config.components[0])
              }
            })
          })
          tab.components[0].$tables = getTables(tab.components[0])
        })
      } else {
        item.action.forEach(btn => {
          if (btn.OpenType === 'popview' && btn.config) {
            btn.config.$tables = getTables(btn.config.components[0])
          }
        })
        item.cols.forEach(col => {
          if (col.type !== 'custom') return
          col.elements.forEach(btn => {
            if (btn.eleType !== 'button') return
            if (btn.OpenType === 'popview' && btn.config) {
              btn.config.$tables = getTables(btn.config.components[0])
            }
          })
        })
        item.$tables = getTables(item)
      }
    })
    // if (formTabs.length > 0) {
    //   this.transformTabs(_resolve, _config, formTabs)
    // } else {
      this.submitConfig(_resolve, _config)
    // }
  }
  transformTabs = (_resolve, _config, formTabs) => {
    let tab = formTabs.shift()
    Api.getSystemConfig({
      func: 'sPC_Get_LongParam',
      MenuID: tab.uuid
    }).then(res => {
      if (res.status) {
        let _LongParam = ''
        if (res.LongParam) {
          try {
            _LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
          } catch (e) {
            console.warn('Parse Failure')
            _LongParam = ''
          }
        }
        if (_LongParam && (_LongParam.type === 'FormTab' || _LongParam.Template === 'FormTab') && _LongParam.enabled) {
          if (!_LongParam.tabgroups) {
            _LongParam.tabgroups = []
          } else if (typeof(_LongParam.tabgroups[0]) === 'string') {
            let _tabgroups = []
            _LongParam.tabgroups.forEach(groupId => {
              let _group = {
                uuid: groupId,
                sublist: fromJS(_LongParam[groupId]).toJS()
              }
              delete _LongParam[groupId]
              _tabgroups.push(_group)
            })
            _LongParam.tabgroups = _tabgroups
          }
          _LongParam.tabgroups = _LongParam.tabgroups.filter(group => group.sublist.length > 0)
          _LongParam.tabgroups.forEach(group => {
            group.sublist = group.sublist.map(tab => {
              if (tab.supMenu === 'mainTable') {
                tab.supMenu = ''
              }
              return tab
            })
          })
          _LongParam.action = _LongParam.action.map(item => {
            if (item.intertype === 'inner' && !item.innerFunc) {
              item.intertype = 'system'
            }
            return item
          })
          delete _LongParam.funcs
          delete _LongParam.tables
        } else {
          _config.components[0].action = _config.components[0].action.filter(btn => btn.uuid !== tab.uuid)
        }
      } else {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        _resolve()
      }
    })
  }
  submitConfig = (_resolve, config) => {
    let tbs = []
    config.components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          if (tab.components[0].$tables) {
            tbs.push(...tab.components[0].$tables)
          }
        })
      } else {
        if (item.$tables) {
          tbs.push(...item.$tables)
        }
      }
    })
    let arr = []
    tbs = tbs.filter(tb => {
      let _tb = tb.toLowerCase()
      if (arr.includes(_tb)) return false
      arr.push(_tb)
      return true
    })
    tbs.sort()
    if (tbs.length && sessionStorage.getItem('mk_tb_names')) {
      let names = sessionStorage.getItem('mk_tb_names')
      tbs = tbs.filter(tb => names.indexOf(',' + tb.toLowerCase() + ',') > -1)
    }
    tbs = tbs.map(tb => `'${tb}'`).join(';')
    let key = md5(config.uuid + tbs.toLowerCase())
    let urlparam = {
      FstId: config.fstMenuId,
      ParentId: config.parentId,
      MenuID: config.uuid,
      MenuName: config.MenuName,
      MenuNo: config.MenuNo,
      EasyCode: config.easyCode,
      type: 'admin',
      OpenType: config.OpenType,
      PageParam: {Template: 'BaseTable', OpenType: 'newtab', hidden: config.hidden},
      MenuType: 'BaseTable'
    }
    let url = window.btoa(window.encodeURIComponent(JSON.stringify(urlparam)))
    config.tbkey = key
    let param = {
      func: 'sPC_TrdMenu_AddUpt',
      FstID: config.fstMenuId || '',
      SndID: config.parentId,
      ParentID: config.parentId,
      MenuID: config.uuid,
      MenuNo: config.MenuNo || '',
      EasyCode: config.easyCode || '',
      Template: 'BaseTable',
      MenuName: config.MenuName || '',
      PageParam: JSON.stringify({Template: 'BaseTable', OpenType: config.OpenType, hidden: config.hidden}),
      open_edition: '',
      debug_md5: key,
      debug_url: url,
      debug_list: window.btoa(tbs),
      LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config)))
    }
    param.LText = Utils.formatOptions(param.LText)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    let save = false
    new Promise(resolve => {
      Api.getSystemConfig(param).then(res => {
        resolve(res)
      })
    }).then(res => { // 删除原菜单
      if (!res || !res.status) return res
      save = true
      localStorage.setItem('menuUpdate', new Date().getTime() + ',' + config.uuid)
      if (this.delButtons.length === 0) return res
      return Api.getSystemConfig({
        func: 'sPC_MainMenu_Del',
        up_type: 'Y',
        MenuID: this.delButtons.join(',')
      })
    }).then(res => {
      if (!res) return
      _resolve()
      if (res.status) {
        delete urlparam.type
        delete urlparam.MenuType
        let _param = window.btoa(window.encodeURIComponent(JSON.stringify(urlparam)))
        window.history.replaceState(null, null, window.location.href.split('#')[0] + `#/tabledesign/${_param}`)
        window.location.reload()
      } else {
        Modal.warning({
          title: res.message,
          okText: '知道了',
          onOk: () => {
            if (save) {
              delete urlparam.type
              delete urlparam.MenuType
              let _param = window.btoa(window.encodeURIComponent(JSON.stringify(urlparam)))
              window.history.replaceState(null, null, window.location.href.split('#')[0] + `#/tabledesign/${_param}`)
              window.location.reload()
            } else {
              window.location.reload()
            }
          }
        })
      }
    })
  }
  getTable = (config, newCon, errors, formActions, formTabs, popActions, oldtabs) => {
    let _card = {
      uuid: Utils.getuuid(),
      uuid: newCon.uuid,
      type: 'table',
      name: name,
      name: newCon.name,
      format: 'array',
      pageable: true,
      switchable: true,
      search: config.search.map(item => {
        item.uuid = Utils.getuuid()
        return item
      }),
      search: [],
      action: [],
      subtype: 'basetable',
      setting: { },
      wrap: { },
      setting: { useMSearch: newCon.useMSearch },
      wrap: {},
      style: {},
      headerStyle: {},
      columns: [],
@@ -122,12 +839,28 @@
      scripts: []
    }
    if (!config) {
      errors.push(newCon.name + '配置信息丢失')
      return _card
    }
    if (oldtabs && newCon.supModule && oldtabs[newCon.supModule]) {
      _card.setting.supModule = [oldtabs[newCon.supModule]]
    } else {
      _card.setting.supModule = ['empty']
    }
    _card.search = config.search.map(item => {
      item.uuid = Utils.getuuid()
      return item
    })
    let _cols = {}
    let _colspan = []
    let lineMarks = []
    config.columns.forEach(col => {
      if (col.type === 'colspan') {
        _colspan.push(col.subfield.split(', '))
        _colspan.push(...col.subfield.split(', '))
      }
      if (!col.field) return
@@ -165,6 +898,7 @@
          if (m.signType === 'line') {
            lineMarks.push({
              $index: lineMarks.length + 1,
              uuid: Utils.getuuid(),
              field: field,
              color: color,
              contrastValue: m.contrastValue || '',
@@ -174,6 +908,7 @@
          } else {
            _col.marks.push({
              $index: _col.marks.length + 1,
              uuid: Utils.getuuid(),
              field: field,
              color: color,
              contrastValue: m.contrastValue || '',
@@ -241,10 +976,12 @@
                datatype: 'dynamic',
                eleType: _cols[sub].type !== 'number' ? 'text' : 'number',
                field: sub,
                height: 1,
                innerHeight: 21,
                height: '',
                innerHeight: 'auto',
                marks: _cols[sub].marks || null,
                noValue: 'show',
                prefix: _cols[sub].prefix || '',
                postfix: _cols[sub].postfix || '',
                style: {},
                width: 24,
                uuid: Utils.getuuid()
@@ -317,33 +1054,101 @@
    }
    let colbtns = []
    let colors = { primary: '#1890ff', yellow: '#c49f47', orange: 'orange', danger: '#ff4d4f', green: '#26C281', dgreen: '#32c5d2', purple: '#8E44AD', cyan: '#13c2c2', gray: '#666666', default: '#333333' }
    let colors = { primary: '#1890ff', yellow: '#c49f47', orange: 'orange', danger: '#ff4d4f', green: '#26C281', dgreen: '#32c5d2', purple: '#8E44AD', cyan: '#13c2c2', gray: '#E7E7EF', default: 'rgba(0, 0, 0, 0.65)' }
    let uuids = {}
    config.action.forEach(btn => {
      let _c = btn.class ? btn.class.replace('border-', '') : ''
      let color = colors[_c] || '#1890ff'
      let _btn = fromJS(btn).toJS()
      _btn.uuid = Utils.getuuid()
      // _btn.uuid = Utils.getuuid()
      delete _btn.position
      delete _btn.linkTab
      uuids[btn.uuid] = _btn.uuid
      if (_btn.intertype === 'inner' && !_btn.innerFunc) {
        _btn.intertype = 'system'
      }
      if ((_btn.intertype === 'outer' || _btn.intertype === 'custom') && !_btn.procMode) { // 兼容外部函数直传类型
        _btn.procMode = !_btn.innerFunc ? 'none' : 'inner'
      }
      if (_btn.funcType === 'print' && _btn.execMode) {
        _btn.OpenType = 'funcbutton'
      } else if (_btn.OpenType === 'blank') {
        _btn.OpenType = 'tab'
      }
      if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
      this.delButtons.push(btn.uuid)
        formActions.push({origin: btn.uuid, uuid: _btn.uuid, name: name, label: btn.label})
      } else if (btn.OpenType === 'popview') {
      _btn.show = 'button'
        popActions.push({origin: btn.uuid, linkTab: btn.linkTab || '', uuid: _btn.uuid, name: name, label: btn.label})
      } else if (btn.OpenType === 'tab') {
        if (btn.tabTemplate === 'FormTab' || !btn.linkmenu || btn.linkmenu.length !== 3) {
      if (_btn.execSuccess === 'equaltab') {
        _btn.execSuccess = 'grid'
        _btn.syncComponent = []
          errors.push(name + '中按钮《' + btn.label + '》不在支持')
        if (newCon.equalTab && oldtabs && oldtabs[newCon.equalTab]) {
          _btn.syncComponent.push(oldtabs[newCon.equalTab])
        }
      } else if (_btn.execSuccess === 'maingrid') {
        _btn.execSuccess = 'mainline'
      }
      if (_btn.execError === 'equaltab') {
        _btn.execError = 'grid'
      } else if (_btn.execError === 'maingrid') {
        _btn.execError = 'mainline'
      }
      if (_btn.popClose === 'equaltab') {
        _btn.popClose = 'grid'
        _btn.syncComponent = []
        if (newCon.equalTab && oldtabs && oldtabs[newCon.equalTab]) {
          _btn.syncComponent.push(oldtabs[newCon.equalTab])
        }
      } else if (_btn.popClose === 'maingrid') {
        _btn.popClose = 'mainline'
      }
      if (_btn.OpenType === 'pop' || (_btn.OpenType === 'funcbutton' && _btn.funcType === 'print' && _btn.execMode === 'pop')) {
        formActions.push({origin: btn.uuid, uuid: _btn.uuid, name: newCon.name, label: btn.label})
      } else if (_btn.OpenType === 'popview') {
        if (!popActions) return
        popActions.push({origin: btn.uuid, linkTab: btn.linkTab || '', uuid: _btn.uuid, name: newCon.name, label: btn.label})
      } else if (_btn.OpenType === 'tab') {
        if (btn.tabTemplate === 'FormTab') {
          if (newCon.isMain !== true) {
            errors.push(newCon.name + '中按钮《' + btn.label + '》不在支持')
            return
          }
          delete _btn.tabTemplate
          _btn.MenuID = 'tab' + md5(btn.uuid).substr(3)
          _btn.MenuName = this.baseMsg.MenuName + '-' + btn.label
          _btn.MenuNo = this.baseMsg.MenuNo + '_' + _btn.MenuID.substr(-4).toUpperCase()
          _btn.hidden = _btn.hidden || 'false'
          _btn.tabType = 'CustomPage'
          _btn.linkmenu = [this.baseMsg.fstMenuId, this.baseMsg.parentId, _btn.MenuID]
          let _tab = {...btn}
          _tab.MenuID = _btn.MenuID
          _tab.MenuNo = _btn.MenuNo
          _tab.MenuName = _btn.MenuName
          formTabs.push(_tab)
        } else if (!btn.linkmenu || btn.linkmenu.length !== 3) {
          errors.push(newCon.name + '中按钮《' + btn.label + '》不在支持')
          return
        }
      }
      if (_btn.tabType === 'CommonTable') {
      uuids[btn.uuid] = true
      if (_btn.tabType === 'CommonTable' || _btn.tabType === 'SubTable') {
        _btn.tabType = 'BaseTable'
      }
@@ -353,10 +1158,12 @@
        _btn.style = {color: color, backgroundColor: 'transparent', borderColor: 'transparent'}
        colbtns.push(_btn)
      } else {
        if (btn.class.indexOf('border') > -1 || btn.class === 'default') {
        if (btn.class === 'default') {
          _btn.style = {color: 'rgba(0, 0, 0, 0.65)', backgroundColor: '#fff', borderColor: '#d9d9d9', marginRight: '15px'}
        } else if (btn.class.indexOf('border') > -1) {
          _btn.style = {color: color, backgroundColor: '#fff', borderColor: color, marginRight: '15px'}
        } else {
          _btn.style = {color: '#fff', backgroundColor: color, borderColor: color, marginRight: '15px'}
          _btn.style = {color: btn.class === 'gray' ? 'rgba(0, 0, 0, 0.65)' : '#fff', backgroundColor: color, borderColor: color, marginRight: '15px'}
        }
        _card.action.push(_btn)
      }
@@ -369,7 +1176,7 @@
        marks: [],
        isSub: false,
        uuid: Utils.getuuid(),
        type: 'action',
        type: 'custom',
        Width: 120,
        elements: colbtns,
        style: {paddingTop: '12px', paddingLeft: '8px', paddingBottom: '12px', paddingRight: '8px'}
@@ -378,12 +1185,18 @@
    let sets = ['tableName', 'interType', 'sysInterface', 'innerFunc', 'interface', 'proInterface', 'outerFunc', 'dataresource', ['queryType', 'query'], 'primaryKey', 'order', 'execute', ['laypage', 'true'], ['pageSize', 10], ['onload', 'true']]
    let wraps = ['tableType', ['bordered', 'true'], 'actionfixed', ['size', 'middle'], ['selected', 'false'], ['tableMode', 'compatible'], ['mask', 'show'], ['borderColor', '#e8e8e8'], 'height', 'controlField', 'controlVal']
    // useMSearch supModule
    _card.scripts = config.setting.scripts || []
    sets.forEach(n => {
      if (n === 'interType' && !['system', 'inner', 'outer'].includes(config.setting.interType)) {
        _card.setting.interType = 'system'
      if (n === 'interType') {
        if (!['system', 'inner', 'outer'].includes(config.setting.interType)) {
          _card.setting.interType = 'system'
        } else if (config.setting.interType === 'inner' && !config.setting.innerFunc) {
          _card.setting.interType = 'system'
        } else {
          _card.setting.interType = config.setting.interType
        }
      } else if (typeof(n) === 'string') {
        _card.setting[n] = config.setting[n] || ''
      } else {
@@ -398,20 +1211,61 @@
      }
    })
    if (config.setting.doubleClick && uuids[config.setting.doubleClick]) {
      _card.wrap.doubleClick = uuids[config.setting.doubleClick]
    } else {
    _card.wrap.doubleClick = config.setting.doubleClick || ''
    if (_card.wrap.doubleClick && !uuids[_card.wrap.doubleClick]) {
      _card.wrap.doubleClick = ''
    }
    _card.errors = []
    let columns = _card.columns.map(c => c.field)
    if (_card.setting.interType === 'system' && _card.setting.execute !== 'false' && !_card.setting.dataresource) {
      _card.errors.push({ level: 0, detail: '未设置数据源!'})
    } else if (_card.setting.interType === 'system' && _card.setting.execute === 'false' && _card.scripts.filter(script => script.status !== 'false').length === 0) {
      _card.errors.push({ level: 0, detail: '数据源中无可用脚本!'})
    } else if (!_card.setting.primaryKey) {
      _card.errors.push({ level: 0, detail: '未设置主键!'})
    } else if (!columns.includes(_card.setting.primaryKey)) {
      _card.errors.push({ level: 0, detail: '主键已失效!'})
    } else if (!_card.setting.supModule) {
      _card.errors.push({ level: 0, detail: '未设置上级组件!'})
    }
    _card.action.forEach(cell => {
      if (cell.hidden === 'true') return
      if (cell.OpenType === 'pop' || (cell.OpenType === 'funcbutton' && cell.execMode === 'pop')) {
        if (!cell.modal || cell.modal.fields.length === 0) {
          _card.errors.push({ level: 0, detail: `按钮“${cell.label}”中表单尚未添加`})
        }
      } else if (cell.OpenType === 'excelIn' && (!cell.verify || !cell.verify.sheet || !cell.verify.columns || cell.verify.columns.length === 0)) {
        _card.errors.push({ level: 0, detail: `按钮“${cell.label}”中导入列未设置!`})
      } else if (cell.OpenType === 'excelOut' && (!cell.verify || !cell.verify.columns || cell.verify.columns.length === 0)) {
        _card.errors.push({ level: 0, detail: `按钮“${cell.label}”中导出列未设置!`})
      }
    })
    _card.cols.forEach(col => {
      if (col.type !== 'custom') return
      col.elements.forEach(cell => {
        if (cell.hidden === 'true' || cell.eleType !== 'button') return
        if (cell.OpenType === 'pop' || (cell.OpenType === 'funcbutton' && cell.execMode === 'pop')) {
          if (!cell.modal || cell.modal.fields.length === 0) {
            _card.errors.push({ level: 0, detail: `按钮“${cell.label}”中表单尚未添加`})
          }
        } else if (cell.OpenType === 'excelIn' && (!cell.verify || !cell.verify.sheet || !cell.verify.columns || cell.verify.columns.length === 0)) {
          _card.errors.push({ level: 0, detail: `按钮“${cell.label}”中导入列未设置!`})
        } else if (cell.OpenType === 'excelOut' && (!cell.verify || !cell.verify.columns || cell.verify.columns.length === 0)) {
          _card.errors.push({ level: 0, detail: `按钮“${cell.label}”中导出列未设置!`})
        }
      })
    })
    return _card
  }
  render() {
    return (
      <div style={{display: 'inline-block'}}>
        <Button className="mk-border-purple" onClick={this.trigger}><ArrowUpOutlined /> 升级</Button>
      </div>
      <Button className="mk-border-purple" onClick={this.trigger}><ArrowUpOutlined /> 升级</Button>
    )
  }
}