|
@@ -244,6 +244,7 @@ import {
|
|
|
addImages,
|
|
|
updateImages,
|
|
|
run,
|
|
|
+ getTaskStatusIsChanged,
|
|
|
} from "@/api/biz/images";
|
|
|
import { getOptionsByType } from "@/api/biz/config";
|
|
|
import FolderPicker from "@/components/FolderPicker";
|
|
@@ -297,6 +298,8 @@ export default {
|
|
|
logDialogVisible: false,
|
|
|
currentLogUrl: "",
|
|
|
dialogTitle: "",
|
|
|
+ runningTaskId: null,
|
|
|
+ taskPollingInterval: null,
|
|
|
};
|
|
|
},
|
|
|
created() {
|
|
@@ -451,6 +454,8 @@ export default {
|
|
|
run(id).then((response) => {
|
|
|
alert("任务开始运行!");
|
|
|
});
|
|
|
+ this.getList();
|
|
|
+ this.runTaskAndPollStatus(id);
|
|
|
},
|
|
|
openFolder(row) {
|
|
|
try {
|
|
@@ -463,6 +468,59 @@ export default {
|
|
|
this.$message.error(`打开文件夹出错: ${error.message}`);
|
|
|
}
|
|
|
},
|
|
|
+ // 运行任务并开始轮询状态
|
|
|
+ runTaskAndPollStatus(id) {
|
|
|
+ this.runningTaskId = id;
|
|
|
+ try {
|
|
|
+ // 开始轮询任务状态
|
|
|
+ this.startPollingTaskStatus(id);
|
|
|
+ } catch (error) {
|
|
|
+ console.error("运行任务失败:", error);
|
|
|
+ this.clearPollingInterval();
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 开始轮询任务状态
|
|
|
+ startPollingTaskStatus(id) {
|
|
|
+ // 先清除可能存在的已有定时器
|
|
|
+ this.clearPollingInterval();
|
|
|
+
|
|
|
+ // 立即查询一次状态
|
|
|
+ this.checkTaskStatus(id);
|
|
|
+
|
|
|
+ // 设置定时器,每3秒查询一次
|
|
|
+ this.taskPollingInterval = setInterval(() => {
|
|
|
+ this.checkTaskStatus(id);
|
|
|
+ }, 3000);
|
|
|
+ },
|
|
|
+
|
|
|
+ // 查询任务状态
|
|
|
+ checkTaskStatus(id) {
|
|
|
+ try {
|
|
|
+ getTaskStatusIsChanged(id).then((response) => {
|
|
|
+ if (response.data) {
|
|
|
+ // 这里根据你的实际状态判断
|
|
|
+ // 状态变化,更新列表并停止轮询
|
|
|
+ this.getList();
|
|
|
+ this.clearPollingInterval();
|
|
|
+ alert("任务已完成!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error("查询任务状态失败:", error);
|
|
|
+ this.clearPollingInterval();
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 清除轮询定时器
|
|
|
+ clearPollingInterval() {
|
|
|
+ if (this.taskPollingInterval) {
|
|
|
+ clearInterval(this.taskPollingInterval);
|
|
|
+ this.taskPollingInterval = null;
|
|
|
+ this.runningTask = {};
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|