From f830c733cbc071f023c9a9a4e1571b7c81d672bf Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 12 十一月 2020 11:47:33 +0800
Subject: [PATCH] 2020-11-12

---
 src/tabviews/custom/index.jsx |   51 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx
index 82880b1..f667bbb 100644
--- a/src/tabviews/custom/index.jsx
+++ b/src/tabviews/custom/index.jsx
@@ -43,8 +43,6 @@
     config: null,         // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑
     mainSearch: null,
     userConfig: null,     // 鐢ㄦ埛鑷畾涔夎缃�
-    arr_field: '',        // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆�
-    setting: null,        // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑
     data: null,           // 鍒楄〃鏁版嵁闆�
     loading: false,       // 鍒楄〃鏁版嵁鍔犺浇涓�
     visible: false,       // 鏍囩椤垫帶鍒�
@@ -67,12 +65,6 @@
       let config = ''
       let userConfig = null
 
-      setTimeout(() => { // 寤舵椂鍔犺浇鐘舵��
-        this.setState({
-          loadingview: false
-        })
-      }, 1500)
-
       try { // 閰嶇疆淇℃伅瑙f瀽
         config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
       } catch (e) {
@@ -89,11 +81,12 @@
           userConfig = null
         }
       }
-
+      
       // 椤甸潰閰嶇疆瑙f瀽閿欒鏃舵彁绀�
       if (!config) {
         this.setState({
-          viewlost: true
+          viewlost: true,
+          loadingview: false
         })
         return
       }
@@ -102,6 +95,7 @@
       if (!config.enabled) {
         this.setState({
           viewlost: true,
+          loadingview: false,
           lostmsg: this.state.dict['main.view.unenabled']
         })
         return
@@ -146,16 +140,24 @@
       })
 
       let params = []
-      config.components = this.formatSetting(config.components, params, mainSearch, permAction)
+      let BID = param && param.BID ? param.BID : ''
+      config.components = this.formatSetting(config.components, params, mainSearch, permAction, BID)
 
       this.setState({
-        BID: param && param.BID ? param.BID : '',
+        BID: BID,
         userConfig: userConfig,
-        setting: config.setting,
         config,
         mainSearch
       }, () => {
-        this.loadmaindata(params)
+        if (!params || params.length === 0) {
+          setTimeout(() => { // 寤舵椂鍔犺浇鐘舵��
+            this.setState({
+              loadingview: false
+            })
+          }, 1000)
+        } else {
+          this.loadmaindata(params)
+        }
       })
     } else {
       this.setState({
@@ -207,7 +209,7 @@
   }
 
   // 鏍煎紡鍖栭粯璁よ缃�
-  formatSetting = (components, params, mainSearch, permAction) => {
+  formatSetting = (components, params, mainSearch, permAction, BID) => {
     return components.map(component => {
       if (component.type === 'tabs') {
         component.subtabs = component.subtabs.map(tab => {
@@ -266,7 +268,7 @@
       // dataName 绯荤粺鐢熸垚鐨勬暟鎹簮鍚嶇О
       // pageable 鏄惁鍒嗛〉锛岀粍浠跺睘鎬э紝涓嶅垎椤电殑缁勪欢鎵嶅彲浠ョ粺涓�鏌ヨ
       if (component.floor === 1 && component.dataName && (!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true' && component.setting.sync === 'true') {
-        let param = this.getDefaultParam(component, mainSearch)
+        let param = this.getDefaultParam(component, mainSearch, BID)
         params.push(param)
       } else if (component.floor === 1) {
         component.setting.sync = 'false'
@@ -279,7 +281,7 @@
   /**
    * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
    */
-  getDefaultParam = (component, mainSearch) => {
+  getDefaultParam = (component, mainSearch, BID) => {
     const { columns, search, setting, dataName, format } = component
     
     let searchlist = []
@@ -300,6 +302,7 @@
     let _dataresource = setting.dataresource
     let _customScript = setting.customScript
 
+    
     if (setting.queryType === 'statistics' || _customScript) {
       let allSearch = Utils.getAllSearchOptions(searchlist)
       let regoptions = allSearch.map(item => {
@@ -313,10 +316,11 @@
         if (_dataresource && setting.queryType === 'statistics') {
           _dataresource = _dataresource.replace(item.reg, item.value)
         }
-        if (_customScript) {
-          _customScript = _customScript.replace(item.reg, item.value)
-        }
+        _customScript = _customScript.replace(item.reg, item.value)
       })
+
+      _dataresource = _dataresource.replace(/@BID@/ig, BID)
+      _customScript = _customScript.replace(/@BID@/ig, BID)
     }
 
     let _search = ''
@@ -353,7 +357,6 @@
    * @description 涓昏〃鏁版嵁鍔犺浇
    */ 
   loadmaindata = (params) => {
-    if (!params || params.length === 0) return
     let LText_field = []
     let LText = params.map((item, index) => {
       let _sql = item.sql
@@ -381,6 +384,8 @@
     param.LText_field = Utils.formatOptions(param.LText_field)
     param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
     param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+
+    this.setState({loading: true, loadingview: false})
 
     Api.getLocalConfig(param).then(result => {
       if (result.status) {
@@ -511,11 +516,11 @@
 
   render() {
     const { menuType, MenuNo } = this.props
-    const { loadingview, viewlost, config } = this.state
+    const { loadingview, viewlost, config, loading } = this.state
 
     return (
       <div className="custom-page-wrap" id={this.state.ContainerId} style={config ? config.style : null}>
-        {loadingview && <Spin size="large" />}
+        {(loadingview || loading) ? <Spin size="large" /> : null}
         <Row>{this.getComponents()}</Row>
         {MenuNo && options.sysType !== 'cloud' && menuType !== 'HS' ? <Button
           icon="copy"

--
Gitblit v1.8.0