king
2021-01-14 3cbad93c94c39730e45600efeabdfebcd424c2cc
src/menu/popview/index.jsx
@@ -11,6 +11,7 @@
import Utils from '@/utils/utils.js'
import zhCN from '@/locales/zh-CN/mob.js'
import enUS from '@/locales/en-US/mob.js'
import MKEmitter from '@/utils/events.js'
import asyncComponent from '@/utils/asyncComponent'
import { modifyCustomMenu } from '@/store/action'
@@ -23,7 +24,9 @@
const SourceWrap = asyncComponent(() => import('@/menu/modelsource'))
const MenuShell = asyncComponent(() => import('@/menu/menushell'))
const BgController = asyncComponent(() => import('@/menu/bgcontroller'))
const PasteController = asyncComponent(() => import('@/menu/pastecontroller'))
const PaddingController = asyncComponent(() => import('@/menu/padcontroller'))
const StyleCombControlButton = asyncComponent(() => import('@/menu/stylecombcontrolbutton'))
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
sessionStorage.setItem('isEditState', 'true')
@@ -46,6 +49,7 @@
    oriConfig: null,
    openEdition: '',
    config: null,
    customComponents: []
  }
  UNSAFE_componentWillMount() {
@@ -56,6 +60,13 @@
    }, () => {
      this.getMenuParam()
    })
  }
  componentDidMount () {
    MKEmitter.addListener('delButtons', this.delButtons)
    MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
    this.updateCustomComponent()
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -69,6 +80,67 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('delButtons', this.delButtons)
    MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
  }
  updateCustomComponent = () => {
    Api.getSystemConfig({
      func: 's_get_custom_components',
      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
          coms.push({
            type: 'menu',
            title: item.c_name,
            url: item.images,
            component: config.type,
            subtype: config.subtype,
            config
          })
        })
      }
      this.setState({customComponents: coms})
    })
  }
  updateComponentStyle = (parentId, keys, style) => {
    const { config } = this.state
    if (config.uuid !== parentId) return
    let components = config.components.map(item => {
      if (keys.includes(item.uuid)) {
        item.style = {...item.style, ...style}
      }
      return item
    })
    this.setState({
      config: {...config, components: []}
    }, () => {
      this.setState({
        config: {...config, components: components}
      })
    })
  }
  delButtons = (items) => {
    this.setState({delButtons: [...this.state.delButtons, ...items]})
  }
  closeView = () => {
@@ -98,7 +170,8 @@
  }
  getMenuParam = () => {
    const { MenuId, MenuType } = this.state
    const { btn } = this.props
    const { MenuId } = this.state
    let param = {
      func: 'sPC_Get_LongParam',
@@ -123,18 +196,20 @@
            MenuID: MenuId,
            Template: 'CustomPage',
            enabled: false,
            MenuName: btn.config.MenuName + '-' + btn.label,
            MenuNo: '',
            tables: [],
            components: [],
            viewType: 'popview',
            style: {
              backgroundColor: '#ffffff', backgroundImage: '',
              paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'
            },
            MenuType: MenuType
          }
        } else {
          config.uuid = MenuId
          config.MenuID = MenuId
          config.MenuType = config.MenuType || MenuType
          config.Template = 'CustomPage'
        }
        this.setState({
@@ -142,6 +217,8 @@
          config: fromJS(config).toJS(),
          openEdition: result.open_edition || '',
        })
        this.props.modifyCustomMenu(config)
      } else {
        notification.warning({
          top: 92,
@@ -163,6 +240,8 @@
          item.subtabs.forEach(tab => {
            traversal(tab.components)
          })
        } else if (item.type === 'group') {
          traversal(item.components)
        } else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
          item.action && item.action.forEach(btn => {
            buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
@@ -215,6 +294,8 @@
        item.subtabs.forEach(tab => {
          tab.components = this.filterConfig(tab.components)
        })
      } else if (item.type === 'group') {
        item.components = this.filterConfig(item.components)
      } else if (item.type === 'table' && item.subtype === 'normaltable') {
        item.search = item.search.filter(a => !a.origin)
        item.action = item.action.filter(a => !a.origin)
@@ -225,11 +306,11 @@
  }
  submitConfig = () => {
    // const { btn } = this.props
    const { btn } = this.props
    const { openEdition, delButtons } = this.state
    let config = fromJS(this.state.config).toJS()
    if (config.cacheUseful === 'true' && !config.cacheTime) {
    if ((config.cacheUseful === 'true' && !config.cacheTime) || !config.MenuNo || !config.MenuName) {
      notification.warning({
        top: 92,
        message: '请完善菜单基本信息!',
@@ -247,14 +328,15 @@
    let _config = fromJS(config).toJS()
    delete _config.tableFields
    let _name = (btn.component.name ? btn.component.name + '-' : '') + btn.label
    let param = {
      func: 'sPC_Tab_AddUpt',
      func: 'sPC_ButtonParam_AddUpt',
      ParentID: btn.config.uuid,
      MenuID: _config.uuid,
      MenuNo: _config.tabNo,
      MenuNo: _config.MenuNo || '',
      Template: 'CustomPage',
      MenuName: _config.tabName,
      Remark: '',
      Sort: 0,
      MenuName: _name,
      PageParam: JSON.stringify({Template: 'CustomPage'}),
      LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
    }
@@ -265,7 +347,7 @@
    let btnParam = {             // 添加菜单按钮
      func: 'sPC_Button_AddUpt',
      Type: 40,                  // 添加菜单下的按钮type为40,按钮下的按钮type为60
      Type: 60,                  // 添加菜单下的按钮type为40,按钮下的按钮type为60
      ParentID: _config.uuid,
      MenuNo: _config.MenuNo,
      Template: 'CustomPage',
@@ -444,9 +526,18 @@
    this.props.modifyCustomMenu(config)
  }
  insert = (item) => {
    let config = fromJS(this.state.config).toJS()
    config.components.push(item)
    this.setState({config})
    this.props.modifyCustomMenu(config)
  }
  render () {
    const { btn } = this.props
    const { activeKey, MenuType, dict, config, menuloading } = this.state
    const { activeKey, MenuType, dict, config, menuloading, customComponents } = this.state
    return (
      <DndProvider backend={HTML5Backend}>
@@ -464,6 +555,9 @@
              <Panel header={dict['mob.component']} key="component">
                <SourceWrap MenuType={MenuType} />
              </Panel>
              {customComponents && customComponents.length ? <Panel header="自定义组件" key="cuscomponent">
                <SourceWrap components={customComponents} MenuType={MenuType} />
              </Panel> : null}
              <Panel header={'背景'} key="background">
                {config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
              </Panel>
@@ -477,6 +571,8 @@
              <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>