king
2023-08-27 da64ab0923bf8817fc8599a6e37b953ce38f64c8
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'
@@ -48,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 = ''
@@ -63,7 +61,6 @@
    menuloading: false,
    oriConfig: null,
    config: null,
    customComponents: [],
    comloading: false,
    settingshow: sessionStorage.getItem('settingshow') !== 'false',
    eyeopen: false,
@@ -81,7 +78,6 @@
    }
    
    if (!sessionStorage.getItem('UserID')) {
      sessionStorage.removeItem('isEditState')
      sessionStorage.removeItem('appType')
      this.props.history.replace('/login')
      return
@@ -126,18 +122,7 @@
    
    MKEmitter.addListener('changePopview', this.initPopview)
    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
    setTimeout(() => {
      if (sessionStorage.getItem('app_custom_components')) {
        let list = sessionStorage.getItem('app_custom_components')
        list = JSON.parse(list)
        this.setCustomComponent(list)
      } else {
        this.updateCustomComponent()
      }
      this.getAppPictures()
      this.getPrintTemp()
      this.getRoleFields()
      setGLOBFuncs()
    }, 1000)
@@ -208,7 +193,6 @@
    }
    MKEmitter.removeListener('changePopview', this.initPopview)
    MKEmitter.removeListener('triggerMenuSave', this.triggerMenuSave)
    MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
  }
  triggerMenuSave = () => {
@@ -238,135 +222,6 @@
    window.GLOB.customMenu = config
    this.setState({view: '', popConfig: null})
  }
  getPrintTemp = () => {
    if (!sessionStorage.getItem('printTemps')) {
      let _sql = `select ID,Images,PrintTempNO+PrintTempName as PN from sPrintTemplate
      where appkey= @appkey@ and Deleted=0 and typechartwo='web_print'
      union select ID,Images,a.PrintTempNO+PrintTempName as PN
      from (select * from sPrintTemplate where appkey= '' and Deleted=0 and typechartwo='web_print') a
      left join (select PrintTempNO from sPrintTemplate where appkey= @appkey@ and Deleted=0 ) b
      on a.PrintTempNO=b.PrintTempNO
      left join (select Srcid from sPrintTemplate_Log where appkey='' and apicode= @appkey@ and Deleted=0 ) c
      on a.ID=c.Srcid where b.PrintTempNO is null and c.Srcid is null`
      let param = {
        func: 'sPC_Get_SelectedList',
        LText: Utils.formatOptions(_sql),
        obj_name: 'data',
        arr_field: 'PN,ID,Images'
      }
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
      param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 云端数据验证
      Api.getSystemConfig(param).then(res => {
        if (res.status) {
          let temps = res.data.map(temp => {
            return {
              value: temp.ID,
              text: temp.PN
            }
          })
          sessionStorage.setItem('printTemps', JSON.stringify(temps))
        } else {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          })
        }
      })
    }
  }
  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.getSystemConfig({...param, typecharone: 'image'}).then(res => {
          resolve(res.data)
        })
      }, 500)
    }), new Promise(resolve => {
      setTimeout(() => {
        Api.getSystemConfig({...param, typecharone: 'video'}).then(res => {
          resolve(res.data)
        })
      }, 1000)
    }), new Promise(resolve => {
      setTimeout(() => {
        Api.getSystemConfig({...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] || []))
    })
  }
  updateCustomComponent = () => {
    Api.getSystemConfig({
      func: 's_get_custom_components',
      typename: '',
      typecharone: ''
    }).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      } else if (res.cus_list) {
        sessionStorage.setItem('app_custom_components', JSON.stringify(res.cus_list))
        this.setCustomComponent(res.cus_list)
      }
    })
  }
  setCustomComponent = (cus_list) => {
    let coms = []
    cus_list.forEach(item => {
      let config = ''
      try {
        config = JSON.parse(window.decodeURIComponent(window.atob(item.long_param)))
      } catch (e) {
        console.warn('Parse Failure')
        config = ''
      }
      if (!config || !item.c_name) return
      window.GLOB.UserComponentMap.set(item.c_id, item.c_name)
      coms.push({
        uuid: item.c_id,
        type: 'menu',
        title: item.c_name,
        url: item.images,
        component: config.type,
        subtype: config.subtype,
        config
      })
    })
    this.setState({customComponents: coms})
  }
  initPopview = (card, btn) => {
@@ -438,7 +293,7 @@
      MenuID: MenuId
    }
    Api.getSystemConfig(param).then(result => {
    Api.getCloudConfig(param).then(result => {
      if (result.status) {
        let config = null
@@ -651,6 +506,8 @@
        comloading: false,
        needUpdate: true
      })
      window.GLOB.customMenu = config
      return
    }
@@ -662,7 +519,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
@@ -729,6 +586,8 @@
      config.components = this.setPopView(config.components, parents, popbtns)
      this.setState({ delButtons: bts, config, comloading: false })
      window.GLOB.customMenu = config
    })
  }
@@ -816,7 +675,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
@@ -963,15 +822,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),
@@ -991,7 +850,7 @@
      }).then(res => { // 页面保存
        if (!res || !res.status) return res
        return Api.getSystemConfig(param)
        return Api.getCloudConfig(param)
      }).then(res => { // 按钮删除
        if (!res || !res.status) return res
@@ -1014,7 +873,7 @@
            func: 'sPC_MainMenu_Del',
            MenuID: this.state.delButtons.join(',')
          }
          return Api.getSystemConfig(_param)
          return Api.getCloudConfig(_param)
        }
      }, this.netError).then(res => { // 页面按钮关系保存
        if (!res || !res.status) return res
@@ -1024,7 +883,7 @@
        })
        if (MenuType !== 'billPrint') {
          return Api.getSystemConfig(btnParam)
          return Api.getCloudConfig(btnParam)
        } else {
          return {
            status: true
@@ -1043,7 +902,6 @@
            message: '保存成功',
            duration: 2
          })
          MKEmitter.emit('completeSave')
        } else {
          notification.warning({
            top: 92,
@@ -1051,6 +909,7 @@
            duration: 5
          })
        }
        MKEmitter.emit('completeSave')
      }, this.netError)
    }, 300 + (+sessionStorage.getItem('mkDelay')))
  }
@@ -1067,12 +926,13 @@
        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 = []
@@ -1240,7 +1100,7 @@
  }
  render () {
    const { view, comloading, MenuType, MenuId, config, settingshow, ParentId, menuloading, customComponents, eyeopen, needUpdate } = this.state
    const { view, comloading, MenuType, MenuId, config, settingshow, ParentId, menuloading, eyeopen, needUpdate } = this.state
    return (
      <ConfigProvider locale={_locale}>
@@ -1288,9 +1148,6 @@
                  <Panel header="元素" key="element">
                    <Modulecell />
                  </Panel>
                  {customComponents && customComponents.length ? <Panel header="自定义组件" key="cuscomponent">
                    <SourceWrap components={customComponents} MenuType={MenuType} />
                  </Panel> : null}
                  <Panel header="页面样式" key="background">
                    {config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
                  </Panel>