客户转接系统
This commit is contained in:
@@ -144,7 +144,20 @@ func (r *Repository) ensureDefaultAdmin() error {
|
|||||||
Nickname: "超级管理员",
|
Nickname: "超级管理员",
|
||||||
Status: "active",
|
Status: "active",
|
||||||
}
|
}
|
||||||
return r.db.Create(&admin).Error
|
if err := r.db.Create(&admin).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动关联 super_admin 角色
|
||||||
|
var superAdminRole model.Role
|
||||||
|
if err := r.db.Where("code = ?", "super_admin").First(&superAdminRole).Error; err == nil {
|
||||||
|
r.db.Create(&model.AdminUserRole{
|
||||||
|
AdminID: admin.ID,
|
||||||
|
RoleID: superAdminRole.ID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func toDTO(admin model.AdminUser) AdminDTO {
|
func toDTO(admin model.AdminUser) AdminDTO {
|
||||||
|
|||||||
@@ -686,12 +686,11 @@ func (r *Repository) GetAvailableSupportAdmins() ([]SupportAdminDTO, error) {
|
|||||||
}
|
}
|
||||||
var admins []adminRow
|
var admins []adminRow
|
||||||
err := r.db.Table("admin_users AS au").
|
err := r.db.Table("admin_users AS au").
|
||||||
Select("au.id, au.nickname").
|
Select("DISTINCT au.id, COALESCE(NULLIF(au.nickname, ''), au.username) AS nickname").
|
||||||
Joins("JOIN admin_user_roles AS aur ON aur.admin_user_id = au.id").
|
Joins("JOIN admin_user_roles AS aur ON aur.admin_user_id = au.id").
|
||||||
Joins("JOIN role_permissions AS rp ON rp.role_id = aur.role_id").
|
Joins("JOIN role_permissions AS rp ON rp.role_id = aur.role_id").
|
||||||
Joins("JOIN permissions AS p ON p.id = rp.permission_id").
|
Joins("JOIN permissions AS p ON p.id = rp.permission_id").
|
||||||
Where("au.status = ? AND p.code = ?", "active", "chat:view").
|
Where("au.status = ? AND p.code = ?", "active", "chat:view").
|
||||||
Distinct("au.id").
|
|
||||||
Scan(&admins).Error
|
Scan(&admins).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -722,9 +721,9 @@ func (r *Repository) GetAvailableSupportAdmins() ([]SupportAdminDTO, error) {
|
|||||||
result := make([]SupportAdminDTO, len(admins))
|
result := make([]SupportAdminDTO, len(admins))
|
||||||
for i, a := range admins {
|
for i, a := range admins {
|
||||||
result[i] = SupportAdminDTO{
|
result[i] = SupportAdminDTO{
|
||||||
ID: a.ID,
|
ID: a.ID,
|
||||||
Nickname: a.Nickname,
|
Nickname: a.Nickname,
|
||||||
ChatCount: loadMap[a.ID],
|
ChatCount: loadMap[a.ID],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ var defaultConfigs = []defaultConfig{
|
|||||||
{Key: "settlement.platform_fee_rate", Value: "0.00", Description: "平台抽成比例"},
|
{Key: "settlement.platform_fee_rate", Value: "0.00", Description: "平台抽成比例"},
|
||||||
{Key: "settlement.owner_cycle_days", Value: "0", Description: "号主结算周期天数"},
|
{Key: "settlement.owner_cycle_days", Value: "0", Description: "号主结算周期天数"},
|
||||||
{Key: "withdraw.min_amount", Value: "100", Description: "提现最低金额预留"},
|
{Key: "withdraw.min_amount", Value: "100", Description: "提现最低金额预留"},
|
||||||
{Key: "chat.default_support_admin_id", Value: "1", Description: "订单群聊默认接入的客服管理员 ID"},
|
{Key: "chat.default_support_admin_id", Value: "1", Description: "订单群聊回退客服 ID(仅当无可用客服时使用)"},
|
||||||
{Key: homeAnnouncementsConfigKey, Value: defaultHomeAnnouncementsConfigValue(), Description: "移动端首页公告 JSON 数组"},
|
{Key: homeAnnouncementsConfigKey, Value: defaultHomeAnnouncementsConfigValue(), Description: "移动端首页公告 JSON 数组"},
|
||||||
{Key: homeBannersConfigKey, Value: defaultHomeBannersConfigValue(), Description: "移动端首页轮播图 JSON 数组"},
|
{Key: homeBannersConfigKey, Value: defaultHomeBannersConfigValue(), Description: "移动端首页轮播图 JSON 数组"},
|
||||||
{Key: publishOptionsConfigKey, Value: defaultPublishOptionsConfigValue(), Description: "发布页选项配置 JSON"},
|
{Key: publishOptionsConfigKey, Value: defaultPublishOptionsConfigValue(), Description: "发布页选项配置 JSON"},
|
||||||
|
|||||||
@@ -67,6 +67,27 @@ INSERT IGNORE INTO role_permissions (role_id, permission_id)
|
|||||||
SELECT r.id, p.id FROM roles r, permissions p
|
SELECT r.id, p.id FROM roles r, permissions p
|
||||||
WHERE r.code = 'finance' AND p.code IN ('dashboard:view', 'wallet:view', 'order:view');
|
WHERE r.code = 'finance' AND p.code IN ('dashboard:view', 'wallet:view', 'order:view');
|
||||||
|
|
||||||
|
-- -------------------------------------------
|
||||||
|
-- 管理员账号
|
||||||
|
-- -------------------------------------------
|
||||||
|
|
||||||
|
-- 生成 admin 密码 hash: admin123456
|
||||||
|
INSERT INTO admin_users (username, password_hash, nickname, status) VALUES
|
||||||
|
('admin', '$2a$10$vvDd.cYJCOBl9kr5jdRYXu9C/7GXcHmXsG17zJPHzPOZ0XGbqcWNS', '超级管理员', 'active'),
|
||||||
|
('kf1', '$2a$10$7cx3B4IWunLZO24o11YVGu4qY1J1naDdsTyvoCpcnOO.GV15qaf3C', '客服1', 'active'),
|
||||||
|
('kf2', '$2a$10$m6kLCXciFygpqIGUZ9LQtuEFAl40hb.S7zJmMiuC83WrU7OQM3TPC', '客服2', 'active')
|
||||||
|
ON DUPLICATE KEY UPDATE nickname = VALUES(nickname);
|
||||||
|
|
||||||
|
-- admin 关联 super_admin 角色
|
||||||
|
INSERT IGNORE INTO admin_user_roles (admin_user_id, role_id)
|
||||||
|
SELECT au.id, r.id FROM admin_users au, roles r
|
||||||
|
WHERE au.username = 'admin' AND r.code = 'super_admin';
|
||||||
|
|
||||||
|
-- 客服关联 cs 角色
|
||||||
|
INSERT IGNORE INTO admin_user_roles (admin_user_id, role_id)
|
||||||
|
SELECT au.id, r.id FROM admin_users au, roles r
|
||||||
|
WHERE au.username IN ('kf1', 'kf2') AND r.code = 'cs';
|
||||||
|
|
||||||
-- -------------------------------------------
|
-- -------------------------------------------
|
||||||
-- 系统配置
|
-- 系统配置
|
||||||
-- -------------------------------------------
|
-- -------------------------------------------
|
||||||
@@ -80,6 +101,6 @@ INSERT INTO system_configs (`key`, `value`, description) VALUES
|
|||||||
('platform.fee_ratio', '0.1', '平台抽成比例'),
|
('platform.fee_ratio', '0.1', '平台抽成比例'),
|
||||||
('listing.review_required', 'true', '商品是否需要审核'),
|
('listing.review_required', 'true', '商品是否需要审核'),
|
||||||
('order.pending_payment_timeout_minutes', '15', '待支付超时时间(分钟)'),
|
('order.pending_payment_timeout_minutes', '15', '待支付超时时间(分钟)'),
|
||||||
('chat.default_support_admin_id', '1', '订单群聊默认接入的客服管理员 ID'),
|
('chat.default_support_admin_id', '1', '订单群聊回退客服 ID(仅当无可用客服时使用)'),
|
||||||
('chat.auto_welcome_message', '欢迎加入订单群聊!如有任何问题,请随时沟通。', '建群后自动发送的欢迎话术')
|
('chat.auto_welcome_message', '欢迎加入订单群聊!如有任何问题,请随时沟通。', '建群后自动发送的欢迎话术')
|
||||||
ON DUPLICATE KEY UPDATE description = VALUES(description);
|
ON DUPLICATE KEY UPDATE description = VALUES(description);
|
||||||
|
|||||||
Vendored
+5
@@ -12,6 +12,9 @@ export {}
|
|||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
ElAlert: typeof import('element-plus/es')['ElAlert']
|
ElAlert: typeof import('element-plus/es')['ElAlert']
|
||||||
|
ElAvatar: typeof import('element-plus/es')['ElAvatar']
|
||||||
|
ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb']
|
||||||
|
ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem']
|
||||||
ElButton: typeof import('element-plus/es')['ElButton']
|
ElButton: typeof import('element-plus/es')['ElButton']
|
||||||
ElCarousel: typeof import('element-plus/es')['ElCarousel']
|
ElCarousel: typeof import('element-plus/es')['ElCarousel']
|
||||||
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
|
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
|
||||||
@@ -27,6 +30,8 @@ declare module 'vue' {
|
|||||||
ElIcon: typeof import('element-plus/es')['ElIcon']
|
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||||
ElInput: typeof import('element-plus/es')['ElInput']
|
ElInput: typeof import('element-plus/es')['ElInput']
|
||||||
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
|
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
|
||||||
|
ElMenu: typeof import('element-plus/es')['ElMenu']
|
||||||
|
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
||||||
ElOption: typeof import('element-plus/es')['ElOption']
|
ElOption: typeof import('element-plus/es')['ElOption']
|
||||||
ElPagination: typeof import('element-plus/es')['ElPagination']
|
ElPagination: typeof import('element-plus/es')['ElPagination']
|
||||||
ElRadio: typeof import('element-plus/es')['ElRadio']
|
ElRadio: typeof import('element-plus/es')['ElRadio']
|
||||||
|
|||||||
@@ -18,12 +18,13 @@ import {
|
|||||||
} from '@element-plus/icons-vue'
|
} from '@element-plus/icons-vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
|
||||||
import { logoutAdmin } from '@/api/adminAuth'
|
import { logoutAdmin } from '@/api/adminAuth'
|
||||||
import { useAdminSessionStore } from '@/stores/adminSession'
|
import { useAdminSessionStore } from '@/stores/adminSession'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const route = useRoute()
|
||||||
const adminSession = useAdminSessionStore()
|
const adminSession = useAdminSessionStore()
|
||||||
const isCollapsed = ref(false)
|
const isCollapsed = ref(false)
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ const navItems = computed(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const activeMenu = computed(() => route.path)
|
||||||
const adminName = computed(() => adminSession.nickname || adminSession.username || '管理员')
|
const adminName = computed(() => adminSession.nickname || adminSession.username || '管理员')
|
||||||
|
|
||||||
async function handleLogout() {
|
async function handleLogout() {
|
||||||
@@ -77,7 +79,7 @@ async function handleLogout() {
|
|||||||
<div class="admin-sidebar-header">
|
<div class="admin-sidebar-header">
|
||||||
<RouterLink class="admin-brand" to="/admin/dashboard">
|
<RouterLink class="admin-brand" to="/admin/dashboard">
|
||||||
<span class="brand-mark">H</span>
|
<span class="brand-mark">H</span>
|
||||||
<span class="brand-text">哈夫币后台</span>
|
<span class="brand-text" v-show="!isCollapsed">哈夫币后台</span>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
<el-icon class="collapse-btn" @click="isCollapsed = !isCollapsed">
|
<el-icon class="collapse-btn" @click="isCollapsed = !isCollapsed">
|
||||||
<Fold v-if="!isCollapsed" />
|
<Fold v-if="!isCollapsed" />
|
||||||
@@ -85,21 +87,41 @@ async function handleLogout() {
|
|||||||
</el-icon>
|
</el-icon>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav class="admin-nav">
|
<el-menu
|
||||||
<RouterLink v-for="item in navItems" :key="item.to" class="admin-nav-link" :to="item.to">
|
: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>
|
<el-icon><component :is="item.icon" /></el-icon>
|
||||||
<span class="nav-text">{{ item.label }}</span>
|
<template #title>{{ item.label }}</template>
|
||||||
</RouterLink>
|
</el-menu-item>
|
||||||
</nav>
|
</el-menu>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<section class="admin-workspace">
|
<section class="admin-workspace">
|
||||||
<header class="admin-topbar">
|
<header class="admin-topbar">
|
||||||
<div>
|
<div class="topbar-left">
|
||||||
<span>管理系统</span>
|
<el-breadcrumb separator="/">
|
||||||
<strong>{{ adminName }}</strong>
|
<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>
|
</div>
|
||||||
<el-button :icon="SwitchButton" @click="handleLogout">退出</el-button>
|
|
||||||
</header>
|
</header>
|
||||||
<main class="admin-main">
|
<main class="admin-main">
|
||||||
<slot />
|
<slot />
|
||||||
@@ -107,3 +129,139 @@ async function handleLogout() {
|
|||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</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">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch, computed } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { fetchSupportAdmins, transferChat, type SupportAdmin } from '@/api/chats'
|
import { fetchSupportAdmins, transferChat, type SupportAdmin } from '@/api/chats'
|
||||||
|
import { User } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: boolean
|
modelValue: boolean
|
||||||
@@ -19,6 +20,11 @@ const submitting = ref(false)
|
|||||||
const admins = ref<SupportAdmin[]>([])
|
const admins = ref<SupportAdmin[]>([])
|
||||||
const selectedAdminId = ref<number | null>(null)
|
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) => {
|
watch(() => props.modelValue, (val) => {
|
||||||
visible.value = val
|
visible.value = val
|
||||||
if (val) {
|
if (val) {
|
||||||
@@ -58,21 +64,38 @@ async function handleSubmit() {
|
|||||||
submitting.value = false
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-dialog v-model="visible" title="转接会话" width="400px">
|
<el-dialog v-model="visible" title="转接会话" width="480px">
|
||||||
<div v-loading="loading" class="transfer-content">
|
<div v-loading="loading" class="transfer-content">
|
||||||
<p class="tip">选择要转接给的客服:</p>
|
<p class="tip">选择要转接给的客服:</p>
|
||||||
<el-radio-group v-model="selectedAdminId" class="admin-list">
|
<el-radio-group v-model="selectedAdminId" class="admin-list">
|
||||||
<el-radio
|
<el-radio
|
||||||
v-for="admin in admins"
|
v-for="admin in sortedAdmins"
|
||||||
:key="admin.id"
|
:key="admin.id"
|
||||||
:value="admin.id"
|
:value="admin.id"
|
||||||
class="admin-item"
|
class="admin-item"
|
||||||
>
|
>
|
||||||
<span class="admin-name">{{ admin.nickname }}</span>
|
<div class="admin-info">
|
||||||
<span class="admin-count">当前 {{ admin.chat_count }} 个会话</span>
|
<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>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
<el-empty v-if="!loading && admins.length === 0" description="暂无可用客服" />
|
<el-empty v-if="!loading && admins.length === 0" description="暂无可用客服" />
|
||||||
@@ -107,12 +130,21 @@ async function handleSubmit() {
|
|||||||
.admin-item {
|
.admin-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
gap: 12px;
|
||||||
height: auto;
|
height: auto;
|
||||||
padding: 12px;
|
padding: 12px 16px;
|
||||||
border: 1px solid #e5e7eb;
|
border: 1px solid #e5e7eb;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
margin-right: 0;
|
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 {
|
.admin-item.is-checked {
|
||||||
@@ -120,12 +152,44 @@ async function handleSubmit() {
|
|||||||
background: #ecf5ff;
|
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 {
|
.admin-name {
|
||||||
font-weight: 500;
|
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 {
|
.admin-count {
|
||||||
color: #9ca3af;
|
color: #9ca3af;
|
||||||
font-size: 13px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+100
-8
@@ -10,17 +10,92 @@ BACKEND_PID=""
|
|||||||
FRONTEND_PID=""
|
FRONTEND_PID=""
|
||||||
CLEANED_UP=0
|
CLEANED_UP=0
|
||||||
|
|
||||||
|
# 颜色定义
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[1;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
printf "\033[1;34m[dev]\033[0m %s\n" "$*"
|
printf "${BLUE}[dev]${NC} %s\n" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_success() {
|
||||||
|
printf "${GREEN}[dev]${NC} %s\n" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_warn() {
|
||||||
|
printf "${YELLOW}[dev]${NC} %s\n" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_error() {
|
||||||
|
printf "${RED}[dev]${NC} %s\n" "$*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
need_cmd() {
|
need_cmd() {
|
||||||
if ! command -v "$1" >/dev/null 2>&1; then
|
if ! command -v "$1" >/dev/null 2>&1; then
|
||||||
printf "缺少命令:%s\n" "$1" >&2
|
log_error "缺少命令:$1"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
cat << EOF
|
||||||
|
用法: ./scripts/dev.sh [选项]
|
||||||
|
|
||||||
|
选项:
|
||||||
|
--reset-db 重置数据库(删除并重建)
|
||||||
|
--seed-only 仅重新加载种子数据
|
||||||
|
--no-frontend 不启动前端
|
||||||
|
--no-backend 不启动后端
|
||||||
|
-h, --help 显示帮助信息
|
||||||
|
|
||||||
|
环境变量:
|
||||||
|
DEV_RESET_DB=1 等同于 --reset-db
|
||||||
|
|
||||||
|
示例:
|
||||||
|
./scripts/dev.sh # 正常启动
|
||||||
|
./scripts/dev.sh --reset-db # 重置数据库后启动
|
||||||
|
./scripts/dev.sh --seed-only # 重新加载种子数据
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# 参数解析
|
||||||
|
RESET_DB="${DEV_RESET_DB:-0}"
|
||||||
|
SEED_ONLY=0
|
||||||
|
NO_FRONTEND=0
|
||||||
|
NO_BACKEND=0
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--reset-db)
|
||||||
|
RESET_DB=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--seed-only)
|
||||||
|
SEED_ONLY=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--no-frontend)
|
||||||
|
NO_FRONTEND=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--no-backend)
|
||||||
|
NO_BACKEND=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
log_error "未知选项: $1"
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
if [[ "${CLEANED_UP}" == "1" ]]; then
|
if [[ "${CLEANED_UP}" == "1" ]]; then
|
||||||
return
|
return
|
||||||
@@ -57,8 +132,8 @@ wait_container_healthy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_database() {
|
init_database() {
|
||||||
if [[ "${DEV_RESET_DB:-0}" == "1" ]]; then
|
if [[ "${RESET_DB}" == "1" ]]; then
|
||||||
log "DEV_RESET_DB=1,重建开发数据库..."
|
log_warn "重置数据库..."
|
||||||
docker exec hfb-mysql mysql -uroot -prootsecret -e \
|
docker exec hfb-mysql mysql -uroot -prootsecret -e \
|
||||||
"DROP DATABASE IF EXISTS hfb_sys; CREATE DATABASE hfb_sys CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
"DROP DATABASE IF EXISTS hfb_sys; CREATE DATABASE hfb_sys CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||||
fi
|
fi
|
||||||
@@ -76,8 +151,13 @@ init_database() {
|
|||||||
log "执行迁移:$(basename "${migration}")"
|
log "执行迁移:$(basename "${migration}")"
|
||||||
docker exec -i hfb-mysql mysql -uhfb -psecret --default-character-set=utf8mb4 hfb_sys < "${migration}"
|
docker exec -i hfb-mysql mysql -uhfb -psecret --default-character-set=utf8mb4 hfb_sys < "${migration}"
|
||||||
done
|
done
|
||||||
|
log_success "数据库初始化完成"
|
||||||
|
elif [[ "${SEED_ONLY}" == "1" ]]; then
|
||||||
|
log "重新加载种子数据..."
|
||||||
|
docker exec -i hfb-mysql mysql -uhfb -psecret --default-character-set=utf8mb4 hfb_sys < "${ROOT_DIR}/backend/migrations/000002_seed.sql"
|
||||||
|
log_success "种子数据加载完成"
|
||||||
else
|
else
|
||||||
log "数据库已存在,跳过迁移(使用 DEV_RESET_DB=1 重建)"
|
log "数据库已存在,跳过迁移(使用 --reset-db 重建)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,10 +236,22 @@ main() {
|
|||||||
wait_container_healthy hfb-minio "MinIO"
|
wait_container_healthy hfb-minio "MinIO"
|
||||||
|
|
||||||
init_database
|
init_database
|
||||||
start_backend
|
|
||||||
start_frontend
|
|
||||||
|
|
||||||
log "开发环境已启动"
|
# 仅加载种子数据模式
|
||||||
|
if [[ "${SEED_ONLY}" == "1" ]]; then
|
||||||
|
log_success "种子数据加载完成,退出"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${NO_BACKEND}" == "0" ]]; then
|
||||||
|
start_backend
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${NO_FRONTEND}" == "0" ]]; then
|
||||||
|
start_frontend
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_success "开发环境已启动"
|
||||||
log "前台:http://localhost:5173"
|
log "前台:http://localhost:5173"
|
||||||
log "后台:http://localhost:5173/admin/login(admin / admin123456)"
|
log "后台:http://localhost:5173/admin/login(admin / admin123456)"
|
||||||
log "按 Ctrl+C 停止前后端;Docker 依赖会保留运行"
|
log "按 Ctrl+C 停止前后端;Docker 依赖会保留运行"
|
||||||
|
|||||||
Reference in New Issue
Block a user