From 2bd27ed70d0082515afad08b9a5f7f4c5b5cc208 Mon Sep 17 00:00:00 2001 From: sophie <16087569+sophie_liang@user.noreply.gitee.com> Date: Wed, 22 Apr 2026 16:22:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E8=AF=84=E4=BB=B7=E6=98=AF=E5=90=A6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/config.ts | 7 ++++--- frontend/src/views/ChatView.vue | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/config.ts b/frontend/src/config.ts index 5080244c..e90210e5 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -1,4 +1,4 @@ -export const config = { +export const config = { appTitle: 'AI工作台', auth: { wecom: { @@ -12,13 +12,14 @@ export const config = { } }, workspace: { - enableFeedback: true, + // true 显示评分区;false 隐藏评分区 + showChatRating: false, // 聊天窗口“源文件展示”开关配置 sourceFiles: { // 是否显示源文件区域(包含上方文件按钮 + 下方“源文档”详情) showSourceFiles: true, // 是否显示 MD 源文件(文件名后缀为 .md/.markdown) - showMdFiles: true, + showMdFiles: false, // 当 showMdFiles=true 时,MD 源文件是否默认展开“源文档”详情 expandMdByDefault: false, }, diff --git a/frontend/src/views/ChatView.vue b/frontend/src/views/ChatView.vue index 625d57cc..70193f45 100644 --- a/frontend/src/views/ChatView.vue +++ b/frontend/src/views/ChatView.vue @@ -1,4 +1,4 @@ - + + + + + + + 意见反馈 + + + + + + + + 反馈类型 + + + {{ item }} + + + + + + 反馈模块 + + {{ item }} + + + + + 反馈内容* + + + {{ error }} + + {{ content.length }}/2000 + + + + + + + 取消 + + + + {{ submitting ? '提交中' : '提交' }} + + + + + diff --git a/frontend/src/composables/useChat.ts b/frontend/src/composables/useChat.ts index 7e72d3e9..9a6f8e00 100644 --- a/frontend/src/composables/useChat.ts +++ b/frontend/src/composables/useChat.ts @@ -23,6 +23,7 @@ interface ChatMessage { content: string; retriever_resources?: RetrieverResource[]; attribution_parts?: string[]; + chat_log_id?: number; } // 统一资源格式为数组,兼容 list 或 { data: list } 两种结构 @@ -263,6 +264,12 @@ export function useChat() { } } } else if (data.event === 'message_end') { + if (botMsgIndex !== null && Number.isInteger(data.chat_log_id)) { + const currentBotMsg = messages.value[botMsgIndex]; + if (currentBotMsg) { + currentBotMsg.chat_log_id = Number(data.chat_log_id); + } + } if (data.conversation_id) { conversationId.value = data.conversation_id; } diff --git a/frontend/src/i18n.ts b/frontend/src/i18n.ts index 5f9bf276..f12ef4a4 100644 --- a/frontend/src/i18n.ts +++ b/frontend/src/i18n.ts @@ -1,4 +1,4 @@ - + import { createI18n } from 'vue-i18n'; const messages = { @@ -757,7 +757,10 @@ const messages = { theme_preference: 'Theme Preference', password_hash: 'Password Hash', reset_token: 'Reset Token', - reset_token_expiry: 'Reset Token Expiry' + reset_token_expiry: 'Reset Token Expiry', + feedback_module: 'Feedback Module', + feedback_type: 'Feedback Type', + source_page: 'Source Page' }, tables: { users: 'Users', @@ -766,6 +769,24 @@ const messages = { departments: 'Departments', agents: 'Agents', permission_requests: 'Permission Requests' + }, + feedbackValues: { + types: { + feature_suggestion: 'Feature Suggestion', + issue_feedback: 'Issue Feedback', + experience_optimization: 'Experience Optimization' + }, + modules: { + knowledge_base: 'Knowledge Base', + general: 'General', + workflow: 'Workflow', + account_permission: 'Account & Permissions' + }, + pages: { + workspace: 'Workspace', + chat: 'Chat', + unknown: 'Unknown' + } } }, diff --git a/frontend/src/views/AdminView.vue b/frontend/src/views/AdminView.vue index 59807f0a..df273a00 100644 --- a/frontend/src/views/AdminView.vue +++ b/frontend/src/views/AdminView.vue @@ -133,12 +133,6 @@ interface UsageReport { by_day: { date: string; count: number }[]; } -interface FeedbackReport { - total: number; - avg_score: number; - distribution: { score: number; count: number }[]; -} - interface WecomBindingRow { id: number; username: string; @@ -364,7 +358,6 @@ const saveUser = async () => { const permissionRequests = ref([]); const usageReport = ref(null); -const feedbackReport = ref(null); const wecomBindings = ref([]); const wecomLoginAudits = ref([]); const wecomBindForm = ref({ @@ -840,10 +833,6 @@ const loadReports = async () => { if (usageRes.ok) { usageReport.value = await usageRes.json(); } - const feedbackRes = await fetch('/api/admin/reports/feedback', { headers: getAuthHeaders() }); - if (feedbackRes.ok) { - feedbackReport.value = await feedbackRes.json(); - } } catch (e) { console.error('Error loading reports:', e); } @@ -1649,8 +1638,12 @@ const loadTableData = async () => { for (const [key, value] of Object.entries(columnFilters.value)) { if (value) params.append(key, value); } - - const res = await fetch(`/api/admin/database/${currentTable.value}?${params.toString()}`, { + + const url = currentTable.value === 'feedbacks' + ? `/api/admin/reports/general-feedbacks?${params.toString()}` + : `/api/admin/database/${currentTable.value}?${params.toString()}`; + + const res = await fetch(url, { headers: getAuthHeaders() }); if (res.ok) { @@ -1796,7 +1789,11 @@ const startResizeColumn = (key: string, e: MouseEvent) => { const loadTableCount = async (table: string) => { try { - const res = await fetch(`/api/admin/database/${table}/count`, { + const countUrl = table === 'feedbacks' + ? '/api/admin/reports/general-feedbacks/count' + : `/api/admin/database/${table}/count`; + + const res = await fetch(countUrl, { headers: getAuthHeaders() }); if (!res.ok) return 0; @@ -1826,10 +1823,133 @@ const handleFilterChange = () => { const isChatLogsTable = computed(() => currentTable.value === 'chat_logs'); const visibleReportKeys = computed(() => { - if (chatLogsColumns.value.length === 0) return Object.keys(tableData.value[0] || {}); - return chatLogsColumns.value.filter((c) => c.visible).map((c) => c.key); + let keys: string[]; + if (chatLogsColumns.value.length === 0) { + keys = Object.keys(tableData.value[0] || {}); + } else { + keys = chatLogsColumns.value.filter((c) => c.visible).map((c) => c.key); + } + + if (currentTable.value === 'feedbacks') { + return keys.filter((k) => k !== 'id' && k !== 'user_id'); + } + + return keys; }); + +const resolveReportLang = () => { + const l = String(locale.value || 'en').toLowerCase(); + if (l.startsWith('zh-cn')) return 'zh-CN'; + if (l.startsWith('zh-tw')) return 'zh-TW'; + if (l.startsWith('th')) return 'th'; + return 'en'; +}; + +const feedbackReportI18nMap: Record; + types: Record; + modules: Record; + pages: Record; +}> = { + en: { + columns: { + feedback_module: 'Feedback Module', + feedback_type: 'Feedback Type', + source_page: 'Source Page', + }, + types: { + feature_suggestion: 'Feature Suggestion', + issue_feedback: 'Issue Feedback', + experience_optimization: 'Experience Optimization', + }, + modules: { + knowledge_base: 'Knowledge Base', + general: 'General', + workflow: 'Workflow', + account_permission: 'Account & Permissions', + }, + pages: { + workspace: 'Workspace', + chat: 'Chat', + unknown: 'Unknown', + }, + }, + 'zh-CN': { + columns: { + feedback_module: '\u53cd\u9988\u6a21\u5757', + feedback_type: '\u53cd\u9988\u7c7b\u578b', + source_page: '\u6765\u6e90\u9875\u9762', + }, + types: { + feature_suggestion: '\u529f\u80fd\u5efa\u8bae', + issue_feedback: '\u95ee\u9898\u53cd\u9988', + experience_optimization: '\u4f53\u9a8c\u4f18\u5316', + }, + modules: { + knowledge_base: '\u77e5\u8bc6\u5e93', + general: '\u901a\u7528', + workflow: '\u5de5\u4f5c\u6d41', + account_permission: '\u8d26\u53f7\u6743\u9650', + }, + pages: { + workspace: '\u5de5\u4f5c\u53f0', + chat: '\u5bf9\u8bdd', + unknown: '\u672a\u77e5', + }, + }, + 'zh-TW': { + columns: { + feedback_module: '\u53cd\u994b\u6a21\u7d44', + feedback_type: '\u53cd\u994b\u985e\u578b', + source_page: '\u4f86\u6e90\u9801\u9762', + }, + types: { + feature_suggestion: '\u529f\u80fd\u5efa\u8b70', + issue_feedback: '\u554f\u984c\u56de\u994b', + experience_optimization: '\u9ad4\u9a57\u512a\u5316', + }, + modules: { + knowledge_base: '\u77e5\u8b58\u5eab', + general: '\u901a\u7528', + workflow: '\u5de5\u4f5c\u6d41', + account_permission: '\u5e33\u865f\u6b0a\u9650', + }, + pages: { + workspace: '\u5de5\u4f5c\u53f0', + chat: '\u5c0d\u8a71', + unknown: '\u672a\u77e5', + }, + }, + th: { + columns: { + feedback_module: '\u0e42\u0e21\u0e14\u0e39\u0e25\u0e02\u0e49\u0e2d\u0e40\u0e2a\u0e19\u0e2d\u0e41\u0e19\u0e30', + feedback_type: '\u0e1b\u0e23\u0e30\u0e40\u0e20\u0e17\u0e02\u0e49\u0e2d\u0e40\u0e2a\u0e19\u0e2d\u0e41\u0e19\u0e30', + source_page: '\u0e2b\u0e19\u0e49\u0e32\u0e15\u0e49\u0e19\u0e17\u0e32\u0e07', + }, + types: { + feature_suggestion: '\u0e02\u0e49\u0e2d\u0e40\u0e2a\u0e19\u0e2d\u0e41\u0e19\u0e30\u0e1f\u0e35\u0e40\u0e08\u0e2d\u0e23\u0e4c', + issue_feedback: '\u0e41\u0e08\u0e49\u0e07\u0e1b\u0e31\u0e0d\u0e2b\u0e32', + experience_optimization: '\u0e1b\u0e23\u0e31\u0e1a\u0e1b\u0e23\u0e38\u0e07\u0e1b\u0e23\u0e30\u0e2a\u0e1a\u0e01\u0e32\u0e23\u0e13\u0e4c', + }, + modules: { + knowledge_base: '\u0e04\u0e25\u0e31\u0e07\u0e04\u0e27\u0e32\u0e21\u0e23\u0e39\u0e49', + general: '\u0e17\u0e31\u0e48\u0e27\u0e44\u0e1b', + workflow: '\u0e40\u0e27\u0e34\u0e23\u0e4c\u0e01\u0e42\u0e1f\u0e25\u0e27\u0e4c', + account_permission: '\u0e1a\u0e31\u0e0d\u0e0a\u0e35\u0e41\u0e25\u0e30\u0e2a\u0e34\u0e17\u0e18\u0e34\u0e4c', + }, + pages: { + workspace: '\u0e40\u0e27\u0e34\u0e23\u0e4c\u0e01\u0e2a\u0e40\u0e1b\u0e0b', + chat: '\u0e41\u0e0a\u0e17', + unknown: '\u0e44\u0e21\u0e48\u0e17\u0e23\u0e32\u0e1a', + }, + }, +}; + const getReportColumnLabel = (key: string) => { + const lang = resolveReportLang(); + const enPack = feedbackReportI18nMap['en'] || { columns: {}, types: {}, modules: {}, pages: {} }; + const direct = feedbackReportI18nMap[lang]?.columns?.[key] || enPack.columns[key]; + if (direct) return direct; const i18nKey = `admin.report.columns.${key}`; const translated = t(i18nKey); if (translated && translated !== i18nKey) return translated; @@ -1863,36 +1983,103 @@ const getTranslatedValue = (i18nKey: string, fallbackValue: any) => { return translated && translated !== i18nKey ? translated : fallbackValue; }; +const normalizeFeedbackKey = (value: any) => { + if (value === null || value === undefined) return ''; + const raw = String(value).trim(); + if (!raw) return ''; + const map: Record = { + '\u529f\u80fd\u5efa\u8bae': 'feature_suggestion', + '\u95ee\u9898\u53cd\u9988': 'issue_feedback', + '\u4f53\u9a8c\u4f18\u5316': 'experience_optimization', + '\u77e5\u8bc6\u5e93': 'knowledge_base', + '\u901a\u7528': 'general', + '\u5de5\u4f5c\u6d41': 'workflow', + '\u8d26\u53f7\u6743\u9650': 'account_permission', + workspace: 'workspace', + chat: 'chat', + unknown: 'unknown', + }; + const normalized = raw.toLowerCase().replace(/[\s\-]+/g, '_'); + return map[raw] || map[normalized] || normalized; +}; + +const getTranslatedFeedbackValue = (group: 'types' | 'modules' | 'pages', value: any) => { + const normalized = normalizeFeedbackKey(value); + if (!normalized) return value; + const lang = resolveReportLang(); + const enPack = feedbackReportI18nMap['en'] || { columns: {}, types: {}, modules: {}, pages: {} }; + const dict = feedbackReportI18nMap[lang]?.[group] || enPack[group]; + return dict?.[normalized] || value; +}; + +const formatReportDateTime = (value: any) => { + if (value === null || value === undefined || value === '') return value; + const d = new Date(value); + if (Number.isNaN(d.getTime())) return value; + + const localeMap: Record = { + 'zh-CN': 'zh-CN', + 'zh-TW': 'zh-TW', + en: 'en-US', + th: 'th-TH', + }; + const lang = resolveReportLang(); + const localeName = localeMap[lang] || 'en-US'; + + return new Intl.DateTimeFormat(localeName, { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, + }).format(d); +}; + const getReportCellValue = (row: any, key: string) => { const value = row?.[key]; - // 根据 is_active 这一列的值进行多语言翻译(布尔值兼容多种后端返回格式) + if (key === 'is_active') { const truthy = value === true || value === 1 || value === '1' || value === 'true' || value === 'True'; return truthy ? t('admin.status.active') : t('admin.status.disabled'); } - // 用户报表值翻译:角色(guest/user/admin) -> 中文角色名 if (key === 'role' && typeof value === 'string') { return getTranslatedValue(`admin.role.${value}`, value); } - // 用户报表值翻译:状态(active/disabled/pending/rejected) -> 中文状态名 if (key === 'status' && typeof value === 'string') { return getTranslatedValue(`admin.status.${value}`, value); } - // 用户报表值翻译:主题偏好(light/dark/system) -> 中文主题名 if (key === 'theme_preference' && typeof value === 'string') { return getTranslatedValue(`theme.${value}`, value); } - // 用户报表值翻译:语言(zh-CN/zh-TW/en/th) -> 语言名称 + if (key === 'feedback_type') { + return getTranslatedFeedbackValue('types', value); + } + + if (key === 'feedback_module') { + return getTranslatedFeedbackValue('modules', value); + } + + if (key === 'source_page') { + return getTranslatedFeedbackValue('pages', value); + } + + // format datetime fields in report table + if (typeof value === 'string' && (key.endsWith('_at') || key === 'created_at' || key === 'updated_at')) { + return formatReportDateTime(value); + } + if (key === 'language' && typeof value === 'string') { const languageLabelMap: Record = { - 'zh-CN': '简体中文', - 'zh-TW': '繁體中文', + 'zh-CN': '\u7b80\u4f53\u4e2d\u6587', + 'zh-TW': '\u7e41\u9ad4\u4e2d\u6587', en: 'English', - th: 'ไทย', + th: '\u0e44\u0e17\u0e22', }; return languageLabelMap[value] || value; } @@ -2478,7 +2665,7 @@ const handlePermissionImport = async (event: Event) => { - {{ feedbackReport?.avg_score?.toFixed(1) ?? '0.0' }} + {{ String(tableData.length || 0) }} {{ t('admin.dash.avgRating') }} diff --git a/frontend/src/views/ChatView.vue b/frontend/src/views/ChatView.vue index 70193f45..c2a35195 100644 --- a/frontend/src/views/ChatView.vue +++ b/frontend/src/views/ChatView.vue @@ -1,4 +1,4 @@ - +