king
2022-04-29 eec619b6e3339e9999a7a1c2c5454cef5d763b24
src/views/mobdesign/index.jsx
@@ -1,47 +1,198 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { DndProvider } from 'react-dnd'
import { withRouter } from 'react-router'
import { is, fromJS } from 'immutable'
import moment from 'moment'
import HTML5Backend from 'react-dnd-html5-backend'
import { Icon, Tabs, notification, Modal } from 'antd'
// import html2canvas from 'html2canvas'
import { ConfigProvider, notification, Modal, Collapse, Switch, Button, message, Spin, Typography } from 'antd'
import { DoubleLeftOutlined, DoubleRightOutlined, HomeOutlined, LoginOutlined, RedoOutlined, ArrowLeftOutlined } from '@ant-design/icons'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import Utils, { setGLOBFuncs } from '@/utils/utils.js'
import zhCN from '@/locales/zh-CN/mob.js'
import enUS from '@/locales/en-US/mob.js'
import antdEnUS from 'antd/es/locale/en_US'
import antdZhCN from 'antd/es/locale/zh_CN'
import MKEmitter from '@/utils/events.js'
import MenuUtils from '@/utils/utils-custom.js'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
const { TabPane } = Tabs
const { Panel } = Collapse
const { confirm } = Modal
const { Paragraph } = Typography
const Header = asyncComponent(() => import('@/mob/header'))
const Controller = asyncComponent(() => import('@/mob/controller'))
const MenuForm = asyncComponent(() => import('./menuform'))
const MobShell = asyncComponent(() => import('@/mob/mobshell'))
const SourceWrap = asyncComponent(() => import('@/mob/modelsource'))
const DataSource = asyncComponent(() => import('@/mob/datasource'))
const CreateView = asyncComponent(() => import('@/pc/createview'))
const Transfer = asyncComponent(() => import('@/pc/transfer'))
const Versions = asyncComponent(() => import('@/menu/versions'))
const ViewNodes = asyncComponent(() => import('@/menu/viewnodes'))
const SourceWrap = asyncComponent(() => import('@/mob/modulesource'))
const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
const SysInterface = asyncComponent(() => import('@/menu/sysinterface'))
const Quotecomponent = asyncComponent(() => import('@/pc/quotecomponent'))
const PasteController = asyncComponent(() => import('@/menu/pastecontroller'))
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
const UrlFieldComponent = asyncComponent(() => import('@/menu/urlfieldcomponent'))
const PictureController = asyncComponent(() => import('@/menu/picturecontroller'))
const ModalController = asyncComponent(() => import('@/mob/modalconfig/controller'))
const SearchController = asyncComponent(() => import('@/mob/searchconfig/controller'))
const StyleCombController = asyncComponent(() => import('@/menu/stylecombcontroller'))
const StyleCombControlButton = asyncComponent(() => import('@/menu/stylecombcontrolbutton'))
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
class Mobile extends Component {
sessionStorage.setItem('isEditState', 'true')
sessionStorage.setItem('editMenuType', 'menu') // 编辑菜单类型
sessionStorage.setItem('appType', 'mob')       // 应用类型
document.body.className = ''
window.GLOB.UserComponentMap = new Map() // 缓存用户自定义组件
window.GLOB.TabsMap = new Map()          // 缓存用户操作的标签页
window.GLOB.CacheIndependent = new Map()
window.GLOB.urlFields = []               // url变量
window.GLOB.customMenu = null            // 保存菜单信息
class MobDesign extends Component {
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    appId: this.props.match.params.appId,
    appType: this.props.match.params.appType,
    appCode: this.props.match.params.appCode,
    appName: this.props.match.params.appName,
    localedict: sessionStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS,
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    loading: true,
    MenuId: '',
    MenuName: '',
    MenuNo: '',
    activeKey: 'component',
    menuloading: false,
    oriConfig: null,
    parentId: '',
    openEdition: '',
    saveIng: false,
    config: null,
    pageIndex: 0,
    editElem: null
    customComponents: [],
    direction: 'vertical',
    settingshow: true,
    controlshow: true,
    comloading: false,
    adapters: [],
    viewType: 'menu'
  }
  UNSAFE_componentWillMount() {
    this.getAppParam(this.props.match.params.appId)
    if (this.props.memberLevel < 30) return
    try {
      let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
      if (param.type === 'app') {
        sessionStorage.setItem('appId', param.ID || '')
        sessionStorage.setItem('lang', param.lang || 'zh-CN')
        sessionStorage.setItem('kei_no', param.kei_no || '')
        sessionStorage.setItem('role_type', param.role_type || 'true')
        sessionStorage.setItem('login_types', param.login_types || 'false')
        sessionStorage.setItem('typename', param.typename || 'mob')
        sessionStorage.setItem('adapter', param.adapter || '')
        sessionStorage.setItem('sysBgColor', param.sysBgColor || '#ffffff')
        sessionStorage.setItem('userbind', param.userbind || '')
        sessionStorage.setItem('instantMessage', param.instantMessage || '')
        this.setState({
          localedict: sessionStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS,
          dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
        })
        this.getAppMessage(param.MenuID)
      } else if (param.type === 'view') {
        window.GLOB.winWidth = 420
        window.GLOB.winHeight = 738
        window.GLOB.shellWidth = 376
        window.GLOB.shellHeight = 680
        if (sessionStorage.getItem('typename') === 'pad') {
          window.GLOB.winWidth = 736
          window.GLOB.winHeight = 945
          window.GLOB.shellWidth = 640
          window.GLOB.shellHeight = 853
        }
        let adapters = sessionStorage.getItem('adapter')
        if (adapters) {
          adapters = adapters.split(',')
        } else {
          adapters = []
        }
        this.setState({
          adapters,
          MenuId: param.MenuID,
          viewType: /^userbind/.test(param.MenuID) ? 'userbind' : 'menu'
        }, () => {
          this.getMenuParam(param)
          this.getRelationMenus()
        })
      }
    } catch (e) {
      notification.warning({
        top: 92,
        message: '菜单信息解析错误!',
        duration: 5
      })
    }
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (this.props.match.params.param !== nextProps.match.params.param) {
      window.location.reload()
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    if (this.props.memberLevel < 30) {
      document.getElementById('mk-mob-design-view').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh; height: 100vh; background: #fff;">本应用没有PC端页面的编辑权限,请联系管理员!</div>'
      return
    }
    MKEmitter.addListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.addListener('triggerMenuSave', this.submitConfig)
    MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
    setTimeout(() => {
      this.updateCustomComponent()
      this.getAppPictures()
      this.getSmStemp()
      setGLOBFuncs()
    }, 1000)
    document.onkeydown = (event) => {
      let e = event || window.event
      let keyCode = e.keyCode || e.which || e.charCode
      let preKey = ''
      if (e.ctrlKey) {
        preKey = 'ctrl'
      }
      if (e.shiftKey) {
        preKey = 'shift'
      } else if (e.altKey) {
        preKey = 'alt'
      }
      if (!preKey || !keyCode) return
      let _shortcut = `${preKey}+${keyCode}`
      if (_shortcut === 'ctrl+83') {
        let node = document.getElementById('save-modal-config')
        if (!node) {
          node = document.getElementById('save-config')
        }
        if (node) {
          node.click()
        }
        return false
      }
    }
  }
  /**
@@ -51,317 +202,1783 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('changeEditMenu', this.changeEditMenu)
    MKEmitter.removeListener('triggerMenuSave', this.submitConfig)
    MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
    MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
  }
  jumpToManage = () => {
    const { oriConfig, config } = this.state
    const _this = this
  getSmStemp = () => {
    let _sql = `select ID,TemplateCode,SignName from (select * from bd_msn_sms_temp where deleted=0 and status=20 ) a
      inner join (select openid from sapp where id='${window.GLOB.appkey}') b
      on a.openid=b.openid`
    if (!is(fromJS(oriConfig), fromJS(config))) {
    _sql = Utils.formatOptions(_sql)
    let param = {
      func: 'sPC_Get_SelectedList',
      LText: _sql,
      obj_name: 'data',
      arr_field: 'ID,TemplateCode,SignName'
    }
    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 => {
      let msgs = []
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      } else if (res.data) {
        msgs = res.data
      }
      sessionStorage.setItem('msgTemplate', JSON.stringify(msgs))
    })
  }
  changeEditMenu = (menu) => {
    const { oriConfig, config } = this.state
    if (!oriConfig || !is(fromJS(oriConfig), fromJS(config))) {
      notification.warning({
        top: 92,
        message: '配置信息未保存!',
        duration: 5
      })
      return
    } else if (['AIService'].includes(menu.MenuID)) {
      notification.warning({
        top: 92,
        message: '系统页面不可编辑!',
        duration: 5
      })
      return
    } else if (menu.routerUrl) {
      this.props.history.push(menu.routerUrl)
      return
    }
    let param = {
      MenuID: menu.MenuID,
      copyMenuId: menu.copyMenuId || '',
      clearMenu: menu.clearMenu !== 'false',
      type: 'view'
    }
    param.MenuNo = menu.MenuNo || ''
    param.MenuName = menu.MenuName || ''
    param = window.btoa(window.encodeURIComponent(JSON.stringify(param)))
    if (param === this.props.match.params.param) return
    this.props.history.push('/mobdesign/' + param)
  }
  getAppMessage = (MenuID) => {
    Api.getSystemConfig({
      func: 's_get_keyids',
      bid: sessionStorage.getItem('appId')
    }).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
      let homeId = ''
      let appViewList = []
      if (res.data && res.data.length > 0) {
        appViewList = res.data
        appViewList.forEach(item => {
          if (item.keys_type === 'index') {
            homeId = item.keys_id
          }
        })
      }
      if (!homeId) {
        homeId = MenuID || Utils.getuuid()
        let param = {
          func: 's_kei_link_keyids_addupt',
          BID: sessionStorage.getItem('appId'),
          exec_type: 'y',
          LText: ''
        }
        appViewList.unshift({
          appkey: window.GLOB.appkey || '',
          bid: sessionStorage.getItem('appId') || '',
          kei_no: sessionStorage.getItem('kei_no') || '',
          keys_id: homeId,
          keys_type: 'index',
          remark: '首页'
        })
        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))
            this.props.history.replace('/mobdesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({MenuID: homeId, type: 'view'}))))
          }
        })
      } else {
        sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
        this.props.history.replace('/mobdesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({MenuID: MenuID || homeId, type: 'view'}))))
      }
    })
  }
  getAppPictures = () => {
    if (sessionStorage.getItem('app_videos') || sessionStorage.getItem('app_pictures')) return
    Api.getSystemConfig({
      func: 's_url_db_adduptdel',
      PageIndex: 0,  // 0 代表全部
      PageSize: 0,   // 0 代表全部
      typecharone: 'image',
      type: 'search'
    }).then(res => {
      if (res.status) {
        sessionStorage.setItem('app_pictures', JSON.stringify(res.data || []))
      }
      Api.getSystemConfig({
        func: 's_url_db_adduptdel',
        PageIndex: 0,  // 0 代表全部
        PageSize: 0,   // 0 代表全部
        typecharone: 'video',
        type: 'search'
      }).then(res => {
        if (res.status) {
          sessionStorage.setItem('app_videos', JSON.stringify(res.data || []))
        }
      })
      Api.getSystemConfig({
        func: 's_url_db_adduptdel',
        PageIndex: 0,  // 0 代表全部
        PageSize: 0,   // 0 代表全部
        typecharone: 'color',
        type: 'search'
      }).then(res => {
        if (res.status) {
          sessionStorage.setItem('app_colors', JSON.stringify(res.data || []))
        }
      })
    })
  }
  updateCustomComponent = () => {
    Api.getSystemConfig({
      func: 's_get_custom_components',
      typename: sessionStorage.getItem('typename'),
      typecharone: ''
    }).then(res => {
      let coms = []
      if (res.cus_list && res.cus_list.length > 0) {
        res.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,
            width: config.width || 24,
            config
          })
        })
      }
      this.setState({customComponents: coms})
      this.getRoleFields()
    })
  }
  updateComponentStyle = (parentId, keys, style) => {
    const { config } = this.state
    if (config.uuid !== parentId) return
    let components = config.components.map(item => {
      if (keys.includes(item.uuid)) {
        item.style = {...item.style, ...style}
      }
      return item
    })
    this.setState({
      config: {...config, components},
      comloading: true
    }, () => {
      this.setState({
        comloading: false
      })
    })
  }
  closeView = () => {
    const { oriConfig, config } = this.state
    if (!config) {
      window.close()
    } else if (!oriConfig || !is(fromJS(oriConfig), fromJS(config))) {
      confirm({
        title: '配置已修改,放弃保存吗?',
        title: '配置信息未保存,确定关闭吗?',
        content: '',
        okText: _this.state.dict['mob.confirm'],
        cancelText: _this.state.dict['mob.cancel'],
        onOk() {
          _this.props.history.replace('/mobmanage')
          window.close()
        },
        onCancel() {}
      })
    } else {
      _this.props.history.replace('/mobmanage')
      window.close()
    }
  }
  triggerSave = () => {
    const { config, openEdition, parentId } = this.state
  backView = () => {
    const { oriConfig, config } = this.state
    this.setState({
      saveIng: true
    })
    if (!config) {
      window.history.back()
    } else if (!oriConfig || !is(fromJS(oriConfig), fromJS(config))) {
      confirm({
        title: '配置信息未保存,确定后退吗?',
        content: '',
        onOk() {
          window.history.back()
        },
        onCancel() {}
      })
    } else {
      window.history.back()
    }
  }
  getMenuParam = (urlParam) => {
    const { MenuId } = this.state
    let param = {
      func: 'sPC_TrdMenu_AddUpt',
      ParentID: config.entrance ? '' : parentId,
      MenuID: config.uuid,
      MenuNo: config.MenuNo,
      EasyCode: '',
      Template: '',
      MenuName: '',
      PageParam: '',
      LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config))),
      // LText: _vals.func.map(item => `select '${menu.MenuID}' as MenuID,'${item.func}' as ProcName,'${item.label}' as MenuName`),
      // LTexttb: _tables.map(item => `select '${menu.MenuID}' as MenuID,'${item}' as tbName`),
      TypeCharOne: 'mob'
    }
    let _LText = ''
    // _LText = _LText.join(' union all ')
    let _LTexttb = ''
    // _LTexttb = _LTexttb.join(' union all ')
    param.LText = Utils.formatOptions(_LText)
    param.LTexttb = Utils.formatOptions(_LTexttb)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    if (openEdition) { // 版本管理
      param.open_edition = openEdition
    }
    Api.getSystemConfig(param).then(response => {
      if (response.status) {
        this.setState({
          oriConfig: fromJS(config).toJS(),
          openEdition: response.open_edition || '',
          saveIng: false
        })
      } else {
        notification.warning({
          top: 92,
          message: response.message,
          duration: 5
        })
      }
    })
  }
  getAppParam = (id) => {
    Api.getSystemConfig({
      func: 'sPC_Get_LongParam',
      MenuID: id,
      TypeCharOne: 'mob'
    }).then(result => {
      if (result.status) {
        let config = null
      TypeCharOne: sessionStorage.getItem('kei_no'),
      typename: sessionStorage.getItem('typename'),
      MenuID: MenuId
    }
        if (result.LongParam) {
          try {
            config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
          } catch (e) {
            console.warn('Parse Failure')
            config = null
          }
        }
        if (!config) {
          config = {
            version: 1.0,
            entrance: true,
            label: '',
            uuid: this.props.match.params.appId,
            pageIndex: 0,
            MenuNo: this.props.match.params.appCode,
            sourcelist: [],
            components: []
          }
        }
        this.setState({
          oriConfig: config,
          config: fromJS(config).toJS(),
          openEdition: result.open_edition || '',
        })
      } else {
    Api.getSystemConfig(param).then(result => {
      if (!result.status) {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
        this.setState({loading: false})
        return
      } else if (!result.LongParam && urlParam.copyMenuId) {
        this.getCopyParam(urlParam)
      } else {
        let config = null
        let isCreate = false
        try {
          config = result.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) : null
        } catch (e) {
          console.warn('Parse Failure')
          config = null
        }
        if (/^userbind/.test(MenuId)) {
          this.setUserBindMenu(config, result)
          return
        }
        if (!config) {
          isCreate = true
          config = {
            version: 1.0,
            uuid: MenuId,
            MenuID: MenuId,
            Template: 'webPage',
            enabled: false,
            MenuName: urlParam.MenuName || '',
            MenuNo: urlParam.MenuNo || '',
            tables: [],
            components: [],
            viewType: 'menu',
            statusBarbgColor: sessionStorage.getItem('sysBgColor') || '#ffffff',
            style: {
              backgroundColor: sessionStorage.getItem('sysBgColor') || '#ffffff', backgroundImage: ''
            }
          }
        }
        config.uuid = MenuId
        config.MenuID = MenuId
        config.open_edition = result.open_edition || ''
        window.GLOB.urlFields = config.urlFields || []
        let indeComs = []
        config.components.forEach(item => {
          if (item.type === 'navbar') {
            indeComs.push(fromJS(item).toJS())
          }
        })
        if (indeComs.length === 0) {
          this.setState({
            oriConfig: isCreate ? null : config,
            config: fromJS(config).toJS(),
            activeKey: isCreate ? 'basedata' : 'component',
            loading: false
          })
          window.GLOB.customMenu = config
        } else {
          this.jointComponents(config, indeComs, isCreate)
        }
      }
    })
    this.getAppMenus()
  }
  getRelationMenus = () => {
    const { MenuId } = this.state
    let param = {
      func: 's_get_menu_used_list',
      TypeCharOne: sessionStorage.getItem('kei_no'),
      typename: sessionStorage.getItem('typename'),
      par_menuid: MenuId,
      // used_menuid: MenuId
    }
    Api.getSystemConfig(param).then(result => {
      if (!result.status) {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
        return
      }
    })
  }
  deleteCard = (id) => {
    let _this = this
  setUserBindMenu = (config, result) => {
    const { MenuId } = this.state
    let isCreate = !config
    if (!config) {
      config = {
        version: 1.0,
        uuid: MenuId,
        MenuID: MenuId,
        Template: 'webPage',
        enabled: false,
        MenuName: '用户绑定',
        MenuNo: 'user_bind',
        tables: [],
        components: [],
        viewType: 'userbind',
        statusBarbgColor: '#ffffff',
        style: {
          backgroundColor: '#ffffff', backgroundImage: ''
        }
      }
      config.components.push({
        subcards:[
          {
            uuid: Utils.getuuid(), setting: {width:24, primaryId: '', click: ''}, style: {}, backStyle: {},
            elements: [{maxWidth: 120, datatype: 'static', width: 24, marks: null, url: 'http://cloud.mk9h.cn/Content/images/20220120/cb5cd13a-2ef4-41cc-ab6a-a202f1c04da5.png', style: {borderRadius: '50%'}, eleType: 'picture', link: '', uuid: Utils.getuuid(), lenWidRadio: '1:1', $type: ''}],
            backElements: []
          }
        ],
        headerStyle: {}, parentId: '', width: 24, scripts: [], btnlog: [], pageable: false,
        wrap: {name: 'logo', width: 24, datatype: 'static', cardType: '', blacklist: []},
        name: 'logo', floor: 1, switchable: true,
        setting:{interType: 'system'}, tabId: '', style:{paddingTop: '8vh', paddingBottom: '10vh'}, dataName: Utils.getuuid(), format: 'object', subtype: 'propcard', type: 'card', uuid: Utils.getuuid(), columns: []
      })
      config.components.push({
        uuid: Utils.getuuid(),
        type: 'login',
        floor: 1,
        tabId: '',
        parentId: '',
        dataName: '',
        width: 24,
        name: '用户绑定',
        subtype: 'bindlogin',
        wrap: { name: '用户绑定', width: 24, loginWays: ['uname_pwd'], shortcut: 'none', height: '45vh' },
        style: {},
        loginWays: [
          {type: 'uname_pwd', label: '账号登录', shortcut: 'none'},
          {type: 'sms_vcode', label: '短信登录'},
        ]
      })
      config.components.push({
        subcards:[
          {
            uuid: Utils.getuuid(), setting: {width:24, primaryId: '', click: ''}, style: {}, backStyle: {},
            elements: [{datatype: 'static', width: 24, marks: null, height: null, value: 'Power by Minkesoft', style: { fontSize: '13px', textAlign: 'center'}, eleType: 'text', link: '', uuid: Utils.getuuid(), $type: ''}],
            backElements: []
          }
        ],
        headerStyle: {}, parentId: '', width: 24, scripts: [], btnlog: [], pageable: false,
        wrap: {name: 'Power', width: 24, datatype: 'static', cardType: '', blacklist: []},
        name: 'Power', floor: 1, switchable: true,
        setting:{interType: 'system'}, tabId: '', style:{}, dataName: Utils.getuuid(), format: 'object', subtype: 'propcard', type: 'card', uuid: Utils.getuuid(), columns: []
      })
    }
    config.uuid = MenuId
    config.MenuID = MenuId
    config.open_edition = result.open_edition || ''
    this.setState({
      oriConfig: isCreate ? null : config,
      config: fromJS(config).toJS(),
      activeKey: isCreate ? 'basedata' : 'component',
      loading: false
    })
    window.GLOB.customMenu = config
  }
  getAppMenus = () => {
    let _param = {
      func: 's_get_app_menus',
      TypeCharOne: sessionStorage.getItem('kei_no'),
      typename: sessionStorage.getItem('typename'),
      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(',')
      if (sessionStorage.getItem('userbind')) {
        appIndeList = appIndeList + ',' + sessionStorage.getItem('userbind')
      }
      if (sessionStorage.getItem('instantMessage')) {
        appIndeList = appIndeList + ',' + sessionStorage.getItem('instantMessage')
      }
      let menus = res.menus.filter(item => appIndeList.indexOf(item.MenuID) === -1)
      menus = menus.map(item => {
        item.value = item.MenuID
        item.label = item.MenuName
        return item
      })
      sessionStorage.setItem('appMenus', JSON.stringify(menus))
      sessionStorage.setItem('allMenus', JSON.stringify(res.menus || []))
    })
  }
  getCopyParam = (urlParam) => {
    const { MenuId } = this.state
    let param = {
      func: 'sPC_Get_LongParam',
      TypeCharOne: sessionStorage.getItem('kei_no'),
      typename: sessionStorage.getItem('typename'),
      MenuID: urlParam.copyMenuId
    }
    Api.getSystemConfig(param).then(result => {
      if (!result.status) {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
        this.setState({loading: false})
        return
      } else if (!result.LongParam) {
        notification.warning({
          top: 92,
          message: '未查询到复制菜单配置信息!',
          duration: 5
        })
      }
      let config = null
      try {
        config = result.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) : null
      } catch (e) {
        console.warn('Parse Failure')
        config = null
      }
      if (!config) {
        config = {
          version: 1.0,
          uuid: MenuId,
          MenuID: MenuId,
          Template: 'webPage',
          enabled: false,
          MenuName: '',
          MenuNo: '',
          tables: [],
          components: [],
          viewType: 'menu',
          style: {
            backgroundColor: '#ffffff', backgroundImage: '', paddingLeft: '20px', paddingRight: '20px'
          }
        }
      } else {
        config.components = MenuUtils.resetConfig(config.components, {}, urlParam.clearMenu)
        config.enabled = false
        message.success('复制成功,保存后生效。')
      }
      config.uuid = MenuId
      config.MenuID = MenuId
      config.open_edition = ''
      config.MenuName = urlParam.MenuName || ''
      config.MenuNo = urlParam.MenuNo || ''
      let indeComs = []
      config.components.forEach(item => {
        if (item.type === 'navbar') {
          indeComs.push(fromJS(item).toJS())
        }
      })
      if (indeComs.length === 0) {
        this.setState({
          oriConfig: null,
          config: fromJS(config).toJS(),
          loading: false
        })
        window.GLOB.customMenu = config
      } else {
        this.jointComponents(config, indeComs, true)
      }
    })
  }
  jointComponents = (config, indeComs, isCreate) => {
    let deffers = indeComs.map(item => {
      return new Promise(resolve => {
        Api.getSystemConfig({
          func: 'sPC_Get_LongParam',
          TypeCharOne: sessionStorage.getItem('kei_no'),
          typename: sessionStorage.getItem('typename'),
          MenuID: item.uuid
        }).then(res => {
          res.uuid = item.uuid
          if (!res.status) {
            notification.warning({
              top: 92,
              message: res.message,
              duration: 5
            })
          }
          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: isCreate ? null : fromJS(config).toJS(),
        activeKey: isCreate ? 'basedata' : 'component',
        config: config,
        loading: false
      })
      window.GLOB.customMenu = config
    })
  }
  getMenuMessage = () => {
    const { config } = this.state
    let traversal = (components) => {
      let list = []
      components.forEach(item => {
        let m = {
          key: item.uuid,
          title: item.name,
          children: []
        }
        if (item.type === 'topbar' || item.type === 'login' || item.type === 'navbar' || (item.type === 'menubar' && item.subtype === 'commonbar')) {
          return null
        } else if (item.type === 'tabs') {
          let tabs = []
          let mm = []
          item.subtabs.forEach(tab => {
            let s = traversal(tab.components)
            if (s.length === 0) return
            tabs.push({
              key: tab.uuid,
              title: tab.label,
              children: s
            })
            mm.push(...s)
          })
          if (tabs.length > 0) {
            m.children = tabs
          }
          if (item.setting.permission === 'true') {
            list.push(m)
          } else if (mm.length) {
            list.push(...mm)
          }
          return null
        } else if (item.type === 'group') {
          m.children = traversal(item.components)
          if (item.setting.permission === 'true') {
            list.push(m)
          } else if (m.children.length) {
            list.push(...m.children)
          }
          return null
        } if (item.plot && item.plot.permission !== 'true') {
          return null
        } if (item.wrap && item.wrap.permission !== 'true') {
          return null
        } else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
          item.action && item.action.forEach(btn => {
            this.checkBtn(btn)
            m.children.push({
              key: btn.uuid,
              title: btn.label,
            })
          })
          item.subcards.forEach(card => {
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
              this.checkBtn(cell)
              m.children.push({
                key: cell.uuid,
                title: cell.label,
              })
            })
          })
        } else if (item.type === 'carousel' || item.type === 'timeline') {
          item.subcards.forEach(card => {
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
              this.checkBtn(cell)
              m.children.push({
                key: cell.uuid,
                title: cell.label,
              })
            })
          })
        } else if (item.type === 'balcony') {
          item.elements && item.elements.forEach(cell => {
            if (cell.eleType !== 'button') return
            this.checkBtn(cell)
            m.children.push({
              key: cell.uuid,
              title: cell.label,
            })
          })
        } else if (item.type === 'menubar') {
          if (item.wrap.title) {
            m.title = item.wrap.title
          }
          m.children = item.subMenus.map(menu => {
            return {
              key: menu.uuid,
              title: menu.setting.name
            }
          })
        } else if (item.type === 'form') {
          m.children = item.subcards.map(m => {
            return {
              key: m.uuid,
              title: m.setting.title
            }
          })
        } else if (item.type === 'table' && item.subtype === 'normaltable') {
          item.action && item.action.forEach(btn => {
            this.checkBtn(btn)
            m.children.push({
              key: btn.uuid,
              title: btn.label,
            })
          })
          item.cols && item.cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              this.checkBtn(btn)
              m.children.push({
                key: btn.uuid,
                title: btn.label,
              })
            })
          })
        }
        list.push(m)
      })
      return list
    }
    let trees = traversal(config.components)
    return trees
  }
  getSubMenus = () => {
    const { config } = this.state
    let menus = []
    let menuObj = {}
    let allMenus = JSON.parse(sessionStorage.getItem('allMenus'))
    allMenus.forEach(item => {
      menuObj[item.MenuID] = item
    })
    let traversal = (components) => {
      components.forEach(item => {
        if (item.type === 'topbar') {
          if (item.wrap.linkmenu && menuObj[item.wrap.linkmenu]) {
            menus.push(menuObj[item.wrap.linkmenu])
          }
          if (item.wrap.menus) {
            item.wrap.menus.forEach(m => {
              if (!menuObj[m.menu]) return
              menus.push(menuObj[m.menu])
            })
          }
        } else if (item.type === 'login') {
          if (item.wrap.linkmenu && menuObj[item.wrap.linkmenu]) {
            menus.push(menuObj[item.wrap.linkmenu])
          }
        } else if (item.type === 'menubar' && item.subtype !== 'commonbar') {
          item.subMenus.forEach(m => {
            if (m.setting.type === 'menu') {
              if (menuObj[m.uuid]) {
                menus.push(menuObj[m.uuid])
              } else {
                menus.push({
                  MenuID: m.uuid,
                  MenuName: m.setting.name,
                  MenuNo: m.setting.MenuNo
                })
              }
            } else if (m.setting.type === 'linkmenu' && menuObj[m.setting.linkMenuId]) {
              menus.push(menuObj[m.setting.linkMenuId])
            }
          })
        } else if (item.type === 'tabs') {
          item.subtabs.forEach(tab => {
            traversal(tab.components)
          })
        } else if (item.type === 'group') {
          traversal(item.components)
        } else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
          item.action && item.action.forEach(btn => {
            if (btn.linkmenu && menuObj[btn.linkmenu]) {
              menus.push(menuObj[btn.linkmenu])
            } else if (btn.openmenu && menuObj[btn.openmenu]) {
              menus.push(menuObj[btn.openmenu])
            }
          })
          item.subcards.forEach(card => {
            if (card.setting.click === 'menu' && menuObj[card.setting.menu]) {
              menus.push(menuObj[card.setting.menu])
            } else if (card.setting.click === 'menus' && card.menus) {
              card.menus.forEach(m => {
                if (menuObj[m.menu]) {
                  menus.push(menuObj[m.menu])
                }
              })
            }
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
              if (cell.linkmenu && menuObj[cell.linkmenu]) {
                menus.push(menuObj[cell.linkmenu])
              } else if (cell.openmenu && menuObj[cell.openmenu]) {
                menus.push(menuObj[cell.openmenu])
              }
            })
          })
        } else if (item.type === 'carousel' || item.type === 'timeline') {
          item.subcards.forEach(card => {
            if (card.setting.click === 'menu' && menuObj[card.setting.menu]) {
              menus.push(menuObj[card.setting.menu])
            }
            card.elements && card.elements.forEach(cell => {
              if (cell.eleType !== 'button') return
              if (cell.linkmenu && menuObj[cell.linkmenu]) {
                menus.push(menuObj[cell.linkmenu])
              } else if (cell.openmenu && menuObj[cell.openmenu]) {
                menus.push(menuObj[cell.openmenu])
              }
            })
          })
        } else if (item.type === 'balcony') {
          item.elements && item.elements.forEach(cell => {
            if (cell.eleType !== 'button') return
            if (cell.linkmenu && menuObj[cell.linkmenu]) {
                menus.push(menuObj[cell.linkmenu])
              } else if (cell.openmenu && menuObj[cell.openmenu]) {
                menus.push(menuObj[cell.openmenu])
              }
          })
        } else if (item.type === 'form') {
          item.subcards.forEach(m => {
            if (m.subButton && m.subButton.linkmenu && menuObj[m.subButton.linkmenu]) {
              menus.push(menuObj[m.subButton.linkmenu])
            }
          })
        } else if (item.type === 'table' && item.subtype === 'normaltable') {
          item.action && item.action.forEach(btn => {
            if (btn.linkmenu && menuObj[btn.linkmenu]) {
              menus.push(menuObj[btn.linkmenu])
            } else if (btn.openmenu && menuObj[btn.openmenu]) {
              menus.push(menuObj[btn.openmenu])
            }
          })
          item.cols && item.cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.linkmenu && menuObj[btn.linkmenu]) {
                menus.push(menuObj[btn.linkmenu])
              } else if (btn.openmenu && menuObj[btn.openmenu]) {
                menus.push(menuObj[btn.openmenu])
              }
            })
          })
        }
      })
    }
    traversal(config.components)
    let map = new Map()
    menus = menus.filter(m => {
      if (map.has(m.MenuID)) return false
      map.set(m.MenuID, true)
      return true
    })
    return menus
  }
  checkBtn = (btn) => {
    if (['prompt', 'exec', 'pop'].includes(btn.OpenType) && btn.Ot === 'required' && btn.verify && btn.verify.scripts && btn.verify.scripts.length > 0) {
      let hascheck = false
      btn.verify.scripts.forEach(item => {
        if (item.status === 'false') return
        if (/\$check@|@check\$/ig.test(item.sql)) {
          hascheck = true
        }
      })
      if (hascheck) {
        notification.warning({
          top: 92,
          message: `可选择多行的按钮《${btn.label}》中 $check@ 或 @check$ 将不会生效!`,
          duration: 5
        })
      }
    }
  }
  getMiniStyle = (config) => {
    config.miniStyle = this.transferStyle(config.style)
    let traversal = (components) => {
      return components.map(item => {
        if (item.style) {
          item.miniStyle = this.transferStyle(item.style)
        }
        if (item.headerStyle) {
          item.miniHeaderStyle = this.transferStyle(item.headerStyle)
        }
        if (item.action && item.action.length > 0) {
          item.action = item.action.map(btn => {
            btn.miniStyle = this.transferStyle(btn.style)
            return btn
          })
        }
        if (item.type === 'tabs') {
          item.subtabs.forEach(tab => {
            tab.components = traversal(tab.components)
          })
        } else if (item.type === 'group') {
          item.components = traversal(item.components)
        } else if (['card', 'carousel', 'timeline'].includes(item.type) || (item.type === 'table' && item.subtype === 'tablecard')) {
          item.subcards.forEach(card => {
            card.miniStyle = this.transferStyle(card.style)
            card.elements = card.elements.map(cell => {
              cell.miniStyle = this.transferStyle(cell.style)
              return cell
            })
          })
        } else if (item.type === 'balcony') {
          item.elements && item.elements.forEach(cell => {
            cell.miniStyle = this.transferStyle(cell.style)
          })
        } else if (item.type === 'menubar') {
          item.subMenus = item.subMenus.map(menu => {
            menu.miniStyle = this.transferStyle(menu.style)
            return menu
          })
        } else if (item.type === 'table' && item.subtype === 'normaltable') {
          let getCols = (cols) => {
            return cols.map(col => {
              if (col.type === 'colspan') {
                col.subcols = getCols(col.subcols || [])
              } else if (col.type === 'custom' || col.type === 'action') {
                col.elements = col.elements.map(cell => {
                  cell.miniStyle = this.transferStyle(cell.style)
                  return cell
                })
              }
              return col
            })
          }
          item.cols = getCols(item.cols)
        }
        return item
      })
    }
    config.components = traversal(config.components)
    return config
  }
  transferStyle = (style = {}) => {
    let _style = ''
    Object.keys(style).forEach(key => {
      if (['hShadow', 'vShadow', 'shadowBlur', 'shadowColor'].includes(key)) return
      if (!style[key]) return
      _style += `${key.replace(/[A-Z]/g, m => '-' + m.toLowerCase())}:${style[key]};`
    })
    return _style
  }
  submitConfig = () => {
    const { adapters } = this.state
    let config = fromJS(this.state.config).toJS()
    confirm({
      title: '确定删除元素吗?',
      content: '',
      okText: this.state.dict['mob.confirm'],
      cancelText: this.state.dict['mob.cancel'],
      onOk() {
        config.components = config.components.filter(item => item.uuid !== id)
    if (!config.MenuName || !config.MenuNo || (config.cacheUseful === 'true' && !config.cacheTime)) {
      notification.warning({
        top: 92,
        message: '请完善菜单基本信息!',
        duration: 5
      })
      this.setState({
        settingshow: true,
        activeKey: 'basedata'
      })
      return
    }
        _this.setState({
          config: config
    this.setState({
      menuloading: true
    })
    setTimeout(() => {
      if (config.enabled && this.verifyConfig()) {
        config.enabled = false
      }
      let roleParam = {type: 'view', version: '1.0', key: config.uuid, title: config.MenuName, children: []}
      roleParam.children = this.getMenuMessage()
      config.loginview = false
      config.tabview = false
      if (config.permission !== 'true') {
        roleParam.pass = true
        roleParam.children = []
      }
      config.components.forEach(item => {
        if (item.type === 'login') {
          roleParam.login = true
          roleParam.children = []
          config.loginview = true
        } else if (item.type === 'navbar') {
          config.tabview = true
        }
      })
      if (adapters.includes('wxmini')) {
        config = this.getMiniStyle(config)
      }
      let subMenus = this.getSubMenus()
      let menus_used_list = subMenus.map(m => `'${config.uuid}','${config.MenuName || ''}','${config.MenuNo || ''}','${m.MenuID}','${m.MenuName}'`).join(';')
      menus_used_list = window.btoa(window.encodeURIComponent(menus_used_list || 'del'))
      let param = {
        func: 'sPC_TrdMenu_AddUpt',
        FstID: 'mk_app',
        SndID: 'mk_app',
        ParentID: 'mk_app',
        MenuID: config.uuid,
        MenuNo: config.MenuNo || '',
        EasyCode: '',
        Template: 'webPage',
        TypeCharOne: sessionStorage.getItem('kei_no'),
        Typename: sessionStorage.getItem('typename'),
        MenuName: config.MenuName || '',
        PageParam: JSON.stringify({Template: 'webPage'}),
        open_edition: config.open_edition,
        menus_rolelist: window.btoa(window.encodeURIComponent(JSON.stringify(roleParam))),
        LText: '',
        LTexttb: '',
        menus_used_list
      }
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt('', param.timestamp)
      new Promise(resolve => {
        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.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
        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 roles = {
                type: 'navbar',
                version: '1.0',
                key: item.uuid,
                title: item.name,
                children: []
              }
              if (item.wrap.permission === 'true') {
                roles.children = item.menus.map(menu => {
                  return {
                    key: menu.MenuID,
                    title: menu.name
                  }
                })
              } else {
                roles.pass = true
              }
              let _param = {
                func: 'sPC_TrdMenu_AddUpt',
                FstID: 'mk_app',
                SndID: 'mk_app',
                ParentID: 'mk_app',
                MenuID: item.uuid,
                MenuNo: item.wrap.MenuNo || Utils.getuuid(),
                EasyCode: '',
                Template: item.type,
                TypeCharOne: sessionStorage.getItem('kei_no'),
                Typename: sessionStorage.getItem('typename'),
                MenuName: item.name || '',
                PageParam: JSON.stringify({Template: item.type}),
                open_edition: _item ? (_item.open_edition || '') : '',
                menus_rolelist: window.btoa(window.encodeURIComponent(JSON.stringify(roles))),
                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
                  })
                  this.setState({ menuloading: false })
                  return
                }
                new_open_edition[item.uuid] = res.open_edition || ''
                resolve()
              })
            })
          })
          Promise.all(deffers).then(() => {
            let appViewList = sessionStorage.getItem('appViewList')
            appViewList = JSON.parse(appViewList)
            let _appViewList = fromJS(appViewList).toJS()
            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
                  })
                } else {
                  appViewList = appViewList.map(view => {
                    if (view.keys_id === item.uuid) {
                      view.remark = item.name
                    }
                    return view
                  })
                }
              }
              return item
            })
            if (!is(fromJS(appViewList), fromJS(_appViewList))) {
              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
                  })
                  this.setState({ menuloading: false })
                } else {
                  sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
                  resolve(true)
                }
              })
            } else {
              resolve(true)
            }
          })
        }
      }).then(res => { // 页面保存
        if (!res) return
        return Api.getSystemConfig(param)
      }).then(res => {
        if (!res) return
        if (res.status) {
          config.open_edition = res.open_edition || ''
          this.setState({
            config,
            oriConfig: fromJS(config).toJS(),
            menuloading: false
          })
          notification.success({
            top: 92,
            message: '保存成功',
            duration: 2
          })
        } else {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          })
          this.setState({
            menuloading: false
          })
        }
        MKEmitter.emit('completeSave')
      })
    }, 300)
  }
  getRoleFields = () => {
    if (sessionStorage.getItem('sysRoles') || sessionStorage.getItem('permFuncField')) return
    Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
      if (res.status) {
        let _permFuncField = []
        let _sysRoles = []
        if (res.Roles && res.Roles.length > 0) {
          _sysRoles = res.Roles.map(role => {
            return {
              uuid: Utils.getuuid(),
              value: role.RoleID,
              text: role.RoleName
            }
          })
        }
        if (res.sModular && res.sModular.length > 0) {
          res.sModular.forEach(field => {
            if (field.ModularNo) {
              _permFuncField.push(field.ModularNo)
            }
          })
          _permFuncField = _permFuncField.sort()
        }
        sessionStorage.setItem('sysRoles', JSON.stringify(_sysRoles))
        sessionStorage.setItem('permFuncField', JSON.stringify(_permFuncField))
      }
    })
  }
  onEnabledChange = () => {
    const { config } = this.state
    if (!config || (!config.enabled && this.verifyConfig(true))) {
      return
    }
    this.setState({
      config: {...config, enabled: !config.enabled}
    })
  }
  verifyConfig = (show) => {
    const { config } = this.state
    let error = ''
    let searchSum = 0
    let swipes = []
    let check = (components) => {
      components.forEach(item => {
        if (error) return
        if (item.type === 'tabs') {
          item.subtabs.forEach(tab => {
            check(tab.components)
          })
          return
        } else if (item.type === 'group') {
          check(item.components)
          return
        } else if (item.type === 'navbar' && !item.wrap.MenuNo) {
          error = `导航栏《${item.name}》未设置菜单参数!`
        } else if (item.type === 'topbar') {
          if (item.wrap.type === 'search' || item.wrap.type === 'searchIcon' || (item.wrap.type === 'navbar' && item.wrap.search === 'true')) {
            searchSum += 1
          }
        } else if (item.type === 'search') {
          searchSum += 1
          if (!item.wrap.field) {
            error = `搜索条件《${item.name}》未设置搜索字段!`
          }
        } else if (item.subtype === 'propcard' && item.subcards.length === 0) {
          error = `组件《${item.name}》中卡片不可为空!`
          return
        } else if (item.type === 'login' && !item.wrap.linkmenu && item.wrap.link !== 'menu') {
          error = '登录组件未设置关联菜单!'
          return
        }
        if (item.wrap && item.wrap.pagestyle === 'slide') {
          swipes.push(item.name)
        }
        if (['voucher'].includes(item.subtype)) return
        if (['propcard', 'brafteditor', 'sandbox', 'tabbar', 'stepform', 'tabform'].includes(item.subtype) && item.wrap.datatype === 'static') return
        if (['balcony'].includes(item.type) && item.wrap.datatype === 'static') return
        if (['menubar'].includes(item.type) && item.wrap.datatype !== 'dynamic') return
        if (item.setting) {
          if (item.setting.interType === 'system' && item.setting.execute !== 'false' && !item.setting.dataresource) {
            error = `组件《${item.name}》未设置数据源!`
          } else if (item.setting.interType === 'system' && item.setting.execute === 'false' && item.scripts.length === 0) {
            error = `组件《${item.name}》未设置数据源!`
          } else if (!item.setting.primaryKey) {
            error = `组件《${item.name}》未设置主键!`
          } else if (!item.setting.supModule && !['navbar', 'balcony', 'menubar'].includes(item.type)) {
            error = `组件《${item.name}》未设置上级组件!`
          }
        }
        if (item.type === 'bar' || item.type === 'line' || item.type === 'pie') {
          if (!item.plot.Xaxis) {
            error = `组件《${item.name}》图表字段尚未设置!`
          }
        } else if (item.type === 'dashboard' && !item.plot.valueField) {
          error = `组件《${item.name}》显示值尚未设置!`
        } else if (item.type === 'scatter' && (!item.plot.Xaxis || !item.plot.Yaxis || !item.plot.gender)) {
          error = `组件《${item.name}》坐标轴尚未设置!`
        }
      })
    }
    check(config.components)
    // if (!error && viewType === 'userbind' && config.components.filter(item => item.type === 'login').length === 0) {
    //   error = '用户绑定页面必须添加登录。'
    // }
    if (!error && searchSum > 1) {
      error = '搜索组件与导航栏的搜索功能不可同时使用。'
    } else if (!error && swipes.length > 1) {
      error = `页面中不可同时使用多个滑动加载组件。(${swipes.join('、')})`
    }
    if (show && error) {
      notification.warning({
        top: 92,
        message: error,
        duration: 5
      })
    }
    return error
  }
  // 更新配置信息
  updateConfig = (config) => {
    this.setState({
      config: config
    })
    window.GLOB.customMenu = config
  }
  insert = (item) => {
    let config = fromJS(this.state.config).toJS()
    if (item.type === 'search') {
      notification.warning({
        top: 92,
        message: '移动端搜索组件不可粘贴!',
        duration: 5
      })
      return
    }
    if (item.type === 'topbar') {
      if (config.components.findIndex(m => m.type === 'topbar') > -1) {
        notification.warning({
          top: 92,
          message: '导航栏不可重复添加!',
          duration: 5
        })
        return
      }
      if (!config.style.paddingTop) {
        config.style.paddingTop = '50px'
      }
    }
    config.components.push(item)
    this.setState({config})
    window.GLOB.customMenu = config
    notification.success({
      top: 92,
      message: '粘贴成功!',
      duration: 2
    })
  }
  refreshView = () => {
    const { oriConfig, config } = this.state
    if (!oriConfig || !is(fromJS(oriConfig), fromJS(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 = () => {
    const { oriConfig, config } = this.state
    if (!oriConfig || !is(fromJS(oriConfig), fromJS(config))) {
      notification.warning({
        top: 92,
        message: '配置信息未保存!',
        duration: 5
      })
      return
    }
    let param = {
      func: 's_kei_link_keyids_addupt',
      BID: sessionStorage.getItem('appId'),
      exec_type: 'y',
      LText: ''
    }
    let appViewList = sessionStorage.getItem('appViewList')
    appViewList = appViewList ? JSON.parse(appViewList) : []
    appViewList = appViewList.filter(item => item.keys_type !== 'index')
    appViewList.unshift({
      appkey: window.GLOB.appkey || '',
      bid: sessionStorage.getItem('appId') || '',
      kei_no: sessionStorage.getItem('kei_no') || '',
      keys_id: config.MenuID,
      keys_type: 'index',
      remark: config.MenuName
    })
    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)
    confirm({
      title: '确定设置本页面为首页吗?',
      content: '',
      onOk() {
        Api.getSystemConfig(param).then(result => {
          if (!result.status) {
            notification.warning({
              top: 92,
              message: result.message,
              duration: 5
            })
          } else {
            sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
          }
        })
      },
      onCancel() {}
    })
  }
  testFunc = () => {
    let datas = [{
      name: 'a',
      arr_field: 'MapCode,Country',
      par_tablename: '',
      type: '',
      primaryKey: 'MapCode',
      foreign_key: '',
      sql: `select MapCode,Country from @tc1`,
      script: `declare @tc1 table (MapCode nvarchar(50),Country nvarchar(50)) insert into @tc1 (MapCode,Country) select MapCode,Country from sMap where Province=''`
    }, {
      name: 'b',
      arr_field: 'MapCode,Province,ParMapCode',
      par_tablename: 'a',
      type: 'array',
      primaryKey: 'MapCode',
      foreign_key: 'ParMapCode',
      sql: `select MapCode,Province,ParMapCode from @tc2`,
      script: `declare @tc2 table (MapCode nvarchar(50),Province nvarchar(50),ParMapCode nvarchar(50)) insert into @tc2 (MapCode,Province,ParMapCode) select MapCode,Province,ParMapCode from sMap where Province!='' and City=''`
    }, {
      name: 'c',
      arr_field: 'MapCode,City,ParMapCode',
      par_tablename: 'b',
      type: 'array',
      primaryKey: 'MapCode',
      foreign_key: 'ParMapCode',
      sql: `select MapCode,City,ParMapCode from @tc3`,
      script: `declare @tc3 table (MapCode nvarchar(50),City nvarchar(50),ParMapCode nvarchar(50)) insert into @tc3 (MapCode,City,ParMapCode) select MapCode,City,ParMapCode from sMap where City!='' and Area=''`
    }, {
      name: 'd',
      arr_field: 'MapCode,Area,ParMapCode',
      par_tablename: 'c',
      type: 'array',
      primaryKey: 'MapCode',
      foreign_key: 'ParMapCode',
      sql: `select MapCode,Area,ParMapCode from sMap where Area!=''`,
      script: ``
    }]
  setLoginView = () => {
    const { oriConfig, config } = this.state
    let LText = datas.map((item, index) => {
      // item.par_tablename = ''
      // item.foreign_key = ''
      let _orderBy = 'MapCode desc'
      let _search = ''
      let _sql = `select top 1000 ${item.arr_field} from (select ${item.arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from (${item.sql}) tb ${_search}) tmptable order by tmptable.rows `
      return `Select '${item.name}' as tablename,'${window.btoa(window.encodeURIComponent(_sql))}' as LText,'${window.btoa(window.encodeURIComponent(item.script))}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort`
    })
    let LText_field = []
    datas.forEach(item => {
      item.arr_field.split(',').forEach(cell => {
        LText_field.push(`Select '${item.name}' as tablename,'${cell}' as fieldname,'nvarchar(50)' as field_type`)
    if (!oriConfig || !is(fromJS(oriConfig), fromJS(config))) {
      notification.warning({
        top: 92,
        message: '配置信息未保存!',
        duration: 5
      })
    })
    let param = {
      func: 'sPC_Get_structured_data',
      LText: LText.join(' union all '),
      LText_field: LText_field.join(' union all ')
      return
    }
    param.LText = Utils.formatOptions(param.LText)
    param.LText_field = Utils.formatOptions(param.LText_field)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    let param = {
      func: 's_kei_link_keyids_addupt',
      BID: sessionStorage.getItem('appId'),
      exec_type: 'y',
      LText: ''
    }
    Api.getLocalConfig(param)
  }
    let appViewList = sessionStorage.getItem('appViewList')
    appViewList = appViewList ? JSON.parse(appViewList) : []
    appViewList = appViewList.filter(item => item.keys_type !== 'login')
  // save = () => {
  //   html2canvas(document.getElementById('view')).then(canvas => {
  //     let imgUri = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream'); // 获取生成的图片的url
  //     window.location.href = imgUri; // 下载图片
  //   })
  // }
  editCard = (element) => {
    this.setState({
      editElem: element
    appViewList.unshift({
      appkey: window.GLOB.appkey || '',
      bid: sessionStorage.getItem('appId') || '',
      kei_no: sessionStorage.getItem('kei_no') || '',
      keys_id: config.MenuID,
      keys_type: 'login',
      remark: config.MenuName
    })
  }
  updateStyle = (proper) => {
    const { config } = this.state
    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)
    config.components = config.components.map(component => {
      if (component.uuid === proper.componentId) {
        Object.keys(component).forEach(key => {
          let _uuid = component[key].uuid
          if (_uuid && (_uuid === proper.uuid || _uuid === proper.classId)) {
            if (component[key].substyle) {
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
            } else {
              component[key].style = {...component[key].style, ...proper.style}
              // eslint-disable-next-line
              for (let index in component[key].style) {
                if (component[key].style[index] === '') {
                  delete component[key].style[index]
                }
              }
            }
    let hasLogin = config.components.findIndex(item => item.type === 'login') > -1
    confirm({
      title: '确定设置本页面为登录页吗?',
      content: hasLogin ? '' : '当前页面尚未添加登录组件。',
      onOk() {
        Api.getSystemConfig(param).then(result => {
          if (!result.status) {
            notification.warning({
              top: 92,
              message: result.message,
              duration: 5
            })
          } else {
            sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
          }
        })
      }
      return component
      },
      onCancel() {}
    })
    this.setState({config})
  }
  updateConfig = (config) => {
  changeView = (val) => {
    if (val !== 'vertical') {
      window.GLOB.winWidth = 992
      window.GLOB.winHeight = 690
      window.GLOB.shellWidth = 853
      window.GLOB.shellHeight = 640
    } else {
      window.GLOB.winWidth = 736
      window.GLOB.winHeight = 945
      window.GLOB.shellWidth = 640
      window.GLOB.shellHeight = 853
    }
    this.setState({
      config: config
      direction: val,
      comloading: true
    }, () => {
      this.setState({ comloading: false })
    })
  }
  resetConfig = (config) => {
    this.setState({
      config: config,
      comloading: true
    }, () => {
      this.setState({
        comloading: false
      })
    })
    window.GLOB.customMenu = config
  }
  render () {
    const { saveIng, appType, config, editElem } = this.state
    const { viewType, localedict, comloading, loading, settingshow, controlshow, activeKey, dict, MenuId, config, menuloading, customComponents, adapters } = this.state
    return (
      <div className="mobile-view">
        <Header view="design" jumpToManage={this.jumpToManage} triggerSave={this.triggerSave} saveIng={saveIng} />
        <DndProvider backend={HTML5Backend}>
          <div className="mob-body">
            <div className="mob-tool">
              <div className="mob-tool-content">
                <div className="plus-content">
                  <Icon type="plus-circle" />添 加 组 件
                </div>
                <div className="useable-component">
                  <SourceWrap appType={appType} />
                </div>
      <ConfigProvider locale={localedict}>
        <div className={'mk-mob-view ' + viewType} id="mk-mob-design-view">
          <Header changeView={this.changeView}/>
          {loading ? <Spin className="view-spin" size="large" /> : null}
          <DndProvider backend={HTML5Backend}>
            <div className={'menu-setting ' + (!settingshow ? 'hidden' : '')}>
              <div className="draw">
                {settingshow ? <DoubleLeftOutlined onClick={() => {this.setState({settingshow: false})}} /> : null}
                {!settingshow ? <DoubleRightOutlined onClick={() => {this.setState({settingshow: true})}} /> : null}
              </div>
              <div className="mob-tool-other"></div>
              <div className="pc-setting-tools">
                <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
                  {/* 基本信息 */}
                  <Panel header={dict['mob.basemsg']} forceRender className="basedata" key="basedata">
                    {/* 菜单信息 */}
                    {config ? <MenuForm
                      dict={dict}
                      config={config}
                      MenuId={MenuId}
                      adapters={adapters}
                      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}
                  </Panel>
                  {/* 组件添加 */}
                  <Panel header={dict['mob.component']} className="component" key="component">
                    <SourceWrap />
                  </Panel>
                  {customComponents && customComponents.length ? <Panel header="自定义组件" className="cuscomponent" key="cuscomponent">
                    <SourceWrap components={customComponents} />
                  </Panel> : null}
                  <Panel header={'页面样式'} key="background">
                    {config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
                  </Panel>
                </Collapse>
              </div>
            </div>
            {appType === 'mob' && config ?
              <div className="mob-shell">
                <MobShell
                  config={config}
                  deleteCard={this.deleteCard}
                  editCard={this.editCard}
                  editId={editElem ? editElem.uuid : ''}
                  handleList={this.updateConfig}
                />
              </div> : null
            }
            <div className="mob-setting">
              {config ? <Tabs defaultActiveKey="1" animated={false} size="small">
                <TabPane tab="配置" key="1">
                  <Controller editElem={editElem} updateStyle={this.updateStyle} />
                </TabPane>
                <TabPane tab="数据源" key="2">
                  <DataSource config={config} updateConfig={this.updateConfig} />
                </TabPane>
              </Tabs> : null}
            <div className={'menu-control ' + (!controlshow ? 'hidden' : '')}>
              <div className="draw">
                {controlshow ? <DoubleRightOutlined onClick={() => {this.setState({controlshow: false})}}/> : null}
                {!controlshow ? <DoubleLeftOutlined onClick={() => {this.setState({controlshow: true})}}/> : null}
              </div>
              <div className="wrap">
                <Button type="primary" onClick={this.submitConfig} id="save-config" loading={menuloading}>{dict['mob.save']}</Button>
                <Switch className="big" checkedChildren={dict['mob.enable']} unCheckedChildren={dict['mob.disable']} checked={config && config.enabled} onChange={this.onEnabledChange} />
                <ArrowLeftOutlined title="后退" className="back-view" onClick={this.backView}/>
                <CreateView resetmenu={this.getAppMenus} />
                <PasteController insert={this.insert} />
                <ViewNodes config={config} MenuId={MenuId}/>
                <SysInterface config={config} updateConfig={this.updateConfig}/>
                <PictureController/>
                <Quotecomponent config={config} updateConfig={this.updateConfig}/>
                <Button className="mk-border-green set-home" onClick={this.setHomeView}><HomeOutlined /> 设为首页</Button>
                <Button className="mk-border-purple set-login" 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 : ''}/>
                <StyleCombControlButton menu={config} />
                <Button className="mk-border-danger" onClick={this.refreshView}><RedoOutlined /> 强制刷新</Button>
                <Button type="default" onClick={this.closeView}>关闭</Button>
              </div>
            </div>
          </div>
        </DndProvider>
      </div>
            <div className={'menu-body menu-view' + (menuloading ? 'saving' : '')}>
              {config && !comloading ? <div className="mob-shell" style={{width: window.GLOB.shellWidth, height: window.GLOB.shellHeight}}>
                <MobShell menu={config} handleList={this.updateConfig} />
              </div> : null}
            </div>
          </DndProvider>
          <StyleController />
          <StyleCombController />
          <ModalController />
          <SearchController />
        </div>
      </ConfigProvider>
    )
  }
}
const mapStateToProps = () => {
  return {}
const mapStateToProps = (state) => {
  return {
    memberLevel: state.memberLevel
  }
}
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(Mobile)
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(MobDesign))