king
2022-05-12 b8aa5da1b2873bea760483cc5ab335fde9fb6de6
src/menu/popview/index.jsx
@@ -1,11 +1,11 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { DndProvider } from 'react-dnd'
import { is, fromJS } from 'immutable'
import moment from 'moment'
import HTML5Backend from 'react-dnd-html5-backend'
import { notification, Modal, Collapse, Card, Switch, Button } from 'antd'
import { EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons'
import Api from '@/api'
import Utils from '@/utils/utils.js'
@@ -13,7 +13,6 @@
import enUS from '@/locales/en-US/mob.js'
import MKEmitter from '@/utils/events.js'
import asyncComponent from '@/utils/asyncComponent'
import { modifyCustomMenu } from '@/store/action'
import './index.scss'
@@ -21,8 +20,11 @@
const { confirm } = Modal
const MenuForm = asyncComponent(() => import('./menuform'))
const SourceWrap = asyncComponent(() => import('@/menu/modelsource'))
const Versions = asyncComponent(() => import('@/menu/versions'))
const Header = asyncComponent(() => import('@/menu/header'))
const SourceWrap = asyncComponent(() => import('@/menu/modulesource'))
const MenuShell = asyncComponent(() => import('@/menu/menushell'))
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
const BgController = asyncComponent(() => import('@/menu/bgcontroller'))
const PasteController = asyncComponent(() => import('@/menu/pastecontroller'))
const PaddingController = asyncComponent(() => import('@/menu/padcontroller'))
@@ -38,17 +40,16 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    MenuType: '',
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    MenuId: '',
    MenuNo: '',
    tableFields: [],
    delButtons: [],
    activeKey: 'basedata',
    menuloading: false,
    oriConfig: null,
    openEdition: '',
    config: null,
    customComponents: [],
    comloading: false,
    eyeopen: false
  }
  UNSAFE_componentWillMount() {
@@ -63,7 +64,10 @@
  componentDidMount () {
    MKEmitter.addListener('delButtons', this.delButtons)
    MKEmitter.addListener('triggerMenuSave', this.submitConfig)
    MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
    this.updateCustomComponent()
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -78,7 +82,45 @@
      return
    }
    MKEmitter.removeListener('delButtons', this.delButtons)
    MKEmitter.removeListener('triggerMenuSave', this.submitConfig)
    MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
  }
  updateCustomComponent = () => {
    Api.getSystemConfig({
      func: 's_get_custom_components',
      typename: sessionStorage.getItem('appType'),
      typecharone: ''
    }).then(res => {
      let coms = []
      if (res.cus_list && res.cus_list.length > 0) {
        res.cus_list.forEach(item => {
          let config = ''
          try {
            config = JSON.parse(window.decodeURIComponent(window.atob(item.long_param)))
          } catch (e) {
            console.warn('Parse Failure')
            config = ''
          }
          if (!config || !item.c_name) return
          window.GLOB.UserComponentMap.set(item.c_id, item.c_name)
          coms.push({
            uuid: item.c_id,
            type: 'menu',
            title: item.c_name,
            url: item.images,
            component: config.type,
            subtype: config.subtype,
            config
          })
        })
      }
      this.setState({customComponents: coms})
    })
  }
  updateComponentStyle = (parentId, keys, style) => {
@@ -94,10 +136,11 @@
    })
    this.setState({
      config: {...config, components: []}
      config: {...config, components},
      comloading: true
    }, () => {
      this.setState({
        config: {...config, components: components}
        comloading: false
      })
    })
  }
@@ -114,11 +157,9 @@
      return
    }
    let _config = fromJS(config).toJS()
    delete _config.tableFields
    const _this = this
    if (!is(fromJS(oriConfig), fromJS(_config))) {
    if (!is(fromJS(oriConfig), fromJS(config))) {
      confirm({
        title: '配置已修改,放弃保存吗?',
        content: '',
@@ -139,6 +180,11 @@
    let param = {
      func: 'sPC_Get_LongParam',
      MenuID: MenuId
    }
    if (sessionStorage.getItem('appType') === 'pc') {
      param.TypeCharOne = sessionStorage.getItem('kei_no')
      param.Typename = 'pc'
    }
    Api.getSystemConfig(param).then(result => {
@@ -172,15 +218,17 @@
        } else {
          config.uuid = MenuId
          config.MenuID = MenuId
          config.Template = 'CustomPage'
        }
        config.open_edition = result.open_edition || ''
        this.setState({
          oriConfig: config,
          config: fromJS(config).toJS(),
          openEdition: result.open_edition || '',
          config: fromJS(config).toJS()
        })
        this.props.modifyCustomMenu(config)
        window.GLOB.customMenu = config
      } else {
        notification.warning({
          top: 92,
@@ -191,7 +239,7 @@
    })
  }
  getMenuMessage = () => {
  getMenuMessage = (delButtons) => {
    const { config } = this.state
    let buttons = []
    let _sort = 1
@@ -206,37 +254,88 @@
          traversal(item.components)
        } else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
          item.action && item.action.forEach(btn => {
            if (btn.hidden === 'true') {
              delButtons.push(btn.uuid)
              return
            }
            this.checkBtn(btn)
            buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
            _sort++
          })
          item.subcards.forEach(card => {
          item.subcards && item.subcards.forEach(card => {
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
              if (cell.hidden === 'true') {
                delButtons.push(cell.uuid)
                return
              }
              this.checkBtn(cell)
              buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
              _sort++
            })
            card.backElements && card.backElements.forEach(cell => {
              if (cell.eleType !== 'button') return
              if (cell.hidden === 'true') {
                delButtons.push(cell.uuid)
                return
              }
              this.checkBtn(cell)
              buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
              _sort++
            })
          })
        } else if (item.type === 'line' || item.type === 'bar') {
        } else if (item.type === 'carousel' || item.type === 'timeline') {
          item.subcards.forEach(card => {
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
              if (cell.hidden === 'true') {
                delButtons.push(cell.uuid)
                return
              }
              this.checkBtn(cell)
              buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
              _sort++
            })
          })
        } else if (item.type === 'balcony') {
          item.elements && item.elements.forEach(cell => {
            if (cell.eleType !== 'button') return
            if (cell.hidden === 'true') {
              delButtons.push(cell.uuid)
              return
            }
            this.checkBtn(cell)
            buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
            _sort++
          })
        } else if (item.type === 'line' || item.type === 'bar' || item.type === 'chart') {
          item.action && item.action.forEach(btn => {
            if (btn.hidden === 'true') {
              delButtons.push(btn.uuid)
              return
            }
            this.checkBtn(btn)
            buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
            _sort++
          })
        } else if (item.type === 'table' && item.subtype === 'normaltable') {
        } else if (item.type === 'table' && (item.subtype === 'normaltable' || item.subtype === 'editable')) {
          item.action && item.action.forEach(btn => {
            if (btn.origin) return
            if (btn.hidden === 'true') {
              delButtons.push(btn.uuid)
              return
            }
            this.checkBtn(btn)
            buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
            _sort++
          })
          item.cols && item.cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.hidden === 'true') {
                delButtons.push(btn.uuid)
                return
              }
              this.checkBtn(btn)
              buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
              _sort++
            })
@@ -248,6 +347,26 @@
    traversal(config.components)
    return buttons
  }
  checkBtn = (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
        })
      }
    }
  }
  filterConfig = (components) => {
@@ -269,7 +388,6 @@
  submitConfig = () => {
    const { btn } = this.props
    const { openEdition, delButtons } = this.state
    let config = fromJS(this.state.config).toJS()
    if ((config.cacheUseful === 'true' && !config.cacheTime) || !config.MenuNo || !config.MenuName) {
@@ -281,52 +399,56 @@
      return
    }
    config.components = this.filterConfig(config.components)
    if (config.enabled && this.verifyConfig()) {
      config.enabled = false
    }
    let _config = fromJS(config).toJS()
    delete _config.tableFields
    let _name = (btn.component.name ? btn.component.name + '-' : '') + btn.label
    let param = {
      func: 'sPC_ButtonParam_AddUpt',
      ParentID: btn.config.uuid,
      MenuID: _config.uuid,
      MenuNo: _config.MenuNo || '',
      Template: 'CustomPage',
      MenuName: _name,
      PageParam: JSON.stringify({Template: 'CustomPage'}),
      LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
    }
    if (openEdition) { // 版本管理
      param.open_edition = openEdition
    }
    let btnParam = {             // 添加菜单按钮
      func: 'sPC_Button_AddUpt',
      Type: 60,                  // 添加菜单下的按钮type为40,按钮下的按钮type为60
      ParentID: _config.uuid,
      MenuNo: _config.MenuNo,
      Template: 'CustomPage',
      PageParam: '',
      LongParam: '',
      LText: []
    }
    btnParam.LText = this.getMenuMessage()
    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)
    this.setState({
      menuloading: true
    }, () => {
    })
    setTimeout(() => {
      config.components = this.filterConfig(config.components)
      if (config.enabled && this.verifyConfig()) {
        config.enabled = false
      }
      let _name = (btn.component.name ? btn.component.name + '-' : '') + btn.label
      let param = {
        func: 'sPC_ButtonParam_AddUpt',
        ParentID: btn.config.uuid,
        MenuID: config.uuid,
        MenuNo: config.MenuNo || '',
        Template: 'CustomPage',
        MenuName: _name,
        PageParam: JSON.stringify({Template: 'CustomPage'}),
        LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config))),
        open_edition: config.open_edition
      }
      let btnParam = {             // 添加菜单按钮
        func: 'sPC_Button_AddUpt',
        Type: 60,                  // 添加菜单下的按钮type为40,按钮下的按钮type为60
        ParentID: config.uuid,
        MenuNo: config.MenuNo,
        Template: 'CustomPage',
        PageParam: '',
        LongParam: '',
        LText: []
      }
      let delButtons = fromJS(this.state.delButtons).toJS()
      if (sessionStorage.getItem('appType') === 'pc') {
        param.TypeCharOne = sessionStorage.getItem('kei_no')
        param.Typename = 'pc'
        btnParam.LText = ''
      } else {
        btnParam.LText = this.getMenuMessage(delButtons)
        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)
      }
      new Promise(resolve => {
        if (delButtons.length === 0) {
          resolve({
@@ -362,9 +484,11 @@
        if (!res) return
        if (res.status) {
          config.open_edition = res.open_edition || ''
          this.setState({
            oriConfig: fromJS(_config).toJS(),
            openEdition: res.open_edition || ''
            config,
            oriConfig: fromJS(config).toJS()
          })
          if (btnParam.LText) {
@@ -389,31 +513,24 @@
        if (!res) return
        
        if (res.status) {
          this.setState({
            menuloading: false,
            config: {...config, components: []}
          }, () => {
            this.setState({
              config: {...this.state.config, components: this.state.oriConfig.components}
            })
          })
          notification.success({
            top: 92,
            message: '保存成功',
            duration: 2
          })
        } else {
          this.setState({
            menuloading: false
          })
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          })
        }
        this.setState({
          menuloading: false
        })
        MKEmitter.emit('completeSave')
      })
    })
    }, 300)
  }
  onEnabledChange = () => {
@@ -432,25 +549,47 @@
    const { config } = this.state
    let error = ''
    config.components.forEach(item => {
      if (error) return
      if (item.subtype === 'propcard' && item.wrap.datatype === 'static') return
    let check = (components) => {
      components.forEach(item => {
        if (error) return
        if (item.type === 'tabs') {
          item.subtabs.forEach(tab => {
            check(tab.components)
          })
          return
        } else if (item.type === 'group') {
          check(item.components)
          return
        }
        if (['propcard', 'brafteditor', 'sandbox', 'stepform', 'tabform'].includes(item.subtype) && item.wrap.datatype === 'static') return
        if (['balcony'].includes(item.type) && item.wrap.datatype === 'static') return
        if (item.setting) {
          if (item.setting.interType === 'system' && item.setting.execute !== 'false' && !item.setting.dataresource) {
            error = `组件《${item.name}》未设置数据源!`
          } else if (item.setting.interType === 'system' && item.setting.execute === 'false' && item.scripts.length === 0) {
            error = `组件《${item.name}》未设置数据源!`
          } else if (!item.setting.primaryKey) {
            error = `组件《${item.name}》未设置主键!`
          } else if (!item.setting.supModule && item.type !== 'balcony') {
            error = `组件《${item.name}》未设置上级组件!`
          }
        }
        if (item.type === 'bar' || item.type === 'line' || item.type === 'pie') {
          if (!item.plot.Xaxis) {
            error = `组件《${item.name}》图表字段尚未设置!`
          }
        } else if (item.type === 'dashboard' && !item.plot.valueField) {
          error = `组件《${item.name}》显示值尚未设置!`
        } else if (item.type === 'scatter' && (!item.plot.Xaxis || !item.plot.Yaxis || !item.plot.gender)) {
          error = `组件《${item.name}》坐标轴尚未设置!`
        } else if (item.type === 'tree' && (!item.wrap.valueField || !item.wrap.labelField || !item.wrap.parentField)) {
          error = `组件《${item.name}》基本信息尚未设置!`
        }
      })
    }
      if (item.setting) {
        if (item.setting.interType === 'system' && item.setting.execute !== 'false' && !item.setting.dataresource) {
          error = `组件《${item.name}》未设置数据源!`
        } else if (item.setting.interType === 'system' && item.setting.execute === 'false' && item.scripts.length === 0) {
          error = `组件《${item.name}》未设置数据源!`
        } else if (item.setting.interType && !item.setting.primaryKey) {
          error = `组件《${item.name}》未设置主键!`
        }
      }
      if (item.type === 'bar' || item.type === 'line' || item.type === 'pie') {
        if (!item.plot.Xaxis) {
          error = `组件《${item.name}》图表字段尚未设置!`
        }
      }
    })
    check(config.components)
    if (show && error) {
      notification.warning({
@@ -469,23 +608,29 @@
      config: config
    })
    this.props.modifyCustomMenu(config)
    window.GLOB.customMenu = config
  }
  resetConfig = (config) => {
    this.setState({
      config,
      comloading: true
    }, () => {
      this.setState({
        comloading: false
      })
    })
    window.GLOB.customMenu = config
  }
  /**
   * @description 更新常用表信息,快捷添加后更新配置信息
   */
  updatetable = (config, fields) => {
    const { tableFields } = this.state
  updatetable = (config) => {
    this.setState({ config })
    config.tableFields = fields ? fields : tableFields
    this.setState({
      tableFields: fields ? fields : tableFields,
      config
    })
    this.props.modifyCustomMenu(config)
    window.GLOB.customMenu = config
  }
  insert = (item) => {
@@ -494,66 +639,83 @@
    config.components.push(item)
    this.setState({config})
    this.props.modifyCustomMenu(config)
    window.GLOB.customMenu = config
    notification.success({
      top: 92,
      message: '粘贴成功!',
      duration: 2
    })
  }
  refreshConfig = () => {
    this.setState({
      delButtons: [],
      activeKey: 'basedata',
      menuloading: false,
      oriConfig: null,
      config: null,
    }, () => {
      this.getMenuParam()
    })
  }
  render () {
    const { btn } = this.props
    const { activeKey, MenuType, dict, config, menuloading } = this.state
    const { activeKey, comloading, dict, config, menuloading, customComponents, MenuId, eyeopen } = this.state
    return (
      <DndProvider backend={HTML5Backend}>
        <div className="menu-body">
          <div className="menu-setting">
            <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
              {/* 基本信息 */}
              <Panel header={dict['mob.basemsg']} key="basedata">
                {/* 菜单信息 */}
                {config ? <MenuForm dict={dict} config={config} btn={btn} updateConfig={this.updateConfig}/> : null}
                {/* 表名添加 */}
                {config ? <TableComponent config={config} updatetable={this.updatetable}/> : null}
              </Panel>
              {/* 组件添加 */}
              <Panel header={dict['mob.component']} key="component">
                <SourceWrap MenuType={MenuType} />
              </Panel>
              <Panel header={'背景'} key="background">
                {config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
              </Panel>
              <Panel header={'内边距'} key="padding">
                {config ? <PaddingController config={config} updateConfig={this.updateConfig} /> : null}
              </Panel>
            </Collapse>
      <div className="pc-poper-view">
        <Header />
        <DndProvider backend={HTML5Backend}>
          <div className="menu-body">
            <div className="menu-setting">
              <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
                {/* 基本信息 */}
                <Panel header={dict['mob.basemsg']} key="basedata">
                  {/* 菜单信息 */}
                  {config ? <MenuForm dict={dict} config={config} btn={btn} updateConfig={this.updateConfig}/> : null}
                  {/* 表名添加 */}
                  {config ? <TableComponent config={config} updatetable={this.updatetable}/> : null}
                </Panel>
                {/* 组件添加 */}
                <Panel header={dict['mob.component']} key="component">
                  <SourceWrap MenuType="" />
                </Panel>
                {customComponents && customComponents.length ? <Panel header="自定义组件" key="cuscomponent">
                  <SourceWrap components={customComponents} MenuType="" />
                </Panel> : null}
                <Panel header={'页面背景'} key="background">
                  {config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
                </Panel>
                <Panel header={'页面内边距'} key="padding">
                  {config ? <PaddingController config={config} updateConfig={this.updateConfig} /> : null}
                </Panel>
              </Collapse>
            </div>
            <div className={'menu-view' + (menuloading ? ' saving' : '') + (eyeopen ? ' eye-open' : '')}>
              <Card title={
                <div> {config && config.MenuName} </div>
              } bordered={false} extra={
                <div>
                  <Button className="mk-border-purple" onClick={() => this.setState({eyeopen: !eyeopen})}>{!eyeopen ? <EyeOutlined /> : <EyeInvisibleOutlined />} 组件名</Button>
                  <Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''} updateConfig={this.refreshConfig}/>
                  <ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
                  <StyleCombControlButton menu={config} />
                  <PasteController insert={this.insert} />
                  {config ? <Switch className="big" checkedChildren={dict['mob.enable']} unCheckedChildren={dict['mob.disable']} checked={config.enabled} onChange={this.onEnabledChange} /> : null}
                  <Button type="primary" id="save-pop-config" onClick={this.submitConfig} loading={menuloading}>{dict['mob.save']}</Button>
                  <Button type="default" onClick={this.closeView}>{dict['mob.return']}</Button>
                </div>
              } style={{ width: '100%' }}>
                {config && !comloading ? <MenuShell menu={config} handleList={this.updateConfig} /> : null}
              </Card>
            </div>
          </div>
          <div className={'menu-view ' + (menuloading ? 'saving' : '')}>
            <Card title={
              <div> {config && config.MenuName} </div>
            } bordered={false} extra={
              <div>
                <StyleCombControlButton menu={config} />
                <PasteController type="menu" Tab={null} insert={this.insert} />
                {config ? <Switch className="big" checkedChildren={dict['mob.enable']} unCheckedChildren={dict['mob.disable']} checked={config.enabled} onChange={this.onEnabledChange} /> : null}
                <Button type="primary" onClick={this.submitConfig} loading={menuloading}>{dict['mob.save']}</Button>
                <Button type="default" onClick={this.closeView}>{dict['mob.return']}</Button>
              </div>
            } style={{ width: '100%' }}>
              {config && config.components ? <MenuShell menu={config} handleList={this.updateConfig} /> : null}
            </Card>
          </div>
        </div>
      </DndProvider>
        </DndProvider>
      </div>
    )
  }
}
const mapStateToProps = () => {
  return {}
}
const mapDispatchToProps = (dispatch) => {
  return {
    modifyCustomMenu: (customMenu) => dispatch(modifyCustomMenu(customMenu))
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(MenuDesign)
export default MenuDesign