瀏覽代碼

模板保存跟之前所有保存的模板作对比

Luolei 6 年之前
父節點
當前提交
87c6d028a2
共有 2 個文件被更改,包括 26 次插入13 次删除
  1. 25 12
      src/components/Operation/index.jsx
  2. 1 1
      src/containers/OtherHistory.js

+ 25 - 12
src/components/Operation/index.jsx

@@ -8,6 +8,7 @@ import PreviewContainer from '@containers/PreviewContainer';
 import { ConfirmModal, Notify } from '@commonComp';
 import { changeVisible } from '@store/actions/tabTemplate';
 import {getAllDataList,getAllDataStringList} from '@utils/tools';
+import { initItemList } from '@store/async-actions/tabTemplate';
 import store from '@store';
 
 
@@ -150,7 +151,11 @@ class Operation extends Component {
     }
   }
   saveHis(type) {
-    let flg = this.getAllData()
+    let baseList = store.getState();
+    if(baseList.tabTemplate.items.length == 0){
+      store.dispatch(initItemList());         //获取模板列表
+    }
+    let flg = this.getAllData();
     if(flg){
       this.setState({
         visible: true,
@@ -169,14 +174,16 @@ class Operation extends Component {
     let jsonData = getAllDataList(baseList);
     let jsonStr = getAllDataStringList(baseList);
     let whichSign = baseList.typeConfig.typeConfig;
-    let activeItemData = baseList.tabTemplate.activeItem;
-    // let preview = (activeItemData.preview).split('-').join('');
-
+    let tmpLis = baseList.tabTemplate.items;
     if (whichSign == 0) {
-      if (activeItemData && JSON.stringify(activeItemData) != '{}' && (activeItemData.dataJson == JSON.stringify(jsonData)) && (JSON.stringify(jsonStr) == JSON.stringify(JSON.parse(activeItemData.preview)))) {
-        Notify.info('该模板已保存');
-        return false;
-      }else if (
+      for(let i = 0;i <tmpLis.length;i++){
+        let dataStr = tmpLis[i].dataJson;
+        if(dataStr == JSON.stringify(jsonData)){
+          Notify.info('该模板已保存');
+          return false;
+        }
+      }
+      if (
         JSON.stringify(jsonData.advice) == '{}' &&
         jsonData.chief.length < 1 &&
         jsonData.diag.length < 1 &&
@@ -193,10 +200,16 @@ class Operation extends Component {
         return true;
       }
     } else if(whichSign == 1) {
-      if (activeItemData && JSON.stringify(activeItemData) != '{}' && (JSON.stringify(jsonStr) == JSON.stringify(JSON.parse(activeItemData.preview)))) {
-        Notify.info('该模板已保存');
-        return false;
-      }else if (JSON.stringify(jsonData.advice) == '{}' && 
+      for(let i = 0;i <tmpLis.length;i++){
+        let dataStr = tmpLis[i].preview;
+        let jsStr = tmpLis[i].dataJson;
+        console.log(dataStr == JSON.stringify(jsonStr))
+        if(JSON.stringify(JSON.parse(dataStr)) == JSON.stringify(jsonStr) && jsStr == JSON.stringify(jsonData)){
+          Notify.info('该模板已保存');
+          return false;
+        }
+      }
+      if (JSON.stringify(jsonData.advice) == '{}' && 
           jsonStr.chief == '[]' && 
           jsonStr.present == '[]' && 
           jsonStr.other == '[]' && 

+ 1 - 1
src/containers/OtherHistory.js

@@ -9,7 +9,7 @@ import {fullfillText} from '@common/js/func';
 import {didPushParamChange} from '@utils/tools.js';
 import {ISREAD} from "../store/types/homePage";
 
-function mapStateToProps(state){
+function mapStateToProps(state){ console.log(state)
   const {otherHistory,homePage,typeConfig,mainSuit} = state;
   const hasMain = mainSuit.saveText.join('')||mainSuit.data.length;
   return {