king
2023-06-14 08cce3334a2dc81d690b518136b0aaea64e48b0b
src/templates/comtableconfig/updatetable/index.jsx
@@ -21,6 +21,7 @@
  state = {}
  delButtons = []
  baseMsg = {}
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
@@ -52,8 +53,14 @@
  }
  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,
@@ -80,13 +87,14 @@
    let formActions = []
    let popActions = []
    let errors = []
    let formTabs = []
    let mainTb = {name: '主表', uuid: Utils.getuuid(), useMSearch: 'false', isMain: true}
    let oldtabs = {
      mainTable: mainTb.uuid
    }
    let tbl = this.getTable(config, mainTb, errors, formActions, popActions, oldtabs)
    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) {
@@ -183,7 +191,7 @@
        _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, popActions, oldtabs)
              tab.components[0] = this.getTable(menus[tab.components[0].linkTab], tab.components[0], errors, formActions, formTabs, popActions, oldtabs)
              return tab
            })
@@ -191,14 +199,14 @@
          return item
        })
        this.setPopView(_resolve, _config, formActions, popActions, errors)
        this.setPopView(_resolve, _config, formActions, formTabs, popActions, errors)
      })
    } else {
      this.setPopView(_resolve, _config, formActions, popActions, errors)
      this.setPopView(_resolve, _config, formActions, formTabs, popActions, errors)
    }
  }
  setPopView = (_resolve, _config, formActions, popActions, errors) => {
  setPopView = (_resolve, _config, formActions, formTabs, popActions, errors) => {
    if (popActions.length > 0) {
      let defers = popActions.map((item, i) => {
        return new Promise((resolve) => {
@@ -256,22 +264,24 @@
                      uuid: btn.uuid,
                      MenuID: btn.uuid,
                      ParentId: tab.components[0].uuid,
                      enabled: false,
                      MenuName: btn.label,
                      tables: _config.tables || [],
                      Template: 'BaseTable',
                      components: [this.getTable(menus[btn.uuid], mainTb, errors, formActions)],
                      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 !== 'action') return
                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'}
@@ -280,14 +290,15 @@
                        uuid: btn.uuid,
                        MenuID: btn.uuid,
                        ParentId: tab.components[0].uuid,
                        enabled: false,
                        MenuName: btn.label,
                        tables: _config.tables || [],
                        Template: 'BaseTable',
                        components: [this.getTable(menus[btn.uuid], mainTb, errors, formActions)],
                        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 + '》配置信息丢失')
                    }
@@ -305,22 +316,24 @@
                    uuid: btn.uuid,
                    MenuID: btn.uuid,
                    ParentId: item.uuid,
                    enabled: false,
                    MenuName: btn.label,
                    tables: _config.tables || [],
                    Template: 'BaseTable',
                    components: [this.getTable(menus[btn.uuid], mainTb, errors, formActions)],
                    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 !== 'action') return
              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'}
@@ -329,14 +342,15 @@
                      uuid: btn.uuid,
                      MenuID: btn.uuid,
                      ParentId: item.uuid,
                      enabled: false,
                      MenuName: btn.label,
                      tables: _config.tables || [],
                      Template: 'BaseTable',
                      components: [this.getTable(menus[btn.uuid], mainTb, errors, formActions)],
                      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 + '》配置信息丢失')
                  }
@@ -346,14 +360,33 @@
          }
        })
        this.setPopForm(_resolve, _config, formActions, errors)
        this.setPopForm(_resolve, _config, formActions, formTabs, errors)
      })
    } else {
      this.setPopForm(_resolve, _config, formActions, errors)
      this.setPopForm(_resolve, _config, formActions, formTabs, errors)
    }
  }
  setPopForm = (_resolve, _config, formActions, 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) => {
@@ -419,8 +452,9 @@
                }
              })
              tab.components[0].cols.forEach(col => {
                if (col.type !== 'action') return
                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')) {
@@ -456,8 +490,9 @@
              }
            })
            item.cols.forEach(col => {
              if (col.type !== 'action') return
              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')) {
@@ -477,10 +512,10 @@
          }
        })
        this.saveConfig(_resolve, _config, errors)
        this.saveConfig(_resolve, _config, errors, formTabs)
      })
    } else {
      this.saveConfig(_resolve, _config, errors)
      this.saveConfig(_resolve, _config, errors, formTabs)
    }
  }
@@ -500,8 +535,9 @@
      }
    })
    item.cols.forEach(col => {
      if (col.type !== 'action') return
      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 = {
@@ -518,7 +554,7 @@
    })
  }
  saveConfig = (_resolve, _config, errors) => {
  saveConfig = (_resolve, _config, errors, formTabs) => {
    let err = errors.join(';')
    let _this = this
@@ -529,17 +565,17 @@
        content: '',
        onOk() {
          return new Promise(resolve => {
            _this.saveNewMenu(resolve, _config)
            _this.saveNewMenu(resolve, _config, formTabs)
          })
        },
        onCancel() {}
      })
    } else {
      this.saveNewMenu(_resolve, _config)
      this.saveNewMenu(_resolve, _config, formTabs)
    }
  }
  saveNewMenu = (_resolve, _config) => {
  saveNewMenu = (_resolve, _config, formTabs) => {
    _config.components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
@@ -549,8 +585,9 @@
            }
          })
          tab.components[0].cols.forEach(col => {
            if (col.type !== 'action') return
            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])
              }
@@ -566,8 +603,9 @@
          }
        })
        item.cols.forEach(col => {
          if (col.type !== 'action') return
          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])
            }
@@ -578,53 +616,100 @@
      }
    })
    // 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 => {
    config.components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          if (tab.components[0].$tables) {
            tbs.push(...tab.components[0].$tables)
          }
          tab.components[0].errors = []
          let columns = tab.components[0].columns.map(c => c.field)
          if (tab.components[0].setting.interType === 'system' && tab.components[0].setting.execute !== 'false' && !tab.components[0].setting.dataresource) {
            tab.components[0].errors.push({ level: 0, detail: '未设置数据源!'})
          } else if (tab.components[0].setting.interType === 'system' && tab.components[0].setting.execute === 'false' && tab.components[0].scripts.filter(script => script.status !== 'false').length === 0) {
            tab.components[0].errors.push({ level: 0, detail: '数据源中无可用脚本!'})
          } else if (!tab.components[0].setting.primaryKey) {
            tab.components[0].errors.push({ level: 0, detail: '未设置主键!'})
          } else if (!columns.includes(tab.components[0].setting.primaryKey)) {
            tab.components[0].errors.push({ level: 0, detail: '主键已失效!'})
          } else if (!tab.components[0].setting.supModule) {
            tab.components[0].errors.push({ level: 0, detail: '未设置上级组件!'})
          }
        })
      } else {
        if (item.$tables) {
          tbs.push(...item.$tables)
        }
        item.errors = []
        let columns = item.columns.map(c => c.field)
        if (item.setting.interType === 'system' && item.setting.execute !== 'false' && !item.setting.dataresource) {
          item.errors.push({ level: 0, detail: '未设置数据源!'})
        } else if (item.setting.interType === 'system' && item.setting.execute === 'false' && item.scripts.filter(script => script.status !== 'false').length === 0) {
          item.errors.push({ level: 0, detail: '数据源中无可用脚本!'})
        } else if (!item.setting.primaryKey) {
          item.errors.push({ level: 0, detail: '未设置主键!'})
        } else if (!columns.includes(item.setting.primaryKey)) {
          item.errors.push({ level: 0, detail: '主键已失效!'})
        } else if (!item.setting.supModule) {
          item.errors.push({ level: 0, detail: '未设置上级组件!'})
        }
      }
    })
    this.submitConfig(_resolve, _config, tbs)
  }
  submitConfig = (_resolve, config, tbs) => {
    let arr = []
    tbs = tbs.filter(tb => {
      let _tb = tb.toLowerCase()
@@ -734,7 +819,7 @@
    })
  }
  getTable = (config, newCon, errors, formActions, popActions, oldtabs) => {
  getTable = (config, newCon, errors, formActions, formTabs, popActions, oldtabs) => {
    let _card = {
      uuid: newCon.uuid,
      type: 'table',
@@ -759,7 +844,7 @@
      return _card
    }
    if (newCon.supModule && oldtabs[newCon.supModule]) {
    if (oldtabs && newCon.supModule && oldtabs[newCon.supModule]) {
      _card.setting.supModule = [oldtabs[newCon.supModule]]
    } else {
      _card.setting.supModule = ['empty']
@@ -969,7 +1054,7 @@
    }
    let colbtns = []
    let colors = { primary: '#1890ff', yellow: '#c49f47', orange: 'orange', danger: '#ff4d4f', green: '#26C281', dgreen: '#32c5d2', purple: '#8E44AD', cyan: '#13c2c2', gray: '#666666', default: 'rgba(0, 0, 0, 0.65)' }
    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 => {
@@ -982,6 +1067,9 @@
      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'
@@ -1029,7 +1117,29 @@
        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' || !btn.linkmenu || btn.linkmenu.length !== 3) {
        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
@@ -1053,7 +1163,7 @@
        } 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)
      }
@@ -1066,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'}
@@ -1106,6 +1216,50 @@
      _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
  }