king
2021-03-05 e36eb1999794bd71e76482b92a0b0b20f49d0032
src/views/pcdesign/index.jsx
@@ -26,6 +26,7 @@
const MenuShell = asyncComponent(() => import('@/pc/menushell'))
const SourceWrap = asyncComponent(() => import('@/pc/modulesource'))
const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
const Quotecomponent = asyncComponent(() => import('@/pc/quotecomponent'))
const PasteController = asyncComponent(() => import('@/menu/pastecontroller'))
const PaddingController = asyncComponent(() => import('@/pc/padcontroller'))
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
@@ -41,6 +42,7 @@
sessionStorage.setItem('appType', 'pc')        // 应用类型
document.body.className = ''
window.GLOB.UserComponentMap = new Map() // 缓存用户自定义组件
window.GLOB.CacheIndependent = new Map()
class MenuDesign extends Component {
  state = {
@@ -49,20 +51,18 @@
    MenuId: '',
    MenuName: '',
    MenuNo: '',
    tableFields: [],
    delButtons: [],
    copyButtons: [],
    thawButtons: [],
    activeKey: 'basedata',
    menuloading: false,
    oriConfig: null,
    openEdition: '',
    config: null,
    popBtn: null,             // 弹窗标签页
    visible: false,
    customComponents: [],
    settingshow: true,
    controlshow: true,
    settingshow: sessionStorage.getItem('settingshow') !== 'false',
    controlshow: sessionStorage.getItem('controlshow') !== 'false',
  }
  UNSAFE_componentWillMount() {
@@ -105,6 +105,7 @@
    MKEmitter.addListener('thawButtons', this.thawButtons)
    MKEmitter.addListener('copyButtons', this.copyButtons)
    MKEmitter.addListener('changePopview', this.initPopview)
    MKEmitter.addListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
    setTimeout(() => {
@@ -124,8 +125,25 @@
    MKEmitter.removeListener('thawButtons', this.thawButtons)
    MKEmitter.removeListener('copyButtons', this.copyButtons)
    MKEmitter.removeListener('changePopview', this.initPopview)
    MKEmitter.removeListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
  }
  changeEditMenu = (menu) => {
    const { oriConfig, config } = this.state
    if (!is(fromJS(oriConfig), fromJS(config))) {
      notification.warning({
        top: 92,
        message: '配置已修改,请保存!',
        duration: 5
      })
      return
    }
    this.props.history.replace('/pcdesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({MenuID: menu.MenuID, type: 'view'}))))
    window.location.reload()
  }
  getAppMessage = () => {
@@ -133,7 +151,7 @@
      func: 's_get_keyids',
      bid: sessionStorage.getItem('appId')
    }).then(res => {
      if (!res) {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
@@ -144,7 +162,11 @@
      let homeId = ''
      if (this.state.MenuId) {
        let appViewList = res.data && res.data.length > 0 ? res.data : []
        homeId = this.state.MenuId
        sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
      } else {
        let appViewList = []
        if (res.data && res.data.length > 0) {
@@ -204,6 +226,8 @@
  }
  getAppPictures = () => {
    if (sessionStorage.getItem('app_videos') || sessionStorage.getItem('app_pictures')) return
    Api.getSystemConfig({
      func: 's_url_db_adduptdel',
      PageIndex: 0,  // 0 代表全部
@@ -305,26 +329,23 @@
  }
  initPopview = (card, btn) => {
    // const { oriConfig, config } = this.state
    const { oriConfig, config } = this.state
    // let _config = fromJS(config).toJS()
    // delete _config.tableFields
    if (!is(fromJS(oriConfig), fromJS(config))) {
      notification.warning({
        top: 92,
        message: '配置已修改,请保存!',
        duration: 5
      })
      return
    }
    // if (!is(fromJS(oriConfig), fromJS(_config))) {
    //   notification.warning({
    //     top: 92,
    //     message: '配置已修改,请保存!',
    //     duration: 5
    //   })
    //   return
    // }
    btn.config = fromJS(config).toJS()
    btn.component = card
    // btn.config = _config
    // btn.component = card
    sessionStorage.setItem('editMenuType', 'popview') // 编辑弹窗标签
    // sessionStorage.setItem('editMenuType', 'popview') // 编辑弹窗标签
    // this.setState({popBtn: btn, visible: true})
    this.setState({popBtn: btn, visible: true})
  }
  closeView = () => {
@@ -335,10 +356,7 @@
      return
    }
    let _config = fromJS(config).toJS()
    delete _config.tableFields
    if (!is(fromJS(oriConfig), fromJS(_config))) {
    if (!is(fromJS(oriConfig), fromJS(config))) {
      confirm({
        title: '配置已修改,放弃保存吗?',
        content: '',
@@ -379,7 +397,6 @@
            uuid: MenuId,
            MenuID: MenuId,
            Template: 'webPage',
            easyCode: '',
            enabled: false,
            MenuName: '',
            MenuNo: '',
@@ -394,14 +411,25 @@
        
        config.uuid = MenuId
        config.MenuID = MenuId
        config.open_edition = result.open_edition || ''
        this.setState({
          oriConfig: config,
          config: fromJS(config).toJS(),
          openEdition: result.open_edition || '',
        let indeComs = []
        config.components.forEach(item => {
          if (item.type === 'navbar') {
            indeComs.push(fromJS(item).toJS())
          }
        })
        this.props.modifyCustomMenu(config)
        if (indeComs.length === 0) {
          this.setState({
            oriConfig: config,
            config: fromJS(config).toJS(),
          })
          this.props.modifyCustomMenu(config)
        } else {
          this.jointComponents(config, indeComs)
        }
      } else {
        notification.warning({
          top: 92,
@@ -409,6 +437,107 @@
          duration: 5
        })
      }
    })
    let _param = {
      func: 's_get_app_menus',
      TypeCharOne: sessionStorage.getItem('kei_no'),
      typename: 'pc',
      LText: `select '${window.GLOB.appkey}'`,
      timestamp: moment().format('YYYY-MM-DD HH:mm:ss')
    }
    _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
    Api.getSystemConfig(_param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
      let appIndeList = sessionStorage.getItem('appViewList')
      appIndeList = JSON.parse(appIndeList)
      appIndeList = appIndeList.map(item => (item.keys_type !== 'index' ? item.keys_id : '')).join(',')
      let menus = res.menus.filter(item => appIndeList.indexOf(item.MenuID) === -1)
      sessionStorage.setItem('appMenus', JSON.stringify(menus))
    })
  }
  jointComponents = (config, indeComs) => {
    let deffers = indeComs.map(item => {
      return new Promise(resolve => {
        Api.getSystemConfig({
          func: 'sPC_Get_LongParam',
          TypeCharOne: sessionStorage.getItem('kei_no'),
          typename: 'pc',
          MenuID: item.uuid
        }).then(res => {
          res.uuid = item.uuid
          if (!res.status) {
            notification.warning({
              top: 92,
              message: res.message,
              duration: 5
            })
            return
          }
          resolve(res)
        })
      })
    })
    Promise.all(deffers).then(result => {
      let _conf = {}
      result.forEach(res => {
        let _config = null
        try {
          _config = res.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(res.LongParam))) : null
        } catch (e) {
          console.warn('Parse Failure')
          _config = null
        }
        if (_config) {
          _config.open_edition = res.open_edition || ''
          _conf[res.uuid] = _config
          window.GLOB.CacheIndependent.set(res.uuid, fromJS(_config).toJS())
        }
      })
      let _length = config.components.length
      config.components = config.components.map(item => {
        if (item.type === 'navbar') {
          if (_conf[item.uuid]) {
            item = _conf[item.uuid]
          } else {
            item = null
          }
        }
        return item
      })
      config.components = config.components.filter(Boolean)
      if (_length > config.components.length) {
        notification.warning({
          top: 92,
          message: '部分组件已删除!',
          duration: 5
        })
      }
      this.setState({
        oriConfig: fromJS(config).toJS(),
        config: config
      })
      this.props.modifyCustomMenu(config)
    })
  }
@@ -512,7 +641,7 @@
  }
  submitConfig = () => {
    const { openEdition, delButtons, copyButtons, thawButtons } = this.state
    const { delButtons, copyButtons, thawButtons } = this.state
    let config = fromJS(this.state.config).toJS()
    if (!config.MenuName || !config.MenuNo || (config.cacheUseful === 'true' && !config.cacheTime)) {
@@ -535,41 +664,33 @@
        config.enabled = false
      }
      let _config = fromJS(config).toJS()
      delete _config.tableFields
      let parMenuId = 'pc' + sessionStorage.getItem('kei_no') + sessionStorage.getItem('lang')
      let parMenuId = sessionStorage.getItem('kei_no') + 'pc' + sessionStorage.getItem('lang')
      let param = {
        func: 'sPC_TrdMenu_AddUpt',
        FstID: parMenuId,
        SndID: parMenuId,
        ParentID: parMenuId,
        MenuID: _config.uuid,
        MenuNo: _config.MenuNo || '',
        EasyCode: _config.easyCode || '',
        MenuID: config.uuid,
        MenuNo: config.MenuNo || '',
        EasyCode: '',
        Template: 'webPage',
        TypeCharOne: sessionStorage.getItem('kei_no'),
        Typename: 'pc',
        MenuName: _config.MenuName || '',
        MenuName: config.MenuName || '',
        PageParam: JSON.stringify({Template: 'webPage'}),
        LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(_config))),
        open_edition: config.open_edition,
        LText: '',
        LTexttb: ''
      }
      param.LText = Utils.formatOptions(param.LText)
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
      if (!openEdition) { // 版本管理
        param.open_edition = openEdition
      }
      param.secretkey = Utils.encrypt('', param.timestamp)
      let btnParam = {             // 添加菜单按钮
        func: 'sPC_Button_AddUpt',
        Type: 40,                  // 添加菜单下的按钮type为40,按钮下的按钮type为60
        ParentID: _config.uuid,
        MenuNo: _config.MenuNo,
        ParentID: config.uuid,
        MenuNo: config.MenuNo,
        Template: 'webPage',
        PageParam: '',
        LongParam: '',
@@ -586,31 +707,129 @@
      btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
      new Promise(resolve => {
        // html2canvas(document.getElementById('menu-shell-inner')).then(canvas => {
        //   let _param = {
        //     Base64Img: canvas.toDataURL('image/png') // 获取生成的图片
        //   }
        let _config = fromJS(config).toJS()
        let indeComs = []
        _config.components = _config.components.map(item => {
          if (item.type === 'navbar') {
            indeComs.push(item)
            return {
              type: 'navbar',
              uuid: item.uuid
            }
          }
          return item
        })
        //   _param.rduri = options.cloudServiceApi
        //   _param.userid = sessionStorage.getItem('CloudUserID') || ''
        //   _param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
        param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
        //   Api.fileuploadbase64(_param).then(result => {
        //     if (result.status) {
        //       let Images = Utils.getcloudurl(result.Images)
        //       param.PageParam = JSON.stringify({Template: 'webPage', Images})
        //       resolve(true)
        //     } else {
        //       notification.warning({
        //         top: 92,
        //         message: result.ErrMesg,
        //         duration: 5
        //       })
        //       resolve(false)
        //     }
        //   })
        // })
        resolve(true)
        if (indeComs.length === 0) {
          resolve(true)
        } else {
          let new_open_edition = {}
          let deffers = indeComs.map(item => {
            return new Promise(resolve => {
              let _item = window.GLOB.CacheIndependent.get(item.uuid)
              if (_item && is(fromJS(_item), fromJS(item))) {
                new_open_edition[item.uuid] = item.open_edition || ''
                resolve()
                return
              }
              let _param = {
                func: 'sPC_TrdMenu_AddUpt',
                FstID: parMenuId,
                SndID: parMenuId,
                ParentID: parMenuId,
                MenuID: item.uuid,
                MenuNo: item.wrap.MenuNo || '',
                EasyCode: '',
                Template: item.type,
                TypeCharOne: sessionStorage.getItem('kei_no'),
                Typename: 'pc',
                MenuName: item.name || '',
                PageParam: JSON.stringify({Template: item.type}),
                open_edition: item.open_edition || '',
                LText: '',
                LTexttb: ''
              }
              _param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(item)))
              _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
              _param.secretkey = Utils.encrypt('', _param.timestamp)
              Api.getSystemConfig(_param).then(res => {
                if (!res.status) {
                  notification.warning({
                    top: 92,
                    message: res.message,
                    duration: 5
                  })
                  return
                }
                new_open_edition[item.uuid] = res.open_edition || ''
                resolve()
              })
            })
          })
          Promise.all(deffers).then(() => {
            let appViewList = sessionStorage.getItem('appViewList')
            appViewList = JSON.parse(appViewList)
            let _length = appViewList.length
            let appIndeList = appViewList.map(item => item.keys_id).join(',')
            config.components = config.components.map(item => {
              if (item.type === 'navbar') {
                item.open_edition = new_open_edition[item.uuid] || ''
                window.GLOB.CacheIndependent.set(item.uuid, fromJS(item).toJS())
                if (appIndeList.indexOf(item.uuid) === -1) {
                  appViewList.unshift({
                    appkey: window.GLOB.appkey || '',
                    bid: sessionStorage.getItem('appId') || '',
                    kei_no: sessionStorage.getItem('kei_no') || '',
                    keys_id: item.uuid,
                    keys_type: 'navbar',
                    remark: item.name
                  })
                }
              }
              return item
            })
            if (appViewList.length > _length) {
              let param = {
                func: 's_kei_link_keyids_addupt',
                BID: sessionStorage.getItem('appId'),
                exec_type: 'y',
                LText: ''
              }
              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.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
              param.secretkey = Utils.encrypt('', param.timestamp)
              Api.getSystemConfig(param).then(result => {
                if (!result.status) {
                  notification.warning({
                    top: 92,
                    message: result.message,
                    duration: 5
                  })
                } else {
                  sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
                  resolve(true)
                }
              })
            } else {
              resolve(true)
            }
          })
        }
      }).then(res => { // 按钮删除
        if (!res) return
@@ -664,9 +883,10 @@
        if (!res) return
        if (res.status) {
          config.open_edition = res.open_edition || ''
          this.setState({
            oriConfig: fromJS(_config).toJS(),
            openEdition: res.open_edition || ''
            oriConfig: fromJS(config).toJS(),
          })
          if (btnParam.LText) {
@@ -738,7 +958,7 @@
                    let _param = {
                      func: 'sPC_ButtonParam_AddUpt',
                      ParentID: _config.uuid,
                      ParentID: config.uuid,
                      MenuID: item.uuid,
                      MenuNo: '',
                      Template: 'webPage',
@@ -805,6 +1025,7 @@
  }
  getRoleFields = () => {
    if (sessionStorage.getItem('sysRoles') || sessionStorage.getItem('permFuncField')) return
    Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
      if (res.status) {
        let _permFuncField = []
@@ -900,20 +1121,24 @@
    this.props.modifyCustomMenu(config)
  }
  /**
   * @description 更新常用表信息,快捷添加后更新配置信息
   */
  updatetable = (config, fields) => {
    const { tableFields } = this.state
  refreshView = () => {
    const { oriConfig, config } = this.state
    config.tableFields = fields ? fields : tableFields
    if (!is(fromJS(oriConfig), fromJS(config))) {
      notification.warning({
        top: 92,
        message: '配置已修改,请保存!',
        duration: 5
      })
      return
    }
    this.setState({
      tableFields: fields ? fields : tableFields,
      config
    })
    this.props.modifyCustomMenu(config)
    sessionStorage.removeItem('sysRoles')
    sessionStorage.removeItem('permFuncField')
    sessionStorage.removeItem('app_videos')
    sessionStorage.removeItem('app_pictures')
    window.location.reload()
  }
  render () {
@@ -925,8 +1150,8 @@
          <DndProvider backend={HTML5Backend}>
            <div className={'menu-setting ' + (!settingshow ? 'hidden' : '')}>
              <div className="draw">
                {settingshow ? <Icon onClick={() => this.setState({settingshow: false})} type="double-left" /> : null}
                {!settingshow ? <Icon onClick={() => this.setState({settingshow: true})} type="double-right" /> : null}
                {settingshow ? <Icon onClick={() => {sessionStorage.setItem('settingshow', 'false'); this.setState({settingshow: false})}} type="double-left" /> : null}
                {!settingshow ? <Icon onClick={() => {sessionStorage.setItem('settingshow', 'true'); this.setState({settingshow: true})}} type="double-right" /> : null}
              </div>
              <div className="pc-setting-tools">
                <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
@@ -940,7 +1165,7 @@
                      updateConfig={this.updateConfig}
                    /> : null}
                    {/* 表名添加 */}
                    {config ? <TableComponent config={config} updatetable={this.updatetable}/> : null}
                    {config ? <TableComponent config={config} updatetable={this.updateConfig}/> : null}
                  </Panel>
                  {/* 组件添加 */}
                  <Panel header={dict['mob.component']} key="component">
@@ -960,8 +1185,8 @@
            </div>
            <div className={'menu-control ' + (!controlshow ? 'hidden' : '')}>
              <div className="draw">
                {controlshow ? <Icon onClick={() => this.setState({controlshow: false})} type="double-right" /> : null}
                {!controlshow ? <Icon onClick={() => this.setState({controlshow: true})} type="double-left" /> : null}
                {controlshow ? <Icon onClick={() => {sessionStorage.setItem('controlshow', 'false'); this.setState({controlshow: false})}} type="double-right" /> : null}
                {!controlshow ? <Icon onClick={() => {sessionStorage.setItem('controlshow', 'true'); this.setState({controlshow: true})}} type="double-left" /> : null}
              </div>
              <Button type="primary" onClick={this.submitConfig} loading={menuloading}>{dict['mob.save']}</Button>
              <Switch className="big" checkedChildren={dict['mob.enable']} unCheckedChildren={dict['mob.disable']} checked={config && config.enabled} onChange={this.onEnabledChange} />
@@ -969,6 +1194,8 @@
              <StyleCombControlButton menu={config} />
              <SysInterface config={config} updateConfig={this.updateConfig}/>
              <PictureController/>
              <Quotecomponent config={config} updateConfig={this.updateConfig}/>
              <Button className="mk-border-danger" icon="redo" onClick={this.refreshView}>强制刷新</Button>
              <Button type="default" onClick={this.closeView}>{dict['mob.return']}</Button>
            </div>
            <div className={'menu-body ' + (menuloading ? 'saving' : '')}>