king
2023-12-14 0eb129a9beddbb86ae74d7106a8e60823206b8d5
src/templates/modalconfig/index.jsx
@@ -1,6 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { fromJS } from 'immutable'
import { DndProvider } from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'
import { Button, Card, Modal, Collapse, notification, Switch } from 'antd'
@@ -20,11 +20,11 @@
const { Panel } = Collapse
const { confirm } = Modal
const Versions = asyncComponent(() => import('@/menu/versions'))
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
// const Versions = asyncComponent(() => import('@/menu/versions'))
// const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
const ModalForm = asyncComponent(() => import('@/templates/zshare/modalform'))
const EditComponent = asyncComponent(() => import('@/templates/zshare/editcomponent'))
// const EditComponent = asyncComponent(() => import('@/templates/zshare/editcomponent'))
const DragElement = asyncComponent(() => import('./dragelement'))
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
@@ -407,110 +407,110 @@
    })
  }
  submitConfig = () => {
    const { editAction } = this.props
    const { config, menu, openEdition } = this.state
  // submitConfig = () => {
  //   const { editAction } = this.props
  //   const { config, menu, openEdition } = this.state
    if (config.fields[0] && config.fields[0].origin) {
      notification.warning({
        top: 92,
        message: '请添加表单',
        duration: 10
      })
      return
    }
  //   if (config.fields[0] && config.fields[0].origin) {
  //     notification.warning({
  //       top: 92,
  //       message: '请添加表单',
  //       duration: 10
  //     })
  //     return
  //   }
    let _LongParam = ''
    let _config = fromJS(config).toJS()
  //   let _LongParam = ''
  //   let _config = fromJS(config).toJS()
    try {
      _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
    } catch (e) {
      notification.warning({
        top: 92,
        message: '编译错误',
        duration: 10
      })
      return
    }
  //   try {
  //     _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
  //   } catch (e) {
  //     notification.warning({
  //       top: 92,
  //       message: '编译错误',
  //       duration: 10
  //     })
  //     return
  //   }
    let param = {
      func: 'sPC_ButtonParam_AddUpt',
      ParentID: menu.MenuID,
      MenuID: editAction.uuid,
      MenuNo: menu.MenuNo,
      Template: 'Modal',
      MenuName: editAction.label,
      PageParam: JSON.stringify({Template: 'Modal'}),
      LongParam: _LongParam
    }
  //   let param = {
  //     func: 'sPC_ButtonParam_AddUpt',
  //     ParentID: menu.MenuID,
  //     MenuID: editAction.uuid,
  //     MenuNo: menu.MenuNo,
  //     Template: 'Modal',
  //     MenuName: editAction.label,
  //     PageParam: JSON.stringify({Template: 'Modal'}),
  //     LongParam: _LongParam
  //   }
    if (openEdition) {
      param.open_edition = openEdition
    }
  //   if (openEdition) {
  //     param.open_edition = openEdition
  //   }
    if (this.state.closeVisible) {
      this.setState({
        closeloading: true
      })
    } else {
      this.setState({
        menuloading: true
      })
    }
  //   if (this.state.closeVisible) {
  //     this.setState({
  //       closeloading: true
  //     })
  //   } else {
  //     this.setState({
  //       menuloading: true
  //     })
  //   }
    Api.getCloudConfig(param).then(response => {
      if (response.status) {
        this.setState({
          openEdition: response.open_edition || '',
          menuloading: false,
          closeloading: false,
          closeVisible: false,
          originConfig: _config,
          config: _config
        })
        notification.success({
          top: 92,
          message: '保存成功',
          duration: 2
        })
      } else {
        this.setState({
          closeloading: false,
          menuloading: false
        })
        notification.warning({
          top: 92,
          message: response.message,
          duration: 10
        })
      }
    })
  }
  //   Api.getCloudConfig(param).then(response => {
  //     if (response.status) {
  //       this.setState({
  //         openEdition: response.open_edition || '',
  //         menuloading: false,
  //         closeloading: false,
  //         closeVisible: false,
  //         originConfig: _config,
  //         config: _config
  //       })
  //       notification.success({
  //         top: 92,
  //         message: '保存成功',
  //         duration: 2
  //       })
  //     } else {
  //       this.setState({
  //         closeloading: false,
  //         menuloading: false
  //       })
  //       notification.warning({
  //         top: 92,
  //         message: response.message,
  //         duration: 10
  //       })
  //     }
  //   })
  // }
  cancelConfig = () => {
    const { config, originConfig } = this.state
    let _this = this
    // const { config, originConfig } = this.state
    // let _this = this
    let isOrigin = config.fields.filter(item => item.origin).length > 0
    if (isOrigin) {
      confirm({
        content: '尚未提交,确定放弃保存吗?',
        onOk() {
          _this.handleViewBack()
        },
        onCancel() {}
      })
    } else {
      if (!is(fromJS(config), fromJS(originConfig))) {
        this.setState({
          closeVisible: true
        })
      } else {
        this.handleViewBack()
      }
    }
    // let isOrigin = config.fields.filter(item => item.origin).length > 0
    // if (isOrigin) {
    //   confirm({
    //     content: '尚未提交,确定放弃保存吗?',
    //     onOk() {
    //       _this.handleViewBack()
    //     },
    //     onCancel() {}
    //   })
    // } else {
    //   if (!is(fromJS(config), fromJS(originConfig))) {
    //     this.setState({
    //       closeVisible: true
    //     })
    //   } else {
    //     this.handleViewBack()
    //   }
    // }
    this.handleViewBack()
  }
  /**
@@ -681,8 +681,8 @@
  }
  render () {
    const { editAction } = this.props
    const { config, openEdition } = this.state
    // const { editAction } = this.props
    const { config } = this.state
    if (!config) return null
    
@@ -713,11 +713,11 @@
          <div className="setting">
            <Card title="表单配置" bordered={false} extra={
              <div>
                <Button type="danger" onClick={this.clearConfig}>清空</Button>
                <Versions MenuId={editAction.uuid} open_edition={openEdition} updateConfig={this.refreshConfig}/>
                <ReplaceField type="form" config={config} updateConfig={this.updateconfig}/>
                <EditComponent options={['form']} type="formboard" config={this.state.config} plusFields={this.plusFields}/>
                <Button type="primary" id="save-config" onClick={this.submitConfig} loading={this.state.menuloading}>保存</Button>
                {/* <Button type="danger" onClick={this.clearConfig}>清空</Button> */}
                {/* <Versions MenuId={editAction.uuid} open_edition={openEdition} updateConfig={this.refreshConfig}/> */}
                {/* <ReplaceField type="form" config={config} updateConfig={this.updateconfig}/> */}
                {/* <EditComponent options={['form']} type="formboard" config={this.state.config} plusFields={this.plusFields}/> */}
                {/* <Button type="primary" id="save-config" onClick={this.submitConfig} loading={this.state.menuloading}>保存</Button> */}
                <Button onClick={this.cancelConfig}>返回</Button>
              </div>
            } style={{ width: '100%' }}>
@@ -792,7 +792,7 @@
            wrappedComponentRef={(inst) => this.settingRef = inst}
          />
        </Modal>
        <Modal
        {/* <Modal
          bodyStyle={{textAlign: 'center', color: '#000000', fontSize: '16px'}}
          closable={false}
          maskClosable={false}
@@ -806,7 +806,7 @@
          destroyOnClose
        >
          配置已修改,是否保存配置信息?
        </Modal>
        </Modal> */}
        <StyleController />
      </div>
    )