king
2022-09-06 fa381753ef2a2b25b1c0722549ac17e333da79be
src/views/mobdesign/index.jsx
@@ -1,5 +1,4 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { DndProvider } from 'react-dnd'
import { withRouter } from 'react-router'
import { is, fromJS } from 'immutable'
@@ -56,6 +55,8 @@
window.GLOB.urlFields = []               // url变量
window.GLOB.customMenu = null            // 保存菜单信息
const memberLevel = Utils.getMemberLevel()
class MobDesign extends Component {
  state = {
    localedict: sessionStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS,
@@ -75,11 +76,12 @@
    comloading: false,
    adapters: [],
    viewType: 'menu',
    eyeopen: false
    eyeopen: false,
    modalStatus: false       // 弹窗是否开启,判断ctrl+s是否可用
  }
  UNSAFE_componentWillMount() {
    if (this.props.memberLevel < 30) return
    if (memberLevel < 30) return
    try {
      let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
@@ -149,18 +151,27 @@
  }
  componentDidMount () {
    if (this.props.memberLevel < 30) {
    if (memberLevel < 30) {
      document.getElementById('mk-mob-design-view').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh; height: 100vh; background: #fff;">本应用没有PC端页面的编辑权限,请联系管理员!</div>'
      return
    }
    MKEmitter.addListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.addListener('modalStatus', this.modalStatus)
    MKEmitter.addListener('triggerMenuSave', this.submitConfig)
    MKEmitter.addListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
    setTimeout(() => {
      this.updateCustomComponent()
      if (sessionStorage.getItem('app_custom_components')) {
        let list = sessionStorage.getItem('app_custom_components')
        list = JSON.parse(list)
        this.setCustomComponent(list)
      } else {
        this.updateCustomComponent()
      }
      this.getAppPictures()
      this.getSmStemp()
      this.getRoleFields()
      setGLOBFuncs()
    }, 1000)
@@ -183,6 +194,15 @@
      let _shortcut = `${preKey}+${keyCode}`
      if (_shortcut === 'ctrl+83') {
        if (this.state.modalStatus) {
          notification.warning({
            top: 92,
            message: '请保存' + this.state.modalStatus,
            duration: 5
          })
          return false
        }
        let node = document.getElementById('save-modal-config')
        if (!node) {
          node = document.getElementById('save-config')
@@ -203,10 +223,15 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.removeListener('modalStatus', this.modalStatus)
    MKEmitter.removeListener('triggerMenuSave', this.submitConfig)
    MKEmitter.removeListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
  }
  modalStatus = (val) => {
    this.setState({modalStatus: val})
  }
  getSmStemp = () => {
@@ -396,36 +421,46 @@
      typename: sessionStorage.getItem('typename'),
      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,
            width: config.width || 24,
            config
          })
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      } else if (res.cus_list) {
        sessionStorage.setItem('app_custom_components', JSON.stringify(res.cus_list))
        this.setCustomComponent(res.cus_list)
      }
      this.setState({customComponents: coms})
      this.getRoleFields()
    })
  }
  setCustomComponent = (cus_list) => {
    let coms = []
    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) => {
@@ -534,7 +569,8 @@
            Template: 'webPage',
            enabled: false,
            MenuName: urlParam.MenuName || '',
            MenuNo: urlParam.MenuNo || '',
            // MenuNo: urlParam.MenuNo || '',
            MenuNo: '',
            tables: [],
            components: [],
            viewType: 'menu',
@@ -784,7 +820,8 @@
      config.MenuID = MenuId
      config.open_edition = ''
      config.MenuName = urlParam.MenuName || ''
      config.MenuNo = urlParam.MenuNo || ''
      // config.MenuNo = urlParam.MenuNo || ''
      config.MenuNo = ''
      let indeComs = []
      config.components.forEach(item => {
@@ -940,7 +977,6 @@
          item.action && item.action.forEach(btn => {
            if (btn.hidden === 'true') return
            this.checkBtn(btn)
            m.children.push({
              key: btn.uuid,
              title: btn.label,
@@ -951,7 +987,6 @@
              if (cell.eleType !== 'button') return
              if (cell.hidden === 'true') return
              this.checkBtn(cell)
              m.children.push({
                key: cell.uuid,
                title: cell.label,
@@ -964,7 +999,6 @@
              if (cell.eleType !== 'button') return
              if (cell.hidden === 'true') return
              this.checkBtn(cell)
              m.children.push({
                key: cell.uuid,
                title: cell.label,
@@ -976,7 +1010,6 @@
            if (cell.eleType !== 'button') return
            if (cell.hidden === 'true') return
            this.checkBtn(cell)
            m.children.push({
              key: cell.uuid,
              title: cell.label,
@@ -994,17 +1027,18 @@
            }
          })
        } else if (item.type === 'form') {
          m.children = item.subcards.map(m => {
            return {
              key: m.uuid,
              title: m.setting.title
            }
          })
          if (item.subtype !== 'simpleform') {
            m.children = item.subcards.map(m => {
              return {
                key: m.uuid,
                title: m.setting.title
              }
            })
          }
        } else if (item.type === 'table' && item.subtype === 'normaltable') {
          item.action && item.action.forEach(btn => {
            if (btn.hidden === 'true') return
            this.checkBtn(btn)
            m.children.push({
              key: btn.uuid,
              title: btn.label,
@@ -1015,7 +1049,6 @@
            col.elements.forEach(btn => {
              if (btn.hidden === 'true') return
              this.checkBtn(btn)
              m.children.push({
                key: btn.uuid,
                title: btn.label,
@@ -1071,7 +1104,8 @@
                menus.push({
                  MenuID: m.uuid,
                  MenuName: m.setting.name,
                  MenuNo: m.setting.MenuNo
                  // MenuNo: m.setting.MenuNo
                  MenuNo: ''
                })
              }
            } else if (m.setting.type === 'linkmenu' && menuObj[m.setting.linkMenuId]) {
@@ -1175,26 +1209,6 @@
    })
    return menus
  }
  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
        })
      }
    }
  }
  getMiniStyle = (config) => {
@@ -1309,9 +1323,8 @@
      config.loginview = false
      config.tabview = false
      if (config.permission !== 'true') {
      if (roleParam.children.length === 0) {
        roleParam.pass = true
        roleParam.children = []
      }
      config.components.forEach(item => {
@@ -1326,6 +1339,19 @@
      if (adapters.includes('wxmini')) {
        config = this.getMiniStyle(config)
        if (config.statusBarbgColor && !config.statusBarHexColor && /^rgba/ig.test(config.statusBarbgColor)) {
          let hexify = (color) => {
            let values = color.replace(/rgba?\(/, '').replace(/\)/, '').replace(/[\s+]/g, '').split(',')
            let a = parseFloat(values[3] || 1)
            let r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255)
            let g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255)
            let b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255)
            return '#' + ('0' + r.toString(16)).slice(-2) + ('0' + g.toString(16)).slice(-2) + ('0' + b.toString(16)).slice(-2)
          }
          config.statusBarHexColor = hexify(config.statusBarbgColor)
        }
      }
      let subMenus = this.getSubMenus()
@@ -1540,7 +1566,7 @@
        }
        MKEmitter.emit('completeSave')
      })
    }, 300)
    }, 300 + (+sessionStorage.getItem('mkDelay')))
  }
  getRoleFields = () => {
@@ -1593,16 +1619,16 @@
    let searchSum = 0
    let swipes = []
    let check = (components) => {
    let check = (components, level, sign) => {
      components.forEach(item => {
        if (error) return
        if (item.type === 'tabs') {
          item.subtabs.forEach(tab => {
            check(tab.components)
            check(tab.components, level + 1, tab.uuid)
          })
          return
        } else if (item.type === 'group') {
          check(item.components)
          check(item.components, level, sign)
          return
        } else if (item.type === 'navbar' && !item.wrap.MenuNo) {
          error = `导航栏《${item.name}》未设置菜单参数!`
@@ -1615,46 +1641,20 @@
          if (!item.wrap.field) {
            error = `搜索条件《${item.name}》未设置搜索字段!`
          }
        } else if (item.subtype === 'propcard' && item.subcards.length === 0) {
          error = `组件《${item.name}》中卡片不可为空!`
          return
        } else if (item.type === 'login' && !item.wrap.linkmenu && item.wrap.link !== 'menu') {
          error = '登录组件未设置关联菜单!'
          return
        }
        if (item.wrap && item.wrap.pagestyle === 'slide') {
          swipes.push(item.name)
        if (item.wrap && item.wrap.pagestyle === 'slide' && item.pageable && item.setting.laypage !== 'false') {
          // swipes.push(item.name)
          swipes.push({level, name: item.name, sign})
        }
        if (['voucher'].includes(item.subtype)) return
        if (['propcard', 'brafteditor', 'sandbox', 'tabbar', 'stepform', 'tabform'].includes(item.subtype) && item.wrap.datatype === 'static') return
        if (['balcony'].includes(item.type) && item.wrap.datatype === 'static') return
        if (['menubar'].includes(item.type) && item.wrap.datatype !== 'dynamic') 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 && !['navbar', 'balcony', 'menubar'].includes(item.type)) {
            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}》坐标轴尚未设置!`
        }
        item.errors && item.errors.forEach(err => {
          if (err.level !== 0 || error) return
          error = `组件《${item.name}》${err.detail}`
        })
      })
    }
    check(config.components)
    check(config.components, 1, 'view')
    // if (!error && viewType === 'userbind' && config.components.filter(item => item.type === 'login').length === 0) {
    //   error = '用户绑定页面必须添加登录。'
@@ -1662,8 +1662,27 @@
    if (!error && searchSum > 1) {
      error = '搜索组件与导航栏的搜索功能不可同时使用。'
    } else if (!error && swipes.length > 1) {
      error = `页面中不可同时使用多个滑动加载组件。(${swipes.join('、')})`
    } else if (!error && swipes.length > 0) {
      swipes.forEach(cell => {
        if (!error && cell.level > 2) {
          error = `不可在多层标签页中使用滑动加载组件。(${cell.name})`
        }
      })
      if (!error) {
        let levels = swipes.map(s => s.level)
        levels = Array.from(new Set(levels))
        if (levels.length > 1) {
          error = `不可在页面与标签页中同时使用滑动加载组件。(${swipes.map(s => s.name).join('、')})`
        }
      }
      if (!error) {
        let signs = swipes.map(s => s.sign)
        signs = Array.from(new Set(signs))
        if (signs.length !== swipes.length) {
          error = `页面中(或同一标签页中)不可同时使用多个滑动加载组件。(${swipes.map(s => s.name).join('、')})`
        }
      }
    }
    if (show && error) {
@@ -1916,7 +1935,7 @@
              <div className="pc-setting-tools">
                <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
                  {/* 基本信息 */}
                  <Panel header={dict['mob.basemsg']} forceRender className="basedata" key="basedata">
                  <Panel header="基本信息" forceRender className="basedata" key="basedata">
                    {/* 菜单信息 */}
                    {config ? <MenuForm
                      dict={dict}
@@ -1985,14 +2004,4 @@
  }
}
const mapStateToProps = (state) => {
  return {
    memberLevel: state.memberLevel
  }
}
const mapDispatchToProps = () => {
  return {}
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(MobDesign))
export default withRouter(MobDesign)