From 765dae4bf199890e18836fa962bcae30123bcf88 Mon Sep 17 00:00:00 2001 From: liangxu Date: Thu, 14 May 2026 21:14:27 +0800 Subject: [PATCH] fix task article link drawer --- .../GeneratedArticleLinksDrawer.vue | 236 ++++++++++++++++++ .../src/components/InstantTaskTab.vue | 28 ++- .../src/components/ScheduleTaskTab.vue | 101 ++++++-- apps/admin-web/src/i18n/messages/en-US.ts | 5 + apps/admin-web/src/i18n/messages/zh-CN.ts | 5 + apps/admin-web/src/lib/display.ts | 2 + .../admin-web/src/views/ArticleEditorView.vue | 18 ++ .../src/views/CustomGenerateView.vue | 42 +++- packages/shared-types/src/index.ts | 12 + .../tenant/app/instant_task_service.go | 186 ++++++++++---- .../tenant/app/prompt_generate_service.go | 23 ++ .../tenant/app/schedule_task_service.go | 167 +++++++++++-- .../internal/tenant/repository/audit_repo.go | 2 + .../tenant/repository/generated/audit.sql.go | 6 +- .../tenant/repository/queries/audit.sql | 6 +- 15 files changed, 735 insertions(+), 104 deletions(-) create mode 100644 apps/admin-web/src/components/GeneratedArticleLinksDrawer.vue diff --git a/apps/admin-web/src/components/GeneratedArticleLinksDrawer.vue b/apps/admin-web/src/components/GeneratedArticleLinksDrawer.vue new file mode 100644 index 0000000..46d92cc --- /dev/null +++ b/apps/admin-web/src/components/GeneratedArticleLinksDrawer.vue @@ -0,0 +1,236 @@ + + + + + diff --git a/apps/admin-web/src/components/InstantTaskTab.vue b/apps/admin-web/src/components/InstantTaskTab.vue index d2bd67c..0013911 100644 --- a/apps/admin-web/src/components/InstantTaskTab.vue +++ b/apps/admin-web/src/components/InstantTaskTab.vue @@ -7,7 +7,7 @@ import type { Dayjs } from 'dayjs' import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue' import { useI18n } from 'vue-i18n' -import ArticleDetailDrawer from '@/components/ArticleDetailDrawer.vue' +import GeneratedArticleLinksDrawer from '@/components/GeneratedArticleLinksDrawer.vue' import { instantTasksApi, promptRulesApi } from '@/lib/api' import { formatDateTime, getGenerateStatusMeta } from '@/lib/display' import { formatPublishPlatformList } from '@/lib/publish-platforms' @@ -17,8 +17,8 @@ const { t } = useI18n() const page = ref(1) const pageSize = ref(20) const createdRange = ref<[Dayjs, Dayjs] | null>(null) -const detailOpen = ref(false) -const selectedArticleId = ref(null) +const articleLinksOpen = ref(false) +const selectedTask = ref(null) const draftFilters = reactive<{ prompt_rule_id?: number @@ -54,6 +54,7 @@ const statusOptions = computed(() => [ { label: getGenerateStatusMeta('queued').label, value: 'queued' }, { label: getGenerateStatusMeta('running').label, value: 'running' }, { label: getGenerateStatusMeta('completed').label, value: 'completed' }, + { label: getGenerateStatusMeta('partial_success').label, value: 'partial_success' }, { label: getGenerateStatusMeta('failed').label, value: 'failed' }, ]) @@ -135,12 +136,14 @@ function handleTableChange(nextPage: number, nextPageSize: number): void { pageSize.value = nextPageSize } -function openArticle(task: InstantTaskItem): void { - if (!task.article_id) { +const selectedTaskArticles = computed(() => selectedTask.value?.articles ?? []) + +function openTaskArticles(task: InstantTaskItem): void { + if (!task.articles?.length) { return } - selectedArticleId.value = task.article_id - detailOpen.value = true + selectedTask.value = task + articleLinksOpen.value = true } function startPolling(): void { @@ -281,8 +284,8 @@ onBeforeUnmount(() => { shape="circle" size="small" class="action-btn action-eye" - :disabled="!record.article_id" - @click="openArticle(record)" + :disabled="!record.articles?.length" + @click="openTaskArticles(record)" > @@ -293,10 +296,9 @@ onBeforeUnmount(() => { - diff --git a/apps/admin-web/src/components/ScheduleTaskTab.vue b/apps/admin-web/src/components/ScheduleTaskTab.vue index edff780..2b92dc8 100644 --- a/apps/admin-web/src/components/ScheduleTaskTab.vue +++ b/apps/admin-web/src/components/ScheduleTaskTab.vue @@ -2,6 +2,8 @@ import { DeleteOutlined, EditOutlined, + EyeOutlined, + LoadingOutlined, PauseCircleOutlined, PlayCircleOutlined, } from '@ant-design/icons-vue' @@ -9,12 +11,13 @@ import type { ScheduleTask, ScheduleTaskListParams } from '@geo/shared-types' import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query' import { message, type TableColumnsType } from 'ant-design-vue' import type { Dayjs } from 'dayjs' -import { computed, reactive, ref } from 'vue' +import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue' import { useI18n } from 'vue-i18n' +import GeneratedArticleLinksDrawer from '@/components/GeneratedArticleLinksDrawer.vue' import ScheduleTaskModal from '@/components/ScheduleTaskModal.vue' import { promptRulesApi, schedulesApi } from '@/lib/api' -import { formatCronExecutionTime, formatDateTime } from '@/lib/display' +import { formatDateTime, getGenerateStatusMeta, hasActiveGenerationStatus } from '@/lib/display' import { formatError } from '@/lib/errors' import { formatPublishPlatformList } from '@/lib/publish-platforms' @@ -26,6 +29,8 @@ const editingTask = ref(null) const page = ref(1) const pageSize = ref(20) const createdRange = ref<[Dayjs, Dayjs] | null>(null) +const articleLinksOpen = ref(false) +const selectedTask = ref(null) const draftFilters = reactive<{ prompt_rule_id?: number @@ -88,11 +93,16 @@ const columns = computed>(() => [ key: 'prompt_rule_name', width: 180, }, - { title: t('custom.instant.executionStatus'), dataIndex: 'status', key: 'status', width: 140 }, + { + title: t('custom.instant.executionStatus'), + dataIndex: 'generation_status', + key: 'generation_status', + width: 140, + }, { title: t('custom.instant.executionTime'), - dataIndex: 'cron_expr', - key: 'cron_expr', + dataIndex: 'execution_time', + key: 'execution_time', width: 170, }, { @@ -113,7 +123,7 @@ const columns = computed>(() => [ key: 'created_at', width: 170, }, - { title: t('common.actions'), key: 'actions', width: 140, fixed: 'right', align: 'right' }, + { title: t('common.actions'), key: 'actions', width: 176, fixed: 'right', align: 'right' }, ]) const removeMutation = useMutation({ @@ -165,6 +175,45 @@ function handleTableChange(nextPage: number, nextPageSize: number): void { page.value = nextPage pageSize.value = nextPageSize } + +const selectedTaskArticles = computed(() => selectedTask.value?.generated_articles ?? []) + +function openTaskArticles(task: ScheduleTask): void { + selectedTask.value = task + articleLinksOpen.value = true +} + +let pollingTimer: number | null = null + +function startPolling(): void { + if (pollingTimer !== null) return + pollingTimer = window.setInterval(() => { + void listQuery.refetch() + }, 3000) +} + +function stopPolling(): void { + if (pollingTimer === null) return + window.clearInterval(pollingTimer) + pollingTimer = null +} + +watch( + () => listQuery.data.value?.items ?? [], + (items) => { + const hasActive = items.some((item) => hasActiveGenerationStatus(item.generation_status)) + if (hasActive) { + startPolling() + } else { + stopPolling() + } + }, + { immediate: true }, +) + +onBeforeUnmount(() => { + stopPolling() +})