king
2023-08-15 a94b0a4d15b26ecf8fe99f0a1c3e60d60b97766d
src/views/menudesign/index.jsx
@@ -10,7 +10,6 @@
import md5 from 'md5'
import Api from '@/api'
import options from '@/store/options.js'
import Utils, { setGLOBFuncs } from '@/utils/utils.js'
import antdZhCN from 'antd/es/locale/zh_CN'
import MKEmitter from '@/utils/events.js'
@@ -37,6 +36,7 @@
const PasteController = asyncComponent(() => import('@/menu/pastecontroller'))
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
const NormalCss = asyncComponent(() => import('@/menu/normalCss'))
const Versions = asyncComponent(() => import('@/menu/versions'))
const TableNodes = asyncComponent(() => import('@/menu/tablenodes'))
const SysInterface = asyncComponent(() => import('@/menu/sysinterface'))
@@ -47,7 +47,6 @@
const StyleCombControlButton = asyncComponent(() => import('@/menu/stylecombcontrolbutton'))
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
sessionStorage.setItem('isEditState', 'true')
sessionStorage.setItem('appType', '')          // 应用类型
document.body.className = ''
@@ -72,12 +71,27 @@
  }
  UNSAFE_componentWillMount() {
    if (sessionStorage.getItem('devError') === 'true') {
      sessionStorage.clear()
      window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login')
      window.location.reload()
      return
    }
    if (!sessionStorage.getItem('UserID')) {
      sessionStorage.removeItem('appType')
      this.props.history.replace('/login')
      return
    }
    sessionStorage.setItem('editMenuType', 'menu') // 编辑菜单类型
    window.GLOB.curDate = moment().format('YYYY-MM-DD')
    window.GLOB.UserComponentMap = new Map() // 缓存用户自定义组件
    window.GLOB.TabsMap = new Map()          // 缓存用户操作的标签页
    window.GLOB.urlFields = []               // url变量
    window.GLOB.customMenu = null            // 保存菜单信息
    window.GLOB.developing = true
    try {
      let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
@@ -105,6 +119,8 @@
  }
  componentDidMount () {
    if (!sessionStorage.getItem('UserID')) return
    MKEmitter.addListener('changePopview', this.initPopview)
    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
@@ -244,7 +260,7 @@
  
      param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 云端数据验证
  
      Api.getSystemConfig(param).then(res => {
      Api.getCloudConfig(param).then(res => {
        if (res.status) {
          let temps = res.data.map(temp => {
            return {
@@ -277,19 +293,19 @@
    }
    deffers = [new Promise(resolve => {
      setTimeout(() => {
        Api.getSystemConfig({...param, typecharone: 'image'}).then(res => {
        Api.getCloudConfig({...param, typecharone: 'image'}).then(res => {
          resolve(res.data)
        })
      }, 500)
    }), new Promise(resolve => {
      setTimeout(() => {
        Api.getSystemConfig({...param, typecharone: 'video'}).then(res => {
        Api.getCloudConfig({...param, typecharone: 'video'}).then(res => {
          resolve(res.data)
        })
      }, 1000)
    }), new Promise(resolve => {
      setTimeout(() => {
        Api.getSystemConfig({...param, typecharone: 'color'}).then(res => {
        Api.getCloudConfig({...param, typecharone: 'color'}).then(res => {
          resolve(res.data)
        })
      }, 1500)
@@ -303,7 +319,7 @@
  }
  updateCustomComponent = () => {
    Api.getSystemConfig({
    Api.getCloudConfig({
      func: 's_get_custom_components',
      typename: '',
      typecharone: ''
@@ -369,6 +385,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,
@@ -417,7 +435,7 @@
      MenuID: MenuId
    }
    Api.getSystemConfig(param).then(result => {
    Api.getCloudConfig(param).then(result => {
      if (result.status) {
        let config = null
@@ -484,6 +502,7 @@
          })
          this.updatePage(config)
        } else {
          config.components = this.updateComponents(config.components)
          this.setState({
            oriConfig: fromJS(config).toJS(),
            config: config
@@ -497,6 +516,27 @@
          duration: 5
        })
      }
    })
  }
  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
    })
  }
@@ -518,6 +558,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
@@ -555,15 +602,23 @@
      })
    })
    config.cols && config.cols.forEach(col => {
      if (col.type === 'action') {
        col.elements.forEach(cell => {
          if (cell.OpenType === 'popview' && popbtns[cell.uuid]) {
            cell.config = popbtns[cell.uuid]
    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
@@ -593,6 +648,8 @@
        comloading: false,
        needUpdate: true
      })
      window.GLOB.customMenu = config
      return
    }
@@ -604,7 +661,7 @@
        }
    
        setTimeout(() => {
          Api.getSystemConfig(param).then(res => {
          Api.getCloudConfig(param).then(res => {
            let _config = null
            try {
              _config = res.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(res.LongParam))) : null
@@ -671,6 +728,8 @@
      config.components = this.setPopView(config.components, parents, popbtns)
      this.setState({ delButtons: bts, config, comloading: false })
      window.GLOB.customMenu = config
    })
  }
@@ -683,6 +742,11 @@
        if (item.$tables) {
          tbs.push(...item.$tables)
        }
        if (item.wrap && item.wrap.permission === 'false') {
          return
        }
        if (item.action && item.action.length > 0) {
          item.action.forEach(btn => {
            if (btn.hidden === 'true') return
@@ -719,14 +783,20 @@
            _sort++
          })
        } else if (item.type === 'table') {
          item.cols && item.cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.hidden === 'true') return
              buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
              _sort++
          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
                  buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
                  _sort++
                })
              }
            })
          })
          }
          loopCol(item.cols)
        }
      })
    }
@@ -747,7 +817,7 @@
  checkBase = () => {
    const { MenuType, config } = this.state
    if (MenuType === 'billPrint' && config.printPage === 'page' && !config.everyPCount) {
    if (MenuType === 'billPrint' && ((config.printPage === 'page' && !config.everyPCount) || (config.callback === 'true' && !config.callNo))) {
      return false
    } else if (MenuType === 'home' && (config.cacheUseful === 'true' && !config.cacheTime)) {
      return false
@@ -755,6 +825,35 @@
      return false
    }
    return true
  }
  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 = () => {
@@ -775,8 +874,18 @@
    })
    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 = []
@@ -847,7 +956,6 @@
      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 (MenuType === 'billPrint') { // 打印生成页面效果图
@@ -856,15 +964,15 @@
              Base64Img: canvas.toDataURL('image/png') // 获取生成的图片
            }
  
            if (options.cloudServiceApi) {
              param.rduri = options.cloudServiceApi
            if (window.GLOB.cloudServiceApi) {
              param.rduri = window.GLOB.cloudServiceApi
              param.userid = sessionStorage.getItem('CloudUserID') || ''
              param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
            }
  
            Api.fileuploadbase64(param).then(result => {
              if (result.status) {
                Api.getSystemConfig({
                Api.getCloudConfig({
                  func: 's_PrintTemplateMSub',
                  ID: config.uuid,
                  Images: Utils.getcloudurl(result.Images),
@@ -876,7 +984,7 @@
              } else {
                resolve(result)
              }
            })
            }, this.netError)
          })
        } else {
          resolve({status: true})
@@ -884,15 +992,12 @@
      }).then(res => { // 页面保存
        if (!res || !res.status) return res
        return Api.getSystemConfig(param)
        return Api.getCloudConfig(param)
      }).then(res => { // 按钮删除
        if (!res || !res.status) return res
        if (MenuType !== 'billPrint') { // 基本信息改变时,通知菜单列表更新
          let ori = this.state.oriConfig
          if (config.MenuName !== ori.MenuName || config.MenuNo !== ori.MenuNo || config.parentId !== ori.parentId) {
            localStorage.setItem('menuUpdate', new Date().getTime())
          }
          localStorage.setItem('menuUpdate', new Date().getTime() + ',' + config.uuid)
        }
        config.open_edition = res.open_edition || ''
        this.setState({
@@ -910,9 +1015,9 @@
            func: 'sPC_MainMenu_Del',
            MenuID: this.state.delButtons.join(',')
          }
          return Api.getSystemConfig(_param)
          return Api.getCloudConfig(_param)
        }
      }).then(res => { // 页面按钮关系保存
      }, this.netError).then(res => { // 页面按钮关系保存
        if (!res || !res.status) return res
        this.setState({
@@ -920,13 +1025,13 @@
        })
        if (MenuType !== 'billPrint') {
          return Api.getSystemConfig(btnParam)
          return Api.getCloudConfig(btnParam)
        } else {
          return {
            status: true
          }
        }
      }).then(res => {
      }, this.netError).then(res => {
        this.setState({
          menuloading: false
        })
@@ -939,7 +1044,6 @@
            message: '保存成功',
            duration: 2
          })
          MKEmitter.emit('completeSave')
        } else {
          notification.warning({
            top: 92,
@@ -947,14 +1051,30 @@
            duration: 5
          })
        }
      })
        MKEmitter.emit('completeSave')
      }, this.netError)
    }, 300 + (+sessionStorage.getItem('mkDelay')))
  }
  netError = (error) => {
    this.setState({
      menuloading: false
    })
    if (!error) {
      notification.warning({
        top: 92,
        message: '保存失败,请检查网络是否正常。',
        duration: 5
      })
    }
    MKEmitter.emit('completeSave')
  }
  getRoleFields = () => {
    if (sessionStorage.getItem('sysRoles')) return
    Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
    Api.getCloudConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
      if (res.status) {
        let _permFuncField = []
        let _sysRoles = []
@@ -987,17 +1107,23 @@
  onEnabledChange = () => {
    const { config } = this.state
    if (!config || (!config.enabled && this.verifyConfig(true))) {
      return
    }
    let _config = {...config, enabled: !config.enabled}
    this.setState({
      config: {...config, enabled: !config.enabled}
    })
    delete _config.force
    if (!_config.enabled) {
      this.setState({
        config: _config
      })
    } else if (this.verifyConfig(_config)) {
      this.setState({
        config: _config
      })
    }
  }
  verifyConfig = (show) => {
    const { config, MenuType } = this.state
  verifyConfig = (config) => {
    const { MenuType } = this.state
    let error = ''
    let check = (components) => {
@@ -1025,7 +1151,7 @@
    check(config.components)
    if (show && error) {
    if (config.enabled && error) {
      notification.warning({
        top: 92,
        message: error,
@@ -1041,12 +1167,14 @@
        carousel: '轮播',
        tree: '树形列表',
        chart: '自定义图表',
        editor: '富文本',
        group: '分组'
        // editor: '富文本',
        group: '分组',
        iframe: 'iframe'
      }
      let subforbid = {
        editable: '可编辑表格',
        voucher: '凭证'
        voucher: '凭证',
        account: '账套'
      }
      config.components.forEach(item => {
@@ -1057,7 +1185,7 @@
        }
      })
      if (show && error) {
      if (config.enabled && error) {
        notification.warning({
          top: 92,
          message: error,
@@ -1066,7 +1194,7 @@
      }
    }
    return error
    return error === ''
  }
  // 更新配置信息
@@ -1153,6 +1281,7 @@
                    {/* 表名添加 */}
                    {config ? <TableComponent config={config} updatetable={this.updateConfig}/> : null}
                    {config ? <Paragraph style={{padding: '15px 0px 0px 18px'}} copyable={{ text: MenuId }}>菜单ID</Paragraph> : null}
                    {config ? <NormalCss config={config} updateConfig={this.updateConfig}/> : null}
                  </Panel>
                  {/* 组件添加 */}
                  <Panel header="组件" key="component">
@@ -1180,7 +1309,7 @@
                    <PictureController/>
                    <StyleCombControlButton menu={config} />
                    <PasteController insert={this.insert} />
                    <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}
                    <Button type="primary" id="save-config" className={needUpdate ? 'update-tip' : ''} onClick={this.submitConfig} loading={menuloading}>保存</Button>
                    <Button type="default" onClick={this.closeView}>关闭</Button>
                  </div>