From da34633b25d16359cd91a656acad5e811f9972b7 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 14 三月 2023 18:09:54 +0800
Subject: [PATCH] 2023-03-14

---
 src/tabviews/custom/components/code/sand-box/index.jsx |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/tabviews/custom/components/code/sand-box/index.jsx b/src/tabviews/custom/components/code/sand-box/index.jsx
index 0663d06..8ccc32b 100644
--- a/src/tabviews/custom/components/code/sand-box/index.jsx
+++ b/src/tabviews/custom/components/code/sand-box/index.jsx
@@ -24,6 +24,8 @@
     html: '',
   }
 
+  loaded = false
+
   UNSAFE_componentWillMount () {
     const { data, initdata } = this.props
     let _config = fromJS(this.props.config).toJS()
@@ -49,12 +51,15 @@
       if (_sync && data) {
         _data = data[_config.dataName] || {}
         _sync = false
+        this.loaded = true
       } else if (_sync && initdata) {
         _data = initdata || {}
         _sync = false
+        this.loaded = true
       }
     } else {
       _data = {}
+      this.loaded = true
     }
     
     if (_config.css) {
@@ -84,15 +89,15 @@
   }
 
   componentDidMount () {
-    const { config, sync } = this.state
+    const { config } = this.state
 
     MKEmitter.addListener('reloadData', this.reloadData)
 
-    if (config.$cache && (config.setting.sync !== 'true' || sync)) {
+    if (config.$cache && !this.loaded) {
       Api.getLCacheConfig(config.uuid).then(res => {
-        if (!res) return
+        if (!res || this.loaded) return
 
-        this.setState({data: res[0]}, () => {
+        this.setState({data: res}, () => {
           this.renderView()
         })
       })
@@ -122,13 +127,15 @@
         _data = nextProps.data[config.dataName]
       }
 
-      this.setState({sync: false, data: _data})
+      this.loaded = true
 
       if (!is(fromJS(this.state.data), fromJS(_data))) {
         setTimeout(() => {
           this.renderView()
         }, 10)
       }
+
+      this.setState({sync: false, data: _data})
     } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({}, () => {
         this.loadData()
@@ -159,6 +166,7 @@
         data: {},
         loading: false
       })
+      this.loaded = true
       return
     }
 
@@ -180,20 +188,21 @@
     if (result.status) {
       let _data = result.data || {}
 
-      if (config.$cache) {
+      this.loaded = true
+      if (config.$cache && config.setting.onload !== 'false') {
         Api.writeCacheConfig(config.uuid, result.data || '')
+      }
+
+      if (!is(fromJS(this.state.data), fromJS(_data))) {
+        setTimeout(() => {
+          this.renderView()
+        }, 10)
       }
 
       this.setState({
         data: _data,
         loading: false
       })
-      
-      if (!is(fromJS(this.state.data), fromJS(_data))) {
-        setTimeout(() => {
-          this.renderView()
-        }, 10)
-      }
     } else {
       this.setState({
         loading: false

--
Gitblit v1.8.0