From 9a11e62adeb8d435b52a361eb62d5b59e1deef2a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 23 五月 2024 21:14:50 +0800
Subject: [PATCH] 2024-05-23

---
 src/templates/modalconfig/index.jsx |  438 ++++++++++++++++--------------------------------------
 1 files changed, 131 insertions(+), 307 deletions(-)

diff --git a/src/templates/modalconfig/index.jsx b/src/templates/modalconfig/index.jsx
index 97c1bdd..cabfc7d 100644
--- a/src/templates/modalconfig/index.jsx
+++ b/src/templates/modalconfig/index.jsx
@@ -1,33 +1,29 @@
 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 moment from 'moment'
 import { Button, Card, Modal, Collapse, notification, Switch } from 'antd'
 import { SettingOutlined } from '@ant-design/icons'
 
 import Api from '@/api'
-import Utils from '@/utils/utils.js'
 import { getModalForm } from '@/templates/zshare/formconfig'
-
 import SourceElement from './dragelement/source'
 import SettingForm from './settingform'
 import MenuForm from './menuform'
 import asyncComponent from '@/utils/asyncComponent'
 import { BaseConfig, SearchItems } from './source'
 import { updateForm } from '@/utils/utils-update.js'
-import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 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'))
@@ -126,7 +122,8 @@
   }
 
   componentDidMount() {
-    MKEmitter.addListener('submitStyle', this.getStyle)
+    window.GLOB.formId = ''
+
     document.onkeydown = (event) => {
       let e = event || window.event
       let keyCode = e.keyCode || e.which || e.charCode
@@ -159,7 +156,6 @@
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
    */
   componentWillUnmount () {
-    MKEmitter.removeListener('submitStyle', this.getStyle)
     this.setState = () => {
       return
     }
@@ -186,24 +182,6 @@
     }
 
     this.props.handleView(param)
-  }
-
-  getStyle = (comIds, style) => {
-    const { config } = this.state
-
-    if (comIds[0] !== 'form') return
-
-    let Index = config.fields.findIndex(n => n.uuid === comIds[1])
-
-    if (Index === -1) return
-    
-    let _config = fromJS(config).toJS()
-
-    _config.fields[Index].style = style
-
-    this.setState({
-      config: _config
-    })
   }
 
   /**
@@ -238,208 +216,55 @@
   handleForm = (_card) => {
     const { menu, tabConfig, subTabConfig } = this.props
     const { config } = this.state
+    
     let card = fromJS(_card).toJS()
-    let _inputfields = []
-    let _tabfields = []
-    let _linkableFields = []
-    let _linksupFields = []
-    let standardform = null
-
-    let uniq = new Map()
-    let index = null
-    uniq.set(card.field, true)
-
-    let _inputIndex = 1
-    let _tabIndex = 1
-    let _linkIndex = 1
-    config.fields.forEach((item, i) => {
-      if (card.uuid === item.uuid) {
-        index = i
-      }
-
-      let label = item.label || ''
-      if (item.field && item.field.toLowerCase() !== label.toLowerCase()) {
-        label = label + ' (' + item.field + ')'
-      }
-
-      if (['text', 'number', 'textarea', 'color'].includes(item.type) && card.field !== item.field) {
-        _inputfields.push({
-          field: item.field,
-          label: _inputIndex + '銆�' + label
-        })
-        _inputIndex++
-      }
-      if (card.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type)) {
-        _tabfields.push({
-          field: item.field,
-          label: _tabIndex + '銆�' + label
-        })
-        _tabIndex++
-      }
-
-      if (item.type === 'switch') {
-        _linksupFields.push({
-          field: item.field,
-          label: _linkIndex + '銆�' + label
-        })
-      }
-
-      if (!['select', 'link', 'radio', 'checkcard'].includes(item.type)) return
-      if (item.type === 'checkcard' && item.multiple === 'true') return // 閫夐」鍗″閫�
-      if (item.field && !uniq.has(item.field)) {
-        uniq.set(item.field, true)
-
-        _linkableFields.push({
-          field: item.field,
-          label: _linkIndex + '銆�' + item.label + ' (琛ㄥ崟)'
-        })
-        _linksupFields.push({
-          field: item.field,
-          label: _linkIndex + '銆�' + label
-        })
-        _linkIndex++
-      }
-    })
-
-    _tabfields.unshift({field: '', label: '鍘熻〃鍗�'})
-
-    if (index !== null) {
-      if (index === 0) {
-        standardform = config.fields[index + 1] || null
-      } else {
-        standardform = config.fields[index - 1] || null
-      }
-    }
-
+    let columns = []
     if (subTabConfig) {
-      subTabConfig.columns.forEach(col => {
-        if (col.field && !uniq.has(col.field)) {
-          uniq.set(col.field, true)
-
-          _linkableFields.push({
-            field: col.field,
-            label: _linkIndex + '銆�' + col.label + ' (鏄剧ず鍒�)'
-          })
-          _linkIndex++
-        }
-      })
+      columns = subTabConfig.columns
     } else if (tabConfig) {
-      tabConfig.columns.forEach(col => {
-        if (col.field && !uniq.has(col.field)) {
-          uniq.set(col.field, true)
-
-          _linkableFields.push({
-            field: col.field,
-            label: _linkIndex + '銆�' + col.label + ' (鏄剧ず鍒�)'
-          })
-          _linkIndex++
-        }
-      })
+      columns = tabConfig.columns
     } else if (menu.LongParam) {
-      menu.LongParam.columns.forEach(col => {
-        if (col.field && !uniq.has(col.field)) {
-          uniq.set(col.field, true)
-
-          _linkableFields.push({
-            field: col.field,
-            label: _linkIndex + '銆�' + col.label + ' (鏄剧ず鍒�)'
-          })
-          _linkIndex++
-        }
-      })
-    }
-
-    if (card.linkSubField && card.linkSubField.length > 0) {
-      let fields = _inputfields.map(item => item.field)
-      card.linkSubField = card.linkSubField.filter(item => fields.includes(item))
-    }
-
-    if (!card.span && standardform && standardform.span) {
-      card.span = standardform.span
-      card.labelwidth = standardform.labelwidth
+      columns = menu.LongParam.columns
     }
 
     this.setState({
-      standardform,
       visible: true,
       card: card,
-      formlist: getModalForm(card, _inputfields, _tabfields, _linkableFields, _linksupFields)
+      formlist: getModalForm(card, config.fields, columns)
     })
   }
 
   /**
    * @description 缂栬緫鍚庢彁浜�
-   * 1銆佽幏鍙栫紪杈戝悗鐨勮〃鍗曚俊鎭�
-   * 2銆佸幓闄ゅ彲鑳藉瓨鍦ㄧ殑绀轰緥琛ㄥ崟
-   * 3銆侀�氳繃loading鍒锋柊
    */
   handleSubmit = () => {
-    this.formRef.handleConfirm().then(res => {
-      let _config = fromJS(this.state.config).toJS()
-      let fieldrepet = false // 瀛楁閲嶅
+    let _config = fromJS(this.state.config).toJS()
 
+    this.formRef.handleConfirm(_config.fields).then(res => {
       _config.fields = _config.fields.map(item => {
-        if (item.uuid !== res.uuid && res.field && item.field && item.field.toLowerCase() === res.field.toLowerCase()) {
-          fieldrepet = true
-        }
-
-        if (item.uuid === res.uuid) {
-          if (item.style) {
-            res.style = item.style
-          }
-          return res
+        if (item.uuid === res.values.uuid) {
+          return res.values
         } else {
           return item
         }
       })
 
-      if (fieldrepet) {
-        notification.warning({
-          top: 92,
-          message: '瀛楁宸插瓨鍦紒',
-          duration: 10
-        })
-        return
-      }
-
       _config.fields = _config.fields.filter(item => !item.origin)
 
-      if (['select', 'multiselect', 'link', 'checkbox', 'radio', 'checkcard'].includes(res.type) && res.resourceType === '1' && /\s/.test(res.dataSource)) {
+      if (res.loading) {
         this.setState({
           sqlVerifing: true
         })
 
-        let param = {
-          func: 's_debug_sql',
-          exec_type: 'y',
-          LText: res.dataSource
-        }
-
-        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
-        param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'${param.timestamp}'`)
-        
-        param.LText = Utils.formatOptions(param.LText)
-        param.secretkey = Utils.encrypt('', param.timestamp)
-
-        if (window.GLOB.mainSystemApi && res.database === 'sso') {
-          param.rduri = window.GLOB.mainSystemApi
-        }
-        
-        Api.genericInterface(param).then(result => {
-          if (result.status) {
-            this.setState({
-              sqlVerifing: false,
-              config: _config,
-              card: null,
-              visible: false
-            })
-          } else {
-            this.setState({sqlVerifing: false})
-            
-            Modal.error({
-              title: result.message
-            })
-          }
+        res.promise().then(() => {
+          this.setState({
+            sqlVerifing: false,
+            config: _config,
+            card: null,
+            visible: false
+          })
+        }, () => {
+          this.setState({sqlVerifing: false})
         })
       } else {
         this.setState({
@@ -471,110 +296,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.getSystemConfig(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()
   }
 
   /**
@@ -670,7 +495,7 @@
       MenuID: editAction.uuid
     }
 
-    Api.getSystemConfig(param).then(res => {
+    Api.getCloudConfig(param).then(res => {
       if (res.status) {
         let _config = ''
         if (res.LongParam) {
@@ -744,10 +569,9 @@
     })
   }
 
-
   render () {
-    const { editAction } = this.props
-    const { config, openEdition } = this.state
+    // const { editAction } = this.props
+    const { config } = this.state
 
     if (!config) return null
     
@@ -778,11 +602,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']} 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%' }}>
@@ -837,7 +661,7 @@
             card={this.state.card}
             formlist={this.state.formlist}
             inputSubmit={this.handleSubmit}
-            standardform={this.state.standardform}
+            fields={config.fields}
             wrappedComponentRef={(inst) => this.formRef = inst}
           />
         </Modal>
@@ -857,7 +681,7 @@
             wrappedComponentRef={(inst) => this.settingRef = inst}
           />
         </Modal>
-        <Modal
+        {/* <Modal
           bodyStyle={{textAlign: 'center', color: '#000000', fontSize: '16px'}}
           closable={false}
           maskClosable={false}
@@ -871,7 +695,7 @@
           destroyOnClose
         >
           閰嶇疆宸蹭慨鏀癸紝鏄惁淇濆瓨閰嶇疆淇℃伅锛�
-        </Modal>
+        </Modal> */}
         <StyleController />
       </div>
     )

--
Gitblit v1.8.0