king
2024-06-28 c8804ceb1fe2dea76f9949c5ea04423876ee2c81
src/views/pcdesign/index.jsx
@@ -3,15 +3,14 @@
import { withRouter } from 'react-router'
import { is, fromJS } from 'immutable'
import HTML5Backend from 'react-dnd-html5-backend'
import { ConfigProvider, notification, Modal, Collapse, Switch, Button, message, Spin, Typography } from 'antd'
import { notification, Modal, Collapse, Switch, Button, message, Spin, Typography } from 'antd'
import { DoubleLeftOutlined, DoubleRightOutlined, HomeOutlined, LoginOutlined, ArrowLeftOutlined, EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons'
import moment from 'moment'
import md5 from 'md5'
import Api from '@/api'
import Utils, { setGLOBFuncs } from '@/utils/utils.js'
import { getTables, getFuncsAndInters } from '@/utils/utils-custom.js'
import antdZhCN from 'antd/es/locale/zh_CN'
import { getTables, getFuncsAndInters, getLangTrans } from '@/utils/utils-custom.js'
import MKEmitter from '@/utils/events.js'
import MenuUtils from '@/utils/utils-custom.js'
import asyncComponent from '@/utils/asyncComponent'
@@ -24,6 +23,7 @@
const { Paragraph } = Typography
const MenuForm = asyncComponent(() => import('./menuform'))
const Debug = asyncComponent(() => import('@/menu/debug'))
const Header = asyncComponent(() => import('@/menu/header'))
const PopView = asyncComponent(() => import('@/views/menudesign/popview'))
const Transfer = asyncComponent(() => import('@/pc/transfer'))
@@ -99,12 +99,25 @@
    try {
      let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
      if (param.lang) {
        sessionStorage.setItem('lang', param.lang)
      }
      if (param.type === 'app') {
        sessionStorage.setItem('appId', param.ID || '')
        sessionStorage.setItem('appName', param.remark || '')
        sessionStorage.setItem('lang', param.lang || 'zh-CN')
        sessionStorage.setItem('kei_no', param.kei_no || '')
        sessionStorage.setItem('sysBgColor', param.sysBgColor || '#ffffff')
        if (param.applangList) {
          sessionStorage.setItem('applangList', param.applangList)
        } else {
          sessionStorage.removeItem('applangList')
        }
        if (param.wxAppId) {
          sessionStorage.setItem('wxAppId', param.wxAppId)
        }
        this.getAppMessage(param.MenuID)
      } else if (param.type === 'view') {
@@ -142,6 +155,10 @@
    MKEmitter.addListener('changePopview', this.initPopview)
    MKEmitter.addListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
    if (sessionStorage.getItem('wxAppId')) {
      window.GLOB.WXAppID = sessionStorage.getItem('wxAppId')
    }
    setTimeout(() => {
      this.getRoleFields()
@@ -239,7 +256,8 @@
      MenuID: menu.MenuID,
      copyMenuId: menu.copyMenuId || '',
      clearMenu: menu.clearMenu !== 'false',
      type: 'view'
      type: 'view',
      lang: sessionStorage.getItem('lang')
    }
    // param.MenuNo = menu.MenuNo || ''
@@ -286,7 +304,7 @@
        let param = {
          func: 's_kei_link_keyids_addupt',
          BID: sessionStorage.getItem('appId'),
          exec_type: 'y',
          exec_type: 'x',
          LText: ''
        }
@@ -301,7 +319,7 @@
        param.LText = appViewList.map(item => `select '${item.keys_id}','${item.keys_type}','${item.kei_no}','${item.appkey}','${item.bid}','${sessionStorage.getItem('CloudUserID')}','${item.remark}'`)
        param.LText = param.LText.join(' union all ')
        param.LText = Utils.formatOptions(param.LText)
        param.LText = Utils.formatOptions(param.LText, 'x')
  
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        param.secretkey = Utils.encrypt('', param.timestamp)
@@ -315,12 +333,12 @@
            })
          } else {
            sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
            this.props.history.replace('/pcdesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({MenuID: homeId, type: 'view'}))))
            this.props.history.replace('/pcdesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({MenuID: homeId, type: 'view', lang: sessionStorage.getItem('lang')}))))
          }
        })
      } else {
        sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
        this.props.history.replace('/pcdesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({MenuID: MenuID || homeId, type: 'view'}))))
        this.props.history.replace('/pcdesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({MenuID: MenuID || homeId, type: 'view', lang: sessionStorage.getItem('lang')}))))
      }
    })
  }
@@ -530,6 +548,7 @@
        config.uuid = MenuId
        config.MenuID = MenuId
        config.Template = 'webPage'
        config.open_edition = result.open_edition || ''
        window.GLOB.urlFields = config.urlFields || []
@@ -736,6 +755,7 @@
      
      config.uuid = MenuId
      config.MenuID = MenuId
      config.Template = 'webPage'
      config.open_edition = ''
      config.MenuName = urlParam.MenuName || ''
      config.MenuNo = ''
@@ -874,7 +894,7 @@
          return
        } else if (item.type === 'card' || item.type === 'carousel' || item.type === 'timeline') {
          item.action && item.action.forEach(btn => {
            if (btn.hidden === 'true') return
            if (btn.hidden === 'true' || btn.permission === 'false') return
            m.children.push({
              key: btn.uuid,
@@ -883,7 +903,7 @@
          })
          item.subcards.forEach(card => {
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button' || cell.hidden === 'true') return
              if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
              m.children.push({
                key: cell.uuid,
@@ -892,7 +912,7 @@
            })
            card.backElements && card.backElements.forEach(cell => {
              if (cell.eleType !== 'button' || cell.hidden === 'true') return
              if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
              m.children.push({
                key: cell.uuid,
@@ -902,7 +922,7 @@
          })
        } else if (item.type === 'balcony') {
          item.elements && item.elements.forEach(cell => {
            if (cell.eleType !== 'button' || cell.hidden === 'true') return
            if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
            m.children.push({
              key: cell.uuid,
@@ -920,7 +940,7 @@
          }
        } else if (item.type === 'table') {
          item.action.forEach(btn => {
            if (btn.hidden === 'true') return
            if (btn.hidden === 'true' || btn.permission === 'false') return
            m.children.push({
              key: btn.uuid,
@@ -933,7 +953,7 @@
                loopCol(col.subcols)
              } else if (col.type === 'custom') {
                col.elements.forEach(cell => {
                  if (cell.eleType !== 'button' || cell.hidden === 'true') return
                  if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
                  m.children.push({
                    key: cell.uuid,
                    title: cell.label,
@@ -1137,6 +1157,18 @@
    if (!this.checkBase()) {
      return
    } else if (this.checklog()) {
      if (sessionStorage.getItem('applangList') && !config.trans) {
      } else {
        notification.success({
          top: 92,
          message: '当前配置未修改,无需保存。',
          duration: 5
        })
        MKEmitter.emit('completeSave')
        return
      }
    }
    this.setState({
@@ -1204,6 +1236,8 @@
      }
      let interfaces = getFuncsAndInters(config)
      roleParam.interfaces = interfaces
      let langSql = getLangTrans(config)
      let param = {
        func: 'sPC_TrdMenu_AddUpt',
@@ -1220,12 +1254,16 @@
        PageParam: JSON.stringify({Template: 'webPage', interfaces}),
        menus_rolelist: window.btoa(window.encodeURIComponent(JSON.stringify(roleParam))),
        open_edition: config.open_edition,
        LText: '',
        LTexttb: '',
        // LText: '',
        // LTexttb: '',
        menus_used_list,
        debug_md5: key,
        debug_url: url,
        debug_list: window.btoa(tbs)
      }
      if (langSql) {
        param.lang_translation = window.btoa(window.encodeURIComponent(langSql))
      }
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
@@ -1306,8 +1344,8 @@
              PageParam: JSON.stringify({Template: NavBar.type}),
              menus_rolelist: window.btoa(window.encodeURIComponent(JSON.stringify(roles))),
              open_edition: NavBar.open_edition,
              LText: '',
              LTexttb: ''
              // LText: '',
              // LTexttb: ''
            }
            _param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(NavBar)))
@@ -1348,13 +1386,13 @@
                  let kparam = {
                    func: 's_kei_link_keyids_addupt',
                    BID: sessionStorage.getItem('appId'),
                    exec_type: 'y',
                    exec_type: 'x',
                    LText: ''
                  }
        
                  kparam.LText = _appViewList.map(item => `select '${item.keys_id}','${item.keys_type}','${item.kei_no}','${item.appkey}','${item.bid}','${sessionStorage.getItem('CloudUserID')}','${item.remark}'`)
                  kparam.LText = kparam.LText.join(' union all ')
                  kparam.LText = Utils.formatOptions(kparam.LText)
                  kparam.LText = Utils.formatOptions(kparam.LText, 'x')
            
                  kparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
                  kparam.secretkey = Utils.encrypt('', kparam.timestamp)
@@ -1403,10 +1441,10 @@
            duration: 2
          })
        } else {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          Modal.warning({
            width: 400,
            title: res.message,
            okText: '知道了'
          })
        }
        MKEmitter.emit('completeSave')
@@ -1546,12 +1584,6 @@
    this.setState({config})
    window.GLOB.customMenu = config
    notification.success({
      top: 92,
      message: '粘贴成功!',
      duration: 2
    })
  }
  setHomeView = () => {
@@ -1569,7 +1601,7 @@
    let param = {
      func: 's_kei_link_keyids_addupt',
      BID: sessionStorage.getItem('appId'),
      exec_type: 'y',
      exec_type: 'x',
      LText: ''
    }
@@ -1588,7 +1620,7 @@
    param.LText = appViewList.map(item => `select '${item.keys_id}','${item.keys_type}','${item.kei_no}','${item.appkey}','${item.bid}','${sessionStorage.getItem('CloudUserID')}','${item.remark}'`)
    param.LText = param.LText.join(' union all ')
    param.LText = Utils.formatOptions(param.LText)
    param.LText = Utils.formatOptions(param.LText, 'x')
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
@@ -1628,7 +1660,7 @@
    let param = {
      func: 's_kei_link_keyids_addupt',
      BID: sessionStorage.getItem('appId'),
      exec_type: 'y',
      exec_type: 'x',
      LText: ''
    }
@@ -1647,7 +1679,7 @@
    param.LText = appViewList.map(item => `select '${item.keys_id}','${item.keys_type}','${item.kei_no}','${item.appkey}','${item.bid}','${sessionStorage.getItem('CloudUserID')}','${item.remark}'`)
    param.LText = param.LText.join(' union all ')
    param.LText = Utils.formatOptions(param.LText)
    param.LText = Utils.formatOptions(param.LText, 'x')
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
@@ -1674,11 +1706,31 @@
    })
  }
  checklog = () => {
    const { oriConfig, config } = this.state
    return is(fromJS(oriConfig), fromJS(config))
  }
  updateLogConfig = (config) => {
    config.open_edition = this.state.config.open_edition || ''
    this.setState({
      config: null
    }, () => {
      this.setState({
        config: config
      })
    })
    window.GLOB.customMenu = config
  }
  render () {
    const { view, loading, comloading, activeKey, settingshow, controlshow, MenuId, config, menuloading, eyeopen, needUpdate } = this.state
    return (
      <ConfigProvider locale={antdZhCN}>
      <>
        <DndProvider backend={HTML5Backend}>
          {view !== 'popview' ? <div className={'mk-pc-view '} id="mk-pc-design-view">
            {loading ? <Spin className="view-spin" size="large" /> : null}
@@ -1726,6 +1778,7 @@
                <Button type="primary" className={needUpdate ? 'update-tip' : ''} id="save-config" onClick={this.submitConfig} loading={menuloading}>保存</Button>
                {config ? <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config.enabled} onChange={this.onEnabledChange} /> : null}
                <ArrowLeftOutlined title="后退" className="back-view" onClick={this.backView}/>
                {config ? <Debug config={config}/> : null}
                <Button className="mk-border-purple" onClick={() => this.setState({eyeopen: !eyeopen})}>{!eyeopen ? <EyeOutlined /> : <EyeInvisibleOutlined />} 组件名</Button>
                <CreateView resetmenu={this.getAppMenus} />
                <PasteController insert={this.insert} />
@@ -1739,7 +1792,7 @@
                <Button className="mk-border-purple" onClick={this.setLoginView}><LoginOutlined/> 设为登录页</Button>
                <ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
                <Transfer MenuID={MenuId} />
                <Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''}/>
                {config ? <Versions MenuId={MenuId} Template="webPage" checklog={this.checklog} updateConfig={this.updateLogConfig}/> : null}
                <Button type="default" onClick={this.closeView}>关闭</Button>
              </div>
            </div>
@@ -1754,7 +1807,7 @@
        <StyleController />
        <StyleCombController />
        <ModalController />
      </ConfigProvider>
      </>
    )
  }
}