491 lines
10 KiB
Vue
491 lines
10 KiB
Vue
/**
|
|
|
|
* features/admin/modules/questions/QuestionsPage.vue
|
|
|
|
* 常用问题管理:Tab「常用问题」+「热点发现」(离线聚合候选)。
|
|
|
|
* 依赖:useQuestionsAdmin、HotFaqCandidatesPanel、QuestionFormModal。
|
|
|
|
* 逻辑:路由 /admin/questions;热点候选晋升后写入 QuickQuestion 并由 Phase 1 FAQ 在线命中。
|
|
|
|
*/
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { onMounted, ref } from 'vue';
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import { Edit, Plus, Trash2, Zap } from 'lucide-vue-next';
|
|
|
|
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
|
|
|
import HotFaqCandidatesPanel from './components/HotFaqCandidatesPanel.vue';
|
|
|
|
import QuestionFormModal from './components/QuestionFormModal.vue';
|
|
|
|
import { useQuestionsAdmin } from './composables/useQuestionsAdmin';
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
const activeTab = ref<'manual' | 'hot'>('manual');
|
|
|
|
|
|
|
|
const {
|
|
|
|
filteredQuestions,
|
|
|
|
agents,
|
|
|
|
form,
|
|
|
|
isLoading,
|
|
|
|
isSaving,
|
|
|
|
showFormModal,
|
|
|
|
showDeleteConfirmDialog,
|
|
|
|
deleteConfirmMessage,
|
|
|
|
filterAgentId,
|
|
|
|
filterCacheOnly,
|
|
|
|
filterStaleOnly,
|
|
|
|
staleCount,
|
|
|
|
searchKeyword,
|
|
|
|
loadAll,
|
|
|
|
openCreateModal,
|
|
|
|
openEditModal,
|
|
|
|
closeFormModal,
|
|
|
|
saveQuestion,
|
|
|
|
saveReviewQuestion,
|
|
|
|
deleteQuestion,
|
|
|
|
closeDeleteConfirm,
|
|
|
|
confirmDelete,
|
|
|
|
truncateQuestionPreview,
|
|
|
|
truncateAnswerPreview,
|
|
|
|
} = useQuestionsAdmin();
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
void loadAll();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<section class="admin-table-section animate-fade-in-up">
|
|
|
|
<div class="admin-table-header admin-table-header--stacked mb-4">
|
|
|
|
<div>
|
|
|
|
<h2 class="section-title">{{ t('admin.question.title') }}</h2>
|
|
|
|
<p class="section-desc mt-1">{{ t('admin.question.subtitle') }}</p>
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
v-if="activeTab === 'manual'"
|
|
|
|
type="button"
|
|
|
|
class="flex items-center gap-2 px-4 py-2 bg-brand-600 text-white rounded-xl hover:bg-brand-700 transition-all shadow-lg shadow-brand-200 active:scale-95 text-sm font-medium"
|
|
|
|
@click="openCreateModal"
|
|
|
|
>
|
|
|
|
<Plus class="w-4 h-4" />
|
|
|
|
<span>{{ t('admin.question.add') }}</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mb-6 flex gap-1 border-b border-default">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="px-4 py-2.5 text-sm font-medium border-b-2 -mb-px transition-colors"
|
|
|
|
:class="activeTab === 'manual' ? 'border-brand-600 text-brand-600' : 'border-transparent text-muted hover:text-secondary'"
|
|
|
|
@click="activeTab = 'manual'"
|
|
|
|
>
|
|
|
|
{{ t('admin.question.tabs.manual') }}
|
|
|
|
<span
|
|
v-if="staleCount > 0"
|
|
class="ml-1.5 inline-flex min-w-[1.25rem] items-center justify-center rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold text-amber-800"
|
|
>
|
|
{{ staleCount }}
|
|
</span>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="px-4 py-2.5 text-sm font-medium border-b-2 -mb-px transition-colors"
|
|
|
|
:class="activeTab === 'hot' ? 'border-brand-600 text-brand-600' : 'border-transparent text-muted hover:text-secondary'"
|
|
|
|
@click="activeTab = 'hot'"
|
|
|
|
>
|
|
|
|
{{ t('admin.question.tabs.hotDiscovery') }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<HotFaqCandidatesPanel v-if="activeTab === 'hot'" />
|
|
|
|
|
|
|
|
<template v-else>
|
|
|
|
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
|
|
|
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<template v-else>
|
|
|
|
<div class="mb-4 flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between">
|
|
|
|
<div class="flex flex-1 flex-wrap items-center gap-3">
|
|
|
|
<input
|
|
|
|
v-model="searchKeyword"
|
|
|
|
type="search"
|
|
|
|
class="input-field text-sm w-full max-w-xs"
|
|
|
|
:placeholder="t('admin.question.filters.search')"
|
|
|
|
/>
|
|
|
|
<select v-model="filterAgentId" class="input-field text-sm w-full max-w-[200px]">
|
|
|
|
<option value="">{{ t('admin.question.filters.allAgents') }}</option>
|
|
|
|
<option v-for="agent in agents" :key="agent.id" :value="agent.id">
|
|
|
|
{{ agent.name }}
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
<label class="inline-flex items-center gap-2 text-sm text-secondary whitespace-nowrap">
|
|
|
|
<input v-model="filterCacheOnly" type="checkbox" class="accent-brand-600" />
|
|
|
|
<span>{{ t('admin.question.filters.cacheOnly') }}</span>
|
|
|
|
</label>
|
|
|
|
<label class="inline-flex items-center gap-2 text-sm text-secondary whitespace-nowrap">
|
|
|
|
<input v-model="filterStaleOnly" type="checkbox" class="accent-brand-600" />
|
|
|
|
<span>{{ t('admin.question.filters.staleOnly') }}</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<p class="text-xs text-muted">
|
|
|
|
{{ t('admin.question.filters.resultCount', { count: filteredQuestions.length }) }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="admin-table-wrap">
|
|
|
|
<table class="admin-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.question.headers.title') }}</th>
|
|
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.question.headers.agent') }}</th>
|
|
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.question.headers.content') }}</th>
|
|
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.question.headers.answer') }}</th>
|
|
|
|
<th class="px-6 py-4 text-left text-xs w-28">{{ t('admin.question.headers.cache') }}</th>
|
|
|
|
<th class="px-6 py-4 text-left text-xs w-20">{{ t('admin.question.headers.hits') }}</th>
|
|
|
|
<th class="px-6 py-4 text-left text-xs w-16">{{ t('admin.question.headers.order') }}</th>
|
|
|
|
<th class="px-6 py-4 text-right text-xs w-28">{{ t('admin.question.headers.actions') }}</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr v-if="filteredQuestions.length === 0">
|
|
|
|
<td colspan="8" class="px-6 admin-table-empty">{{ t('admin.question.noData') }}</td>
|
|
|
|
</tr>
|
|
|
|
<tr v-for="q in filteredQuestions" :key="q.id" class="group">
|
|
|
|
<td class="px-6 py-4">
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
<div class="font-medium text-primary text-sm">{{ q.title }}</div>
|
|
|
|
<span
|
|
|
|
v-if="q.stale_at"
|
|
|
|
class="inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium bg-amber-50 text-amber-800 border border-amber-100"
|
|
|
|
>
|
|
|
|
{{ t('admin.question.badges.stale') }}
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
v-if="!q.is_enabled"
|
|
|
|
class="inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium bg-surface-soft text-muted border border-default"
|
|
|
|
>
|
|
|
|
{{ t('admin.question.badges.disabled') }}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td class="px-6 py-4">
|
|
|
|
<span
|
|
|
|
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-50 text-blue-700 border border-blue-100"
|
|
|
|
>
|
|
|
|
{{ q.agent_name || 'Unknown' }}
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td class="px-6 py-4">
|
|
|
|
<p class="text-sm text-secondary truncate max-w-[180px]" :title="q.question">
|
|
|
|
{{ truncateQuestionPreview(q.question) }}
|
|
|
|
</p>
|
|
|
|
</td>
|
|
|
|
<td class="px-6 py-4">
|
|
|
|
<p
|
|
|
|
v-if="q.cache_enabled && q.answer"
|
|
|
|
class="text-sm text-secondary truncate max-w-[160px]"
|
|
|
|
:title="q.answer"
|
|
|
|
>
|
|
|
|
{{ truncateAnswerPreview(q.answer) }}
|
|
|
|
</p>
|
|
|
|
<span v-else class="text-xs text-muted">—</span>
|
|
|
|
</td>
|
|
|
|
<td class="px-6 py-4">
|
|
|
|
<span
|
|
|
|
v-if="q.cache_enabled"
|
|
|
|
class="inline-flex items-center gap-1 rounded-full px-2.5 py-0.5 text-xs font-medium bg-emerald-50 text-emerald-700 border border-emerald-100"
|
|
|
|
>
|
|
|
|
<Zap class="w-3 h-3" />
|
|
|
|
{{ t('admin.question.badges.cacheOn') }}
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
v-else
|
|
|
|
class="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium bg-surface-soft text-muted border border-default"
|
|
|
|
>
|
|
|
|
{{ t('admin.question.badges.cacheOff') }}
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td class="px-6 py-4 text-sm text-muted tabular-nums">{{ q.hit_count || 0 }}</td>
|
|
|
|
<td class="px-6 py-4 text-sm text-muted tabular-nums">{{ q.sort_order }}</td>
|
|
|
|
<td class="px-6 py-4">
|
|
|
|
<div class="flex justify-end gap-1">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="p-1.5 text-indigo-600 hover:bg-indigo-50 rounded-lg transition-colors"
|
|
|
|
@click="openEditModal(q)"
|
|
|
|
>
|
|
|
|
<Edit class="w-4 h-4" />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="p-1.5 text-red-600 hover:bg-red-50 rounded-lg transition-colors"
|
|
|
|
@click="deleteQuestion(q.id)"
|
|
|
|
>
|
|
|
|
<Trash2 class="w-4 h-4" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<QuestionFormModal
|
|
|
|
:visible="showFormModal"
|
|
|
|
:form="form"
|
|
|
|
:agents="agents"
|
|
|
|
:is-saving="isSaving"
|
|
|
|
@close="closeFormModal"
|
|
|
|
@save="saveQuestion"
|
|
|
|
@review="saveReviewQuestion"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<DeleteConfirmDialog
|
|
|
|
v-model="showDeleteConfirmDialog"
|
|
|
|
:message="deleteConfirmMessage"
|
|
|
|
@cancel="closeDeleteConfirm"
|
|
|
|
@confirm="confirmDelete"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|