From 6def3330d1d1cf4036916ed04c8bbc4128e1e5d0 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 03 五月 2020 19:42:17 +0800
Subject: [PATCH] 2020-05-03

---
 src/templates/comtableconfig/index.jsx |  391 ++++++++-----------------------------------------------
 1 files changed, 57 insertions(+), 334 deletions(-)

diff --git a/src/templates/comtableconfig/index.jsx b/src/templates/comtableconfig/index.jsx
index d9ecd7e..6a548b0 100644
--- a/src/templates/comtableconfig/index.jsx
+++ b/src/templates/comtableconfig/index.jsx
@@ -11,7 +11,9 @@
 import Utils from '@/utils/utils.js'
 import zhCN from '@/locales/zh-CN/model.js'
 import enUS from '@/locales/en-US/model.js'
+import { getMainMenuForm } from '@/templates/zshare/formconfig'
 
+import asyncComponent from '@/utils/asyncComponent'
 import TableComponent from '@/templates/sharecomponent/tablecomponent'
 import FieldsComponent from '@/templates/sharecomponent/fieldscomponent'
 // import ChartGroupComponent from '@/templates/sharecomponent/chartgroupcomponent'
@@ -19,20 +21,21 @@
 import ActionComponent from '@/templates/sharecomponent/actioncomponent'
 import ColumnComponent from '@/templates/sharecomponent/columncomponent'
 
-import SettingForm from './settingform'
+// import SettingForm from './settingform'
 import TabForm from '@/templates/zshare/tabform'
 import MenuForm from '@/templates/zshare/menuform'
 import TabDragElement from '@/templates/zshare/tabdragelement'
 import EditComponent from '@/templates/zshare/editcomponent'
 import SourceElement from '@/templates/zshare/dragsource'
-import CreateFunc from '@/templates/zshare/createfunc'
-import CreateInterface from '@/templates/zshare/createinterface'
+// import CreateFunc from '@/templates/zshare/createfunc'
+// import CreateInterface from '@/templates/zshare/createinterface'
 import Source from './source'
 import './index.scss'
 
 const { Panel } = Collapse
 const { confirm } = Modal
 const CommonDict = (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS
+const SettingComponent = asyncComponent(() => import('@/templates/sharecomponent/settingcomponent'))
 
 class ComTableConfig extends Component {
   static propTpyes = {
@@ -54,10 +57,8 @@
     menuloading: false,      // 鑿滃崟淇濆瓨涓�
     menucloseloading: false, // 鑿滃崟鍏抽棴鏃讹紝閫夋嫨淇濆瓨
     loading: false,          // 鍔犺浇涓紝椤甸潰spin
-    settingVisible: false,   // 鍏ㄥ眬閰嶇疆妯℃�佹
     closeVisible: false,     // 鍏抽棴妯℃�佹
     tables: [],              // 鍙敤琛ㄥ悕
-    selectedTables: [],      // 宸查�夎〃鍚�
     originMenu: null,        // 鍘熷鑿滃崟
     originActions: null,     // 鍘熷鎸夐挳淇℃伅锛屼娇鐢ㄥ凡鏈夌敤鎴锋ā鏉�
     delActions: [],          // 鍒犻櫎鎸夐挳鍒楄〃
@@ -82,7 +83,7 @@
     let _config = ''
 
     if (!_LongParam) {
-      _config = JSON.parse(JSON.stringify(Source.baseConfig))
+      _config = fromJS(Source.baseConfig).toJS()
       if (!menu.isSubtable) { // 涓嶆槸閫夋嫨涓诲瓙琛ㄦ椂锛岄殣钘忔爣绛鹃〉
         _config.tabs = []
       }
@@ -124,13 +125,13 @@
 
         if (item.OpenType === 'pop') { // 鍚湁瀛愰厤缃」鐨勬寜閽�(琛ㄥ崟)
           _oriActions.push({
-            prebtn: JSON.parse(JSON.stringify(item)),
+            prebtn: fromJS(item).toJS(),
             curuuid: uuid,
             Template: 'Modal'
           })
         } else if (item.OpenType === 'tab' || item.OpenType === 'blank') { // 鍚湁瀛愰厤缃」鐨勬寜閽�(鏍囩鍚庡綋鍓嶉〉鎵撳紑)
           _oriActions.push({
-            prebtn: JSON.parse(JSON.stringify(item)),
+            prebtn: fromJS(item).toJS(),
             curuuid: uuid,
             Template: item.tabTemplate
           })
@@ -159,100 +160,16 @@
       activeKey: menu.activeKey || '0',
       optionLibs: optionLibs,
       originActions: _oriActions,
-      originMenu: JSON.parse(JSON.stringify(menu)),
-      selectedTables: _config.tables || [],
-      menuformlist: [
-        {
-          type: 'select',
-          key: 'fstMenuId',
-          label: '涓�绾ц彍鍗�',
-          initVal: menu.fstMenuId,
-          required: true,
-          readonly: false,
-          options: menu.fstMenuList
-        },
-        {
-          type: 'select',
-          key: 'parentId',
-          label: '浜岀骇鑿滃崟',
-          initVal: menu.ParentID,
-          required: true,
-          readonly: false,
-          options: menu.supMenuList
-        },
-        {
-          type: 'text',
-          key: 'menuName',
-          label: this.state.dict['header.menu.menuName'],
-          initVal: menu.MenuName,
-          required: true,
-          readonly: false
-        },
-        {
-          type: 'text',
-          key: 'menuNo',
-          label: this.state.dict['header.menu.menuNo'],
-          initVal: menu.MenuNo,
-          required: true,
-          readonly: false
-        },
-        {
-          type: 'select',
-          key: 'opentype',
-          label: this.state.dict['header.menu.openType'],
-          initVal: menu.PageParam.OpenType,
-          required: true,
-          options: [{
-            MenuID: 'newtab',
-            text: this.state.dict['header.form.tab']
-          }, {
-            MenuID: 'newpage',
-            text: this.state.dict['header.form.newpage']
-          }, {
-            MenuID: 'currenttab',
-            text: this.state.dict['header.form.currenttab']
-          }]
-        },
-        {
-          type: 'text',
-          key: 'easyCode',
-          label: this.state.dict['header.form.easyCode'],
-          initVal: _config.easyCode,
-          required: false,
-          readonly: false
-        }
-      ]
+      originMenu: fromJS(menu).toJS(),
+      menuformlist: getMainMenuForm(menu, _config)
     })
   }
 
   /**
-   * @description 鍔犺浇瀹屾垚鍚�
-   * 1銆佽幏鍙栫郴缁熷彲浣跨敤琛�
-   * 2銆佹牴鎹厤缃俊鎭腑宸蹭娇鐢ㄨ〃鑾峰彇鐩稿叧瀛楁淇℃伅
-   * 3銆佽幏鍙栨墍鏈夋爣绛鹃〉淇℃伅
+   * @description 鍔犺浇瀹屾垚鍚�, 鑾峰彇鎵�鏈夋爣绛鹃〉淇℃伅
    */
   componentDidMount () {
-    Api.getSystemConfig({func: 'sPC_Get_UserTemp', TypeCharTwo: 'tab'}).then(res => {
-      if (res.status) {
-        this.setState({
-          tabviews: res.UserTemp.map(temp => {
-            return {
-              uuid: temp.MenuID,
-              value: temp.MenuID,
-              text: temp.MenuName,
-              type: temp.Template,
-              MenuNo: temp.MenuNo
-            }
-          })
-        })
-      } else {
-        notification.warning({
-          top: 92,
-          message: res.message,
-          duration: 5
-        })
-      }
-    })
+    this.reloadTab(false)
   }
 
   /**
@@ -267,9 +184,9 @@
   /**
    * @description 鍔犺浇鎴栧埛鏂版爣绛句俊鎭�
    */
-  reloadTab = () => {
+  reloadTab = (type) => {
     this.setState({
-      loading: true,
+      loading: type,
       tabviews: []
     })
     Api.getSystemConfig({func: 'sPC_Get_UserTemp', TypeCharTwo: 'tab'}).then(res => {
@@ -286,11 +203,14 @@
             }
           })
         })
-        notification.success({
-          top: 92,
-          message: '鍒锋柊鎴愬姛銆�',
-          duration: 2
-        })
+
+        if (type) {
+          notification.success({
+            top: 92,
+            message: '鍒锋柊鎴愬姛銆�',
+            duration: 2
+          })
+        }
       } else {
         this.setState({
           loading: false
@@ -506,69 +426,6 @@
     }
   }
 
-  /**
-   * @description 鍒涘缓琛ㄦ牸瀛樺偍杩囩▼
-   */
-  tableCreatFunc = () => {
-    const { menu } = this.props
-    const { config } = 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}
-      let newLText = Utils.formatOptions(Utils.getTableFunc(setting, menu, _config)) // 鍒涘缓瀛樺偍杩囩▼sql
-      let DelText = Utils.formatOptions(Utils.dropfunc(setting.innerFunc))          // 鍒犻櫎瀛樺偍杩囩▼sql
-
-      this.refs.tableCreatFunc.exec(setting.innerFunc, newLText, DelText).then(result => {
-        if (result === 'success') {
-          this.setState({
-            config: _config
-          })
-        }
-      })
-    })
-  }
-
-  /**
-   * @description 鍒涘缓琛ㄦ牸鎺ュ彛锛堣鍑猴級
-   */
-  tableCreatInterface = () => {
-    const { menu } = this.props
-    const { config } = this.state
-
-    this.menuformRef.handleConfirm().then(res => {
-      this.settingRef.handleConfirm().then(setting => {
-        if (setting.interType !== 'inner' || setting.innerFunc) {
-          notification.warning({
-            top: 92,
-            message: '鎺ュ彛绫诲瀷涓�-鍐呴儴锛屼笖涓嶅瓨鍦ㄥ唴閮ㄥ嚱鏁版椂锛屾墠鍙互鍒涘缓鎺ュ彛锛�',
-            duration: 5
-          })
-          return
-        }
-  
-        let _config = {...config, setting: setting}
-        let _menu = {
-          type: 'main',
-          MenuID: menu.MenuID,
-          menuName: res.menuName,
-          menuNo: res.menuNo
-        }
-  
-        this.refs.tableCreatInterface.triggerOutInterface(_menu, _config)
-      })
-    })
-  }
-
   deleteElement = (element) => {
     const { config, thawButtons } = this.state
     let _this = this
@@ -645,7 +502,7 @@
     const { menu } = this.props
     const { originMenu, delActions, thawButtons } = this.state
 
-    let config = JSON.parse(JSON.stringify(this.state.config))
+    let config = fromJS(this.state.config).toJS()
 
     this.menuformRef.handleConfirm().then(res => {
       if (config.isAdd) {
@@ -873,7 +730,7 @@
           func: 'sPC_Button_AddUpt',
           Type: 40,                  // 娣诲姞鑿滃崟涓嬬殑鎸夐挳type涓�40锛屾寜閽笅鐨勬寜閽畉ype涓�60
           ParentID: menu.MenuID,
-          MenuNo: res.menuNo,
+          MenuNo: res.MenuNo,
           Template: menu.PageParam.Template || '',
           PageParam: '',
           LongParam: '',
@@ -931,10 +788,10 @@
           SndID: res.parentId,
           ParentID: res.parentId,
           MenuID: menu.MenuID,
-          MenuNo: res.menuNo,
+          MenuNo: res.MenuNo,
           EasyCode: res.easyCode,
           Template: menu.PageParam.Template || '',
-          MenuName: res.menuName,
+          MenuName: res.MenuName,
           PageParam: JSON.stringify(_pageParam),
           LongParam: _LongParam,
           LText: _vals.func.map(item => `select '${menu.MenuID}' as MenuID,'${item.func}' as ProcName,'${item.label}' as MenuName`),
@@ -1054,7 +911,7 @@
           }
         }).then(resp => {
           if (resp === false) return
-          let localParam = JSON.parse(JSON.stringify(param))
+          let localParam = fromJS(param).toJS()
 
           Api.getSystemConfig(param).then(response => {
             if (response.status) {
@@ -1070,8 +927,8 @@
                   ...originMenu,
                   LongParam: _config,
                   PageParam: _pageParam,
-                  MenuName: res.menuName,
-                  MenuNo: res.menuNo,
+                  MenuName: res.MenuName,
+                  MenuNo: res.MenuNo,
                   ParentID: res.parentId,
                   fstMenuId: res.fstMenuId,
                   supMenuList: _supMenuList
@@ -1306,8 +1163,8 @@
           ...originMenu,
           LongParam: _config,
           PageParam: _pageParam,
-          MenuName: res.menuName,
-          MenuNo: res.menuNo,
+          MenuName: res.MenuName,
+          MenuNo: res.MenuNo,
           ParentID: res.parentId,
           fstMenuId: res.fstMenuId
         }
@@ -1328,110 +1185,6 @@
   }
 
   /**
-   * @description 椤甸潰閰嶇疆淇℃伅妯℃�佹鏄剧ず
-   */
-  changeSetting = () => {
-    this.setState({
-      settingVisible: true
-    })
-  }
-
-  /**
-   * @description 淇濆瓨椤甸潰閰嶇疆淇℃伅
-   */
-  settingSave = () => {
-    const { menu } = this.props
-    const {config} = this.state
-
-    this.settingRef.handleConfirm().then(res => {
-      if (
-        res.interType === 'inner' &&
-        !res.innerFunc &&
-        /[^\s]+\s+[^\s]+/ig.test(res.dataresource) &&
-        config.setting.dataresource !== res.dataresource
-      ) {
-        let param = {
-          func: 's_DataSrc_Save',
-          LText: res.dataresource,
-          MenuID: menu.MenuID
-        }
-
-        param.LText = Utils.formatOptions(param.LText)
-        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
-        param.secretkey = Utils.encrypt(param.LText, param.timestamp)
-
-        Api.getLocalConfig(param)
-      }
-
-      
-
-      if (res.interType === 'inner' && !res.innerFunc && /\s/.test(res.dataresource)) {
-        this.setState({
-          sqlVerifing: true
-        })
-
-        let _dataresource = res.dataresource
-
-        if (res.queryType === 'statistics') {
-          let fieldmap = new Map()
-          let options = config.search.map(item => {
-            let _field = item.key
-            let _val = ''
-
-            if (fieldmap.has(_field)) {
-              _field = _field + '1'
-            }
-
-            fieldmap.set(item.key, true)
-
-            if (/date/.test(item.type)) {
-              _val = '1900-01-01'
-            }
-
-            return {
-              reg: new RegExp('@' + _field + '@', 'ig'),
-              value: _val
-            }
-          })
-
-          options.forEach(item => {
-            _dataresource = _dataresource.replace(item.reg, `'${item.value}'`)
-          })
-        }
-
-        let param = {
-          func: 's_debug_sql',
-          LText: _dataresource
-        }
-        param.LText = Utils.formatOptions(param.LText)
-        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
-        param.secretkey = Utils.encrypt(param.LText, param.timestamp)
-        
-        Api.getLocalConfig(param).then(result => {
-          if (result.status) {
-            this.setState({
-              sqlVerifing: false,
-              config: {...config, setting: res},
-              settingVisible: false
-            })
-          } else {
-            this.setState({sqlVerifing: false})
-            
-            Modal.error({
-              title: result.message
-            })
-          }
-        })
-      } else {
-        this.setState({
-          config: {...config, setting: res},
-          settingVisible: false
-        })
-      }
-    })
-  }
-
-  /**
    * @description 璁剧疆鍙厤缃寜閽�
    */
   setSubConfig = (item, type) => {
@@ -1446,14 +1199,14 @@
       })
     } else {
       this.menuformRef.handleConfirm().then(res => {
-        let _config = {...config, tables: this.state.selectedTables, easyCode: res.easyCode}
+        let _config = {...config, easyCode: res.easyCode}
         let _pageParam = {...menu.PageParam, OpenType: res.opentype}
         let _originMenu = {
           ...originMenu,
           LongParam: _config,
           PageParam: _pageParam,
-          MenuName: res.menuName,
-          MenuNo: res.menuNo,
+          MenuName: res.MenuName,
+          MenuNo: res.MenuNo,
           ParentID: res.parentId,
           fstMenuId: res.fstMenuId
         }
@@ -1602,7 +1355,7 @@
    */
   addTabGroup = () => {
     let _this = this
-    let _config = JSON.parse(JSON.stringify(this.state.config))
+    let _config = fromJS(this.state.config).toJS()
 
     confirm({
       content: `纭畾鏂板缓鏍囩缁勫悧锛焋,
@@ -1627,7 +1380,7 @@
    */
   delTabGroup = (groupId) => {
     let _this = this
-    let _config = JSON.parse(JSON.stringify(this.state.config))
+    let _config = fromJS(this.state.config).toJS()
 
     confirm({
       content: `纭畾鍒犻櫎鏍囩缁勫悧锛焋,
@@ -1647,7 +1400,7 @@
   }
 
   handleGroup = (index, type) => {
-    let config = JSON.parse(JSON.stringify(this.state.config))
+    let config = fromJS(this.state.config).toJS()
     
     if (type === 'up') {
       config.tabgroups.splice(index, 0, config.tabgroups.splice(index - 1, 1)[0])
@@ -1683,7 +1436,7 @@
   /**
    * @description 缂栬緫鍔熻兘瀹屾垚鏇存柊锛屽寘鎷В鍐绘寜閽�佺矘璐淬�佹浛鎹㈢瓑
    */
-  updateConfig = (res) => {
+  editConfig = (res) => {
     if (res.type === 'thaw') {
       this.setState({
         thawButtons: res.thawButtons,
@@ -1726,15 +1479,6 @@
   }
 
   /**
-   * @description 鏇存柊鏄剧ず鍒楅厤缃俊鎭�
-   */
-  updatecolumn = (config) => {
-    this.setState({
-      config: config
-    })
-  }
-
-  /**
    * @description 鏇存柊鍥捐〃缁勯厤缃俊鎭�
    */
   updatechartgroup = (config, _chartview) => {
@@ -1757,9 +1501,9 @@
   }
 
   /**
-   * @description 鎵归噺娣诲姞锛屾洿鏂伴厤缃俊鎭�
+   * @description 鏇存柊閰嶇疆淇℃伅
    */
-  updatefield = (config) => {
+  updateconfig = (config) => {
     this.setState({
       config: config
     })
@@ -1777,7 +1521,6 @@
 
     return (
       <div className="common-table-board">
-        {/* <div className="ant-modal-mask"></div> */}
         <DndProvider backend={HTML5Backend}>
           {/* 宸ュ叿鏍� */}
           <div className="tools">
@@ -1809,7 +1552,7 @@
                   config={config}
                   type="search"
                   tableFields={this.state.tableFields}
-                  updatefield={this.updatefield}
+                  updatefield={this.updateconfig}
                 />
               </Panel>
               {/* 鎸夐挳娣诲姞 */}
@@ -1853,7 +1596,7 @@
                   config={config}
                   type="columns"
                   tableFields={this.state.tableFields}
-                  updatefield={this.updatefield}
+                  updatefield={this.updateconfig}
                 />
               </Panel>
               {/* 娣诲姞鏍囩 */}
@@ -1890,18 +1633,25 @@
             <Card title={
               <div>
                 {this.state.dict['header.menu.page.configurable']} 
-                <Icon type="redo" style={{marginLeft: '10px'}} title="鍒锋柊鏍囩鍒楄〃" onClick={this.reloadTab} />
+                <Icon type="redo" style={{marginLeft: '10px'}} title="鍒锋柊鏍囩鍒楄〃" onClick={() => this.reloadTab(true)} />
               </div>
             } bordered={false} extra={
               <div>
-                <EditComponent dict={this.state.dict} type="maintable" config={this.state.config} MenuID={this.props.menu.MenuID} thawButtons={this.state.thawButtons} refresh={this.updateConfig}/>
+                <EditComponent dict={this.state.dict} type="maintable" config={this.state.config} MenuID={this.props.menu.MenuID} thawButtons={this.state.thawButtons} refresh={this.editConfig}/>
                 <Switch className="big" checkedChildren="鍚�" unCheckedChildren="鍋�" checked={this.state.config.enabled} onChange={this.onEnabledChange} />
                 <Button type="primary" onClick={this.changeTemplate}>{this.state.dict['header.menu.template.change']}</Button>
                 <Button type="primary" onClick={this.submitConfig} loading={this.state.menuloading}>{this.state.dict['header.save']}</Button>
                 <Button onClick={this.cancelConfig}>{this.state.dict['header.return']}</Button>
               </div>
             } style={{ width: '100%' }}>
-              <Icon type="setting" onClick={this.changeSetting} />
+              <SettingComponent
+                type="main"
+                config={config}
+                MenuID={this.props.menu.MenuID}
+                menuformRef={this.menuformRef}
+                permFuncField={this.props.permFuncField}
+                updatesetting={this.updateconfig}
+              />
               <SearchComponent
                 menu={{MenuID: this.props.menu.MenuID, MenuName: this.props.menu.MenuName}}
                 config={config}
@@ -1912,9 +1662,10 @@
               />
               <ActionComponent
                 type="main"
-                menu={{MenuID: this.props.menu.MenuID, MenuName: this.props.menu.MenuName, MenuNo: this.props.menu.MenuNo}}
+                menu={{ MenuID: this.props.menu.MenuID, MenuName: this.props.menu.MenuName, MenuNo: this.props.menu.MenuNo }}
                 config={config}
                 tabs={this.state.tabviews}
+                menuformRef={this.menuformRef}
                 pasteContent={this.state.pasteContent}
                 usefulFields={this.props.permFuncField}
                 setSubConfig={(_btn) => this.setSubConfig(_btn, 'button')}
@@ -1926,7 +1677,7 @@
                 menu={this.props.menu}
                 sysRoles={this.props.sysRoles}
                 pasteContent={this.state.pasteContent}
-                updatecolumn={this.updatecolumn}
+                updatecolumn={this.updateconfig}
               />
               {/* 鏍囩缁� */}
               {config.tabgroups.map((groupId, index) => {
@@ -1976,35 +1727,7 @@
             wrappedComponentRef={(inst) => this.tabsFormRef = inst}
           />
         </Modal>
-        {/* 璁剧疆鍏ㄥ眬閰嶇疆鍙婂垪琛ㄦ暟鎹簮 */}
-        <Modal
-          title={this.state.dict['model.edit']}
-          visible={this.state.settingVisible}
-          width={750}
-          maskClosable={false}
-          onCancel={() => { // 鍙栨秷淇敼
-            this.setState({
-              settingVisible: false
-            })
-          }}
-          footer={[
-            <CreateInterface key="interface" dict={this.state.dict} ref="tableCreatInterface" trigger={this.tableCreatInterface}/>,
-            <CreateFunc key="create" dict={this.state.dict} ref="tableCreatFunc" trigger={this.tableCreatFunc}/>,
-            <Button key="cancel" onClick={() => { this.setState({ settingVisible: false }) }}>{this.state.dict['header.cancel']}</Button>,
-            <Button key="confirm" type="primary" loading={this.state.sqlVerifing} onClick={this.settingSave}>{this.state.dict['model.confirm']}</Button>
-          ]}
-          destroyOnClose
-        >
-          <SettingForm
-            dict={this.state.dict}
-            menu={this.props.menu}
-            inputSubmit={this.settingSave}
-            data={config.setting}
-            columns={config.columns}
-            usefulFields={this.props.permFuncField}
-            wrappedComponentRef={(inst) => this.settingRef = inst}
-          />
-        </Modal>
+        {/* 杩斿洖鏃舵湭淇濆瓨鎻愮ず */}
         <Modal
           bodyStyle={{textAlign: 'center', color: '#000000', fontSize: '16px'}}
           closable={false}

--
Gitblit v1.8.0