king
2024-06-21 2bccb9ec7bdefe23292a22bc153463cfa1479a49
src/views/tabledesign/index.jsx
@@ -4,15 +4,15 @@
import { is, fromJS } from 'immutable'
import moment from 'moment'
import HTML5Backend from 'react-dnd-html5-backend'
import { ConfigProvider, notification, Modal, Collapse, Card, Switch, Button, Typography } from 'antd'
import { notification, Modal, Collapse, Card, Switch, Button, Typography } from 'antd'
import { DoubleLeftOutlined, DoubleRightOutlined } from '@ant-design/icons'
import md5 from 'md5'
import Api from '@/api'
import Utils, { setGLOBFuncs } from '@/utils/utils.js'
import antdZhCN from 'antd/es/locale/zh_CN'
import { langs } from '@/store/options'
import MKEmitter from '@/utils/events.js'
import { getTables } from '@/utils/utils-custom.js'
import { getTables, getFuncsAndInters, getLangTrans } from '@/utils/utils-custom.js'
import SourceElement from '@/templates/zshare/dragsource'
import asyncComponent from '@/utils/asyncComponent'
import Source from './source'
@@ -23,7 +23,6 @@
const { Panel } = Collapse
const { confirm } = Modal
const { Paragraph } = Typography
const _locale = antdZhCN
const MenuForm = asyncComponent(() => import('./menuform'))
const PopView = asyncComponent(() => import('./popview'))
@@ -34,6 +33,7 @@
const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
const Debug = asyncComponent(() => import('@/menu/debug'))
const Versions = asyncComponent(() => import('@/menu/versions'))
const Transfer = asyncComponent(() => import('@/menu/transfer'))
const Unattended = asyncComponent(() => import('@/templates/zshare/unattended'))
@@ -42,7 +42,6 @@
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
const PasteBaseTable = asyncComponent(() => import('@/menu/components/share/pastebasetable'))
sessionStorage.setItem('isEditState', 'true')
sessionStorage.setItem('appType', '')          // 应用类型
document.body.className = ''
@@ -59,16 +58,32 @@
    comloading: false,
    settingshow: sessionStorage.getItem('settingshow') !== 'false',
    view: null,
    langName: '',
    popConfig: null
  }
  UNSAFE_componentWillMount() {
    if (sessionStorage.getItem('devError') === 'true') {
      sessionStorage.clear()
      window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login')
      window.location.reload()
      return
    }
    if (!sessionStorage.getItem('UserID')) {
      sessionStorage.removeItem('appType')
      this.props.history.replace('/login')
      return
    }
    sessionStorage.setItem('editMenuType', 'menu') // 编辑菜单类型
    window.GLOB.curDate = moment().format('YYYY-MM-DD')
    window.GLOB.UserComponentMap = new Map() // 缓存用户自定义组件
    window.GLOB.TabsMap = new Map()          // 缓存用户操作的标签页
    window.GLOB.urlFields = []               // url变量
    window.GLOB.customMenu = null            // 保存菜单信息
    window.GLOB.developing = true
    try {
      let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
@@ -78,6 +93,7 @@
        ParentId: param.ParentId || '',
        MenuName: param.MenuName || '',
        MenuNo: param.MenuNo || '',
        langName: sessionStorage.getItem('lang') !== 'zh-CN' && langs[sessionStorage.getItem('lang')] ? `(${langs[sessionStorage.getItem('lang')]})` : ''
      }, () => {
        this.getMenuParam()
      })
@@ -95,10 +111,11 @@
  }
  componentDidMount () {
    if (!sessionStorage.getItem('UserID')) return
    MKEmitter.addListener('changePopview', this.initPopview)
    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
    setTimeout(() => {
      this.getPrintTemp()
      this.getRoleFields()
      setGLOBFuncs()
    }, 1000)
@@ -177,50 +194,6 @@
    this.submitConfig()
  }
  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
          })
        }
      })
    }
  }
  initPopview = (card, btn) => {
    const { config } = this.state
@@ -235,6 +208,26 @@
      _btn.config.MenuID = _btn.uuid
      _btn.config.ParentId = card.uuid
      _btn.config.MenuName = _btn.label
      _btn.config.components = _btn.config.components || []
      _btn.config.components.forEach(item => {
        if (item.type === 'tabs') {
          item.subtabs.forEach(tab => {
            tab.components[0].cols = tab.components[0].cols.map(col => {
              if (col.type === 'action') {
                col.type = 'custom'
              }
              return col
            })
          })
        } else if (item.cols) {
          item.cols = item.cols.map(col => {
            if (col.type === 'action') {
              col.type = 'custom'
            }
            return col
          })
        }
      })
    } else {
      _btn.config = {
        uuid: _btn.uuid,
@@ -263,6 +256,21 @@
  submitPopConfig = (btnconfig) => {
    let config = fromJS(this.state.config).toJS()
    let loopCol = (cols) => {
      cols.forEach(col => {
        if (col.type === 'colspan') {
          loopCol(col.subcols)
        } else if (col.type === 'custom') {
          col.elements.forEach(cell => {
            if (cell.eleType !== 'button') return
            if (cell.OpenType === 'popview' && cell.uuid === btnconfig.uuid) {
              cell.config = btnconfig
            }
          })
        }
      })
    }
    config.components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
@@ -273,14 +281,8 @@
              btn.config = btnconfig
            }
          })
          tab.components[0].cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.OpenType === 'popview' && btn.uuid === btnconfig.uuid) {
                btn.config = btnconfig
              }
            })
          })
          loopCol(tab.components[0].cols)
          tab.components[0].$tables = getTables(tab.components[0])
        })
@@ -290,14 +292,8 @@
            btn.config = btnconfig
          }
        })
        item.cols.forEach(col => {
          if (col.type !== 'action') return
          col.elements.forEach(btn => {
            if (btn.OpenType === 'popview' && btn.uuid === btnconfig.uuid) {
              btn.config = btnconfig
            }
          })
        })
        loopCol(item.cols)
        item.$tables = getTables(item)
      }
@@ -349,7 +345,7 @@
      MenuID: MenuId
    }
    Api.getSystemConfig(param).then(result => {
    Api.getCloudConfig(param).then(result => {
      if (result.status) {
        let config = null
@@ -407,8 +403,20 @@
            if (item.type === 'tabs') {
              item.subtabs.forEach(tab => {
                tab.components[0].name = tab.label
                tab.components[0].cols = tab.components[0].cols.map(col => {
                  if (col.type === 'action') {
                    col.type = 'custom'
                  }
                  return col
                })
              })
            } else {
              item.cols = item.cols.map(col => {
                if (col.type === 'action') {
                  col.type = 'custom'
                }
                return col
              })
              item.name = '主表'
            }
          })
@@ -418,8 +426,8 @@
        window.GLOB.urlFields = config.urlFields || []
        this.setState({
          oriConfig: config,
          config: fromJS(config).toJS()
          oriConfig: config.components[0].isNew ? {} : fromJS(config).toJS(),
          config: config
        })
        window.GLOB.customMenu = config
      } else {
@@ -452,40 +460,54 @@
          let _s = 1
          tab.components[0].action.forEach(btn => {
            if (btn.hidden === 'true') return
            if (btn.hidden === 'true' || btn.permission === 'false') return
            buttons.push(`select '${btn.uuid}' as menuid, '${btn.label}' as menuname, '${_s * 10}' as Sort, '${tab.components[0].uuid}' as parentid, 60 as Type`)
            _s++
          })
          tab.components[0].cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.hidden === 'true') return
              buttons.push(`select '${btn.uuid}' as menuid, '${btn.label}' as menuname, '${_s * 10}' as Sort, '${tab.components[0].uuid}' as parentid, 60 as Type`)
              _s++
          let loopCol = (cols) => {
            cols.forEach(col => {
              if (col.type === 'colspan') {
                loopCol(col.subcols)
              } else if (col.type === 'custom') {
                col.elements.forEach(cell => {
                  if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
                  buttons.push(`select '${cell.uuid}' as menuid, '${cell.label}' as menuname, '${_s * 10}' as Sort, '${tab.components[0].uuid}' as parentid, 60 as Type`)
                  _s++
                })
              }
            })
          })
          }
          loopCol(tab.components[0].cols)
        })
      } else {
        if (item.$tables) {
          tbs.push(...item.$tables)
        }
        item.action.forEach(btn => {
          if (btn.hidden === 'true') return
          if (btn.hidden === 'true' || btn.permission === 'false') return
          buttons.push(`select '${btn.uuid}' as menuid, '${btn.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
          _sort++
        })
        item.cols.forEach(col => {
          if (col.type !== 'action') return
          col.elements.forEach(btn => {
            if (btn.hidden === 'true') return
            buttons.push(`select '${btn.uuid}' as menuid,  '${btn.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
            _sort++
        let loopCol = (cols) => {
          cols.forEach(col => {
            if (col.type === 'colspan') {
              loopCol(col.subcols)
            } else if (col.type === 'custom') {
              col.elements.forEach(cell => {
                if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
                buttons.push(`select '${cell.uuid}' as menuid,  '${cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
                _sort++
              })
            }
          })
        })
        }
        loopCol(item.cols)
      }
    })
@@ -511,6 +533,18 @@
    if (!this.checkBase()) {
      return
    } else if (this.checklog()) {
      if (sessionStorage.getItem('langList') && !config.trans) {
      } else {
        notification.success({
          top: 92,
          message: '当前配置未修改,无需保存。',
          duration: 5
        })
        MKEmitter.emit('completeSave')
        return
      }
    }
    this.setState({
@@ -518,8 +552,14 @@
    })
    setTimeout(() => {
      if (config.enabled && this.verifyConfig()) {
      let _pass = this.verifyConfig(config)
      if (config.enabled && !_pass) {
        config.enabled = false
        config.force = true
      } else if (!config.enabled && config.force && _pass) {
        config.enabled = true
        delete config.force
      }
      let tbs = []
@@ -553,6 +593,10 @@
        config.tbkey = key
      }
      let interfaces = getFuncsAndInters(config)
      let urlFields = config.urlFields ? config.urlFields.join(',') : ''
      let langSql = getLangTrans(config)
      let param = {
        func: 'sPC_TrdMenu_AddUpt',
        FstID: config.fstMenuId || '',
@@ -563,19 +607,22 @@
        EasyCode: config.easyCode || '',
        Template: 'BaseTable',
        MenuName: config.MenuName || '',
        PageParam: JSON.stringify({Template: 'BaseTable', OpenType: config.OpenType || 'newtab', hidden: config.hidden || 'false'}),
        PageParam: JSON.stringify({Template: 'BaseTable', OpenType: config.OpenType || 'newtab', hidden: config.hidden || 'false', menuColor: config.menuColor || '', interfaces, urlFields}),
        open_edition: config.open_edition,
        LText: '',
        LTexttb: '',
        // LText: '',
        // LTexttb: '',
        debug_md5: key,
        debug_url: url,
        debug_list: window.btoa(tbs),
        LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config)))
      }
      param.LText = Utils.formatOptions(param.LText)
      if (langSql) {
        param.lang_translation = window.btoa(window.encodeURIComponent(langSql))
      }
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
      param.secretkey = Utils.encrypt('', param.timestamp)
      let btnParam = {             // 添加菜单按钮
        func: 'sPC_Button_AddUpt',
@@ -583,17 +630,17 @@
        ParentID: config.uuid,
        MenuNo: config.MenuNo,
        Template: 'BaseTable',
        button_proc_edition: 'Y'
        button_proc_edition: 'Y',
        exec_type: 'x'
      }
      btnParam.LText = btns.join(' union all ')
      btnParam.LText = Utils.formatOptions(btnParam.LText)
      btnParam.LText = Utils.formatOptions(btnParam.LText, 'x')
      btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
      btnParam.secretkey = Utils.encrypt('', btnParam.timestamp)
      new Promise(resolve => {
        Api.getSystemConfig(param).then(res => {
        Api.getCloudConfig(param).then(res => {
          resolve(res)
        }, this.netError)
      }).then(res => {
@@ -607,7 +654,7 @@
          oriConfig: fromJS(config).toJS(),
        })
        return Api.getSystemConfig(btnParam)
        return Api.getCloudConfig(btnParam)
      }).then(res => {
        this.setState({
          menuloading: false
@@ -621,14 +668,14 @@
            message: '保存成功',
            duration: 2
          })
          MKEmitter.emit('completeSave')
        } else {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          Modal.warning({
            width: 400,
            title: res.message,
            okText: '知道了'
          })
        }
        MKEmitter.emit('completeSave')
      }, this.netError)
    }, 300 + (+sessionStorage.getItem('mkDelay')))
  }
@@ -637,6 +684,7 @@
    this.setState({
      menuloading: false
    })
    if (!error) {
      notification.warning({
        top: 92,
@@ -644,11 +692,12 @@
        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 = []
@@ -681,17 +730,22 @@
  onEnabledChange = () => {
    const { config } = this.state
    if (!config || (!config.enabled && this.verifyConfig(true))) {
      return
    }
    let _config = {...config, enabled: !config.enabled}
    this.setState({
      config: {...config, enabled: !config.enabled}
    })
    delete _config.force
    if (!_config.enabled) {
      this.setState({
        config: _config
      })
    } else if (this.verifyConfig(_config)) {
      this.setState({
        config: _config
      })
    }
  }
  verifyConfig = (show) => {
    const { config } = this.state
  verifyConfig = (config) => {
    let error = ''
    config.components.forEach(item => {
@@ -725,7 +779,7 @@
      }
    }
    if (show && error) {
    if (config.enabled && error) {
      notification.warning({
        top: 92,
        message: error,
@@ -733,7 +787,7 @@
      })
    }
    return error
    return error === ''
  }
  // 更新配置信息
@@ -782,12 +836,34 @@
    sessionStorage.setItem('settingshow', '' + !this.state.settingshow)
  }
  checklog = () => {
    const { oriConfig, config } = this.state
    return is(fromJS(oriConfig), fromJS(config))
  }
  updateLogConfig = (config) => {
    config.fstMenuId = this.state.config.fstMenuId || config.fstMenuId || ''
    config.parentId = this.state.config.parentId || config.parentId || ''
    config.open_edition = this.state.config.open_edition || ''
    this.setState({
      config: null
    }, () => {
      this.setState({
        config: config
      })
    })
    window.GLOB.customMenu = config
  }
  render () {
    const { view, activeKey, comloading, MenuId, config, settingshow, ParentId, menuloading } = this.state
    const { view, activeKey, comloading, MenuId, config, settingshow, ParentId, menuloading, langName } = this.state
    return (
      <ConfigProvider locale={_locale}>
        <Header />
      <>
        <Header menuName={config ? config.MenuName + langName : ''}/>
        <DndProvider backend={HTML5Backend}>
        {view !== 'popview' ? <div className="pc-table-view">
            <div className="menu-body">
@@ -798,22 +874,23 @@
                <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
                  {/* 基本信息 */}
                  <Panel header="基本信息" key="basedata">
                    {/* 菜单信息 */}
                    {config ? <MenuForm
                      config={config}
                      MenuId={MenuId}
                      parentId={ParentId}
                      MenuName={config.MenuName}
                      MenuNo={config.MenuNo}
                      updateConfig={this.updateConfig}
                    /> : null}
                    {config ? <UrlFieldComponent
                      config={config}
                      updateConfig={this.updateConfig}
                    /> : null}
                    {/* 表名添加 */}
                    {config ? <TableComponent config={config} updatetable={this.updateConfig}/> : null}
                    {config ? <Paragraph style={{padding: '15px 0px 0px 18px'}} copyable={{ text: MenuId }}>菜单ID</Paragraph> : null}
                    {config ? <>
                      <MenuForm
                        config={config}
                        MenuId={MenuId}
                        parentId={ParentId}
                        MenuName={config.MenuName}
                        MenuNo={config.MenuNo}
                        updateConfig={this.updateConfig}
                      />
                      <UrlFieldComponent
                        config={config}
                        updateConfig={this.updateConfig}
                      />
                      {/* 表名添加 */}
                      <TableComponent config={config} updatetable={this.updateConfig}/>
                      <Paragraph style={{padding: '15px 0px 0px 18px'}} copyable={{ text: MenuId }}>菜单ID</Paragraph>
                    </> : null}
                  </Panel>
                  <Panel header="搜索" key="search">
                    {Source.searchItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
@@ -833,17 +910,23 @@
                </Collapse>
              </div>
              <div className={'menu-view' + (menuloading ? ' saving' : '')}>
                <Card title={
                  <div style={{paddingLeft: '15px'}}> {config && config.MenuName} </div>
                } bordered={false} extra={
                  <div>
                <Card bordered={false} extra={
                  <div className="mk-opeartion-list">
                    {/* <Dropdown overlay={
                      <div className="mk-button-dropdown-wrap">
                        <ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
                      </div>
                    } trigger={['click']} placement="bottomCenter">
                      <Button className="mk-button-more">更多<DownOutlined/></Button>
                    </Dropdown> */}
                    {config ? <Debug config={config}/> : null}
                    {config ? <Transfer config={config}/> : null}
                    {config ? <Unattended config={config} updateConfig={this.updateConfig}/> : null}
                    <Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''}/>
                    {config ? <Versions MenuId={MenuId} Template="BaseTable" checklog={this.checklog} updateConfig={this.updateLogConfig}/> : null}
                    <TableNodes config={config} />
                    <ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
                    <PasteBaseTable type="page" insert={this.insert}/>
                    <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config && config.enabled} onChange={this.onEnabledChange} />
                    {config ? <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config.enabled} onChange={this.onEnabledChange} /> : null}
                    <Button type="primary" id="save-config" onClick={this.submitConfig} loading={menuloading}>保存</Button>
                    <Button type="default" onClick={this.closeView}>关闭</Button>
                  </div>
@@ -856,7 +939,7 @@
        </DndProvider>
        <StyleController />
        <ModalController />
      </ConfigProvider>
      </>
    )
  }
}