瀏覽代碼

修复初次记载的逻辑

yangkaixiang 5 月之前
父節點
當前提交
2802259772
共有 2 個文件被更改,包括 20 次插入22 次删除
  1. 1 1
      package.json
  2. 19 21
      src/pages/Alarm/components/components/Formular.jsx

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "dt-alarm-component",
-  "version": "1.1.20",
+  "version": "1.1.21",
   "description": "",
   "main": "lib/index.js",
   "scripts": {

+ 19 - 21
src/pages/Alarm/components/components/Formular.jsx

@@ -95,7 +95,7 @@ const Formular = (props, ref) => {
   const [pointData, setPointData] = useState([]); //点位信息
   const backEndInput = useCallback(
     async (inputStr) => {
-      // const inputStr = '([P_NB4_CW_1_bo_7_AQ]>15)-([P_NB4_CW_1_bo_7_AQ_DIFF_H]+1)';
+      // const inputStr = '[CSZ_1_F]+[CSZ_1_AF]>123[CWS1_AC]+';
       var vars = {};
       pointData.forEach((item, index) => {
         vars[item.point_id] = item.name;
@@ -118,13 +118,11 @@ const Formular = (props, ref) => {
         } else {
           vars = {};
         }
-      }).finally(() => {
+        console.log(vars);
+        initDisplay({ vars: vars, formula: inputStr });
+        outStrRef.current = inputStr;
         setLoading(false)
       })
-
-      console.log(vars);
-      initDisplay({ vars: vars, formula: inputStr });
-      outStrRef.current = inputStr;
     },
     [pointData]
   );
@@ -377,11 +375,11 @@ const Formular = (props, ref) => {
   const convertTextToHtmlWithApi = useCallback(async (text) => {
     // 匹配 [point_id] 模式
     const pointPattern = /\[([^\[\]]+)\]/g;
-    
+
     let match;
     const matches = [];
     const pointIds = [];
-    
+
     // 收集所有匹配项
     while ((match = pointPattern.exec(text)) !== null) {
       matches.push({
@@ -391,12 +389,12 @@ const Formular = (props, ref) => {
       });
       pointIds.push(match[1]);
     }
-    
+
     if (pointIds.length === 0) {
       // 没有点位变量,直接返回原文本
       return text;
     }
-    
+
     // 调用API获取点位信息
     let pointVars = {};
     try {
@@ -405,7 +403,7 @@ const Formular = (props, ref) => {
         count: 20,
         type: 1,
       });
-      
+
       if (res.state === 0) {
         res.data?.forEach((item) => {
           pointVars[item.point_id] = item.name;
@@ -418,19 +416,19 @@ const Formular = (props, ref) => {
         pointVars[id] = id;
       });
     }
-    
+
     let result = text;
-    
+
     // 从后往前替换,避免索引位置变化
     for (let i = matches.length - 1; i >= 0; i--) {
       const matchItem = matches[i];
       const pointName = pointVars[matchItem.pointId] || matchItem.pointId;
       const imgHtml = oneNode(matchItem.pointId, pointName);
-      result = result.substring(0, matchItem.index) + 
-               imgHtml + 
-               result.substring(matchItem.index + matchItem.fullMatch.length);
+      result = result.substring(0, matchItem.index) +
+        imgHtml +
+        result.substring(matchItem.index + matchItem.fullMatch.length);
     }
-    
+
     return result;
   }, []);
 
@@ -450,13 +448,13 @@ const Formular = (props, ref) => {
     }
 
     console.log('原始文本:', cleanedText);
-    
+
     try {
       setLoading(true);
-      
+
       /** 异步获取点位信息并转换为HTML格式 */
       const htmlContent = await convertTextToHtmlWithApi(cleanedText);
-      console.log('转换后的HTML:', htmlContent);
+      // console.log('转换后的HTML:', htmlContent);
 
       /** 将转换后的HTML插入到编辑器中 */
       dtInsertFormular(htmlContent);
@@ -465,7 +463,7 @@ const Formular = (props, ref) => {
       setTimeout(() => {
         setValue();
       }, 0);
-      
+
     } catch (error) {
       console.error('粘贴处理失败:', error);
     } finally {