king
2020-11-18 d3272e82652361e5e9bd045925222ef042b6731f
src/views/menudesign/index.jsx
@@ -22,8 +22,10 @@
const { confirm } = Modal
const _locale = localStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS
const MenuForm = asyncComponent(() => import('./menuform'))
const HomeForm = asyncComponent(() => import('./homeform'))
const PrintMenuForm = asyncComponent(() => import('./printmenuform'))
const Header = asyncComponent(() => import('@/menu/header'))
const MenuForm = asyncComponent(() => import('@/menu/menuform'))
const SourceWrap = asyncComponent(() => import('@/menu/modelsource'))
const MenuShell = asyncComponent(() => import('@/menu/menushell'))
const BgController = asyncComponent(() => import('@/menu/bgcontroller'))
@@ -89,7 +91,13 @@
  closeView = () => {
    const { oriConfig, config } = this.state
    if (!is(fromJS(oriConfig), fromJS(config))) {
    let _config = fromJS(config).toJS()
    delete _config.fstMenuList
    delete _config.permFuncField
    delete _config.sysRoles
    delete _config.tableFields
    if (!is(fromJS(oriConfig), fromJS(_config))) {
      confirm({
        title: '配置已修改,放弃保存吗?',
        content: '',
@@ -103,17 +111,141 @@
    }
  }
  getMenuParam = () => {
    const { MenuId, ParentId, MenuName, MenuNo, MenuType } = this.state
    let param = {
      func: 'sPC_Get_LongParam',
      MenuID: MenuId
    }
    Api.getSystemConfig(param).then(result => {
      if (result.status) {
        let config = null
        try {
          config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
        } catch (e) {
          console.warn('Parse Failure')
          config = null
        }
        if (!config) {
          config = {
            version: 1.0,
            uuid: MenuId,
            MenuID: MenuId,
            parentId: ParentId,
            Template: 'CustomPage',
            easyCode: '',
            enabled: false,
            MenuName: MenuName,
            MenuNo: MenuNo,
            tables: [],
            components: [],
            style: {
              backgroundColor: '#ffffff', backgroundImage: '',
              paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'
            },
            MenuType: MenuType
          }
          if (MenuType === 'billPrint') {
            config.style.paddingTop = '50px'
            config.style.paddingBottom = '50px'
            config.style.paddingLeft = '30px'
            config.style.paddingRight = '30px'
          }
        } else {
          config.uuid = MenuId
          config.MenuID = MenuId
          config.MenuType = config.MenuType || MenuType
        }
        if (MenuType === 'billPrint') {
          config.fstMenuId = 'BillPrintTemp'
          config.parentId = 'BillPrintTemp'
          config.MenuName = MenuName
          config.MenuNo = MenuNo
          config.firstCount = config.firstCount || 5
          config.everyPCount = config.everyPCount || 5
          config.lastCount = config.lastCount || ''
        }
        this.setState({
          oriConfig: config,
          config: fromJS(config).toJS(),
          openEdition: result.open_edition || '',
        })
        this.getRoleFields()
      } else {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
      }
    })
  }
  getMenuMessage = () => {
    const { config } = this.state
    let buttons = []
    let _sort = 1
    let traversal = (components) => {
      components.forEach(item => {
        if (item.type === 'tabs') {
          item.subtabs.forEach(tab => {
            traversal(tab.components)
          })
        } else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
          item.subcards.forEach(card => {
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
              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
              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.action && item.action.forEach(btn => {
            buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
            _sort++
          })
        }
      })
    }
    traversal(config.components)
    return buttons
  }
  submitConfig = () => {
    const { config, openEdition } = this.state
    if (config.MenuType === 'billPrint' && (!config.MenuName || !config.MenuNo)) {
    if (config.MenuType === 'billPrint' && (!config.firstCount || !config.everyPCount)) {
      notification.warning({
        top: 92,
        message: '请完善基本信息!',
        duration: 5
      })
      return
    } else if (config.MenuType === 'custom' && (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId)) {
    } else if (config.MenuType === 'home' && (config.cacheUseful === 'true' && !config.cacheTime)) {
      notification.warning({
        top: 92,
        message: '请完善菜单基本信息!',
        duration: 5
      })
      return
    } else if (config.MenuType === 'custom' && (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId || (config.cacheUseful === 'true' && !config.cacheTime))) {
      notification.warning({
        top: 92,
        message: '请完善菜单基本信息!',
@@ -132,21 +264,6 @@
    delete _config.sysRoles
    delete _config.tableFields
    let funcs = []
    if (config.MenuType !== 'billPrint') {
      _config.components.forEach(component => {
        if (component.setting && component.setting.innerFunc) {
          funcs.push(`select '${_config.uuid}' as MenuID,'${component.setting.innerFunc}' as ProcName,'${component.setting.name}' as MenuName`)
        }
        if (component.action) {
          component.action.forEach(item => {
            if (!item.innerFunc) return
            funcs.push(`select '${_config.uuid}' as MenuID,'${item.innerFunc}' as ProcName,'${item.label}' as MenuName`)
          })
        }
      })
    }
    let param = {
      func: 'sPC_TrdMenu_AddUpt',
      FstID: _config.fstMenuId || '',
@@ -159,8 +276,8 @@
      MenuName: _config.MenuName || '',
      PageParam: JSON.stringify({Template: 'CustomPage', OpenType: 'newtab'}),
      LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(_config))),
      LText: funcs.join(' union all '),
      LTexttb: '', // 表名
      LText: '',
      LTexttb: ''
    }
    param.LText = Utils.formatOptions(param.LText)
@@ -169,6 +286,28 @@
    if (openEdition) { // 版本管理
      param.open_edition = openEdition
    }
    let btnParam = {             // 添加菜单按钮
      func: 'sPC_Button_AddUpt',
      Type: 40,                  // 添加菜单下的按钮type为40,按钮下的按钮type为60
      ParentID: _config.uuid,
      MenuNo: _config.MenuNo,
      Template: 'CustomPage',
      PageParam: '',
      LongParam: '',
      LText: []
    }
    if (config.MenuType !== 'billPrint') {
      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)
    } else {
      btnParam.LText = ''
    }
    this.setState({
@@ -223,7 +362,7 @@
        Api.getSystemConfig(param).then(response => {
          if (response.status) {
            this.setState({
              oriConfig: fromJS(config).toJS(),
              oriConfig: fromJS(_config).toJS(),
              openEdition: response.open_edition || '',
              menuloading: false
            })
@@ -245,98 +384,6 @@
          }
        })
      })
    })
    // Api.getSystemConfig(param).then(response => {
    //   if (response.status) {
    //     this.setState({
    //       oriConfig: fromJS(config).toJS(),
    //       openEdition: response.open_edition || '',
    //       menuloading: false
    //     })
    //     notification.success({
    //       top: 92,
    //       message: '保存成功',
    //       duration: 2
    //     })
    //   } else {
    //     this.setState({
    //       openEdition: response.open_edition || '',
    //       menuloading: false
    //     })
    //     notification.warning({
    //       top: 92,
    //       message: response.message,
    //       duration: 5
    //     })
    //   }
    // })
  }
  getMenuParam = () => {
    const { MenuId, ParentId, MenuName, MenuNo, MenuType } = this.state
    let param = {
      func: 'sPC_Get_LongParam',
      MenuID: MenuId
    }
    Api.getSystemConfig(param).then(result => {
      if (result.status) {
        let config = null
        try {
          config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
        } catch (e) {
          console.warn('Parse Failure')
          config = null
        }
        if (!config) {
          config = {
            version: 1.0,
            uuid: MenuId,
            MenuID: MenuId,
            parentId: ParentId,
            Template: 'CustomPage',
            MenuType: MenuType,
            easyCode: '',
            enabled: false,
            MenuName: MenuName,
            MenuNo: MenuNo,
            tables: [],
            components: [],
            style: {
              backgroundColor: '#ffffff', backgroundImage: '',
              paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'
            }
          }
        } else {
          config.uuid = MenuId
          config.MenuID = MenuId
          config.MenuType = config.MenuType || MenuType
        }
        if (MenuType === 'billPrint') {
          config.FstID = 'BillPrintTemp'
          config.SndID = 'BillPrintTemp'
          config.ParentID = 'BillPrintTemp'
        }
        this.setState({
          oriConfig: config,
          config: fromJS(config).toJS(),
          openEdition: result.open_edition || '',
        })
        this.getRoleFields()
      } else {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
      }
    })
  }
@@ -396,22 +443,6 @@
    const { config } = this.state
    let error = ''
    if (!config.MenuID) {
      notification.warning({
        top: 92,
        message: '请完善菜单基本信息!',
        duration: 5
      })
      return
    } else if (config.MenuType === 'custom' && (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId)) {
      notification.warning({
        top: 92,
        message: '请完善菜单基本信息!',
        duration: 5
      })
      return
    }
    config.components.forEach(item => {
      if (error) return
      if (item.subtype === 'propcard' && item.wrap.datatype === 'static') return
@@ -421,7 +452,7 @@
          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) {
        } else if (item.setting.interType && !item.setting.primaryKey && config.MenuType !== 'billPrint') {
          error = `组件《${item.name}》未设置主键!`
        }
      }
@@ -474,7 +505,7 @@
    return (
      <ConfigProvider locale={_locale}>
        <div className="pc-menu-view" id="view">
          <Header view="design" closeView={this.closeView} />
          <Header />
          <DndProvider backend={HTML5Backend}>
            <div className="menu-body">
              <div className="menu-setting">
@@ -490,6 +521,16 @@
                      MenuName={MenuName}
                      MenuNo={MenuNo}
                      initMenuList={this.initMenuList}
                      updateConfig={this.updateConfig}
                    /> : null}
                    {config && MenuType === 'home' ? <HomeForm
                      dict={dict}
                      config={config}
                      updateConfig={this.updateConfig}
                    /> : null}
                    {config && MenuType === 'billPrint' ? <PrintMenuForm
                      dict={dict}
                      config={config}
                      updateConfig={this.updateConfig}
                    /> : null}
                    {/* 表名添加 */}
@@ -514,6 +555,7 @@
                  <div>
                    {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}