客户转接系统

This commit is contained in:
yml2213
2026-05-27 07:58:21 +08:00
parent 0d9fec01f3
commit 80c7bb18bb
8 changed files with 387 additions and 35 deletions
+169 -11
View File
@@ -18,12 +18,13 @@ import {
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { computed, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useRoute, useRouter } from 'vue-router'
import { logoutAdmin } from '@/api/adminAuth'
import { useAdminSessionStore } from '@/stores/adminSession'
const router = useRouter()
const route = useRoute()
const adminSession = useAdminSessionStore()
const isCollapsed = ref(false)
@@ -57,6 +58,7 @@ const navItems = computed(() => {
})
})
const activeMenu = computed(() => route.path)
const adminName = computed(() => adminSession.nickname || adminSession.username || '管理员')
async function handleLogout() {
@@ -77,7 +79,7 @@ async function handleLogout() {
<div class="admin-sidebar-header">
<RouterLink class="admin-brand" to="/admin/dashboard">
<span class="brand-mark">H</span>
<span class="brand-text">哈夫币后台</span>
<span class="brand-text" v-show="!isCollapsed">哈夫币后台</span>
</RouterLink>
<el-icon class="collapse-btn" @click="isCollapsed = !isCollapsed">
<Fold v-if="!isCollapsed" />
@@ -85,21 +87,41 @@ async function handleLogout() {
</el-icon>
</div>
<nav class="admin-nav">
<RouterLink v-for="item in navItems" :key="item.to" class="admin-nav-link" :to="item.to">
<el-menu
:default-active="activeMenu"
:collapse="isCollapsed"
:collapse-transition="false"
router
class="admin-menu"
>
<el-menu-item v-for="item in navItems" :key="item.to" :index="item.to">
<el-icon><component :is="item.icon" /></el-icon>
<span class="nav-text">{{ item.label }}</span>
</RouterLink>
</nav>
<template #title>{{ item.label }}</template>
</el-menu-item>
</el-menu>
</aside>
<section class="admin-workspace">
<header class="admin-topbar">
<div>
<span>管理系统</span>
<strong>{{ adminName }}</strong>
<div class="topbar-left">
<el-breadcrumb separator="/">
<el-breadcrumb-item :to="{ path: '/admin/dashboard' }">首页</el-breadcrumb-item>
<el-breadcrumb-item v-if="route.meta.title">{{ route.meta.title }}</el-breadcrumb-item>
</el-breadcrumb>
</div>
<div class="topbar-right">
<el-dropdown trigger="click">
<span class="user-info">
<el-avatar :size="32" :icon="User" />
<span class="username">{{ adminName }}</span>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item :icon="SwitchButton" @click="handleLogout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
<el-button :icon="SwitchButton" @click="handleLogout">退出</el-button>
</header>
<main class="admin-main">
<slot />
@@ -107,3 +129,139 @@ async function handleLogout() {
</section>
</div>
</template>
<style scoped>
.admin-shell {
display: flex;
min-height: 100vh;
background-color: #f5f7fa;
}
.admin-sidebar {
width: 220px;
background-color: #304156;
transition: width 0.3s ease;
display: flex;
flex-direction: column;
overflow: hidden;
}
.admin-shell--collapsed .admin-sidebar {
width: 64px;
}
.admin-sidebar-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px;
border-bottom: 1px solid #3d4e5f;
}
.admin-brand {
display: flex;
align-items: center;
gap: 8px;
text-decoration: none;
color: #fff;
overflow: hidden;
}
.brand-mark {
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
background-color: #409eff;
border-radius: 4px;
font-size: 18px;
font-weight: 700;
flex-shrink: 0;
}
.brand-text {
font-size: 16px;
font-weight: 600;
white-space: nowrap;
}
.collapse-btn {
color: #bfcbd9;
cursor: pointer;
font-size: 20px;
flex-shrink: 0;
}
.collapse-btn:hover {
color: #fff;
}
.admin-menu {
flex: 1;
border-right: none;
background-color: transparent;
}
.admin-menu:not(.el-menu--collapse) {
width: 100%;
}
:deep(.el-menu-item) {
color: #bfcbd9;
}
:deep(.el-menu-item:hover) {
background-color: #263445;
}
:deep(.el-menu-item.is-active) {
color: #409eff;
background-color: #263445;
}
.admin-workspace {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.admin-topbar {
height: 56px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
background-color: #fff;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.topbar-left {
display: flex;
align-items: center;
}
.topbar-right {
display: flex;
align-items: center;
}
.user-info {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
color: #606266;
}
.username {
font-size: 14px;
}
.admin-main {
flex: 1;
padding: 24px;
overflow-y: auto;
}
</style>
@@ -1,7 +1,8 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
import { ref, watch, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { fetchSupportAdmins, transferChat, type SupportAdmin } from '@/api/chats'
import { User } from '@element-plus/icons-vue'
const props = defineProps<{
modelValue: boolean
@@ -19,6 +20,11 @@ const submitting = ref(false)
const admins = ref<SupportAdmin[]>([])
const selectedAdminId = ref<number | null>(null)
// 按会话数排序,空闲客服优先
const sortedAdmins = computed(() => {
return [...admins.value].sort((a, b) => a.chat_count - b.chat_count)
})
watch(() => props.modelValue, (val) => {
visible.value = val
if (val) {
@@ -58,21 +64,38 @@ async function handleSubmit() {
submitting.value = false
}
}
function getStatusTag(count: number) {
if (count === 0) return { text: '空闲', type: 'success' }
if (count <= 3) return { text: '正常', type: '' }
return { text: '繁忙', type: 'warning' }
}
</script>
<template>
<el-dialog v-model="visible" title="转接会话" width="400px">
<el-dialog v-model="visible" title="转接会话" width="480px">
<div v-loading="loading" class="transfer-content">
<p class="tip">选择要转接给的客服</p>
<el-radio-group v-model="selectedAdminId" class="admin-list">
<el-radio
v-for="admin in admins"
v-for="admin in sortedAdmins"
:key="admin.id"
:value="admin.id"
class="admin-item"
>
<span class="admin-name">{{ admin.nickname }}</span>
<span class="admin-count">当前 {{ admin.chat_count }} 个会话</span>
<div class="admin-info">
<el-avatar :size="36" :icon="User" />
<div class="admin-detail">
<span class="admin-name">{{ admin.nickname }}</span>
<span class="admin-id">ID: {{ admin.id }}</span>
</div>
</div>
<div class="admin-status">
<el-tag :type="getStatusTag(admin.chat_count).type" size="small">
{{ getStatusTag(admin.chat_count).text }}
</el-tag>
<span class="admin-count">{{ admin.chat_count }} 个会话</span>
</div>
</el-radio>
</el-radio-group>
<el-empty v-if="!loading && admins.length === 0" description="暂无可用客服" />
@@ -107,12 +130,21 @@ async function handleSubmit() {
.admin-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
height: auto;
padding: 12px;
padding: 12px 16px;
border: 1px solid #e5e7eb;
border-radius: 8px;
margin-right: 0;
width: 100%;
}
.admin-item :deep(.el-radio__label) {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
min-width: 0;
}
.admin-item.is-checked {
@@ -120,12 +152,44 @@ async function handleSubmit() {
background: #ecf5ff;
}
.admin-info {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.admin-detail {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 0;
}
.admin-name {
font-weight: 500;
font-size: 14px;
color: #111827;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.admin-id {
color: #9ca3af;
font-size: 12px;
}
.admin-status {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 4px;
flex-shrink: 0;
}
.admin-count {
color: #9ca3af;
font-size: 13px;
font-size: 12px;
}
</style>