feat(dashboard): 增强反馈列表功能,支持用户信息展示

- 在反馈列表中新增用户的用户名和头像字段
- 更新后端接口以支持根据智能体ID过滤反馈记录
- 前端实现反馈详情模态框,提升用户交互体验
- 优化反馈数据的查询逻辑,确保隐私合规性
This commit is contained in:
Wenjie Zhang 2025-10-08 22:36:35 +08:00
parent cfc9b903de
commit 02dff554ac
5 changed files with 455 additions and 151 deletions

View File

@ -638,6 +638,8 @@ class FeedbackListItem(BaseModel):
id: int
user_id: str
username: str | None
avatar: str | None
rating: str
reason: str | None
created_at: str
@ -649,36 +651,48 @@ class FeedbackListItem(BaseModel):
@dashboard.get("/feedbacks", response_model=list[FeedbackListItem])
async def get_all_feedbacks(
rating: str | None = None,
limit: int = 100,
offset: int = 0,
agent_id: str | None = None,
db: Session = Depends(get_db),
current_user: User = Depends(get_admin_user),
):
"""Get all feedback records (Admin only)"""
from src.storage.db.models import MessageFeedback, Message, Conversation
from src.storage.db.models import MessageFeedback, Message, Conversation, User
try:
# Build query with joins
# Build query with joins including User table
# Try both User.id and User.user_id as MessageFeedback.user_id might be stored as either
query = (
db.query(MessageFeedback, Message, Conversation)
db.query(MessageFeedback, Message, Conversation, User)
.join(Message, MessageFeedback.message_id == Message.id)
.join(Conversation, Message.conversation_id == Conversation.id)
.outerjoin(User,
(MessageFeedback.user_id == User.id) |
(MessageFeedback.user_id == User.user_id)
)
)
# Apply filters
if rating and rating in ["like", "dislike"]:
query = query.filter(MessageFeedback.rating == rating)
if agent_id:
query = query.filter(Conversation.agent_id == agent_id)
# Order and paginate
query = query.order_by(MessageFeedback.created_at.desc()).limit(limit).offset(offset)
# Order by creation time (most recent first)
query = query.order_by(MessageFeedback.created_at.desc())
results = query.all()
# Debug logging (privacy-safe)
logger.info(f"Found {len(results)} feedback records")
# Removed sensitive user data from logs for privacy compliance
return [
{
"id": feedback.id,
"message_id": feedback.message_id,
"user_id": feedback.user_id,
"username": user.username if user else None,
"avatar": user.avatar if user else None,
"rating": feedback.rating,
"reason": feedback.reason,
"created_at": feedback.created_at.isoformat(),
@ -686,7 +700,7 @@ async def get_all_feedbacks(
"conversation_title": conversation.title,
"agent_id": conversation.agent_id,
}
for feedback, message, conversation in results
for feedback, message, conversation, user in results
]
except Exception as e:
logger.error(f"Error getting feedbacks: {e}")

View File

@ -48,15 +48,13 @@ export const dashboardApi = {
* 获取用户反馈列表
* @param {Object} params - 查询参数
* @param {string} params.rating - 反馈类型过滤 (like/dislike/all)
* @param {number} params.limit - 每页数量
* @param {number} params.offset - 偏移量
* @param {string} params.agent_id - 智能体ID过滤
* @returns {Promise<Array>} - 反馈列表
*/
getFeedbacks: (params = {}) => {
const queryParams = new URLSearchParams()
if (params.rating && params.rating !== 'all') queryParams.append('rating', params.rating)
if (params.limit) queryParams.append('limit', params.limit)
if (params.offset) queryParams.append('offset', params.offset)
if (params.agent_id) queryParams.append('agent_id', params.agent_id)
return apiAdminGet(`/api/dashboard/feedbacks?${queryParams.toString()}`)
},

View File

@ -0,0 +1,411 @@
<template>
<!-- 反馈列表模态框 -->
<a-modal
v-model:open="modalVisible"
title="用户反馈详情"
width="1200px"
:footer="null"
>
<a-space style="margin-bottom: 16px">
<a-radio-group v-model:value="feedbackFilter" @change="loadFeedbacks">
<a-radio-button value="all">全部</a-radio-button>
<a-radio-button value="like">点赞</a-radio-button>
<a-radio-button value="dislike">点踩</a-radio-button>
</a-radio-group>
</a-space>
<!-- 卡片列表 -->
<div v-if="loadingFeedbacks" class="loading-container">
<a-spin size="large" />
</div>
<div v-else class="feedback-cards-container">
<div
v-for="feedback in feedbacks"
:key="feedback.id"
class="feedback-card"
>
<!-- 卡片头部用户信息和反馈类型 -->
<div class="card-header">
<div class="user-info">
<a-avatar
:src="feedback.avatar"
:size="32"
class="user-avatar"
>
{{ feedback.username ? feedback.username.charAt(0).toUpperCase() : 'U' }}
</a-avatar>
<div class="user-details">
<div class="username">{{ feedback.username || '未知用户' }}</div>
</div>
</div>
<a-tag :color="feedback.rating === 'like' ? 'green' : 'red'" class="rating-tag" size="small">
<template #icon>
<LikeOutlined v-if="feedback.rating === 'like'" />
<DislikeOutlined v-else />
</template>
{{ feedback.rating === 'like' ? '点赞' : '点踩' }}
</a-tag>
</div>
<!-- 卡片内容消息内容和对话信息 -->
<div class="card-content">
<div class="message-section">
<div class="message-content">{{ feedback.message_content }}</div>
</div>
<div class="conversation-section">
<div class="conversation-info">
<div class="info-item">
<span class="label">智能体:</span>
<span class="value">{{ feedback.agent_id }}</span>
</div>
<div class="info-item" v-if="feedback.conversation_title">
<span class="label">对话:</span>
<span class="value">{{ feedback.conversation_title }}</span>
</div>
</div>
</div>
<!-- 反馈原因 -->
<div v-if="feedback.reason" class="reason-section">
<div class="reason-content">{{ feedback.reason }}</div>
</div>
</div>
<!-- 卡片底部时间信息 -->
<div class="card-footer">
<div class="time-info">
<ClockCircleOutlined />
<span>{{ formatFullDate(feedback.created_at) }}</span>
</div>
</div>
</div>
<!-- 空状态 -->
<div v-if="feedbacks.length === 0" class="empty-state">
<a-empty description="暂无反馈数据" />
</div>
</div>
</a-modal>
</template>
<script setup>
import { ref, reactive, watch } from 'vue'
import { message } from 'ant-design-vue'
import { LikeOutlined, DislikeOutlined, ClockCircleOutlined } from '@ant-design/icons-vue'
import { dashboardApi } from '@/apis/dashboard_api'
// Props
const props = defineProps({
agentId: {
type: String,
default: null
}
})
//
const modalVisible = ref(false)
//
const feedbacks = ref([])
const loadingFeedbacks = ref(false)
const feedbackFilter = ref('all')
//
const show = () => {
modalVisible.value = true
loadFeedbacks()
}
//
defineExpose({ show })
//
const loadFeedbacks = async () => {
loadingFeedbacks.value = true
try {
const params = {
rating: feedbackFilter.value === 'all' ? undefined : feedbackFilter.value,
agent_id: props.agentId || undefined,
}
const response = await dashboardApi.getFeedbacks(params)
feedbacks.value = response
} catch (error) {
console.error('加载反馈列表失败:', error)
message.error('加载反馈列表失败')
} finally {
loadingFeedbacks.value = false
}
}
//
const formatFullDate = (dateString) => {
if (!dateString) return '-'
const date = new Date(dateString)
return date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
})
}
// agentId
watch(() => props.agentId, () => {
if (modalVisible.value) {
loadFeedbacks()
}
})
</script>
<style scoped lang="less">
//
.loading-container {
display: flex;
justify-content: center;
align-items: center;
padding: 40px 0;
}
// -
.feedback-cards-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 16px;
max-height: 600px;
overflow-y: auto;
padding-right: 8px;
//
&::-webkit-scrollbar {
width: 6px;
}
&::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 3px;
}
&::-webkit-scrollbar-thumb {
background: #c1c1c1;
border-radius: 3px;
&:hover {
background: #a8a8a8;
}
}
}
// -
.feedback-card {
background: white;
border: 1px solid var(--gray-100);
border-radius: 8px;
transition: all 0.2s ease;
display: flex;
flex-direction: column;
&:hover {
border-color: var(--main-color);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
}
// -
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 16px;
border-bottom: 1px solid var(--gray-100);
background: #fafafa;
border-radius: 8px 8px 0 0;
}
.user-info {
display: flex;
align-items: center;
gap: 8px;
}
.user-avatar {
flex-shrink: 0;
}
.user-details {
.username {
font-weight: 500;
color: var(--gray-900);
font-size: 13px;
line-height: 1.2;
}
}
.rating-tag {
font-weight: 500;
font-size: 11px;
}
// -
.card-content {
padding: 16px;
flex: 1;
display: flex;
flex-direction: column;
gap: 12px;
}
.message-section {
flex: 1;
}
.message-content {
background: #f8f9fa;
padding: 10px;
border-radius: 6px;
// border-left: 3px solid var(--main-color);
font-size: 13px;
line-height: 1.4;
color: var(--gray-800);
word-break: break-word;
}
.conversation-section {
margin: 0;
}
.conversation-info {
display: flex;
flex-direction: column;
gap: 4px;
}
.info-item {
display: flex;
align-items: center;
font-size: 12px;
.label {
color: var(--gray-600);
margin-right: 6px;
min-width: 50px;
font-weight: 500;
}
.value {
color: var(--gray-800);
font-weight: 400;
word-break: break-all;
}
}
.reason-section {
margin: 0;
}
.reason-content {
background: #fff7e6;
padding: 10px;
border-radius: 6px;
border-left: 3px solid #faad14;
font-size: 13px;
line-height: 1.4;
color: var(--gray-800);
word-break: break-word;
}
// -
.card-footer {
padding: 8px 16px;
border-top: 1px solid var(--gray-100);
background: #fafafa;
border-radius: 0 0 8px 8px;
}
.time-info {
display: flex;
align-items: center;
gap: 4px;
font-size: 11px;
color: var(--gray-500);
}
//
.empty-state {
display: flex;
justify-content: center;
align-items: center;
padding: 60px 0;
}
//
@media (max-width: 768px) {
.feedback-cards-container {
grid-template-columns: 1fr;
gap: 12px;
}
.feedback-card {
margin-bottom: 0;
}
.card-header {
padding: 10px 12px;
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.card-content {
padding: 12px;
gap: 10px;
}
.conversation-info {
.info-item {
flex-direction: column;
align-items: flex-start;
gap: 2px;
.label {
min-width: auto;
margin-right: 0;
}
}
}
.card-footer {
padding: 6px 12px;
}
}
@media (max-width: 480px) {
.feedback-cards-container {
gap: 8px;
}
.card-header {
padding: 8px 10px;
}
.card-content {
padding: 10px;
gap: 8px;
}
.message-content,
.reason-content {
padding: 8px;
font-size: 12px;
}
.info-item {
font-size: 11px;
}
}
</style>

View File

@ -18,6 +18,12 @@
<div class="header-item">
<a-button class="header-button" @click="toggleConf" :icon="h(SettingOutlined)"> 配置 </a-button>
</div>
<div class="header-item" v-if="selectedAgentId">
<a-button class="header-button" @click="feedbackModal.show()">
<template #icon><MessageOutlined /></template>
反馈详情
</a-button>
</div>
<div class="header-item">
<a-button
class="header-button"
@ -79,6 +85,9 @@
:isOpen="state.isConfigSidebarOpen"
@close="() => state.isConfigSidebarOpen = false"
/>
<!-- 反馈模态框 -->
<FeedbackModalComponent ref="feedbackModal" :agent-id="selectedAgentId" />
</div>
</div>
</template>
@ -91,19 +100,21 @@ import {
LinkOutlined,
StarOutlined,
StarFilled,
MessageOutlined,
} from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
import { Bot } from 'lucide-vue-next';
import AgentChatComponent from '@/components/AgentChatComponent.vue';
import AgentConfigSidebar from '@/components/AgentConfigSidebar.vue';
import FeedbackModalComponent from '@/components/dashboard/FeedbackModalComponent.vue';
import { useUserStore } from '@/stores/user';
import { useAgentStore } from '@/stores/agent';
import { useInfoStore } from '@/stores/info';
import { storeToRefs } from 'pinia';
// stores
const router = useRouter();
//
const feedbackModal = ref(null)
const userStore = useUserStore();
const agentStore = useAgentStore();
const infoStore = useInfoStore();

View File

@ -75,7 +75,7 @@
<a-button size="small" @click="loadConversations" :loading="loading">
刷新
</a-button>
<a-button size="small" type="primary" @click="showFeedbackList">
<a-button size="small" @click="feedbackModal.show()">
反馈详情
</a-button>
</a-space>
@ -113,56 +113,14 @@
</div>
</div>
<!-- 反馈列表模态框 -->
<a-modal
v-model:open="feedbackModalVisible"
title="用户反馈详情"
width="1000px"
:footer="null"
>
<a-space style="margin-bottom: 16px">
<a-radio-group v-model:value="feedbackFilter" @change="loadFeedbacks">
<a-radio-button value="all">全部</a-radio-button>
<a-radio-button value="like">点赞</a-radio-button>
<a-radio-button value="dislike">点踩</a-radio-button>
</a-radio-group>
</a-space>
<a-table
:columns="feedbackColumns"
:data-source="feedbacks"
:loading="loadingFeedbacks"
:pagination="feedbackPagination"
row-key="id"
size="small"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'rating'">
<a-tag :color="record.rating === 'like' ? 'green' : 'red'">
<template #icon>
<LikeOutlined v-if="record.rating === 'like'" />
<DislikeOutlined v-else />
</template>
{{ record.rating === 'like' ? '点赞' : '点踩' }}
</a-tag>
</template>
<template v-if="column.key === 'reason'">
<span v-if="record.reason">{{ record.reason }}</span>
<span v-else style="color: #999">-</span>
</template>
<template v-if="column.key === 'created_at'">
{{ formatFullDate(record.created_at) }}
</template>
</template>
</a-table>
</a-modal>
<!-- 反馈模态框 -->
<FeedbackModalComponent ref="feedbackModal" />
</div>
</template>
<script setup>
import { ref, reactive, onMounted, onUnmounted } from 'vue'
import { message } from 'ant-design-vue'
import { LikeOutlined, DislikeOutlined } from '@ant-design/icons-vue'
import { dashboardApi } from '@/apis/dashboard_api'
//
@ -173,6 +131,10 @@ import KnowledgeStatsComponent from '@/components/dashboard/KnowledgeStatsCompon
import AgentStatsComponent from '@/components/dashboard/AgentStatsComponent.vue'
import CallStatsComponent from '@/components/dashboard/CallStatsComponent.vue'
import StatsOverviewComponent from '@/components/dashboard/StatsOverviewComponent.vue'
import FeedbackModalComponent from '@/components/dashboard/FeedbackModalComponent.vue'
//
const feedbackModal = ref(null)
// - 使
const basicStats = ref({})
@ -195,17 +157,6 @@ const conversations = ref([])
const loading = ref(false)
const loadingDetail = ref(false)
//
const feedbackModalVisible = ref(false)
const feedbacks = ref([])
const loadingFeedbacks = ref(false)
const feedbackFilter = ref('all')
const feedbackPagination = reactive({
current: 1,
pageSize: 20,
total: 0,
})
//
const callStatsRef = ref(null)
@ -262,49 +213,6 @@ const conversationColumns = [
},
]
//
const feedbackColumns = [
{
title: '反馈类型',
key: 'rating',
width: '10%',
},
{
title: '用户ID',
dataIndex: 'user_id',
key: 'user_id',
width: '12%',
},
{
title: '智能体ID',
dataIndex: 'agent_id',
key: 'agent_id',
width: '12%',
},
{
title: '对话标题',
dataIndex: 'conversation_title',
key: 'conversation_title',
width: '15%',
},
{
title: '消息内容',
dataIndex: 'message_content',
key: 'message_content',
width: '25%',
},
{
title: '反馈原因',
key: 'reason',
width: '16%',
},
{
title: '时间',
key: 'created_at',
width: '10%',
},
]
//
const userStatsRef = ref(null)
const toolStatsRef = ref(null)
@ -419,44 +327,6 @@ const handleTableChange = (pag) => {
loadConversations()
}
//
const formatFullDate = (dateString) => {
if (!dateString) return '-'
const date = new Date(dateString)
return date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
})
}
//
const showFeedbackList = () => {
feedbackModalVisible.value = true
loadFeedbacks()
}
//
const loadFeedbacks = async () => {
loadingFeedbacks.value = true
try {
const params = {
rating: feedbackFilter.value === 'all' ? undefined : feedbackFilter.value,
limit: feedbackPagination.pageSize,
offset: (feedbackPagination.current - 1) * feedbackPagination.pageSize,
}
const response = await dashboardApi.getFeedbacks(params)
feedbacks.value = response
} catch (error) {
console.error('加载反馈列表失败:', error)
message.error('加载反馈列表失败')
} finally {
loadingFeedbacks.value = false
}
}
// -
const cleanupCharts = () => {