king
2021-03-05 e36eb1999794bd71e76482b92a0b0b20f49d0032
src/templates/subtableconfig/index.jsx
@@ -11,7 +11,7 @@
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import Utils from '@/utils/utils.js'
import UtilsUpdate from '@/utils/utils-update.js'
import { updateSubTable } from '@/utils/utils-update.js'
import asyncComponent from '@/utils/asyncComponent'
import SearchComponent from '@/templates/sharecomponent/searchcomponent'
@@ -19,7 +19,6 @@
import ColumnComponent from '@/templates/sharecomponent/columncomponent'
import MenuForm from './menuform'
import EditComponent from '@/templates/zshare/editcomponent'
import SourceElement from '@/templates/zshare/dragsource'
import Source from './source'
import './index.scss'
@@ -27,6 +26,7 @@
const { Panel } = Collapse
const { confirm } = Modal
const EditComponent = asyncComponent(() => import('@/templates/zshare/editcomponent'))
const SettingComponent = asyncComponent(() => import('@/templates/sharecomponent/settingcomponent'))
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
@@ -47,10 +47,9 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,        // 字典
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,        // 字典
    config: null,            // 页面配置
    visible: false,          // 搜索条件、按钮、显示列,模态框显示控制
    tableFields: [],         // 已选表字段集
    menuloading: false,      // 菜单保存中
    menucloseloading: false, // 菜单关闭时,选择保存
    loading: false,          // 加载中,页面spin
@@ -90,6 +89,11 @@
    if (_config.type === 'user') {
      _config.action = _config.action.map(item => {
        let uuid = Utils.getuuid()
        if (item.linkTab) {
          item.linkTab = ''
        }
        if (item.OpenType === 'pop') { // 含有子配置项的按钮
          _oriActions.push({
            prebtn: fromJS(item).toJS(),
@@ -106,7 +110,7 @@
    let _activeKey =  editSubTab ? editSubTab.activeKey : editTab.activeKey
    // 版本兼容
    _config = UtilsUpdate.updateSubTable(_config)
    _config = updateSubTable(_config)
    this.setState({
      openEdition: editSubTab ? (editSubTab.open_edition || '') : (editTab.open_edition || ''),
@@ -195,7 +199,7 @@
    if (editSubTab) {
      _subconfig = tabConfig
      if (editTab.hasOwnProperty('OpenType')) {
        _tabview = editTab.tabType
        _tabview = editTab.tabType || 'SubTable'
      } else {
        _tabview = editTab.type
      }
@@ -275,50 +279,6 @@
      _config.enabled = false
    }
    _config.funcs = []
    _config.funcs.push({
      type: 'view',
      subtype: 'view',
      uuid: _config.uuid,
      intertype: _config.setting.interType || 'system',
      interface: _config.setting.interface || '',
      tableName: _config.setting.tableName || '',
      innerFunc: _config.setting.innerFunc || '',
      outerFunc: _config.setting.outerFunc || ''
    })
    _config.action.forEach(item => {
      let tablename = item.OpenType === 'excelIn' ? (item.sheet || '') : (item.sql || '')
      if (item.OpenType === 'excelOut' && item.intertype === 'system') {
        tablename = _config.setting.tableName || ''
      }
      if (item.OpenType === 'popview') {
        _config.funcs.push({
          type: 'tab',
          subtype: 'btn',
          uuid: item.uuid,
          label: item.label,
          linkTab: item.linkTab
        })
      } else {
        _config.funcs.push({
          type: 'button',
          subtype: 'btn',
          uuid: item.uuid,
          label: item.label,
          tableName: tablename,
          intertype: item.intertype,
          interface: item.interface || '',
          innerFunc: item.innerFunc || '',
          outerFunc: item.outerFunc || '',
          callbackFunc: item.callbackFunc || ''
        })
      }
    })
    if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
      this.setState({
        menucloseloading: true
@@ -329,251 +289,206 @@
      })
    }
    // 保存时删除配置类型,system 、user
    delete _config.type
    delete _config.isAdd
    let _LongParam = ''
    try {
      _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
    } catch (e) {
      notification.warning({
        top: 92,
        message: '编译错误',
        duration: 5
      })
      this.setState({
        menucloseloading: false,
        menuloading: false
      })
      return
    }
    let btnParam = {
      func: 'sPC_Button_AddUpt',
      Type: 40,
      ParentID: _config.uuid,
      MenuNo: _config.tabNo,
      Template: 'SubTable',
      PageParam: '',
      LongParam: '',
      LText: []
    }
    let btntabs = []
    _config.action.forEach((item, index) => {
      if (item.OpenType === 'popview') {
        btntabs.push(`select '${item.uuid}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${(index + 1) * 10}' as Sort`)
      }
      btnParam.LText.push(`select '${item.uuid}' as menuid, '${item.label}' as menuname, '${(index + 1) * 10}' as Sort`)
    })
    btnParam.LText = btnParam.LText.join(' union all ')
    btnParam.LText = Utils.formatOptions(btnParam.LText)
    btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
    let tabParam = { // 添加标签按钮tab页
      func: 'sPC_sMenusTab_AddUpt',
      MenuID: _config.uuid,
      LText: btntabs.join(' union all ')
    }
    tabParam.LText = Utils.formatOptions(tabParam.LText)
    tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
    let param = {
      func: 'sPC_Tab_AddUpt',
      MenuID: _config.uuid,
      MenuNo: _config.tabNo,
      Template: 'SubTable',
      MenuName: _config.tabName,
      Remark: _config.Remark,
      Sort: 0,
      PageParam: JSON.stringify({Template: 'SubTable'}),
      LongParam: _LongParam
    }
    if (openEdition) {
      param.open_edition = openEdition
    }
    // 有按钮或标签删除时,先进行删除操作
    // 删除成功后,保存页面配置
    new Promise(resolve => {
      let deffers = []
      _config.funcs.forEach(item => {
        if (item.type === 'tab') {
          let deffer = new Promise(resolve => {
            Api.getSystemConfig({
              func: 'sPC_Get_LongParam',
              MenuID: item.linkTab
            }).then(result => {
              if (result.status && result.LongParam) {
                let _LongParam = ''
                if (result.LongParam) {
                  try {
                    _LongParam = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
                  } catch (e) {
                    console.warn('Parse Failure')
                    _LongParam = ''
                  }
                }
                if (_LongParam) {
                  item.menuNo = _LongParam.tabNo
                  item.subfuncs = _LongParam.funcs || []
                }
              }
              resolve()
      if (delActions.length > 0) {
        let deffers = delActions.map(item => {
          let _param = {
            func: 'sPC_MainMenu_Del',
            MenuID: item.card.uuid
          }
          let _ParentParam = null
          try {
            _ParentParam = window.btoa(window.encodeURIComponent(JSON.stringify(item.card)))
          } catch (e) {
            console.warn('Stringify Failure')
            _ParentParam = null
          }
          if (_ParentParam) { // 删除按钮时,保存按钮配置信息,用于恢复按钮
            _param.ParentParam = _ParentParam
          }
          return new Promise(resolve => {
            Api.getSystemConfig(_param).then(response => {
              resolve(response)
            })
          })
          deffers.push(deffer)
        }
      })
      if (deffers.length === 0) {
        resolve()
      } else {
        Promise.all(deffers).then(() => {
          resolve()
        })
      }
    }).then(() => {
      // 保存时删除配置类型,system 、user
      delete _config.type
      delete _config.isAdd
      let _LongParam = ''
      try {
        _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
      } catch (e) {
        notification.warning({
          top: 92,
          message: '编译错误',
          duration: 5
        })
        this.setState({
          menucloseloading: false,
          menuloading: false
        })
        return
      }
      let btnParam = {
        func: 'sPC_Button_AddUpt',
        Type: 40,
        ParentID: _config.uuid,
        MenuNo: _config.tabNo,
        Template: 'SubTable',
        PageParam: '',
        LongParam: '',
        LText: []
      }
      let btntabs = []
      _config.action.forEach((item, index) => {
        if (item.OpenType === 'popview') {
          btntabs.push(`select '${item.uuid}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${(index + 1) * 10}' as Sort`)
        }
        btnParam.LText.push(`select '${item.uuid}' as menuid, '${item.label}' as menuname, '${(index + 1) * 10}' as Sort`)
      })
      btnParam.LText = btnParam.LText.join(' union all ')
      btnParam.LText = Utils.formatOptions(btnParam.LText)
      btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
      let tabParam = { // 添加标签按钮tab页
        func: 'sPC_sMenusTab_AddUpt',
        MenuID: _config.uuid,
        LText: btntabs.join(' union all ')
      }
      tabParam.LText = Utils.formatOptions(tabParam.LText)
      tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
      let param = {
        func: 'sPC_Tab_AddUpt',
        MenuID: _config.uuid,
        MenuNo: _config.tabNo,
        Template: 'SubTable',
        MenuName: _config.tabName,
        Remark: _config.Remark,
        Sort: 0,
        PageParam: JSON.stringify({Template: 'SubTable'}),
        LongParam: _LongParam
      }
      if (openEdition) {
        param.open_edition = openEdition
      }
      // 有按钮或标签删除时,先进行删除操作
      // 删除成功后,保存页面配置
      new Promise(resolve => {
        if (delActions.length > 0) {
          let deffers = delActions.map(item => {
            let _param = {
              func: 'sPC_MainMenu_Del',
              MenuID: item.card.uuid
            }
            let _ParentParam = null
            try {
              _ParentParam = window.btoa(window.encodeURIComponent(JSON.stringify(item.card)))
            } catch (e) {
              console.warn('Stringify Failure')
              _ParentParam = null
            }
            if (_ParentParam) { // 删除按钮时,保存按钮配置信息,用于恢复按钮
              _param.ParentParam = _ParentParam
            }
            return new Promise(resolve => {
              Api.getSystemConfig(_param).then(response => {
                resolve(response)
              })
            })
          })
          Promise.all(deffers).then(result => {
            let error = null
            result.forEach(response => {
              if (!response.status) {
                error = response
              }
            })
            if (error) {
              this.setState({
                menuloading: false,
                menucloseloading: false
              })
              notification.warning({
                top: 92,
                message: error.message,
                duration: 5
              })
              resolve(false)
            } else {
              this.setState({
                delActions: []
              })
              resolve(true)
        Promise.all(deffers).then(result => {
          let error = null
          result.forEach(response => {
            if (!response.status) {
              error = response
            }
          })
        } else if (delActions.length === 0) {
          resolve(true)
        }
      }).then(resp => {
        if (resp === false) return
        if (thawButtons.length > 0) {
          let defers = thawButtons.map(item => {
            return new Promise((resolve) => {
              Api.getSystemConfig({
                func: 'sPC_MainMenu_ReDel',
                MenuID: item
              }).then(res => {
                if (res.status) {
                  resolve('')
                } else {
                  resolve(res.message)
                }
              })
            })
          })
          return Promise.all(defers)
        } else {
          return true
        }
      }).then(res => {
        if (res === true || res === false) return res
        let msg = res.filter(Boolean)[0]
        if (msg) {
          notification.warning({
            top: 92,
            message: msg,
            duration: 5
          })
          return false
        } else {
          this.setState({
            thawButtons: []
          })
          return true
        }
      }).then(resp => {
        if (resp === false) return
        Api.getSystemConfig(param).then(response => {
          if (response.status) {
            this.setState({
              openEdition: response.open_edition || '',
              config: _config,
              originConfig: fromJS(_config).toJS()
            }, () => {
              this.setState({
                menuloading: false,
                menucloseloading: false
              })
              this.submitAction(btnParam, tabParam)
            })
          } else {
          if (error) {
            this.setState({
              menuloading: false,
              menucloseloading: false
            })
            notification.warning({
              top: 92,
              message: response.message,
              message: error.message,
              duration: 5
            })
            resolve(false)
          } else {
            this.setState({
              delActions: []
            })
            resolve(true)
          }
        })
      } else if (delActions.length === 0) {
        resolve(true)
      }
    }).then(resp => {
      if (resp === false) return
      if (thawButtons.length > 0) {
        let defers = thawButtons.map(item => {
          return new Promise((resolve) => {
            Api.getSystemConfig({
              func: 'sPC_MainMenu_ReDel',
              MenuID: item
            }).then(res => {
              if (res.status) {
                resolve('')
              } else {
                resolve(res.message)
              }
            })
          })
        })
        return Promise.all(defers)
      } else {
        return true
      }
    }).then(res => {
      if (res === true || res === false) return res
      let msg = res.filter(Boolean)[0]
      if (msg) {
        notification.warning({
          top: 92,
          message: msg,
          duration: 5
        })
        return false
      } else {
        this.setState({
          thawButtons: []
        })
        return true
      }
    }).then(resp => {
      if (resp === false) return
      Api.getSystemConfig(param).then(response => {
        if (response.status) {
          this.setState({
            openEdition: response.open_edition || '',
            config: _config,
            originConfig: fromJS(_config).toJS()
          }, () => {
            this.setState({
              menuloading: false,
              menucloseloading: false
            })
            this.submitAction(btnParam, tabParam)
          })
        } else {
          this.setState({
            menuloading: false,
            menucloseloading: false
          })
          notification.warning({
            top: 92,
            message: response.message,
            duration: 5
          })
        }
      })
    })
  }
  /**
@@ -639,6 +554,7 @@
        let curBtn = config.action.filter(cell => item.curuuid === cell.uuid)[0] // 查看初始化按钮是否存在
        if (!curBtn) return
        if (curBtn.OpenType !== item.prebtn.OpenType) return
        if (curBtn.OpenType === 'funcbutton' && curBtn.execMode !== 'pop') return
        oriActions.push({
          prebtn: item.prebtn,
@@ -751,19 +667,24 @@
          duration: 5
        })
      } else {
        this.setState({
          loading: true
        })
        // 子菜单信息验证通过后,跳转子按钮配置页面
        let _view = ''
        let _subtab = editSubTab
        if (btn.OpenType === 'pop') {
          _view = 'Modal'             // 表单页面
        if (btn.OpenType === 'pop' || btn.execMode === 'pop') {
          _view = 'Modal'      // 表单页面
        } else if (btn.OpenType === 'popview') {
          _view = btn.tabType        // 新弹窗标签模板
          _view = 'SubTable'   // 新弹窗标签模板 tabType 属性已去除
          _subtab = btn
          if (editSubTab) {
            notification.warning({
              top: 92,
              message: '弹窗(标签)中不支持此按钮打开方式!',
              duration: 5
            })
            return
          }
        }
        if (editSubTab) {
@@ -786,6 +707,10 @@
          subConfig: '',
          tabview: _view
        }
        this.setState({
          loading: true
        })
        Api.getSystemConfig({
          func: 'sPC_Get_LongParam',
@@ -896,8 +821,32 @@
      }
    })
    if (config.setting.interType === 'system' && config.setting.default !== 'false' && !config.setting.dataresource) {
      return '尚未设置数据源,不可启用!'
    config.action && config.action.forEach((btn) => {
      if (['prompt', 'exec', 'pop'].includes(btn.OpenType) && btn.Ot === 'required' && btn.verify && btn.verify.scripts && btn.verify.scripts.length > 0) {
        let hascheck = false
        btn.verify.scripts.forEach(item => {
          if (item.status === 'false') return
          if (/\$check@|@check\$/ig.test(item.sql)) {
            hascheck = true
          }
        })
        if (hascheck) {
          notification.warning({
            top: 92,
            message: `可选择多行的按钮《${btn.label}》中 $check@ 或 @check$ 将不会生效!`,
            duration: 5
          })
        }
      }
    })
    if ((config.setting.interType === 'system' || config.setting.requestMode === 'system') && config.setting.default === 'false' && config.setting.scripts && config.setting.scripts.filter(item => item.status !== 'false').length === 0) {
      return '数据源中不执行默认sql,且未添加自定义脚本,不可启用!'
    } else if (config.setting.interType === 'custom' && config.setting.procMode !== 'inner' && config.setting.preScripts && config.setting.preScripts.filter(item => item.status !== 'false').length === 0) {
      return '数据源未设置前置脚本,不可启用!'
    } else if (config.setting.interType === 'custom' && config.setting.callbackType === 'script' && config.setting.cbScripts && config.setting.cbScripts.filter(item => item.status !== 'false').length === 0) {
      return '数据源未设置回调脚本,不可启用!'
    } else if (!config.setting.primaryKey) {
      return '尚未设置主键,不可启用!'
    }  else if (config.columns.length === 0) {
@@ -921,17 +870,7 @@
        config: res.config
      })
    } else if (res.type === 'paste') {
      let config = fromJS(this.state.config).toJS()
      if (res.content.copyType === 'search') {
        config.search.push(res.content)
      } else if (res.content.copyType === 'action') {
        config.action.push(res.content)
      } else if (res.content.copyType === 'columns' && res.content.columns && res.content.columns.length > 0) {
        config.columns = config.columns.filter(col => !col.origin)
        config.columns = [...config.columns, ...res.content.columns]
      }
      this.setState({config})
      this.setState({config: res.config})
    }
  }
@@ -976,32 +915,11 @@
      chartview: _chartview
    })
  }
  /**
   * @description 更新常用表信息,快捷添加后更新配置信息
   */
  updatetable = (config, fields) => {
    const { tableFields } = this.state
    this.setState({
      config: config,
      tableFields: fields ? fields : tableFields
    })
  }
  /**
   * @description 批量添加,更新配置信息
   */
  updatefield = (config) => {
    this.setState({
      config: config
    })
  }
  render () {
    const { activeKey, config, chartview } = this.state
    const confActions = config.action.filter(_action => !_action.origin && ['pop', 'popview', 'blank', 'tab'].includes(_action.OpenType))
    const confActions = config.action.filter(_action => !_action.origin && (['pop', 'popview'].includes(_action.OpenType) || (_action.OpenType === 'funcbutton' && _action.execMode === 'pop')))
    return (
      <div className="model-subtable-board">
@@ -1021,7 +939,7 @@
                <TableComponent
                  config={config}
                  containerId="subtable-basedata"
                  updatetable={this.updatetable}
                  updatetable={this.updateconfig}
                />
              </Panel>
              {/* 搜索条件添加 */}
@@ -1034,8 +952,7 @@
                <FieldsComponent
                  config={config}
                  type="search"
                  tableFields={this.state.tableFields}
                  updatefield={this.updatefield}
                  updatefield={this.updateconfig}
                />
              </Panel>
              {/* 按钮添加 */}
@@ -1078,8 +995,7 @@
                <FieldsComponent
                  config={config}
                  type="columns"
                  tableFields={this.state.tableFields}
                  updatefield={this.updatefield}
                  updatefield={this.updateconfig}
                />
              </Panel>
            </Collapse>
@@ -1092,8 +1008,8 @@
              </div>
            } bordered={false} extra={
              <div>
                <EditComponent dict={this.state.dict} type="subtable" config={this.state.config} thawButtons={this.state.thawButtons} refresh={this.updateConfig}/>
                <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={this.state.config.enabled} onChange={this.onEnabledChange} />
                <EditComponent dict={this.state.dict} options={['search', 'action', 'columns']} config={config} MenuID={config.uuid} thawButtons={this.state.thawButtons} refresh={this.updateConfig}/>
                <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config.enabled} onChange={this.onEnabledChange} />
                <Button type="primary" onClick={this.submitConfig} loading={this.state.menuloading}>{this.state.dict['model.save']}</Button>
                <Button onClick={this.cancelConfig}>{this.state.dict['model.back']}</Button>
              </div>