feat: 新增语音转文字(ASR)功能
- 后端:新增 /api/audio/transcribe 接口,调用 Ollama whisper 进行语音识别 - 前端:新增 AudioTranscribePage.vue 页面,支持 MP3/WAV/M4A/OGG/FLAC 等格式 - 注册路由、工具卡片、智能助手欢迎语更新 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,254 @@
|
||||
<template>
|
||||
<div class="path-coach-panel">
|
||||
<!-- 头部 -->
|
||||
<div class="panel-header">
|
||||
<div class="panel-title-wrap">
|
||||
<span class="panel-title">AI PathCoach</span>
|
||||
<span class="panel-points" :class="{ low: aiPoints <= 0 }">剩余点数 {{ aiPoints }}</span>
|
||||
</div>
|
||||
<el-button text @click="aiChat.toggle()">
|
||||
<el-icon><Close /></el-icon>
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 消息列表 -->
|
||||
<div class="message-list" ref="msgListRef">
|
||||
<div
|
||||
v-for="(msg, idx) in aiChat.messages"
|
||||
:key="idx"
|
||||
:class="['message', msg.role === 'user' ? 'user-msg' : 'assistant-msg']"
|
||||
>
|
||||
<div :class="msg.role === 'user' ? 'ai-bubble-user' : 'ai-bubble-assistant'">
|
||||
{{ msg.content }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 初始快捷动作 -->
|
||||
<div v-if="aiChat.messages.length === 0" class="quick-actions">
|
||||
<div class="quick-actions-title">快捷操作</div>
|
||||
<div class="quick-actions-grid">
|
||||
<el-button
|
||||
v-for="action in quickActions"
|
||||
:key="action.id"
|
||||
class="quick-action-btn"
|
||||
:loading="quickLoading === action.id"
|
||||
@click="sendQuickAction(action.id)"
|
||||
>
|
||||
<el-icon v-if="actionIcon(action.id) === 'ChatLineRound'"><ChatLineRound /></el-icon>
|
||||
<el-icon v-else-if="actionIcon(action.id) === 'Money'"><Money /></el-icon>
|
||||
<el-icon v-else-if="actionIcon(action.id) === 'Compare'"><Refresh /></el-icon>
|
||||
<span>{{ action.label }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 输入区 -->
|
||||
<div class="input-area">
|
||||
<el-input
|
||||
v-model="inputText"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
placeholder="向 AI PathCoach 提问..."
|
||||
:disabled="aiChat.isStreaming"
|
||||
@keydown.ctrl.enter="sendMessage"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="aiChat.isStreaming"
|
||||
@click="sendMessage"
|
||||
style="margin-top: 8px; width: 100%"
|
||||
>
|
||||
{{ aiChat.isStreaming ? '思考中...' : '发送 (Ctrl+Enter)' }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, nextTick } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useAiChatStore } from '@/store/aiChat'
|
||||
import { quickActions as fetchQuickActions, quickAction, streamChat, getAiMe } from '@/api/ai'
|
||||
|
||||
const aiChat = useAiChatStore()
|
||||
const inputText = ref('')
|
||||
const msgListRef = ref(null)
|
||||
const quickActions = ref([])
|
||||
const quickLoading = ref('')
|
||||
const aiPoints = ref(0)
|
||||
|
||||
function actionIcon(id) {
|
||||
return { scenario: 'ChatLineRound', commission: 'Money', compare: 'Compare' }[id] || ''
|
||||
}
|
||||
|
||||
function scrollToBottom() {
|
||||
nextTick(() => {
|
||||
if (msgListRef.value) {
|
||||
msgListRef.value.scrollTop = msgListRef.value.scrollHeight
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function loadQuickActions() {
|
||||
try {
|
||||
const res = await fetchQuickActions()
|
||||
quickActions.value = res.data?.actions || []
|
||||
} catch (e) {
|
||||
quickActions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPoints() {
|
||||
try {
|
||||
const res = await getAiMe()
|
||||
aiPoints.value = res.data?.ai_points ?? 0
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
async function sendMessage() {
|
||||
const text = inputText.value.trim()
|
||||
if (!text || aiChat.isStreaming) return
|
||||
inputText.value = ''
|
||||
|
||||
const history = aiChat.messages.map((m) => ({ role: m.role, content: m.content }))
|
||||
aiChat.addMessage({ role: 'user', content: text })
|
||||
aiChat.addMessage({ role: 'assistant', content: '' })
|
||||
const lastIdx = aiChat.messages.length - 1
|
||||
aiChat.setStreaming(true)
|
||||
scrollToBottom()
|
||||
|
||||
try {
|
||||
await streamChat(text, aiChat.context || {}, history, (chunk) => {
|
||||
aiChat.messages[lastIdx].content += chunk
|
||||
scrollToBottom()
|
||||
})
|
||||
} catch (e) {
|
||||
aiChat.messages[lastIdx].content = e?.message || '请求失败,请稍后重试'
|
||||
} finally {
|
||||
aiChat.setStreaming(false)
|
||||
loadPoints()
|
||||
scrollToBottom()
|
||||
}
|
||||
}
|
||||
|
||||
async function sendQuickAction(actionId) {
|
||||
const label = quickActions.value.find((a) => a.id === actionId)?.label || actionId
|
||||
aiChat.addMessage({ role: 'user', content: `[${label}]` })
|
||||
aiChat.addMessage({ role: 'assistant', content: '' })
|
||||
const lastIdx = aiChat.messages.length - 1
|
||||
quickLoading.value = actionId
|
||||
scrollToBottom()
|
||||
|
||||
try {
|
||||
const res = await quickAction(actionId, aiChat.context || {})
|
||||
aiChat.messages[lastIdx].content = res.data?.result || '(无返回)'
|
||||
} catch (e) {
|
||||
aiChat.messages[lastIdx].content = e?.message || '请求失败'
|
||||
} finally {
|
||||
quickLoading.value = ''
|
||||
loadPoints()
|
||||
scrollToBottom()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadQuickActions()
|
||||
loadPoints()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.path-coach-panel {
|
||||
width: var(--ai-panel-width, 360px);
|
||||
height: 100vh;
|
||||
background: var(--surface-bg);
|
||||
border-left: 1px solid var(--surface-border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
height: var(--top-rail-height);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 16px;
|
||||
background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
|
||||
}
|
||||
|
||||
.panel-title-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--surface-text);
|
||||
}
|
||||
|
||||
.panel-points {
|
||||
font-size: 12px;
|
||||
color: #67c23a;
|
||||
}
|
||||
|
||||
.panel-points.low {
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
.message-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.message {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.user-msg {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.assistant-msg {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.quick-actions {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.quick-actions-title {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
margin-bottom: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.quick-actions-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.quick-action-btn {
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.input-area {
|
||||
padding: 12px 16px;
|
||||
border-top: 1px solid var(--surface-border);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,119 @@
|
||||
<template>
|
||||
<div v-if="section" class="section-tabs">
|
||||
<div class="section-tabs-inner">
|
||||
<el-tabs
|
||||
:model-value="activeTabPath"
|
||||
class="tabs-nav"
|
||||
@tab-change="handleTabChange"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="tab in section.tabs"
|
||||
:key="tab.path"
|
||||
:name="tab.path"
|
||||
>
|
||||
<template #label>
|
||||
<span class="tab-label">
|
||||
<span>{{ tab.label }}</span>
|
||||
<el-badge
|
||||
v-if="tab.path === '/notifications' && unread > 0"
|
||||
:value="unread"
|
||||
:max="99"
|
||||
class="tab-badge"
|
||||
/>
|
||||
</span>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { useNotificationStore } from '@/store/notification'
|
||||
import { resolveSection, resolveTab } from '@/config/navigation'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
const notif = useNotificationStore()
|
||||
|
||||
const section = computed(() => resolveSection(route.path, auth.isAdmin))
|
||||
const activeTabPath = computed(() => resolveTab(route.path, auth.isAdmin)?.path || '')
|
||||
const unread = computed(() => notif.unread)
|
||||
|
||||
function handleTabChange(path) {
|
||||
if (typeof path === 'string' && path && path !== route.path) {
|
||||
router.push(path)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.section-tabs {
|
||||
padding: 0 24px;
|
||||
background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
|
||||
}
|
||||
|
||||
.section-tabs-inner {
|
||||
min-height: var(--top-rail-height);
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.tabs-nav :deep(.el-tabs__header) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tabs-nav {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.tabs-nav :deep(.el-tabs__nav) {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.tabs-nav :deep(.el-tabs__nav-wrap) {
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.tabs-nav :deep(.el-tabs__nav-wrap::after) {
|
||||
background-color: var(--surface-border);
|
||||
}
|
||||
|
||||
.tabs-nav :deep(.el-tabs__item) {
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
color: #606266;
|
||||
font-size: 14px;
|
||||
padding: 0 18px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
transition: color 0.2s ease, background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.tabs-nav :deep(.el-tabs__item:hover) {
|
||||
color: var(--surface-text);
|
||||
background: rgba(64, 158, 255, 0.08);
|
||||
}
|
||||
|
||||
.tabs-nav :deep(.el-tabs__item.is-active) {
|
||||
color: var(--el-color-primary);
|
||||
font-weight: 600;
|
||||
background: linear-gradient(180deg, rgba(64, 158, 255, 0.12) 0%, rgba(64, 158, 255, 0.06) 100%);
|
||||
}
|
||||
|
||||
.tabs-nav :deep(.el-tabs__active-bar) {
|
||||
height: 3px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.tab-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,228 @@
|
||||
<template>
|
||||
<div class="side-nav">
|
||||
<!-- 品牌区(左上角) -->
|
||||
<div class="brand">
|
||||
<div class="brand-content">
|
||||
<el-icon class="brand-logo" :size="24"><School /></el-icon>
|
||||
<div class="brand-text">
|
||||
<div class="brand-name">博昇AI研究院</div>
|
||||
<div class="brand-sub">内部培训平台</div>
|
||||
<div class="brand-en">EAI-Training</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 菜单区 -->
|
||||
<el-menu
|
||||
:default-active="activeSectionKey"
|
||||
:collapse="false"
|
||||
class="nav-menu"
|
||||
@select="handleSectionSelect"
|
||||
>
|
||||
<el-menu-item v-for="section in commonSections" :key="section.key" :index="section.key">
|
||||
<el-icon><component :is="iconMap[section.icon]" /></el-icon>
|
||||
<span>{{ section.label }}</span>
|
||||
</el-menu-item>
|
||||
|
||||
<el-divider v-if="adminSections.length > 0" class="nav-divider" />
|
||||
<template v-if="adminSections.length > 0">
|
||||
<el-menu-item v-for="section in adminSections" :key="section.key" :index="section.key">
|
||||
<el-icon><component :is="iconMap[section.icon]" /></el-icon>
|
||||
<span>{{ section.label }}</span>
|
||||
</el-menu-item>
|
||||
</template>
|
||||
</el-menu>
|
||||
|
||||
<!-- 底部用户信息(左下角) -->
|
||||
<div class="user-footer">
|
||||
<el-divider class="footer-divider" />
|
||||
<div class="user-info">
|
||||
<el-avatar :size="36" class="user-avatar">{{ avatarText }}</el-avatar>
|
||||
<div class="user-meta">
|
||||
<span class="user-name">{{ username }}</span>
|
||||
<el-tag :type="isAdmin ? 'danger' : 'info'" size="small" effect="plain" round>
|
||||
{{ isAdmin ? '管理员' : '普通员工' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
<el-button text type="info" size="small" class="logout-btn" @click="handleLogout">
|
||||
退出登录
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, onBeforeUnmount } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
Collection,
|
||||
EditPen,
|
||||
HomeFilled,
|
||||
Reading,
|
||||
Setting,
|
||||
UserFilled,
|
||||
} from '@element-plus/icons-vue'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { useNotificationStore } from '@/store/notification'
|
||||
import { getVisibleSections, resolveSection } from '@/config/navigation'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
const notif = useNotificationStore()
|
||||
|
||||
const isAdmin = computed(() => auth.isAdmin)
|
||||
const username = computed(() => auth.username)
|
||||
const avatarText = computed(() => (username.value || '用').charAt(0))
|
||||
const unread = computed(() => notif.unread)
|
||||
const sections = computed(() => getVisibleSections(isAdmin.value))
|
||||
const commonSections = computed(() => sections.value.filter((section) => !section.adminOnly))
|
||||
const adminSections = computed(() => sections.value.filter((section) => section.adminOnly))
|
||||
const activeSectionKey = computed(() => resolveSection(route.path, isAdmin.value)?.key || 'workbench')
|
||||
|
||||
const iconMap = {
|
||||
HomeFilled,
|
||||
Reading,
|
||||
EditPen,
|
||||
UserFilled,
|
||||
Collection,
|
||||
Setting,
|
||||
}
|
||||
|
||||
let timer = null
|
||||
onMounted(() => {
|
||||
notif.refresh()
|
||||
timer = setInterval(() => notif.refresh(), 60000)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
if (timer) clearInterval(timer)
|
||||
})
|
||||
|
||||
function handleLogout() {
|
||||
auth.logout()
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
function handleSectionSelect(sectionKey) {
|
||||
const section = sections.value.find((item) => item.key === sectionKey)
|
||||
if (section?.defaultPath && section.defaultPath !== route.path) {
|
||||
router.push(section.defaultPath)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.side-nav {
|
||||
width: var(--nav-width, 220px);
|
||||
height: 100vh;
|
||||
background: var(--surface-bg);
|
||||
border-right: 1px solid var(--surface-border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.brand {
|
||||
height: var(--top-rail-height);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
padding: 0 12px;
|
||||
background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
|
||||
}
|
||||
|
||||
.brand-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
transform: translateX(-6px);
|
||||
}
|
||||
|
||||
.brand-logo {
|
||||
color: var(--el-color-primary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.brand-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.brand-name {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--surface-text);
|
||||
}
|
||||
|
||||
.brand-sub {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--surface-muted);
|
||||
}
|
||||
|
||||
.brand-en {
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.4px;
|
||||
text-transform: uppercase;
|
||||
color: #b1b3b8;
|
||||
}
|
||||
|
||||
.nav-menu {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.nav-divider {
|
||||
margin: 8px 16px;
|
||||
}
|
||||
|
||||
.user-footer {
|
||||
padding: 12px 16px;
|
||||
border-top: 1px solid var(--surface-border);
|
||||
}
|
||||
|
||||
.footer-divider {
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.user-avatar {
|
||||
background: var(--el-color-primary);
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.user-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-size: 14px;
|
||||
color: var(--surface-text);
|
||||
font-weight: 500;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user