From f59a500d24291d7f54b71dcca939a2a23dedca7c Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 18 六月 2020 17:52:03 +0800
Subject: [PATCH] 2020-06-18

---
 src/templates/comtableconfig/index.jsx |  196 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 125 insertions(+), 71 deletions(-)

diff --git a/src/templates/comtableconfig/index.jsx b/src/templates/comtableconfig/index.jsx
index b879a09..8f6904e 100644
--- a/src/templates/comtableconfig/index.jsx
+++ b/src/templates/comtableconfig/index.jsx
@@ -14,15 +14,9 @@
 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'
 import SearchComponent from '@/templates/sharecomponent/searchcomponent'
 import ActionComponent from '@/templates/sharecomponent/actioncomponent'
 import ColumnComponent from '@/templates/sharecomponent/columncomponent'
-import TabsComponent from '@/templates/sharecomponent/tabscomponent'
-import ChartComponent from '@/templates/sharecomponent/chartcomponent'
-import CardComponent from '@/templates/sharecomponent/cardcomponent'
 
 import MenuForm from '@/templates/zshare/menuform'
 import EditComponent from '@/templates/zshare/editcomponent'
@@ -32,8 +26,13 @@
 
 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'))
+const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
+const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
+const ChartGroupComponent = asyncComponent(() => import('@/templates/sharecomponent/chartgroupcomponent'))
+const ChartComponent = asyncComponent(() => import('@/templates/sharecomponent/chartcomponent'))
+const CardComponent = asyncComponent(() => import('@/templates/sharecomponent/cardcomponent'))
+const TabsComponent = asyncComponent(() => import('@/templates/sharecomponent/tabscomponent'))
 
 class ComTableConfig extends Component {
   static propTpyes = {
@@ -44,13 +43,12 @@
   }
 
   state = {
-    dict: CommonDict,        // 瀛楀吀
+    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     config: null,            // 椤甸潰閰嶇疆
     tableFields: [],         // 琛ㄦ牸鏄剧ず鍒�
     fields: null,            // 鎼滅储鏉′欢鍙婃樉绀哄垪锛屽彲閫夊瓧娈�
     menuformlist: null,      // 鍩烘湰淇℃伅琛ㄥ崟瀛楁
     formlist: null,          // 鎼滅储鏉′欢銆佹寜閽�佹樉绀哄垪琛ㄥ崟瀛楁
-    card: null,              // 缂栬緫鍏冪礌
     menuloading: false,      // 鑿滃崟淇濆瓨涓�
     menucloseloading: false, // 鑿滃崟鍏抽棴鏃讹紝閫夋嫨淇濆瓨
     loading: false,          // 鍔犺浇涓紝椤甸潰spin
@@ -65,7 +63,8 @@
     thawButtons: [],         // 宸查�夋嫨瑕佽В鍐荤殑鎸夐挳
     activeKey: '0',          // 榛樿灞曞紑鍩烘湰淇℃伅
     chartview: null,         // 褰撳墠瑙嗗浘
-    pasteContent: null       // 绮樿创閰嶇疆淇℃伅
+    pasteContent: null,      // 绮樿创閰嶇疆淇℃伅
+    openEdition: ''          // 缂栬緫鐗堟湰鏍囪锛岄槻姝㈠浜烘搷浣�
   }
 
   /**
@@ -82,7 +81,7 @@
     if (!_LongParam) {
       _config = fromJS(Source.baseConfig).toJS()
       if (!menu.isSubtable) { // 涓嶆槸閫夋嫨涓诲瓙琛ㄦ椂锛岄殣钘忔爣绛鹃〉
-        _config.tabs = []
+        _config.tabgroups = [{ uuid: 'tabs', sublist: [] }]
       }
       _config.isAdd = true
     } else {
@@ -104,41 +103,75 @@
       })
     }
 
-    // 閰嶇疆榛樿鍊硷紝鍏煎
-    _config.tabs = _config.tabs || []
-    _config.Template = 'CommonTable'
-    _config.easyCode = _config.easyCode || ''
+    if (!_config.version || _config.version < '1.0') {
+      // 閰嶇疆榛樿鍊硷紝鍏煎
+      _config.version = '1.0'
+      _config.Template = 'CommonTable'
+      _config.easyCode = _config.easyCode || ''
+  
+      if (!_config.tabgroups) {
+        _config.tabgroups = [{ uuid: 'tabs', sublist: [] }]
+      } else if (typeof(_config.tabgroups[0]) === 'string') {
+        let _tabgroups = []
+        _config.tabgroups.forEach(groupId => {
+          let _group = {
+            uuid: groupId,
+            sublist: fromJS(_config[groupId]).toJS()
+          }
+  
+          delete _config[groupId]
+  
+          _tabgroups.push(_group)
+        })
+  
+        _config.tabgroups = _tabgroups
+      }
+  
+      // 鍏煎鍥捐〃
+      if (!_config.charts) {
+        _config.expand = false
+        _config.charts = [{
+          uuid: Utils.getuuid(),
+          label: '',
+          title: '',
+          chartType: 'table',
+          icon: 'table',
+          Hide: 'false',
+          blacklist: []
+        }]
+      } else {
+        _config.charts.forEach(card => {
+          if (card.chartType === 'card') {
+            card.details = card.details.map(_cell => {
+              if (!_cell.fontSize) {
+                _cell.fontSize = 14
+              }
+              if (!_cell.width) {
+                _cell.width = 100
+              } else if (_cell.width === 'helf') {
+                _cell.width = 50
+              } else if (_cell.width === 'third') {
+                _cell.width = 33
+              }
+        
+              if (_cell.bold === 'true') {
+                _cell.fontWeight = 'normal'
+              }
 
-    if (!_config.tabgroups) {
-      _config.tabgroups = [{ uuid: 'tabs', sublist: [] }]
-    } else if (typeof(_config.tabgroups[0]) === 'string') {
-      let _tabgroups = []
-      _config.tabgroups.forEach(groupId => {
-        let _group = {
-          uuid: groupId,
-          sublist: fromJS(_config[groupId]).toJS()
-        }
+              if (!_cell.height) {
+                _cell.height = 1
+              }
 
-        delete _config[groupId]
+              return _cell
+            })
 
-        _tabgroups.push(_group)
-      })
-
-      _config.tabgroups = _tabgroups
-    }
-
-    // 鍏煎鍥捐〃
-    if (!_config.charts) {
-      _config.expand = false
-      _config.charts = [{
-        uuid: Utils.getuuid(),
-        label: '',
-        title: '',
-        chartType: 'table',
-        icon: 'table',
-        Hide: 'false',
-        blacklist: []
-      }]
+            if (card.widthType === 'ratio' && card.avatar && card.avatar.widthType !== 'ratio') {
+              card.avatar.widthType = 'ratio'
+              card.avatar.width = 32
+            }
+          }
+        })
+      }
     }
     
     let _oriActions = []
@@ -185,6 +218,7 @@
     this.setState({
       chartview: _config.charts[0].uuid,
       config: _config,
+      openEdition: menu.open_edition || '',
       activeKey: menu.activeKey || '0',
       optionLibs: optionLibs,
       originActions: _oriActions,
@@ -252,13 +286,6 @@
     })
   }
 
-  /**
-   * @description 涓夌骇鑿滃崟鍒囨崲妯℃澘
-   */
-  changeTemplate = () => {
-    this.props.handleView({tabview: 'template'})
-  }
-
   getFuncNames = (data, funcNames, tableNames) => {
     data.forEach(item => {
       if (item.subfuncs) {
@@ -288,7 +315,7 @@
    */
   submitConfig = () => {
     const { menu } = this.props
-    const { originMenu, delActions, thawButtons } = this.state
+    const { originMenu, delActions, thawButtons, openEdition } = this.state
 
     let config = fromJS(this.state.config).toJS()
 
@@ -549,6 +576,10 @@
         param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
         param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
+        if (openEdition) { // 鐗堟湰绠$悊
+          param.open_edition = openEdition
+        }
+
         // 鏈夋寜閽垨鏍囩鍒犻櫎鏃讹紝鍏堣繘琛屽垹闄ゆ搷浣�
         // 鍒犻櫎鎴愬姛鍚庯紝淇濆瓨椤甸潰閰嶇疆
         new Promise(resolve => {
@@ -663,6 +694,7 @@
 
               this.setState({
                 config: _config,
+                openEdition: response.open_edition || '',
                 originMenu: {
                   ...originMenu,
                   LongParam: _config,
@@ -674,7 +706,7 @@
                   supMenuList: _supMenuList
                 }
               })
-    
+
               this.props.reloadmenu()
               
               this.submitAction(btnParam, tabParam)
@@ -684,6 +716,8 @@
               delete localParam.PageParam
               delete localParam.Template
               delete localParam.Sort
+              delete localParam.EasyCode
+              delete localParam.open_edition
 
               Api.getLocalConfig(localParam)
             } else {
@@ -943,7 +977,7 @@
    */
   setSubConfig = (item, type) => {
     const { menu } = this.props
-    const { config, originMenu, optionLibs, activeKey } = this.state
+    const { config, originMenu, optionLibs, activeKey, openEdition } = this.state
 
     if (!originMenu.MenuID) { // menuID涓嶅瓨鍦ㄦ椂锛屼负鏂板缓鑿滃崟锛屾彁绀鸿彍鍗曞皻鏈繚瀛�
       notification.warning({
@@ -995,8 +1029,8 @@
           isbutton = false
         }
 
-        // 淇濆瓨褰撳墠鎵撳紑椤电
-        _originMenu.activeKey = activeKey
+        _originMenu.activeKey = activeKey       // 淇濆瓨褰撳墠鎵撳紑椤电
+        _originMenu.open_edition = openEdition  // 鏇存柊鐗堟湰鍙�
 
         let param = {
           optionLibs: optionLibs,
@@ -1010,6 +1044,11 @@
           editAction: isbutton ? item : '',
           subConfig: '',
           tabview: _view
+        }
+        
+        // 褰撳瓙琛ㄤ娇鐢ㄤ富椤垫悳绱㈡潯浠舵椂锛屽皢涓婚〉鎼滅储鍚戜笅浼犻��
+        if (param.editTab && param.editTab.searchPass === 'true') {
+          param.editTab.mainsearch = fromJS(_config.search).toJS()
         }
 
         this.setState({
@@ -1040,6 +1079,14 @@
               param.subConfig = _LongParam
             } else if (_LongParam && param.tabview === 'SubTable' && _LongParam.Template === 'SubTable') {
               param.subConfig = _LongParam
+            }
+
+            if (param.editTab) {
+              param.editTab.open_edition = res.open_edition || ''
+            } else if (param.editAction) {
+              param.editAction.open_edition = res.open_edition || ''
+            } else if (param.btnTab) {
+              param.btnTab.open_edition = res.open_edition || ''
             }
 
             this.props.handleView(param)
@@ -1099,12 +1146,30 @@
       })
     }
 
-    if (config.setting.interType === 'inner' && !config.setting.innerFunc && !config.setting.dataresource) {
+    let charterr = ''
+    config.charts.forEach(chart => {
+      if (!charterr && ['line', 'bar', 'pie'].includes(chart.chartType) && !chart.Xaxis) {
+        charterr = '鍥捐〃' + (chart.title ? '銆�' + chart.title + '銆�' : '') + '鍧愭爣杞存湭璁剧疆锛屼笉鍙惎鐢紒'
+      }
+    })
+
+    let hasKey = false
+    config.columns.forEach(col => {
+      if (config.setting.primaryKey === col.field) {
+        hasKey = true
+      }
+    })
+
+    if (config.setting.interType === 'inner' && !config.setting.innerFunc && config.setting.default !== 'false' && !config.setting.dataresource) {
       return '鑿滃崟灏氭湭璁剧疆鏁版嵁婧愶紝涓嶅彲鍚敤锛�'
     } else if (!config.setting.primaryKey) {
       return '鑿滃崟灏氭湭璁剧疆涓婚敭锛屼笉鍙惎鐢紒'
+    } else if (!hasKey) {
+      return '鏄剧ず鍒椾腑涓嶅瓨鍦ㄤ富閿瓧娈碉紝涓嶅彲鍚敤锛�'
     } else if (!tabinvalid) {
       return '鑿滃崟鏍囩椤佃缃敊璇紙瀛樺湪澶氳鏍囩鏃讹紝琛屾爣绛句笉鍙负绌猴級锛�'
+    } else if (charterr) {
+      return charterr
     } else {
       return true
     }
@@ -1240,16 +1305,13 @@
                 <TableComponent
                   config={config}
                   containerId="main-basedata"
-                  selectedTables={config.tables || []}
                   updatetable={this.updatetable}
                 />
               </Panel>
               {/* 鎼滅储鏉′欢娣诲姞 */}
               <Panel header={this.state.dict['header.menu.search']} key="1">
                 <div className="search-element">
-                  {Source.searchItems.map((item, index) => {
-                    return (<SourceElement key={index} content={item}/>)
-                  })}
+                  {Source.searchItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
                 </div>
                 <FieldsComponent
                   config={config}
@@ -1261,9 +1323,7 @@
               {/* 鎸夐挳娣诲姞 */}
               <Panel header={this.state.dict['header.menu.action']} key="2">
                 <div className="search-element">
-                  {Source.actionItems.map((item, index) => {
-                    return (<SourceElement key={index} content={item}/>)
-                  })}
+                  {Source.actionItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
                 </div>
                 <div className="config-btn">
                   {confActions.length > 0 ?
@@ -1291,9 +1351,7 @@
               {/* 娣诲姞鏄剧ず鍒� */}
               <Panel header={this.state.dict['header.menu.column']} key="3">
                 <div className="search-element">
-                  {Source.columnItems.map((item, index) => {
-                    return (<SourceElement key={index} content={item}/>)
-                  })}
+                  {Source.columnItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
                 </div>
                 <FieldsComponent
                   config={config}
@@ -1305,9 +1363,7 @@
               {/* 娣诲姞鏍囩 */}
               <Panel header={this.state.dict['header.menu.tab']} key="4">
                 <div className="search-element">
-                  {Source.tabItems.map((item, index) => {
-                    return (<SourceElement key={index} content={item}/>)
-                  })}
+                  {Source.tabItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
                 </div>
                 {configTabs.length > 0 ?
                   <p className="config-btn-title">
@@ -1342,7 +1398,6 @@
               <div>
                 <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>
@@ -1422,7 +1477,6 @@
               </div>
               {/* 鏍囩缁� */}
               <TabsComponent
-                type="main"
                 config={config}
                 tabs={this.state.tabviews}
                 setSubConfig={(item) => this.setSubConfig(item, 'tab')}

--
Gitblit v1.8.0