175 lines
6.3 KiB
Vue
175 lines
6.3 KiB
Vue
/**
|
|
* features/admin/modules/questions/QuestionsPage.vue
|
|
* 常用问题管理独立页面。路由:/admin/questions
|
|
*/
|
|
<script setup lang="ts">
|
|
import { onMounted } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { Edit, Trash2 } from 'lucide-vue-next';
|
|
import DeleteConfirmDialog from '@/components/DeleteConfirmDialog.vue';
|
|
import { useQuestionsAdmin } from './composables/useQuestionsAdmin';
|
|
|
|
const { t } = useI18n();
|
|
|
|
const {
|
|
questions,
|
|
agents,
|
|
form,
|
|
isEditing,
|
|
isLoading,
|
|
isSaving,
|
|
showDeleteConfirmDialog,
|
|
deleteConfirmMessage,
|
|
loadAll,
|
|
resetForm,
|
|
editQuestion,
|
|
saveQuestion,
|
|
deleteQuestion,
|
|
closeDeleteConfirm,
|
|
confirmDelete,
|
|
} = useQuestionsAdmin();
|
|
|
|
onMounted(() => {
|
|
void loadAll();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<section class="section-gap animate-fade-in-up">
|
|
<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="flex items-center justify-between">
|
|
<div>
|
|
<h2 class="section-title">{{ t('admin.question.title') }}</h2>
|
|
<p class="section-desc mt-1">{{ t('admin.question.subtitle') }}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
|
<div class="lg:col-span-1 card p-6 shadow-sm h-fit">
|
|
<h3 class="font-bold text-primary mb-4">
|
|
{{ isEditing ? t('admin.question.edit') : t('admin.question.add') }}
|
|
</h3>
|
|
<div class="space-y-4">
|
|
<div class="space-y-1.5">
|
|
<label class="label-field">{{ t('admin.question.fields.title') }}</label>
|
|
<input
|
|
v-model="form.title"
|
|
class="input-field text-sm"
|
|
:placeholder="t('admin.question.fields.titlePlaceholder')"
|
|
/>
|
|
</div>
|
|
<div class="space-y-1.5">
|
|
<label class="label-field">{{ t('admin.question.fields.targetAgent') }}</label>
|
|
<select v-model="form.agent_id" class="input-field text-sm">
|
|
<option :value="undefined" disabled>{{ t('admin.perm.batchModal.selectAgents') }}</option>
|
|
<option v-for="agent in agents" :key="agent.id" :value="agent.id">
|
|
{{ agent.name }}
|
|
</option>
|
|
</select>
|
|
</div>
|
|
<div class="space-y-1.5">
|
|
<label class="label-field">{{ t('admin.question.fields.sortOrder') }}</label>
|
|
<input v-model.number="form.sort_order" type="number" class="input-field text-sm" />
|
|
</div>
|
|
<div class="space-y-1.5">
|
|
<label class="label-field">{{ t('admin.question.fields.content') }}</label>
|
|
<textarea
|
|
v-model="form.question"
|
|
rows="4"
|
|
class="input-field text-sm"
|
|
:placeholder="t('admin.question.fields.contentPlaceholder')"
|
|
/>
|
|
</div>
|
|
|
|
<div class="flex justify-end gap-2 pt-2">
|
|
<button
|
|
v-if="isEditing"
|
|
type="button"
|
|
class="btn-ghost btn-sm"
|
|
@click="resetForm"
|
|
>
|
|
{{ t('admin.cancel') }}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="btn-primary btn-sm disabled:opacity-50"
|
|
:disabled="isSaving"
|
|
@click="saveQuestion"
|
|
>
|
|
{{ isSaving ? t('admin.save') + '...' : (isEditing ? t('admin.update') : t('admin.add')) }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="lg:col-span-2 admin-table-section">
|
|
<div v-if="questions.length === 0" class="p-8 text-center text-muted">
|
|
{{ t('admin.question.noData') }}
|
|
</div>
|
|
<table v-else class="admin-table">
|
|
<thead>
|
|
<tr>
|
|
<th class="px-6 py-3 text-xs font-semibold text-muted uppercase">
|
|
{{ t('admin.question.headers.title') }}
|
|
</th>
|
|
<th class="px-6 py-3 text-xs font-semibold text-muted uppercase">
|
|
{{ t('admin.question.headers.agent') }}
|
|
</th>
|
|
<th class="px-6 py-3 text-xs font-semibold text-muted uppercase">
|
|
{{ t('admin.question.headers.order') }}
|
|
</th>
|
|
<th class="px-6 py-3 text-xs font-semibold text-muted uppercase text-right">
|
|
{{ t('admin.question.headers.actions') }}
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-subtle">
|
|
<tr v-for="q in questions" :key="q.id">
|
|
<td class="px-6 py-4">
|
|
<div class="font-medium text-primary text-sm">{{ q.title }}</div>
|
|
<div class="text-xs text-muted truncate max-w-xs mt-0.5">{{ q.question }}</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 text-sm text-muted">{{ q.sort_order }}</td>
|
|
<td class="px-6 py-4 text-right flex justify-end gap-2">
|
|
<button
|
|
type="button"
|
|
class="p-1.5 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors"
|
|
@click="editQuestion(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>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<DeleteConfirmDialog
|
|
v-model="showDeleteConfirmDialog"
|
|
:message="deleteConfirmMessage"
|
|
@cancel="closeDeleteConfirm"
|
|
@confirm="confirmDelete"
|
|
/>
|
|
</section>
|
|
</template>
|