king
2021-09-01 31ec63f0419895876cbaba99637a884a32d33d0d
src/templates/comtableconfig/index.jsx
@@ -9,7 +9,7 @@
import Api from '@/api'
import Utils from '@/utils/utils.js'
import UtilsUpdate from '@/utils/utils-update.js'
import { updateCommonTable } from '@/utils/utils-update.js'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
@@ -25,6 +25,8 @@
const { Panel } = Collapse
const { confirm } = Modal
const UrlFieldComponent = asyncComponent(() => import('@/menu/urlfieldcomponent'))
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
const EditComponent = asyncComponent(() => import('@/templates/zshare/editcomponent'))
const SettingComponent = asyncComponent(() => import('@/templates/sharecomponent/settingcomponent'))
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
@@ -42,9 +44,8 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    config: null,            // 页面配置
    tableFields: [],         // 已选的常用表
    formlist: null,          // 搜索条件、按钮、显示列表单字段
    menuloading: false,      // 菜单保存中
    menucloseloading: false, // 菜单关闭时,选择保存
@@ -90,7 +91,7 @@
    _config.easyCode = _config.easyCode || ''
    // 版本兼容
    _config = UtilsUpdate.updateCommonTable(_config)
    _config = updateCommonTable(_config)
    
    let _oriActions = []
    if (_config.type === 'user') {
@@ -101,17 +102,17 @@
          item.linkTab = ''
        }
        if (item.OpenType === 'pop') { // 含有子配置项的按钮(表单)
        if (item.OpenType === 'pop' || item.execMode === 'pop') { // 含有子配置项的按钮(表单)
          _oriActions.push({
            prebtn: fromJS(item).toJS(),
            curuuid: uuid,
            Template: 'Modal'
          })
        } else if (item.OpenType === 'tab' || item.OpenType === 'blank') { // 含有子配置项的按钮(标签后当前页打开)
        } else if (item.OpenType === 'tab' && item.tabTemplate === 'FormTab') { // 含有子配置项的按钮(标签页打开)
          _oriActions.push({
            prebtn: fromJS(item).toJS(),
            curuuid: uuid,
            Template: item.tabTemplate
            Template: 'FormTab'
          })
        }
@@ -202,20 +203,37 @@
    })
  }
  getFuncNames = (data) => {
  getFuncNames = (config) => {
    let funcNames = []
    let tableNames = []
    data.forEach(item => {
      if (item.tableName) {
        tableNames.push(item.tableName)
      }
      if (item.innerFunc) {
        funcNames.push({func: item.innerFunc, label: item.label || ''})
    if (config.setting.tableName) {
      tableNames.push(config.setting.tableName)
    }
    if (config.setting.innerFunc) {
      funcNames.push({func: config.setting.innerFunc, label: config.MenuName || ''})
    }
    if (config.setting.outerFunc) {
      funcNames.push({func: config.setting.outerFunc, label: config.MenuName || ''})
    }
    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.callbackFunc) {
        funcNames.push({func: item.callbackFunc, label: item.label || ''})
      if (['pop', 'prompt', 'exec', 'excelIn', 'excelOut', 'funcbutton'].includes(item.OpenType)) {
        if (tablename) {
          tableNames.push(tablename)
        }
        if (item.innerFunc) {
          funcNames.push({func: item.innerFunc, label: item.label || ''})
        }
        if (item.callbackFunc) {
          funcNames.push({func: item.callbackFunc, label: item.label || ''})
        }
      }
    })
@@ -279,70 +297,6 @@
    if (vresult !== true) {
      _config.enabled = false
    }
    _config.funcs = [] // 页面及子页面存储过程集
    _config.funcs.push({
      type: 'view',
      subtype: 'view',
      uuid: menu.MenuID,
      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 === 'tab' || item.OpenType === 'blank') {
        _config.funcs.push({
          type: 'tab',
          subtype: 'btn',
          uuid: item.uuid,
          label: item.label,
          linkTab: item.uuid
        })
      } else if (item.OpenType === 'popview') {
        _config.funcs.push({
          type: 'tab',
          subtype: 'btn',
          uuid: item.uuid,
          label: item.label,
          linkTab: item.linkTab
        })
      } else if (['pop', 'prompt', 'exec', 'excelIn', 'excelOut'].includes(item.OpenType)) {
        _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 || ''
        })
      }
    })
    _config.tabgroups.forEach(group => {
      group.sublist.forEach(tab => {
        _config.funcs.push({
          type: 'tab',
          subtype: 'tab',
          uuid: tab.uuid,
          label: tab.label,
          linkTab: tab.linkTab
        })
      })
    })
    if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
      this.setState({
@@ -436,7 +390,7 @@
    tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
    let _vals = this.getFuncNames(_config.funcs)
    let _vals = this.getFuncNames(_config)
    let param = {
      func: 'sPC_TrdMenu_AddUpt',
@@ -448,7 +402,7 @@
      EasyCode: _config.easyCode || '',
      Template: _config.Template || '',
      MenuName: _config.MenuName,
      PageParam: JSON.stringify({...menu.PageParam, Template: _config.Template, OpenType: _config.OpenType}),
      PageParam: JSON.stringify({...menu.PageParam, Template: _config.Template, OpenType: _config.OpenType, hidden: _config.hidden || 'false'}),
      LongParam: _LongParam,
      LText: _vals.func.map(item => `select '${menu.MenuID}' as MenuID,'${item.func}' as ProcName,'${item.label}' as MenuName`),
      LTexttb: _vals.table.map(item => `select '${menu.MenuID}' as MenuID,'${item}' as tbName`)
@@ -663,6 +617,8 @@
        let curBtn = config.action.filter(cell => item.curuuid === cell.uuid)[0] // 查看初始化按钮是否存在
        if (!curBtn) return
        if (curBtn.OpenType !== item.prebtn.OpenType) return
        if (curBtn.OpenType === 'tab' && curBtn.tabTemplate !== 'FormTab') return
        if (curBtn.OpenType === 'funcbutton' && curBtn.execMode !== 'pop') return
        oriActions.push({
          prebtn: item.prebtn,
@@ -726,7 +682,7 @@
                    })
                  })
                  _subconfig = window.btoa(window.encodeURIComponent(JSON.stringify(_subconfig)))
                } catch {
                } catch (e) {
                  console.warn('Stringify Failure')
                  _subconfig = ''
                }
@@ -822,16 +778,6 @@
        duration: 5
      })
    } else {
      // 基本信息验证
      if (!config.fstMenuId || !config.ParentId || !config.MenuName || !config.MenuNo) {
        notification.warning({
          top: 92,
          message: this.state.dict['model.menu.basemsg'],
          duration: 5
        })
        this.setState({activeKey: '0'})
        return
      }
      if (!is(fromJS(originMenu), fromJS(config))) { // 菜单信息变化时,提示保存
        notification.warning({
          top: 92,
@@ -841,7 +787,7 @@
        return
      }
      let submenu = menu.fstMenuList.filter(item => item.MenuID === config.fstMenuId)[0]
      let submenu = menu.fstMenuList.filter(_menu => _menu.MenuID === config.fstMenuId)[0]
      let _Menu = {
        ...menu,
@@ -860,17 +806,17 @@
      let isbutton = true
      let _btnTab = null
      
      if (type === 'button' && item.OpenType === 'pop') {
        _view = 'Modal'             // 表单页面
      } else if (type === 'button' && (item.OpenType === 'tab' || item.OpenType === 'blank')) {
        _view = item.tabTemplate    // 新标签页模板
      if (type === 'button' && (item.OpenType === 'pop' || item.execMode === 'pop')) {
        _view = 'Modal'      // 表单页面
      } else if (type === 'button' && item.OpenType === 'tab') {
        _view = 'FormTab'    // 表单标签页模板
        _btnTab = item
      } else if (type === 'button' && item.OpenType === 'popview') {
        _view = item.tabType        // 新弹窗标签模板
        _view = 'SubTable'   // 新弹窗标签模板 tabType 属性已去除
        uuid = item.linkTab
        isbutton = false
      } else if (type === 'tab') {
        _view = item.type           // 标签模板
        _view = 'SubTable'   // 标签模板
        uuid = item.linkTab
        isbutton = false
      }
@@ -1020,9 +966,39 @@
      }
    })
    
    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 (btn.intertype === 'custom' && btn.callbackType === 'script' && (!btn.verify || !btn.verify.cbScripts || !btn.verify.cbScripts.filter(item => item.status !== 'false').length === 0)) {
        notification.warning({
          top: 92,
          message: `按钮《${btn.label}》未设置回调脚本, 将不会生效!`,
          duration: 5
        })
      }
    })
    if (config.setting.interType === 'system' && config.setting.default !== 'false' && !config.setting.dataresource) {
      return '菜单尚未设置数据源,不可启用!'
    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) {
@@ -1099,28 +1075,6 @@
  }
  
  /**
   * @description 更新常用表信息,快捷添加后更新配置信息
   */
  updatetable = (config, fields) => {
    const { tableFields } = this.state
    this.setState({
      config: config,
      tableFields: fields ? fields : tableFields
    })
  }
  /**
   * @description 更新标签配置信息
   */
  updatetabs = (config) => {
    this.setState({
      config: config
    })
  }
  /**
   * @description 更新配置信息
   */
  updateconfig = (config) => {
@@ -1133,7 +1087,7 @@
    const { menu } = this.props
    const { activeKey, config, chartview } = this.state
    const confActions = config.action.filter(_action => !_action.origin && (['pop', 'popview', 'blank'].includes(_action.OpenType) || (_action.OpenType === 'tab' && _action.tabTemplate === 'FormTab')))
    const confActions = config.action.filter(_action => !_action.origin && (['pop', 'popview'].includes(_action.OpenType) || (_action.OpenType === 'tab' && _action.tabTemplate === 'FormTab') || (_action.OpenType === 'funcbutton' && _action.execMode === 'pop')))
    let configTabs = []
    config.tabgroups.forEach(group => {
@@ -1155,11 +1109,15 @@
                  dict={this.state.dict}
                  updatemenu={this.updateconfig}
                />
                {config ? <UrlFieldComponent
                  config={config}
                  updateConfig={this.updateconfig}
                /> : null}
                {/* 表名添加 */}
                <TableComponent
                  config={config}
                  containerId="main-basedata"
                  updatetable={this.updatetable}
                  updatetable={this.updateconfig}
                />
              </Panel>
              {/* 搜索条件添加 */}
@@ -1170,7 +1128,6 @@
                <FieldsComponent
                  config={config}
                  type="search"
                  tableFields={this.state.tableFields}
                  updatefield={this.updateconfig}
                />
              </Panel>
@@ -1210,7 +1167,6 @@
                <FieldsComponent
                  config={config}
                  type="columns"
                  tableFields={this.state.tableFields}
                  updatefield={this.updateconfig}
                />
              </Panel>
@@ -1250,6 +1206,7 @@
              </div>
            } bordered={false} extra={
              <div>
                <ReplaceField type="table" config={config} updateConfig={this.updateconfig}/>
                <EditComponent dict={this.state.dict} options={['search', 'action', 'columns']} config={this.state.config} MenuID={this.props.menu.MenuID} thawButtons={this.state.thawButtons} refresh={this.editConfig}/>
                <Switch className="big" checkedChildren={this.state.dict['model.enable']} unCheckedChildren={this.state.dict['model.disable']} checked={this.state.config.enabled} onChange={this.onEnabledChange} />
                <Button type="primary" onClick={this.submitConfig} loading={this.state.menuloading}>{this.state.dict['model.save']}</Button>
@@ -1321,7 +1278,7 @@
                config={config}
                tabs={this.state.tabviews}
                setSubConfig={(item) => this.setSubConfig(item, 'tab')}
                updatetabs={this.updatetabs}
                updatetabs={this.updateconfig}
              />
            </Card>
          </div>