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