|
@@ -319,11 +319,15 @@ export default {
|
|
selectedRows: [],
|
|
selectedRows: [],
|
|
sortColumn: "",
|
|
sortColumn: "",
|
|
sortOrder: "",
|
|
sortOrder: "",
|
|
|
|
+ analysisStatusCheckers: {}, // 新增:用于存储每个文档的状态检查器
|
|
};
|
|
};
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
this.search();
|
|
this.search();
|
|
},
|
|
},
|
|
|
|
+ beforeDestroy() {
|
|
|
|
+ Object.values(this.analysisStatusCheckers).forEach(clearTimeout);
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
/* 排序 */
|
|
/* 排序 */
|
|
handleSortChange({ prop, order }) {
|
|
handleSortChange({ prop, order }) {
|
|
@@ -395,7 +399,7 @@ export default {
|
|
this.dataList.forEach((row) => {
|
|
this.dataList.forEach((row) => {
|
|
if (ids.includes(row.id)) {
|
|
if (ids.includes(row.id)) {
|
|
row.run = 1; // 设置状态为"解析中"
|
|
row.run = 1; // 设置状态为"解析中"
|
|
- this.checkAnalysisStatus(row);
|
|
|
|
|
|
+ this.startAnalysisStatusChecker(row);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
@@ -419,9 +423,9 @@ export default {
|
|
},
|
|
},
|
|
/* 解析 */
|
|
/* 解析 */
|
|
analysis(row) {
|
|
analysis(row) {
|
|
- if (row.run === 1 || row.run === 5) return; // 如果已经在解析中或待处理,直接返回
|
|
|
|
|
|
+ if (row.run === 1 || row.run === 5) return;
|
|
|
|
|
|
- this.$set(row, "run", 1); // 使用 $set 确保视图更新
|
|
|
|
|
|
+ this.$set(row, "run", 1);
|
|
|
|
|
|
analysis({
|
|
analysis({
|
|
document_id: row.id,
|
|
document_id: row.id,
|
|
@@ -431,48 +435,63 @@ export default {
|
|
})
|
|
})
|
|
.then((res) => {
|
|
.then((res) => {
|
|
if (res.status === 200) {
|
|
if (res.status === 200) {
|
|
- this.checkAnalysisStatus(row);
|
|
|
|
|
|
+ this.startAnalysisStatusChecker(row);
|
|
} else {
|
|
} else {
|
|
this.$message.error("解析请求失败");
|
|
this.$message.error("解析请求失败");
|
|
- this.$set(row, "run", 0); // 如果请求失败,重置状态
|
|
|
|
|
|
+ this.$set(row, "run", 0);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
.catch((error) => {
|
|
.catch((error) => {
|
|
console.error("解析错误:", error);
|
|
console.error("解析错误:", error);
|
|
this.$message.error("解析过程中出现错误");
|
|
this.$message.error("解析过程中出现错误");
|
|
- this.$set(row, "run", 0); // 如果出现错误,重置状态
|
|
|
|
|
|
+ this.$set(row, "run", 0);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
- checkAnalysisStatus(row) {
|
|
|
|
|
|
+
|
|
|
|
+ startAnalysisStatusChecker(row) {
|
|
|
|
+ // 如果已经有一个检查器在运行,先停止它
|
|
|
|
+ if (this.analysisStatusCheckers[row.id]) {
|
|
|
|
+ clearTimeout(this.analysisStatusCheckers[row.id]);
|
|
|
|
+ }
|
|
|
|
+
|
|
const checkStatus = () => {
|
|
const checkStatus = () => {
|
|
getRunStatus({ document_id: row.id })
|
|
getRunStatus({ document_id: row.id })
|
|
.then((res) => {
|
|
.then((res) => {
|
|
if (res.status === 200) {
|
|
if (res.status === 200) {
|
|
- /* */
|
|
|
|
- if (res.data.run === '3') {
|
|
|
|
- this.$set(row, "run",Number(res.data.run));
|
|
|
|
- } else if (res.data.run === '4') {
|
|
|
|
- this.$set(row, "run", Number(res.data.run));
|
|
|
|
|
|
+ const newStatus = Number(res.data.run);
|
|
|
|
+ this.$set(row, "run", newStatus);
|
|
|
|
+
|
|
|
|
+ if (newStatus === 3) {
|
|
|
|
+ this.$message.success("解析成功");
|
|
|
|
+ delete this.analysisStatusCheckers[row.id];
|
|
|
|
+ } else if (newStatus === 4) {
|
|
this.$message.error("解析失败");
|
|
this.$message.error("解析失败");
|
|
- } else if (res.data.run === '1') {
|
|
|
|
- // 如果仍在解析中,5-10秒后再次检查
|
|
|
|
- setTimeout(() => {
|
|
|
|
- this.checkAnalysisStatus(row);
|
|
|
|
- }, 5000 + Math.random() * 5000);
|
|
|
|
|
|
+ delete this.analysisStatusCheckers[row.id];
|
|
|
|
+ } else if (newStatus === 1 || newStatus === 5) {
|
|
|
|
+ // 继续检查
|
|
|
|
+ this.analysisStatusCheckers[row.id] = setTimeout(
|
|
|
|
+ checkStatus,
|
|
|
|
+ 5000 + Math.random() * 5000
|
|
|
|
+ );
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
this.$message.error("获取解析状态失败");
|
|
this.$message.error("获取解析状态失败");
|
|
- this.$set(row, "run", 0); // 如果获取状态失败,重置状态
|
|
|
|
|
|
+ this.$set(row, "run", 0);
|
|
|
|
+ delete this.analysisStatusCheckers[row.id];
|
|
}
|
|
}
|
|
})
|
|
})
|
|
.catch((error) => {
|
|
.catch((error) => {
|
|
console.error("获取解析状态错误:", error);
|
|
console.error("获取解析状态错误:", error);
|
|
this.$message.error("获取解析状态时出现错误");
|
|
this.$message.error("获取解析状态时出现错误");
|
|
- this.$set(row, "run", 0); // 如果出现错误,重置状态
|
|
|
|
|
|
+ this.$set(row, "run", 0);
|
|
|
|
+ delete this.analysisStatusCheckers[row.id];
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+ // 立即开始第一次检查
|
|
checkStatus();
|
|
checkStatus();
|
|
},
|
|
},
|
|
|
|
+
|
|
handleAnalClose() {
|
|
handleAnalClose() {
|
|
this.anaDialogVisible = false;
|
|
this.anaDialogVisible = false;
|
|
},
|
|
},
|
|
@@ -625,6 +644,7 @@ export default {
|
|
if (res.status !== 200) return;
|
|
if (res.status !== 200) return;
|
|
_this.dataList = res.data.documents.map((el) => ({
|
|
_this.dataList = res.data.documents.map((el) => ({
|
|
...el,
|
|
...el,
|
|
|
|
+ token_num: 256,
|
|
start_page: _this.analForm.start_page,
|
|
start_page: _this.analForm.start_page,
|
|
end_page: _this.analForm.end_page,
|
|
end_page: _this.analForm.end_page,
|
|
}));
|
|
}));
|
|
@@ -635,7 +655,7 @@ export default {
|
|
// Initialize the analysis status for each row
|
|
// Initialize the analysis status for each row
|
|
_this.dataList.forEach((row) => {
|
|
_this.dataList.forEach((row) => {
|
|
if (row.run === 1) {
|
|
if (row.run === 1) {
|
|
- _this.checkAnalysisStatus(row);
|
|
|
|
|
|
+ _this.startAnalysisStatusChecker(row);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
})
|
|
})
|