king
2025-04-23 b48528b1a1a88e289fc0b7ad52f2da213a3f9dfe
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 { DoubleLeftOutlined, DoubleRightOutlined } from '@ant-design/icons'
import { notification, Modal, Collapse, Card, Switch, Button, Typography, message, Dropdown } from 'antd'
import { DoubleLeftOutlined, DoubleRightOutlined, CopyOutlined, DownOutlined } 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 Utils from '@/utils/utils.js'
import { langs } from '@/store/options'
import MKEmitter from '@/utils/events.js'
import { getTables } from '@/utils/utils-custom.js'
import { getTables, getFuncsAndInters, getOutMessage, getLangTrans, getAllSqls } 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,15 +33,19 @@
const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
const DelExtraDb = asyncComponent(() => import('@/menu/delExtraDb'))
const LowerField = asyncComponent(() => import('@/menu/lowerField'))
const LowerText = asyncComponent(() => import('@/menu/lowerText'))
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'))
const NormalCopy = asyncComponent(() => import('@/menu/normalCopy'))
const UrlFieldComponent = asyncComponent(() => import('@/menu/urlfieldcomponent'))
const ModalController = asyncComponent(() => import('@/menu/modalconfig/controller'))
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,12 +62,19 @@
    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('isEditState')
      sessionStorage.removeItem('appType')
      this.props.history.replace('/login')
      return
@@ -77,15 +87,21 @@
    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)))
      if (param.lang) {
        sessionStorage.setItem('lang', param.lang)
      }
      this.setState({
        MenuId: param.MenuID,
        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()
      })
@@ -108,9 +124,8 @@
    MKEmitter.addListener('changePopview', this.initPopview)
    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
    setTimeout(() => {
      this.getPrintTemp()
      this.getRoleFields()
      setGLOBFuncs()
      // setGLOBFuncs()
    }, 1000)
    document.onkeydown = (event) => {
@@ -185,50 +200,6 @@
    if (this.state.view === 'popview') return
    
    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) => {
@@ -382,7 +353,7 @@
      MenuID: MenuId
    }
    Api.getSystemConfig(param).then(result => {
    Api.getCloudConfig(param).then(result => {
      if (result.status) {
        let config = null
@@ -463,8 +434,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 {
@@ -497,7 +468,7 @@
          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++
@@ -509,7 +480,7 @@
                loopCol(col.subcols)
              } else if (col.type === 'custom') {
                col.elements.forEach(cell => {
                  if (cell.eleType !== 'button' || cell.hidden === 'true') return
                  if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
                  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++
                })
@@ -524,7 +495,7 @@
          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++
@@ -536,7 +507,7 @@
              loopCol(col.subcols)
            } else if (col.type === 'custom') {
              col.elements.forEach(cell => {
                if (cell.eleType !== 'button' || cell.hidden === 'true') return
                if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
                buttons.push(`select '${cell.uuid}' as menuid,  '${cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
                _sort++
              })
@@ -570,13 +541,25 @@
    if (!this.checkBase()) {
      return
    } else if (this.checklog()) {
      if (sessionStorage.getItem('langList') && !config.trans) {
      } else if (config.enabled && !config.allSqls) {
      } else {
        notification.success({
          top: 92,
          message: '当前配置未修改,无需保存。',
          duration: 5
        })
        MKEmitter.emit('completeSave')
        return
      }
    }
    this.setState({
      menuloading: true
    })
    window.GLOB.saving = true
    setTimeout(() => {
      let _pass = this.verifyConfig(config)
@@ -587,6 +570,52 @@
      } else if (!config.enabled && config.force && _pass) {
        config.enabled = true
        delete config.force
      }
      let long_data = ''
      if (config.enabled) {
        let sqls = getAllSqls(config)
        let _t = moment().format('YYYYMMDDHHmmss')
        let getguid = () => {
          let uuid = ''
          for (let i = 0; i < 18; i++) {
            uuid += String.fromCharCode(Math.floor(Math.random() * 26) + 65)
          }
          uuid = uuid.replace(/minke/ig, 'MNKIE')
          return uuid
        }
        long_data = []
        // let oriIds = {}
        // if (config.allSqls) {
        //   config.allSqls.forEach(item => {
        //     if (!item.md5) return
        //     oriIds[item.uuid + item.md5] = item.v_id
        //   })
        // }
        config.allSqls = sqls.map(item => {
          let v_id = _t + getguid()
          // if (oriIds[item.uuid + item.md5]) {
          //   v_id = oriIds[item.uuid + item.md5]
          // }
          long_data.push(`${md5(window.GLOB.appkey + v_id)},${item.uuid},${v_id},${window.btoa(window.encodeURIComponent(item.LText))},${config.sqlperm === 'false' ? '' : item.roleId || ''}`)
          return {
            uuid: item.uuid,
            v_id: v_id,
            type: item.type,
            reps: item.reps,
            // md5: item.md5 || '',
            luser: item.luser === true
          }
        })
        long_data = long_data.join(';')
      } else {
        delete config.allSqls
      }
      let tbs = []
@@ -616,9 +645,16 @@
        let urlparam = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
        urlparam.type = 'admin'
        urlparam.MenuType = 'BaseTable'
        urlparam.lang = sessionStorage.getItem('lang')
        url = window.btoa(window.encodeURIComponent(JSON.stringify(urlparam)))
        config.tbkey = key
      }
      let interfaces = getFuncsAndInters(config)
      let msg = getOutMessage(config)
      let urlFields = config.urlFields ? config.urlFields.join(',') : ''
      let langSql = getLangTrans(config)
      let param = {
        func: 'sPC_TrdMenu_AddUpt',
@@ -630,19 +666,21 @@
        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, msg, backend: 'level1', enabled: config.enabled, urlFields}),
        open_edition: config.open_edition,
        LText: '',
        LTexttb: '',
        long_data: long_data,
        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',
@@ -650,17 +688,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 => {
@@ -674,13 +712,11 @@
          oriConfig: fromJS(config).toJS(),
        })
        return Api.getSystemConfig(btnParam)
        return Api.getCloudConfig(btnParam)
      }).then(res => {
        this.setState({
          menuloading: false
        })
        window.GLOB.saving = false
        if (!res) return
@@ -690,37 +726,29 @@
            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')))
  }
  netError = (error) => {
  netError = () => {
    this.setState({
      menuloading: false
    })
    window.GLOB.saving = false
    if (!error) {
      notification.warning({
        top: 92,
        message: '保存失败,请检查网络是否正常。',
        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 = []
@@ -859,12 +887,157 @@
    sessionStorage.setItem('settingshow', '' + !this.state.settingshow)
  }
  checklog = () => {
    const { oriConfig, config } = this.state
    return is(fromJS(oriConfig), fromJS(config))
  }
  copyMenu = () => {
    const { config } = this.state
    if (!config.enabled) {
      notification.warning({
        top: 92,
        message: '菜单未启用,不可复制。',
        duration: 5
      })
    } else {
      let msg = { copyType: 'components', type: 'admin', interfaces: [] }
      msg.components = fromJS(config.components).toJS()
      msg.components.forEach((item, i) => {
        if (item.type === 'tabs') {
          item.name = '标签组' + i
          item.width = 24
          item.subtype = 'tabs'
          item.setting = {autoSwitch: 'false', blacklist: [], name: item.name, position: 'top', supModule: [], tabStyle: 'line', width: 24}
          item.subtabs.forEach(tab => {
            tab.components[0].subtype = 'normaltable'
            tab.components[0].width = 24
            tab.components[0].wrap.width = 24
            tab.components[0].wrap.name = tab.components[0].name
            tab.components[0].action.forEach(btn => {
              if (btn.OpenType === 'popview' && btn.config) {
                btn.config.Template = 'CustomPage'
                if (btn.config.components[0]) {
                  btn.config.components[0].subtype = 'normaltable'
                }
              }
            })
            tab.components[0].cols = tab.components[0].cols.filter(col => !(col.field && col.Hide === 'true'))
            tab.components[0].cols.forEach(col => {
              if (col.type !== 'custom') return
              col.elements.forEach(btn => {
                if (btn.OpenType === 'popview' && btn.config) {
                  btn.config.Template = 'CustomPage'
                  if (btn.config.components[0]) {
                    btn.config.components[0].subtype = 'normaltable'
                  }
                }
              })
            })
          })
        } else {
          item.subtype = 'normaltable'
          item.width = 24
          item.wrap.width = 24
          item.wrap.name = item.name
          item.action.forEach(btn => {
            if (btn.OpenType === 'popview' && btn.config) {
              btn.config.Template = 'CustomPage'
              if (btn.config.components[0]) {
                btn.config.components[0].subtype = 'normaltable'
              }
            }
          })
          item.cols = item.cols.filter(col => !(col.field && col.Hide === 'true'))
          item.cols.forEach(col => {
            if (col.type !== 'custom') return
            col.elements.forEach(btn => {
              if (btn.OpenType === 'popview' && btn.config) {
                btn.config.Template = 'CustomPage'
                if (btn.config.components[0]) {
                  btn.config.components[0].subtype = 'normaltable'
                }
              }
            })
          })
        }
      })
      if (msg.components[0].search && msg.components[0].search.length > 0) {
        let cell = {
          uuid: Utils.getuuid(),
          type: 'search',
          width: 24,
          subtype: 'mainsearch',
          name: '搜索',
          search: msg.components[0].search,
          style: {borderBottomColor: '#f0f0f0', borderBottomWidth: '1px'},
          wrap: {float: 'left', blacklist: [], name: '搜索', width: 24}
        }
        cell.wrap.advanceType = msg.components[0].wrap.advanceType || 'modal'
        cell.wrap.advanceWidth = msg.components[0].wrap.advanceWidth || 1000
        cell.wrap.searchLwidth = msg.components[0].wrap.searchLwidth || 33.3
        cell.wrap.searchRatio = msg.components[0].wrap.searchRatio || 6
        cell.wrap.resetContrl = msg.components[0].wrap.resetContrl || 'init'
        cell.wrap.show = msg.components[0].wrap.show || 'true'
        if (cell.wrap.advanceType === 'drawer') {
          cell.wrap.drawerPlacement = msg.components[0].wrap.drawerPlacement || 'left'
        }
        msg.components[0].search = []
        msg.components[0].setting.useMSearch = 'true'
        msg.components.unshift(cell)
        msg.components[0].$tables = getTables(msg.components[0])
        msg.components[1].$tables = getTables(msg.components[1])
      }
      try {
        msg = window.btoa(window.encodeURIComponent(JSON.stringify(msg)))
      } catch (e) {
        console.warn('Stringify Failure')
        msg = ''
      }
      let oInput = document.createElement('input')
      oInput.value = msg
      document.body.appendChild(oInput)
      oInput.select()
      document.execCommand('Copy')
      document.body.removeChild(oInput)
      message.success('复制成功。')
    }
  }
  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">
@@ -875,22 +1048,25 @@
                <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 32px'}} copyable={{ text: MenuId }}>菜单ID:</Paragraph>
                      <Paragraph style={{padding: '0px 0px 0px 18px'}}>复制菜单下所有组件:<CopyOutlined onClick={this.copyMenu} style={{cursor: 'pointer', color: '#1890ff'}} /></Paragraph>
                      <NormalCopy />
                    </> : null}
                  </Panel>
                  <Panel header="搜索" key="search">
                    {Source.searchItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
@@ -910,19 +1086,26 @@
                </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">
                    {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}/>
                    {config ? <Dropdown placement="bottomCenter" overlay={<div className="mk-opeartion-dropdown-wrap">
                      <ReplaceField config={config} updateConfig={this.resetConfig}/>
                      <LowerField config={config} updateConfig={this.resetConfig}/>
                      <DelExtraDb config={config} updateConfig={this.resetConfig}/>
                      <LowerText />
                      <Button onClick={() => window.open('#/ai')}>DeepSeek</Button>
                    </div>} trigger={['hover']}>
                      <div className="mk-button-more">更多<DownOutlined/></div>
                    </Dropdown> : null}
                    {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>
                    <Button type="primary" id="save-config" disabled={!config} onClick={this.submitConfig} loading={menuloading}>保存</Button>
                    <Button type="default" disabled={menuloading} onClick={this.closeView}>关闭</Button>
                  </div>
                } style={{ width: '100%' }}>
                  {config && !comloading ? <MenuShell menu={config} handleList={this.updateConfig} /> : null}
@@ -933,7 +1116,7 @@
        </DndProvider>
        <StyleController />
        <ModalController />
      </ConfigProvider>
      </>
    )
  }
}