277 lines
9.1 KiB
Vue
277 lines
9.1 KiB
Vue
/**
|
|
* features/admin/modules/questions/QuestionsPage.vue
|
|
* 用途:常用问题管理页。一张卡片里放标题、添加按钮、页签、筛选和表格。
|
|
* 依赖:AdminListPage、AdminListTabs、useQuestionsAdmin、useElementProvider、element-plus、QuestionFormModal、HotFaqCandidatesPanel。
|
|
* 逻辑:路由 /admin/questions。骨架用 AdminListPage,页签用 AdminListTabs。
|
|
* 筛选、表格留在本页;热点候选由页签内容区的面板自己渲染。删除在 composable 里用 Element 确认框。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { computed, onMounted, ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { Plus } from '@element-plus/icons-vue';
|
|
import {
|
|
ElButton,
|
|
ElCheckbox,
|
|
ElConfigProvider,
|
|
ElInput,
|
|
ElLoading,
|
|
ElOption,
|
|
ElSelect,
|
|
ElTable,
|
|
ElTableColumn,
|
|
ElTag,
|
|
} from 'element-plus';
|
|
import 'element-plus/dist/index.css';
|
|
import 'element-plus/theme-chalk/dark/css-vars.css';
|
|
import '@/features/admin/styles/element-trial.css';
|
|
import AdminListPage from '@/features/admin/components/AdminListPage.vue';
|
|
import AdminListTabs from '@/features/admin/components/AdminListTabs.vue';
|
|
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
|
|
import type { AdminQuickQuestionRow } from '@/features/admin/types/question.types';
|
|
import HotFaqCandidatesPanel from './components/HotFaqCandidatesPanel.vue';
|
|
import QuestionFormModal from './components/QuestionFormModal.vue';
|
|
import { useQuestionsAdmin } from './composables/useQuestionsAdmin';
|
|
|
|
const vLoading = ElLoading.directive;
|
|
|
|
const { t } = useI18n();
|
|
const { elementLocale } = useElementProvider();
|
|
const activeTab = ref<'manual' | 'hot'>('manual');
|
|
|
|
const {
|
|
filteredQuestions,
|
|
agents,
|
|
form,
|
|
isLoading,
|
|
isSaving,
|
|
showFormModal,
|
|
filterAgentId,
|
|
filterCacheOnly,
|
|
filterStaleOnly,
|
|
staleCount,
|
|
searchKeyword,
|
|
loadAll,
|
|
openCreateModal,
|
|
openEditModal,
|
|
closeFormModal,
|
|
saveQuestion,
|
|
saveReviewQuestion,
|
|
deleteQuestion,
|
|
truncateQuestionPreview,
|
|
truncateAnswerPreview,
|
|
} = useQuestionsAdmin();
|
|
|
|
/**
|
|
* 常用问题和热点发现两个页签。待审数量大于 0 时显示在第一个页签上。
|
|
*/
|
|
const questionTabs = computed(() => [
|
|
{
|
|
name: 'manual',
|
|
label: t('admin.question.tabs.manual'),
|
|
badge: staleCount.value > 0 ? staleCount.value : undefined,
|
|
},
|
|
{
|
|
name: 'hot',
|
|
label: t('admin.question.tabs.hotDiscovery'),
|
|
},
|
|
]);
|
|
|
|
/**
|
|
* 只接受本页的两个页签名,避免公共页签回传任意字符串。
|
|
* @param name - AdminListTabs 当前选中的 name
|
|
*/
|
|
function onQuestionTabChange(name: string): void {
|
|
if (name === 'manual' || name === 'hot') activeTab.value = name;
|
|
}
|
|
|
|
/**
|
|
* 应用筛选。清空时写回空字符串,表示全部应用。
|
|
* @param value - 选中的应用 id;清空为 undefined
|
|
*/
|
|
function onAgentFilterChange(value: number | undefined): void {
|
|
filterAgentId.value = value ?? '';
|
|
}
|
|
|
|
/**
|
|
* 打开编辑弹窗。表格插槽行类型较宽,这里收成常用问题行。
|
|
* @param row - 当前表格行
|
|
*/
|
|
function editQuestion(row: AdminQuickQuestionRow): void {
|
|
openEditModal(row);
|
|
}
|
|
|
|
onMounted(() => {
|
|
void loadAll();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<ElConfigProvider :locale="elementLocale">
|
|
<AdminListPage>
|
|
<template #title>
|
|
<h2 class="section-title">{{ t('admin.question.title') }}</h2>
|
|
<p class="section-desc mt-1">{{ t('admin.question.subtitle') }}</p>
|
|
</template>
|
|
<template #actions>
|
|
<ElButton
|
|
v-if="activeTab === 'manual'"
|
|
type="primary"
|
|
:icon="Plus"
|
|
@click="openCreateModal"
|
|
>
|
|
{{ t('admin.question.add') }}
|
|
</ElButton>
|
|
</template>
|
|
<template #tabs>
|
|
<AdminListTabs :model-value="activeTab" :items="questionTabs" @update:model-value="onQuestionTabChange" />
|
|
</template>
|
|
<template v-if="activeTab === 'manual'" #filters>
|
|
<ElInput
|
|
v-model="searchKeyword"
|
|
clearable
|
|
class="question-filter-search"
|
|
:placeholder="t('admin.question.filters.search')"
|
|
/>
|
|
<ElSelect
|
|
:model-value="filterAgentId === '' ? undefined : filterAgentId"
|
|
class="question-filter-agent"
|
|
clearable
|
|
:placeholder="t('admin.question.filters.allAgents')"
|
|
@update:model-value="onAgentFilterChange"
|
|
>
|
|
<ElOption
|
|
v-for="agent in agents"
|
|
:key="agent.id"
|
|
:label="agent.name"
|
|
:value="agent.id"
|
|
/>
|
|
</ElSelect>
|
|
<ElCheckbox v-model="filterCacheOnly">{{ t('admin.question.filters.cacheOnly') }}</ElCheckbox>
|
|
<ElCheckbox v-model="filterStaleOnly">{{ t('admin.question.filters.staleOnly') }}</ElCheckbox>
|
|
<span class="question-filter-count">
|
|
{{ t('admin.question.filters.resultCount', { count: filteredQuestions.length }) }}
|
|
</span>
|
|
</template>
|
|
|
|
<ElTable
|
|
v-if="activeTab === 'manual'"
|
|
v-loading="isLoading"
|
|
class="hx-admin-table"
|
|
:data="filteredQuestions"
|
|
row-key="id"
|
|
:empty-text="t('admin.question.noData')"
|
|
>
|
|
<ElTableColumn :label="t('admin.question.headers.title')" min-width="200">
|
|
<template #default="{ row }">
|
|
<div class="question-title">
|
|
<span>{{ (row as AdminQuickQuestionRow).title }}</span>
|
|
<ElTag v-if="(row as AdminQuickQuestionRow).stale_at" type="warning" effect="light">
|
|
{{ t('admin.question.badges.stale') }}
|
|
</ElTag>
|
|
<ElTag v-if="!(row as AdminQuickQuestionRow).is_enabled" type="info" effect="light">
|
|
{{ t('admin.question.badges.disabled') }}
|
|
</ElTag>
|
|
</div>
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn :label="t('admin.question.headers.agent')" min-width="140">
|
|
<template #default="{ row }">
|
|
<ElTag effect="light">{{ (row as AdminQuickQuestionRow).agent_name || 'Unknown' }}</ElTag>
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn :label="t('admin.question.headers.content')" min-width="180">
|
|
<template #default="{ row }">
|
|
<span class="question-ellipsis" :title="(row as AdminQuickQuestionRow).question">
|
|
{{ truncateQuestionPreview((row as AdminQuickQuestionRow).question) }}
|
|
</span>
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn :label="t('admin.question.headers.answer')" min-width="160">
|
|
<template #default="{ row }">
|
|
<span
|
|
v-if="(row as AdminQuickQuestionRow).cache_enabled && (row as AdminQuickQuestionRow).answer"
|
|
class="question-ellipsis"
|
|
:title="(row as AdminQuickQuestionRow).answer || ''"
|
|
>
|
|
{{ truncateAnswerPreview((row as AdminQuickQuestionRow).answer || '') }}
|
|
</span>
|
|
<span v-else>—</span>
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn :label="t('admin.question.headers.cache')" width="120">
|
|
<template #default="{ row }">
|
|
<ElTag
|
|
:type="(row as AdminQuickQuestionRow).cache_enabled ? 'success' : 'info'"
|
|
effect="light"
|
|
>
|
|
{{
|
|
(row as AdminQuickQuestionRow).cache_enabled
|
|
? t('admin.question.badges.cacheOn')
|
|
: t('admin.question.badges.cacheOff')
|
|
}}
|
|
</ElTag>
|
|
</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn :label="t('admin.question.headers.hits')" width="88">
|
|
<template #default="{ row }">{{ (row as AdminQuickQuestionRow).hit_count || 0 }}</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn :label="t('admin.question.headers.order')" width="88">
|
|
<template #default="{ row }">{{ (row as AdminQuickQuestionRow).sort_order }}</template>
|
|
</ElTableColumn>
|
|
<ElTableColumn :label="t('admin.question.headers.actions')" width="140" align="right">
|
|
<template #default="{ row }">
|
|
<ElButton link type="primary" @click="editQuestion(row as AdminQuickQuestionRow)">
|
|
{{ t('admin.question.actions.edit') }}
|
|
</ElButton>
|
|
<ElButton link type="danger" @click="deleteQuestion((row as AdminQuickQuestionRow).id)">
|
|
{{ t('admin.question.actions.delete') }}
|
|
</ElButton>
|
|
</template>
|
|
</ElTableColumn>
|
|
</ElTable>
|
|
|
|
<HotFaqCandidatesPanel v-if="activeTab === 'hot'" />
|
|
</AdminListPage>
|
|
|
|
<QuestionFormModal
|
|
:visible="showFormModal"
|
|
:form="form"
|
|
:agents="agents"
|
|
:is-saving="isSaving"
|
|
@close="closeFormModal"
|
|
@save="saveQuestion"
|
|
@review="saveReviewQuestion"
|
|
/>
|
|
</ElConfigProvider>
|
|
</template>
|
|
|
|
<style scoped>
|
|
:deep(.question-filter-search) {
|
|
width: 16rem;
|
|
}
|
|
|
|
:deep(.question-filter-agent) {
|
|
width: 11rem;
|
|
}
|
|
|
|
.question-filter-count {
|
|
margin-left: auto;
|
|
color: var(--el-text-color-secondary);
|
|
font-size: var(--el-font-size-small);
|
|
}
|
|
|
|
.question-title {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.question-ellipsis {
|
|
display: block;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
</style>
|