fix: 修复任务状态检查

This commit is contained in:
tbphp
2025-07-12 21:38:12 +08:00
parent 3db36ed6bf
commit 4acf7193a4
3 changed files with 16 additions and 4 deletions

View File

@@ -1,8 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { keysApi } from "@/api/keys"; import { keysApi } from "@/api/keys";
import type { TaskInfo } from "@/types/models"; import type { TaskInfo } from "@/types/models";
import { appState } from "@/utils/app-state";
import { NButton, NCard, NProgress, NText, useMessage } from "naive-ui"; import { NButton, NCard, NProgress, NText, useMessage } from "naive-ui";
import { onBeforeUnmount, onMounted, ref } from "vue"; import { onBeforeUnmount, onMounted, ref, watch } from "vue";
const taskInfo = ref<TaskInfo>({ is_running: false }); const taskInfo = ref<TaskInfo>({ is_running: false });
const visible = ref(false); const visible = ref(false);
@@ -14,6 +15,13 @@ onMounted(() => {
startPolling(); startPolling();
}); });
watch(
() => appState.taskPollingTrigger,
() => {
startPolling();
}
);
onBeforeUnmount(() => { onBeforeUnmount(() => {
stopPolling(); stopPolling();
}); });

View File

@@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { keysApi } from "@/api/keys"; import { keysApi } from "@/api/keys";
import type { APIKey, Group, KeyStatus } from "@/types/models"; import type { APIKey, Group, KeyStatus } from "@/types/models";
import { appState } from "@/utils/app-state";
import { getGroupDisplayName, maskKey } from "@/utils/display"; import { getGroupDisplayName, maskKey } from "@/utils/display";
import { import {
AddCircleOutline, AddCircleOutline,
@@ -57,9 +58,9 @@ const statusOptions = [
// 更多操作下拉菜单选项 // 更多操作下拉菜单选项
const moreOptions = [ const moreOptions = [
{ label: "导出所有密钥", key: "copyAll" }, // { label: "导出所有密钥", key: "copyAll" },
{ label: "导出有效密钥", key: "copyValid" }, // { label: "导出有效密钥", key: "copyValid" },
{ label: "导出无效密钥", key: "copyInvalid" }, // { label: "导出无效密钥", key: "copyInvalid" },
{ type: "divider" }, { type: "divider" },
{ label: "恢复所有无效密钥", key: "restoreAll" }, { label: "恢复所有无效密钥", key: "restoreAll" },
{ label: "清空所有无效密钥", key: "clearInvalid", props: { style: { color: "#d03050" } } }, { label: "清空所有无效密钥", key: "clearInvalid", props: { style: { color: "#d03050" } } },
@@ -349,6 +350,7 @@ async function validateAllKeys() {
try { try {
await keysApi.validateGroupKeys(props.selectedGroup.id); await keysApi.validateGroupKeys(props.selectedGroup.id);
localStorage.removeItem("last_closed_task"); localStorage.removeItem("last_closed_task");
appState.taskPollingTrigger++;
} catch (_error) { } catch (_error) {
console.error("测试失败"); console.error("测试失败");
} finally { } finally {

View File

@@ -2,8 +2,10 @@ import { reactive } from "vue";
interface AppState { interface AppState {
loading: boolean; loading: boolean;
taskPollingTrigger: number;
} }
export const appState = reactive<AppState>({ export const appState = reactive<AppState>({
loading: false, loading: false,
taskPollingTrigger: 0,
}); });