From e8edfdadb561cd83bf6e1c3e00d55b8cc2aee6d5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 17 十月 2022 17:57:34 +0800
Subject: [PATCH] 2022-10-17

---
 src/templates/sharecomponent/settingcomponent/index.jsx |  187 ++++++++++++++++++++++++----------------------
 1 files changed, 97 insertions(+), 90 deletions(-)

diff --git a/src/templates/sharecomponent/settingcomponent/index.jsx b/src/templates/sharecomponent/settingcomponent/index.jsx
index bc09bd0..85be0a7 100644
--- a/src/templates/sharecomponent/settingcomponent/index.jsx
+++ b/src/templates/sharecomponent/settingcomponent/index.jsx
@@ -1,75 +1,55 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { fromJS } from 'immutable'
-import { Icon, Modal, Button, notification } from 'antd'
+import { is, fromJS } from 'immutable'
+import { Modal, Button } from 'antd'
+import { SettingOutlined } from '@ant-design/icons'
 
-import Utils from '@/utils/utils.js'
-import zhCN from '@/locales/zh-CN/model.js'
-import enUS from '@/locales/en-US/model.js'
-import { getSettingForm } from '@/templates/zshare/formconfig'
-
+import Utils, { FuncUtils } from '@/utils/utils.js'
+import MKEmitter from '@/utils/events.js'
 import SettingForm from './settingform'
 import CreateFunc from '@/templates/zshare/createfunc'
 import CreateInterface from '@/templates/zshare/createinterface'
 
-import './index.scss'
+// import './index.scss'
 
 class SettingComponent extends Component {
   static propTpyes = {
-    type: PropTypes.string,          // 鑿滃崟绫诲瀷
+    mainsearch: PropTypes.any,       // 涓昏〃鐨勬悳绱㈡潯浠讹紝褰撳瓙琛ㄨ缃帴鏀朵富琛ㄦ潯浠舵椂鏈夋晥
     MenuID: PropTypes.string,        // 鑿滃崟ID
     config: PropTypes.object,        // 鑿滃崟閰嶇疆淇℃伅
-    permFuncField: PropTypes.array,  // 瀛樺偍杩囩▼鍙敤寮�澶村瓧娈�
-    menuformRef: PropTypes.any,      // 鑿滃崟鍩烘湰淇℃伅琛ㄥ崟
     updatesetting: PropTypes.func
   }
 
   state = {
-    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
     menu: null,          // 鑿滃崟淇℃伅
+    search: null,        // 鎼滅储鏉′欢锛屽寘鎷富琛ㄦ悳绱�
     formlist: null,      // 琛ㄥ崟淇℃伅
     visible: false,      // 妯℃�佹鎺у埗
-    loading: false       // 璁剧疆淇℃伅楠岃瘉淇濆瓨涓�
+    loading: false,      // 璁剧疆淇℃伅楠岃瘉淇濆瓨涓�
+    record: null
+    
   }
 
   /**
    * @description 鍏ㄥ眬璁剧疆瑙﹀彂
    */
   changeSetting = () => {
-    const { menuformRef, MenuID, config, type, permFuncField } = this.props
+    const { MenuID, config, mainsearch } = this.props
+    let menu = { MenuID: MenuID, MenuName: config.MenuName || config.tabName || '', MenuNo: config.MenuNo || config.tabNo || '' }
 
-    let menu = {MenuID: MenuID}
+    let _search = fromJS(config.search).toJS()
 
-    if (menuformRef) {
-      menu = {MenuID: MenuID, MenuName: menuformRef.props.form.getFieldValue('MenuName') || '', MenuNo: menuformRef.props.form.getFieldValue('MenuNo') || ''}
+    if (mainsearch) { // 缁煎悎涓婚〉鎼滅储鍙婂瓙琛ㄦ悳绱㈡潯浠�
+      _search = [...mainsearch, ..._search]
     }
-
-    let _columns = fromJS(config.columns).toJS()
-
-    let primaryKey = config.setting.primaryKey || ''
-
-    if (!primaryKey || _columns.filter(column => column.field === primaryKey).length === 0) {
-      _columns.forEach(col => {
-        if (col.field.toLowerCase() === 'id') {
-          primaryKey = col.field
-        }
-      })
-    }
-    _columns = _columns.filter(item => item.field && item.type !== 'colspan')
-    _columns = _columns.map(item => {
-      return {
-        value: item.field,
-        text: item.label
-      }
-    })
-
-    _columns.unshift({value: '', text: '鏈缃�'})
 
     this.setState({
       visible: true,
-      formlist: getSettingForm(config.setting, permFuncField, MenuID, primaryKey, _columns, type),
+      search: _search,
       menu: menu
     })
+
+    MKEmitter.emit('modalStatus', '鏁版嵁婧�')
   }
 
   /**
@@ -81,12 +61,17 @@
     this.setState({
       loading: true
     })
-    this.settingRef.handleConfirm().then(res => {
+    this.settingRef.handleConfirm().then(setting => {
+      let res = this.resetSetting(setting, config.setting)
       this.setState({
         visible: false,
         loading: false
       })
+      res.actionfixed = res.actionfixed === 'true'
+
       this.props.updatesetting({...config, setting: res})
+
+      MKEmitter.emit('modalStatus', false)
     }, () => {
       this.setState({
         loading: false
@@ -101,26 +86,13 @@
     const { config } = this.props
     const { menu } = this.state
 
-    this.settingRef.handleConfirm().then(setting => {
+    this.settingRef.handleConfirm('loading').then(setting => {
+      let res = this.resetSetting(setting, config.setting)
+      let _config = {...config, setting: res}
+      let newLText = Utils.formatOptions(FuncUtils.getTableFunc(setting, menu, _config)) // 鍒涘缓瀛樺偍杩囩▼sql
+      let DelText = Utils.formatOptions(FuncUtils.dropfunc(setting.innerFunc))          // 鍒犻櫎瀛樺偍杩囩▼sql
 
-      if (!(setting.interType === 'inner') || !setting.innerFunc) {
-        notification.warning({
-          top: 92,
-          message: '鎺ュ彛绫诲瀷涓�-鍐呴儴锛屼笖瀛樺湪鍐呴儴鍑芥暟鏃讹紝鎵嶅彲浠ュ垱寤哄瓨鍌ㄨ繃绋嬶紒',
-          duration: 5
-        })
-        return
-      }
-
-      let _config = {...config, setting: setting}
-      let newLText = Utils.formatOptions(Utils.getTableFunc(setting, menu, _config)) // 鍒涘缓瀛樺偍杩囩▼sql
-      let DelText = Utils.formatOptions(Utils.dropfunc(setting.innerFunc))          // 鍒犻櫎瀛樺偍杩囩▼sql
-
-      this.refs.funcCreatComponent.exec(setting.innerFunc, newLText, DelText).then(result => {
-        if (result === 'success') {
-          this.props.updatesetting(_config)
-        }
-      })
+      this.refs.funcCreatComponent.exec(setting.innerFunc, newLText, DelText)
     })
   }
 
@@ -128,22 +100,14 @@
    * @description 鍒涘缓琛ㄦ牸鎺ュ彛锛堣鍑猴級
    */
   tableCreatInterface = () => {
-    const { config, type } = this.props
+    const { config } = this.props
     const { menu } = this.state
 
-    this.settingRef.handleConfirm().then(setting => {
-      if (setting.interType !== 'inner' || setting.innerFunc) {
-        notification.warning({
-          top: 92,
-          message: '鎺ュ彛绫诲瀷涓�-鍐呴儴锛屼笖涓嶅瓨鍦ㄥ唴閮ㄥ嚱鏁版椂锛屾墠鍙互鍒涘缓鎺ュ彛锛�',
-          duration: 5
-        })
-        return
-      }
-
-      let _config = {...config, setting: setting}
+    this.settingRef.handleConfirm('loading').then(setting => {
+      let res = this.resetSetting(setting, config.setting)
+      let _config = {...config, setting: res}
       let _menu = {
-        type: type,
+        type: config.Template === 'CommonTable' ? 'main' : 'subtable',
         MenuID: menu.MenuID,
         menuName: menu.MenuName,
         menuNo: menu.MenuNo
@@ -151,6 +115,52 @@
 
       this.refs.tableCreatInterface.triggerOutInterface(_menu, _config)
     })
+  }
+
+  resetSetting = (s, ori) => {
+    let setting = fromJS(s).toJS()
+    let maxScript = 0
+
+    setting.show = ori.show || 'true'
+    setting.advanceType = ori.advanceType || 'modal'
+    setting.advanceWidth = ori.advanceWidth || 1000
+    setting.drawerPlacement = ori.drawerPlacement || 'right'
+    setting.searchRatio = ori.searchRatio || 6
+    setting.searchLwidth = ori.searchLwidth !== undefined ? ori.searchLwidth : 33.3
+
+    if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
+      window.GLOB.funcs.forEach(m => {
+        let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig')
+        setting.scripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+
+          if (item.status === 'false') return
+
+          if (/exec\s/ig.test(item.sql)) {
+            maxScript = 1000
+          } else if (item.sql.length > maxScript) {
+            maxScript = item.sql.length
+          }
+        })
+        setting.preScripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+        })
+        setting.cbScripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+        })
+        if (setting.dataresource) {
+          setting.dataresource = setting.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+        }
+      })
+    }
+
+    setting.maxScript = maxScript
+
+    return setting
+  }
+
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
   }
 
   /**
@@ -163,39 +173,36 @@
   }
 
   render() {
-    const { config, type } = this.props
-    const { dict, visible } = this.state
+    const { config } = this.props
+    const { visible, search, menu, record } = this.state
 
     return (
-      <div className="model-menu-setting">
-        <Icon type="setting" onClick={this.changeSetting} />
+      <>
+        <SettingOutlined style={{position: 'absolute', fontSize: '18px', right: '7px', top: '5px', padding: '10px', zIndex: 1}} onClick={this.changeSetting} />
         {/* 璁剧疆鍏ㄥ眬閰嶇疆鍙婂垪琛ㄦ暟鎹簮 */}
         <Modal
-          wrapClassName="model-table-setting-verify-modal"
-          title={dict['model.edit']}
+          wrapClassName="mk-pop-modal"
           visible={visible}
-          width={900}
+          width={'75vw'}
           maskClosable={false}
-          onCancel={() => { this.setState({ visible: false })}}
+          onCancel={() => { MKEmitter.emit('modalStatus', false); this.setState({ visible: false, loading: false })}}
           footer={[
-            <CreateInterface key="interface" dict={dict} ref="tableCreatInterface" trigger={this.tableCreatInterface}/>,
-            <CreateFunc key="create" dict={dict} ref="funcCreatComponent" trigger={this.tableCreatFunc}/>,
-            <Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>{this.state.dict['header.cancel']}</Button>,
-            <Button key="confirm" type="primary" loading={this.state.loading} onClick={this.settingSave}>{this.state.dict['model.confirm']}</Button>
+            record && record.interType === 'system' ? <CreateInterface key="interface" loading={this.state.interloading} ref="tableCreatInterface" trigger={this.tableCreatInterface}/> : null,
+            record && record.interType === 'inner' ? <CreateFunc key="create" ref="funcCreatComponent" trigger={this.tableCreatFunc}/> : null,
+            <Button key="cancel" onClick={() => { MKEmitter.emit('modalStatus', false); this.setState({ visible: false, loading: false }) }}>鍙栨秷</Button>,
+            <Button key="confirm" type="primary" loading={this.state.loading} onClick={this.settingSave}>纭畾</Button>
           ]}
           destroyOnClose
         >
           <SettingForm
-            type={type}
-            dict={dict}
-            menu={this.state.menu}
+            menu={menu}
             config={config}
-            inputSubmit={this.settingSave}
-            formlist={this.state.formlist}
+            search={search}
+            updRecord={(record) => this.setState({record: fromJS(record).toJS()})}
             wrappedComponentRef={(inst) => this.settingRef = inst}
           />
         </Modal>
-      </div>
+      </>
     )
   }
 }

--
Gitblit v1.8.0