king
2024-06-21 2bccb9ec7bdefe23292a22bc153463cfa1479a49
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 { DoubleLeftOutlined, DoubleRightOutlined, HomeOutlined, LoginOutlined, RedoOutlined, ArrowLeftOutlined, EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons'
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 } 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'))
@@ -51,8 +51,6 @@
sessionStorage.setItem('appType', 'pc')        // 应用类型
sessionStorage.setItem('typename', 'pc')
document.body.className = ''
const memberLevel = Utils.getMemberLevel()
class MenuDesign extends Component {
  state = {
@@ -87,7 +85,7 @@
      return
    }
    
    if (memberLevel < 30) return
    if (window.GLOB.memberLevel < 30) return
    sessionStorage.setItem('editMenuType', 'menu') // 编辑菜单类型
@@ -101,12 +99,21 @@
    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')
        }
        this.getAppMessage(param.MenuID)
      } else if (param.type === 'view') {
@@ -137,7 +144,7 @@
  componentDidMount () {
    if (!sessionStorage.getItem('UserID')) return
    if (memberLevel < 30) {
    if (window.GLOB.memberLevel < 30) {
      document.getElementById('mk-pc-design-view').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh; height: 100vh; background: #fff;">本应用没有PC端页面的编辑权限,请联系管理员!</div>'
      return
    }
@@ -146,7 +153,6 @@
    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
    setTimeout(() => {
      this.getAppPictures()
      this.getRoleFields()
      setGLOBFuncs()
    }, 1000)
@@ -242,7 +248,8 @@
      MenuID: menu.MenuID,
      copyMenuId: menu.copyMenuId || '',
      clearMenu: menu.clearMenu !== 'false',
      type: 'view'
      type: 'view',
      lang: sessionStorage.getItem('lang')
    }
    // param.MenuNo = menu.MenuNo || ''
@@ -289,7 +296,7 @@
        let param = {
          func: 's_kei_link_keyids_addupt',
          BID: sessionStorage.getItem('appId'),
          exec_type: 'y',
          exec_type: 'x',
          LText: ''
        }
@@ -304,7 +311,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)
@@ -318,50 +325,13 @@
            })
          } 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')}))))
      }
    })
  }
  getAppPictures = () => {
    if (sessionStorage.getItem('app_pictures')) return
    let deffers = []
    let param = {
      func: 's_url_db_adduptdel',
      PageIndex: 0,  // 0 代表全部
      PageSize: 0,   // 0 代表全部
      type: 'search'
    }
    deffers = [new Promise(resolve => {
      setTimeout(() => {
        Api.getCloudConfig({...param, typecharone: 'image'}).then(res => {
          resolve(res.data)
        })
      }, 500)
    }), new Promise(resolve => {
      setTimeout(() => {
        Api.getCloudConfig({...param, typecharone: 'video'}).then(res => {
          resolve(res.data)
        })
      }, 1000)
    }), new Promise(resolve => {
      setTimeout(() => {
        Api.getCloudConfig({...param, typecharone: 'color'}).then(res => {
          resolve(res.data)
        })
      }, 1500)
    })]
    Promise.all(deffers).then(response => {
      sessionStorage.setItem('app_pictures', JSON.stringify(response[0] || []))
      sessionStorage.setItem('app_videos', JSON.stringify(response[1] || []))
      sessionStorage.setItem('app_colors', JSON.stringify(response[2] || []))
    })
  }
@@ -570,6 +540,7 @@
        config.uuid = MenuId
        config.MenuID = MenuId
        config.Template = 'webPage'
        config.open_edition = result.open_edition || ''
        window.GLOB.urlFields = config.urlFields || []
@@ -776,6 +747,7 @@
      
      config.uuid = MenuId
      config.MenuID = MenuId
      config.Template = 'webPage'
      config.open_edition = ''
      config.MenuName = urlParam.MenuName || ''
      config.MenuNo = ''
@@ -914,7 +886,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,
@@ -923,7 +895,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,
@@ -932,7 +904,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,
@@ -942,7 +914,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,
@@ -960,7 +932,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,
@@ -973,7 +945,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,
@@ -1177,6 +1149,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({
@@ -1243,6 +1227,10 @@
        config.tbkey = key
      }
      let interfaces = getFuncsAndInters(config)
      roleParam.interfaces = interfaces
      let langSql = getLangTrans(config)
      let param = {
        func: 'sPC_TrdMenu_AddUpt',
        FstID: 'mk_app',
@@ -1255,15 +1243,19 @@
        TypeCharOne: sessionStorage.getItem('kei_no'),
        Typename: 'pc',
        MenuName: config.MenuName || '',
        PageParam: JSON.stringify({Template: 'webPage'}),
        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')
@@ -1344,8 +1336,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)))
@@ -1386,13 +1378,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)
@@ -1441,10 +1433,10 @@
            duration: 2
          })
        } else {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          Modal.warning({
            width: 400,
            title: res.message,
            okText: '知道了'
          })
        }
        MKEmitter.emit('completeSave')
@@ -1584,30 +1576,6 @@
    this.setState({config})
    window.GLOB.customMenu = config
    notification.success({
      top: 92,
      message: '粘贴成功!',
      duration: 2
    })
  }
  refreshView = () => {
    if (!is(fromJS(this.state.oriConfig || {}), fromJS(this.state.config || {}))) {
      notification.warning({
        top: 92,
        message: '配置信息未保存!',
        duration: 5
      })
      return
    }
    sessionStorage.removeItem('sysRoles')
    sessionStorage.removeItem('permFuncField')
    sessionStorage.removeItem('app_videos')
    sessionStorage.removeItem('app_pictures')
    window.location.reload()
  }
  setHomeView = () => {
@@ -1625,7 +1593,7 @@
    let param = {
      func: 's_kei_link_keyids_addupt',
      BID: sessionStorage.getItem('appId'),
      exec_type: 'y',
      exec_type: 'x',
      LText: ''
    }
@@ -1644,7 +1612,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)
@@ -1684,7 +1652,7 @@
    let param = {
      func: 's_kei_link_keyids_addupt',
      BID: sessionStorage.getItem('appId'),
      exec_type: 'y',
      exec_type: 'x',
      LText: ''
    }
@@ -1703,7 +1671,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)
@@ -1730,11 +1698,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}
@@ -1747,17 +1735,18 @@
                <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
                  {/* 基本信息 */}
                  <Panel header="基本信息" key="basedata">
                    {/* 菜单信息 */}
                    {config ? <MenuForm
                      config={config}
                      MenuId={MenuId}
                      updateConfig={this.updateConfig}
                    /> : null}
                    {config ? <UrlFieldComponent config={config} updateConfig={this.updateConfig}/> : null}
                    {/* 表名添加 */}
                    {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}
                    {config ? <>
                      <MenuForm
                        config={config}
                        MenuId={MenuId}
                        updateConfig={this.updateConfig}
                      />
                      <UrlFieldComponent config={config} updateConfig={this.updateConfig}/>
                      {/* 表名添加 */}
                      <TableComponent config={config} updatetable={this.updateConfig}/>
                      <Paragraph style={{padding: '15px 0px 0px 18px'}} copyable={{ text: MenuId }}>菜单ID</Paragraph>
                      <NormalCss config={config} updateConfig={this.updateConfig}/>
                    </> : null}
                  </Panel>
                  {/* 组件添加 */}
                  <Panel header="组件" key="component">
@@ -1781,6 +1770,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} />
@@ -1794,8 +1784,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 : ''}/>
                <Button className="mk-border-danger" onClick={this.refreshView}><RedoOutlined /> 强制刷新</Button>
                {config ? <Versions MenuId={MenuId} Template="webPage" checklog={this.checklog} updateConfig={this.updateLogConfig}/> : null}
                <Button type="default" onClick={this.closeView}>关闭</Button>
              </div>
            </div>
@@ -1810,7 +1799,7 @@
        <StyleController />
        <StyleCombController />
        <ModalController />
      </ConfigProvider>
      </>
    )
  }
}