refactor(knowledge-processing): streamline cancel parse functionality and enhance user confirmation dialogs

- Refactored the cancel parse logic in `knowledge-processing-timeline.vue` to remove the dialog dependency, directly handling cancellation confirmation within the function.
- Introduced a `t-popconfirm` component for confirming cancellation actions in both `DocumentListView.vue` and `DocumentBatchBar.vue`, improving user experience with clear confirmation prompts.
- Updated the `KnowledgeBase.vue` to utilize new confirmation methods for reparse and delete actions, ensuring consistent user interactions across the application.
- Enhanced localization strings for better clarity in confirmation messages, supporting a more intuitive user experience.
This commit is contained in:
wizardchen
2026-06-03 15:41:45 +08:00
committed by lyingbug
parent 26895aadc9
commit f2cfc5fdc3
4 changed files with 171 additions and 275 deletions
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, reactive, onMounted, onBeforeUnmount, watch, computed, nextTick } from 'vue'
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
import { MessagePlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse } from '@/api/knowledge-base/index'
import { knowledgeSpansPayloadHasTrace } from '@/utils/knowledgeTrace'
@@ -473,31 +473,20 @@ const canCancelParse = computed<boolean>(() => {
return isPolling(status)
})
function onCancelParse() {
async function onCancelParseConfirm() {
if (cancelling.value) return
const id = props.knowledgeId
if (!id) return
const dialog = DialogPlugin.confirm({
header: t('knowledgeBase.cancelParse'),
body: t('knowledgeBase.cancelParseConfirmBody', { title: props.docTitle || id }) as string,
confirmBtn: { content: t('knowledgeBase.cancelParse') as string, theme: 'danger' },
cancelBtn: t('common.cancel') as string,
theme: 'warning',
onConfirm: async () => {
cancelling.value = true
try {
await cancelKnowledgeParse(id)
MessagePlugin.success(t('knowledgeBase.cancelParseSubmitted'))
await fetchSpans({ manual: true })
} catch (e: any) {
MessagePlugin.error(e?.message || t('knowledgeBase.cancelParseFailed'))
} finally {
cancelling.value = false
dialog.hide()
}
},
onClose: () => dialog.destroy(),
})
cancelling.value = true
try {
await cancelKnowledgeParse(id)
MessagePlugin.success(t('knowledgeBase.cancelParseSubmitted'))
await fetchSpans({ manual: true })
} catch (e: any) {
MessagePlugin.error(e?.message || t('knowledgeBase.cancelParseFailed'))
} finally {
cancelling.value = false
}
}
function onAttemptChange(n: number) {
@@ -1353,12 +1342,22 @@ const stageBreakdown = computed<StageRowSummary[]>(() => {
@click="onManualRefresh">
<t-icon name="refresh" size="14px" />
</button>
<button v-if="canCancelParse" type="button" class="kp-icon-btn kp-icon-btn-danger"
:class="{ 'kp-icon-btn-spin': cancelling }" :disabled="cancelling"
:title="t('knowledgeBase.cancelParse')" :aria-label="t('knowledgeBase.cancelParse')"
@click="onCancelParse">
<t-icon :name="cancelling ? 'loading' : 'close-circle'" size="15px" />
</button>
<t-popconfirm
v-if="canCancelParse"
theme="warning"
:content="t('knowledgeBase.cancelParseConfirmBody', { title: props.docTitle || props.knowledgeId })"
:confirm-btn="{ content: t('knowledgeBase.cancelParse'), theme: 'danger' }"
:cancel-btn="{ content: t('common.cancel') }"
placement="bottom"
@confirm="onCancelParseConfirm"
>
<button type="button" class="kp-icon-btn kp-icon-btn-danger"
:class="{ 'kp-icon-btn-spin': cancelling }" :disabled="cancelling"
:title="t('knowledgeBase.cancelParse')" :aria-label="t('knowledgeBase.cancelParse')"
@click.stop>
<t-icon :name="cancelling ? 'loading' : 'close-circle'" size="15px" />
</button>
</t-popconfirm>
<t-button v-if="data?.parse_status === 'failed'" size="small" theme="primary" variant="outline"
@click="onRetry">
<t-icon name="refresh" size="14px" />