king
2023-06-14 08cce3334a2dc81d690b518136b0aaea64e48b0b
src/views/mobdesign/index.jsx
@@ -81,6 +81,14 @@
  }
  UNSAFE_componentWillMount() {
    if (!sessionStorage.getItem('UserID')) {
      sessionStorage.removeItem('isEditState')
      sessionStorage.removeItem('editMenuType')
      sessionStorage.removeItem('appType')
      this.props.history.replace('/login')
      return
    }
    if (memberLevel < 30) return
    try {
      let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
@@ -103,6 +111,7 @@
        window.GLOB.winHeight = 738
        window.GLOB.shellWidth = 376
        window.GLOB.shellHeight = 680
        window.GLOB.curDate = moment().format('YYYY-MM-DD')
        let adapters = sessionStorage.getItem('adapter')
        if (adapters) {
@@ -139,6 +148,7 @@
  }
  componentDidMount () {
    if (!sessionStorage.getItem('UserID')) return
    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
@@ -232,6 +242,8 @@
      _btn.config.MenuID = _btn.uuid
      _btn.config.ParentId = card.uuid
      _btn.config.MenuName = _btn.label
      _btn.config.components = this.updateComponents(_btn.config.components || [])
    } else {
      _btn.config = {
        uuid: _btn.uuid,
@@ -298,15 +310,23 @@
      })
    })
    config.cols && config.cols.forEach(col => {
      if (col.type === 'action') {
    if (config.cols) {
      let loopCol = (cols) => {
        cols.forEach(col => {
          if (col.type === 'colspan') {
            loopCol(col.subcols)
          } else if (col.type === 'custom') {
        col.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
          if (cell.OpenType === 'popview' && popbtns[cell.uuid]) {
            cell.config = popbtns[cell.uuid]
          }
        })
      }
    })
      }
      loopCol(config.cols)
    }
    config.elements && config.elements.forEach(cell => {
      if (cell.eleType !== 'button') return
@@ -604,6 +624,8 @@
          this.setState({
            needUpdate: true
          })
        } else {
          config.components = this.updateComponents(config.components)
        }
        let navItem = null
@@ -823,6 +845,8 @@
          this.setState({
            needUpdate: true
          })
        } else {
          config.components = this.updateComponents(config.components)
        }
        config.enabled = false
@@ -921,6 +945,27 @@
    })
  }
  updateComponents = (components) => { // 兼容性升级 table
    return components.map(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          tab.components = this.updateComponents(tab.components)
        })
      } else if (item.type === 'group') {
        item.components = this.updateComponents(item.components)
      } else if (item.type === 'table') {
        item.cols = item.cols.map(col => {
          if (col.type === 'action') {
            col.type = 'custom'
          }
          return col
        })
      }
      return item
    })
  }
  collectTB = (components) => {
    return components.map(item => {
      if (item.type === 'tabs') {
@@ -939,6 +984,13 @@
      if (item.subtype === 'tablecard') { // 兼容
        item.type = 'card'
      } else if (item.type === 'table') {
        item.cols = item.cols.map(col => {
          if (col.type === 'action') {
            col.type = 'custom'
          }
          return col
        })
      }
      delete item.tabId
@@ -1081,17 +1133,22 @@
              title: btn.label,
            })
          })
          item.cols && item.cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.hidden === 'true') return
          let loopCol = (cols) => {
            cols.forEach(col => {
              if (col.type === 'colspan') {
                loopCol(col.subcols)
              } else if (col.type === 'custom') {
                col.elements.forEach(cell => {
                  if (cell.eleType !== 'button' || cell.hidden === 'true') return
              m.children.push({
                key: btn.uuid,
                title: btn.label,
                    key: cell.uuid,
                    title: cell.label,
              })
            })
              }
          })
          }
          loopCol(item.cols)
        }
        list.push(m)
@@ -1181,19 +1238,25 @@
              })
            }
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
              if (cell.linkmenu && menuObj[cell.linkmenu]) {
                menus.push(menuObj[cell.linkmenu])
              } else if (cell.openmenu && menuObj[cell.openmenu]) {
                menus.push(menuObj[cell.openmenu])
              }
            })
            if (item.subtype === 'dualdatacard') {
              card.backElements && card.backElements.forEach(cell => {
                if (cell.linkmenu && menuObj[cell.linkmenu]) {
                  menus.push(menuObj[cell.linkmenu])
                } else if (cell.openmenu && menuObj[cell.openmenu]) {
                  menus.push(menuObj[cell.openmenu])
                }
              })
            }
          })
        } else if (item.type === 'balcony') {
          item.elements && item.elements.forEach(cell => {
            if (cell.eleType !== 'button') return
            if (cell.linkmenu && menuObj[cell.linkmenu]) {
                menus.push(menuObj[cell.linkmenu])
              } else if (cell.openmenu && menuObj[cell.openmenu]) {
@@ -1214,16 +1277,22 @@
              menus.push(menuObj[btn.openmenu])
            }
          })
          item.cols && item.cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.linkmenu && menuObj[btn.linkmenu]) {
                menus.push(menuObj[btn.linkmenu])
              } else if (btn.openmenu && menuObj[btn.openmenu]) {
                menus.push(menuObj[btn.openmenu])
          let loopCol = (cols) => {
            cols.forEach(col => {
              if (col.type === 'colspan') {
                loopCol(col.subcols)
              } else if (col.type === 'custom') {
                col.elements.forEach(cell => {
                  if (cell.linkmenu && menuObj[cell.linkmenu]) {
                    menus.push(menuObj[cell.linkmenu])
                  } else if (cell.openmenu && menuObj[cell.openmenu]) {
                    menus.push(menuObj[cell.openmenu])
              }
            })
              }
          })
          }
          loopCol(item.cols)
        }
      })
    }
@@ -1287,7 +1356,7 @@
            return cols.map(col => {
              if (col.type === 'colspan') {
                col.subcols = getCols(col.subcols || [])
              } else if (col.type === 'custom' || col.type === 'action') {
              } else if (col.type === 'custom') {
                col.elements = col.elements.map(cell => {
                  cell.miniStyle = this.transferStyle(cell.style)
                  return cell
@@ -1321,6 +1390,35 @@
    return _style
  }
  resetSyncQuery = (components) => {
    return components.map(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          tab.components = this.resetSyncQuery(tab.components)
        })
      } else if (item.type === 'group') {
        item.components = this.resetSyncQuery(item.components)
      } else if (item.setting && item.setting.interType === 'system' && item.setting.sync === 'true') {
        let sql = ''
        if (item.setting.execute !== 'false' && item.setting.dataresource) {
          sql = item.setting.dataresource
        }
        item.scripts && item.scripts.forEach(script => {
          if (script.status === 'false') return
          sql += script.sql
        })
        if (sql.length > 8000) {
          item.setting.sync = 'false'
        }
      }
      return item
    })
  }
  submitConfig = () => {
    const { adapters } = this.state
    let config = fromJS(this.state.config).toJS()
@@ -1342,9 +1440,21 @@
      menuloading: true
    })
    window.GLOB.saving = true
    setTimeout(() => {
      if (config.enabled && this.verifyConfig()) {
      let _pass = this.verifyConfig(config)
      if (config.enabled && !_pass) {
        config.enabled = false
        config.force = true
      } else if (!config.enabled && config.force && _pass) {
        config.enabled = true
        delete config.force
      }
      if (config.cacheUseful !== 'true') {
        config.components = this.resetSyncQuery(config.components)
      }
      let tbs = []
@@ -1589,6 +1699,8 @@
          menuloading: false
        })
        window.GLOB.saving = false
        if (!res) return
        if (res.status) {
@@ -1623,6 +1735,9 @@
    this.setState({
      menuloading: false
    })
    window.GLOB.saving = false
    if (!error) {
      notification.warning({
        top: 92,
@@ -1668,17 +1783,22 @@
  onEnabledChange = () => {
    const { config } = this.state
    if (!config || (!config.enabled && this.verifyConfig(true))) {
      return
    }
    let _config = {...config, enabled: !config.enabled}
    delete _config.force
    if (!_config.enabled) {
    this.setState({
      config: {...config, enabled: !config.enabled}
        config: _config
      })
    } else if (this.verifyConfig(_config)) {
      this.setState({
        config: _config
    })
  }
  }
  verifyConfig = (show) => {
    const { config } = this.state
  verifyConfig = (config) => {
    let error = ''
    let searchSum = 0
    let swipes = []
@@ -1745,7 +1865,7 @@
      }
    }
    if (show && error) {
    if (config.enabled && error) {
      notification.warning({
        top: 92,
        message: error,
@@ -1753,7 +1873,7 @@
      })
    }
    return error
    return error === ''
  }
  // 更新配置信息
@@ -1769,12 +1889,22 @@
    let config = fromJS(this.state.config).toJS()
    if (item.type === 'search') {
      if (config.components.filter(card => card.type === 'topbar' && card.wrap.type !== 'navbar').length > 0) {
      notification.warning({
        top: 92,
        message: '移动端搜索组件不可粘贴!',
          message: '导航栏使用了搜索,不可添加搜索组件!',
        duration: 5
      })
      return
      }
      if (config.components.filter(card => card.type === 'search').length > 0) {
        notification.warning({
          top: 92,
          message: '搜索条件不可重复添加!',
          duration: 5
        })
        return
      }
    }
    
    if (item.type === 'topbar') {
@@ -2036,7 +2166,7 @@
              </div>
              <div className="wrap">
                <Button type="primary" className={needUpdate ? 'update-tip' : ''} onClick={this.submitConfig} id="save-config" loading={menuloading}>保存</Button>
                <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config && config.enabled} onChange={this.onEnabledChange} />
                {config ? <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config.enabled} onChange={this.onEnabledChange} /> : null}
                <ArrowLeftOutlined title="后退" className="back-view" onClick={this.backView}/>
                <Button className="mk-border-purple" onClick={() => this.setState({eyeopen: !eyeopen})}>{!eyeopen ? <EyeOutlined /> : <EyeInvisibleOutlined />} 组件名</Button>
                <CreateView resetmenu={this.getAppMenus} />