功能:更新消息中心和 YumiNail 模块
This commit is contained in:
@@ -0,0 +1,907 @@
|
||||
<template>
|
||||
<div class="admin-layout" :class="{ 'admin-layout--mobile': isMobile }">
|
||||
<template v-if="!isMobile">
|
||||
<a-layout>
|
||||
<a-layout-sider
|
||||
v-model:collapsed="collapsed"
|
||||
:trigger="null"
|
||||
collapsible
|
||||
class="sider"
|
||||
width="240"
|
||||
>
|
||||
<div class="logo">
|
||||
<h1 v-if="!collapsed">后台管理</h1>
|
||||
<h1 v-else>后台</h1>
|
||||
</div>
|
||||
<a-menu
|
||||
:selectedKeys="selectedKeys"
|
||||
mode="inline"
|
||||
theme="dark"
|
||||
@click="handleMenuClick"
|
||||
>
|
||||
<a-menu-item
|
||||
v-for="item in filteredMenuItems"
|
||||
:key="item.key"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="item.icon" />
|
||||
</template>
|
||||
<span>{{ item.label }}</span>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</a-layout-sider>
|
||||
|
||||
<a-layout>
|
||||
<a-layout-header class="header">
|
||||
<div class="header-shell">
|
||||
<div class="header-left">
|
||||
<MenuUnfoldOutlined v-if="collapsed" class="trigger" @click="toggleCollapsed" />
|
||||
<MenuFoldOutlined v-else class="trigger" @click="toggleCollapsed" />
|
||||
|
||||
<div v-if="isBootstrapAdmin" class="shop-hint">
|
||||
<span>当前暂无可用门店,请先前往店铺管理创建</span>
|
||||
<a-button type="link" @click="router.push('/admin/shops')">去创建</a-button>
|
||||
</div>
|
||||
|
||||
<div v-else-if="shopOptions.length > 1" class="shop-switcher">
|
||||
<span class="shop-switcher-label">当前门店</span>
|
||||
<a-select
|
||||
v-model:value="selectedShopId"
|
||||
class="shop-select"
|
||||
:options="shopSelectOptions"
|
||||
:loading="shopSwitchLoading"
|
||||
@change="handleShopChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else class="shop-pill">
|
||||
<ShopOutlined />
|
||||
<span>{{ currentShopName }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="header-right">
|
||||
<a-dropdown>
|
||||
<a class="user-dropdown" @click.prevent>
|
||||
<a-avatar :size="32" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
<span class="username">{{ userInfo?.nickname || '管理员' }}</span>
|
||||
<DownOutlined />
|
||||
</a>
|
||||
<template #overlay>
|
||||
<a-menu>
|
||||
<a-menu-item key="home" @click="router.push('/admin')">
|
||||
<template #icon>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
工作台
|
||||
</a-menu-item>
|
||||
<a-menu-item key="profile" @click="router.push('/admin/profile')">
|
||||
<template #icon>
|
||||
<IdcardOutlined />
|
||||
</template>
|
||||
我的
|
||||
</a-menu-item>
|
||||
<a-menu-divider />
|
||||
<a-menu-item key="logout" @click="handleLogout">
|
||||
<template #icon>
|
||||
<LogoutOutlined />
|
||||
</template>
|
||||
退出登录
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</template>
|
||||
</a-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</a-layout-header>
|
||||
|
||||
<a-layout-content class="content">
|
||||
<div class="content-shell">
|
||||
<router-view />
|
||||
</div>
|
||||
</a-layout-content>
|
||||
</a-layout>
|
||||
</a-layout>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="mobile-shell">
|
||||
<header class="mobile-topbar">
|
||||
<button class="mobile-icon-btn" type="button" @click="mobileDrawerOpen = true">
|
||||
<MenuOutlined />
|
||||
</button>
|
||||
<div class="mobile-title-block">
|
||||
<span class="mobile-eyebrow">{{ currentMobileSectionLabel }}</span>
|
||||
<strong class="mobile-title">{{ currentMobileTitle }}</strong>
|
||||
</div>
|
||||
<button class="mobile-avatar-btn" type="button" @click="router.push('/admin/profile')">
|
||||
<a-avatar :size="34" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<section class="mobile-context">
|
||||
<div class="mobile-context__primary">{{ currentShopName }}</div>
|
||||
<div class="mobile-context__secondary">{{ roleLabel }}</div>
|
||||
</section>
|
||||
|
||||
<main class="mobile-content">
|
||||
<router-view />
|
||||
</main>
|
||||
|
||||
<nav class="mobile-tabbar">
|
||||
<button
|
||||
v-for="tab in mobileTabs"
|
||||
:key="tab.key"
|
||||
class="mobile-tabbar__item"
|
||||
:class="{ 'is-active': activeMobileTab === tab.key }"
|
||||
type="button"
|
||||
@click="handleMobileTabClick(tab.path)"
|
||||
>
|
||||
<component :is="tab.icon" />
|
||||
<span>{{ tab.label }}</span>
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<a-drawer
|
||||
v-model:open="mobileDrawerOpen"
|
||||
placement="left"
|
||||
:width="320"
|
||||
class="mobile-drawer"
|
||||
:closable="false"
|
||||
root-class-name="admin-mobile-drawer"
|
||||
>
|
||||
<div class="drawer-account">
|
||||
<a-avatar :size="46" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
<div class="drawer-account__body">
|
||||
<div class="drawer-account__title">{{ userInfo?.nickname || userInfo?.account || '后台账号' }}</div>
|
||||
<div class="drawer-account__meta">{{ roleLabel }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-shop-card">
|
||||
<span class="drawer-shop-card__label">当前门店</span>
|
||||
<strong class="drawer-shop-card__value">{{ currentShopName }}</strong>
|
||||
<p class="drawer-shop-card__desc">{{ shopScopeText }}</p>
|
||||
<a-button type="default" block @click="openProfileFromDrawer">
|
||||
{{ shopOptions.length > 1 ? '切换门店' : '查看账号信息' }}
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<div class="drawer-section__title">二级模块</div>
|
||||
<button
|
||||
v-for="item in filteredMenuItems"
|
||||
:key="item.key"
|
||||
class="drawer-link"
|
||||
type="button"
|
||||
@click="openPathFromDrawer(item.key)"
|
||||
>
|
||||
<div class="drawer-link__icon">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
<div class="drawer-link__body">
|
||||
<div class="drawer-link__title">{{ item.label }}</div>
|
||||
</div>
|
||||
<RightOutlined class="drawer-link__arrow" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<div class="drawer-section__title">会话操作</div>
|
||||
<a-space direction="vertical" style="width: 100%">
|
||||
<a-button block @click="openPathFromDrawer('/admin/profile')">打开我的</a-button>
|
||||
<a-button block danger @click="handleLogout">退出当前账号</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
</a-drawer>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
DashboardOutlined,
|
||||
DownOutlined,
|
||||
GiftOutlined,
|
||||
HomeOutlined,
|
||||
IdcardOutlined,
|
||||
LogoutOutlined,
|
||||
MenuFoldOutlined,
|
||||
MenuOutlined,
|
||||
MenuUnfoldOutlined,
|
||||
RightOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
ShopOutlined,
|
||||
ShoppingOutlined,
|
||||
TagOutlined,
|
||||
TeamOutlined,
|
||||
UserOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { adminAuthApi, type UserVO } from '@/api/admin'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import {
|
||||
getAdminCurrentShopName,
|
||||
getAdminRoleLabel,
|
||||
getAdminShopOptions,
|
||||
isBootstrapAdminUser
|
||||
} from './admin-helpers'
|
||||
|
||||
type AdminMenuItem = {
|
||||
key: string
|
||||
icon: any
|
||||
label: string
|
||||
permissionCode: string
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
const collapsed = ref(false)
|
||||
const mobileDrawerOpen = ref(false)
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const selectedKeys = ref<string[]>([route.path])
|
||||
const selectedShopId = ref<string>()
|
||||
const shopSwitchLoading = ref(false)
|
||||
const { loadUserPermissions, hasPermission, clearPermissions, userPermissions } = usePermission()
|
||||
|
||||
const menuItems: AdminMenuItem[] = [
|
||||
{ key: '/admin', icon: HomeOutlined, label: '首页', permissionCode: '' },
|
||||
{ key: '/admin/dashboard', icon: DashboardOutlined, label: '仪表盘', permissionCode: 'dashboard:view' },
|
||||
{ key: '/admin/users', icon: UserOutlined, label: '用户管理', permissionCode: 'user:view' },
|
||||
{ key: '/admin/products', icon: ShopOutlined, label: '作品管理', permissionCode: 'product:view' },
|
||||
{ key: '/admin/coupons', icon: GiftOutlined, label: '优惠券管理', permissionCode: 'coupon:view' },
|
||||
{ key: '/admin/shops', icon: HomeOutlined, label: '店铺管理', permissionCode: 'shop:view' },
|
||||
{ key: '/admin/permissions', icon: SafetyCertificateOutlined, label: '权限管理', permissionCode: 'permission:view' },
|
||||
{ key: '/admin/tags', icon: TagOutlined, label: '标签管理', permissionCode: 'tag:view' },
|
||||
{ key: '/admin/orders', icon: ShoppingOutlined, label: '订单管理', permissionCode: 'order:view' },
|
||||
{ key: '/admin/nail-artists', icon: TeamOutlined, label: '美甲师管理', permissionCode: 'nail_artist:view' }
|
||||
]
|
||||
|
||||
const mobileTabs = [
|
||||
{ key: 'workbench', label: '工作台', path: '/admin', icon: HomeOutlined },
|
||||
{ key: 'orders', label: '订单', path: '/admin/orders', icon: ShoppingOutlined },
|
||||
{ key: 'manage', label: '经营', path: '/admin/manage', icon: DashboardOutlined },
|
||||
{ key: 'profile', label: '我的', path: '/admin/profile', icon: UserOutlined }
|
||||
]
|
||||
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
const shopOptions = computed(() => getAdminShopOptions(userInfo.value))
|
||||
const shopSelectOptions = computed(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
const shopScopeText = computed(() => {
|
||||
if (!shopOptions.value.length) {
|
||||
return '游客模式'
|
||||
}
|
||||
return `可登录门店:${shopOptions.value.map(shop => shop.name).join(' / ')}`
|
||||
})
|
||||
|
||||
const filteredMenuItems = computed(() => {
|
||||
userPermissions.value
|
||||
let visibleItems = menuItems.filter(item => {
|
||||
if (!item.permissionCode) {
|
||||
return true
|
||||
}
|
||||
if (isBootstrapAdmin.value && item.key === '/admin/shops') {
|
||||
return true
|
||||
}
|
||||
return hasPermission(item.permissionCode)
|
||||
})
|
||||
if (isBootstrapAdmin.value) {
|
||||
visibleItems = visibleItems.filter(item => item.key === '/admin' || item.key === '/admin/shops')
|
||||
}
|
||||
return visibleItems
|
||||
})
|
||||
|
||||
const activeMobileTab = computed(() => {
|
||||
if (route.path === '/admin' || route.path === '/admin/dashboard') {
|
||||
return 'workbench'
|
||||
}
|
||||
if (route.path.startsWith('/admin/orders')) {
|
||||
return 'orders'
|
||||
}
|
||||
if (
|
||||
route.path === '/admin/manage' ||
|
||||
route.path.startsWith('/admin/users') ||
|
||||
route.path.startsWith('/admin/products') ||
|
||||
route.path.startsWith('/admin/coupons') ||
|
||||
route.path.startsWith('/admin/shops') ||
|
||||
route.path.startsWith('/admin/permissions') ||
|
||||
route.path.startsWith('/admin/tags') ||
|
||||
route.path.startsWith('/admin/nail-artists')
|
||||
) {
|
||||
return 'manage'
|
||||
}
|
||||
if (route.path.startsWith('/admin/profile')) {
|
||||
return 'profile'
|
||||
}
|
||||
return 'workbench'
|
||||
})
|
||||
|
||||
const currentMobileSectionLabel = computed(() => {
|
||||
switch (activeMobileTab.value) {
|
||||
case 'orders':
|
||||
return '订单'
|
||||
case 'manage':
|
||||
return '经营'
|
||||
case 'profile':
|
||||
return '我的'
|
||||
default:
|
||||
return '工作台'
|
||||
}
|
||||
})
|
||||
|
||||
const currentMobileTitle = computed(() => {
|
||||
const currentMenu = menuItems.find(item => item.key === route.path)
|
||||
if (currentMenu) {
|
||||
return currentMenu.label
|
||||
}
|
||||
if (route.path === '/admin/manage') {
|
||||
return '经营模块'
|
||||
}
|
||||
if (route.path === '/admin/profile') {
|
||||
return '账号与门店'
|
||||
}
|
||||
return '后台管理'
|
||||
})
|
||||
|
||||
const persistAdminSession = (payload: any) => {
|
||||
localStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
localStorage.setItem('adminRefreshToken', payload.refreshToken)
|
||||
localStorage.setItem('adminUserInfo', JSON.stringify(payload.userInfo))
|
||||
sessionStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
}
|
||||
|
||||
const toggleCollapsed = () => {
|
||||
collapsed.value = !collapsed.value
|
||||
}
|
||||
|
||||
const handleMenuClick = (info: any) => {
|
||||
router.push(info.key)
|
||||
}
|
||||
|
||||
const openPathFromDrawer = (path: string) => {
|
||||
mobileDrawerOpen.value = false
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
const openProfileFromDrawer = () => {
|
||||
openPathFromDrawer('/admin/profile')
|
||||
}
|
||||
|
||||
const handleMobileTabClick = (path: string) => {
|
||||
if (route.path !== path) {
|
||||
router.push(path)
|
||||
}
|
||||
}
|
||||
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出登录',
|
||||
content: '退出后需要重新登录后台。',
|
||||
okText: '确认',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
await runWithGlobalLoading(async () => {
|
||||
try {
|
||||
await adminAuthApi.logout()
|
||||
} catch (error) {
|
||||
console.error('退出失败:', error)
|
||||
} finally {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
clearPermissions()
|
||||
message.success('已退出登录')
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const cache = localStorage.getItem('adminUserInfo')
|
||||
if (cache) {
|
||||
userInfo.value = JSON.parse(cache)
|
||||
}
|
||||
if (!userInfo.value) {
|
||||
return
|
||||
}
|
||||
selectedShopId.value = userInfo.value.shopId ? String(userInfo.value.shopId) : undefined
|
||||
} catch (error) {
|
||||
console.error('获取后台用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleShopChange = async (shopId: unknown) => {
|
||||
if (typeof shopId !== 'string' && typeof shopId !== 'number') {
|
||||
return
|
||||
}
|
||||
const normalizedShopId = String(shopId)
|
||||
if (!normalizedShopId || normalizedShopId === String(userInfo.value?.shopId || '')) {
|
||||
return
|
||||
}
|
||||
shopSwitchLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
const response = await adminAuthApi.switchShop(normalizedShopId)
|
||||
persistAdminSession(response as any)
|
||||
await fetchUserInfo()
|
||||
await loadUserPermissions()
|
||||
})
|
||||
message.success('门店上下文已切换')
|
||||
window.location.reload()
|
||||
} catch (error: any) {
|
||||
console.error('切换门店失败:', error)
|
||||
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
|
||||
message.error(error?.message || '切换门店失败')
|
||||
} finally {
|
||||
shopSwitchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
newPath => {
|
||||
selectedKeys.value = menuItems.some(item => item.key === newPath) ? [newPath] : []
|
||||
mobileDrawerOpen.value = false
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchUserInfo()
|
||||
if (isBootstrapAdmin.value) {
|
||||
clearPermissions()
|
||||
return
|
||||
}
|
||||
await loadUserPermissions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-layout {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.sider {
|
||||
background:
|
||||
linear-gradient(
|
||||
180deg,
|
||||
var(--admin-mobile-shell-start) 0%,
|
||||
var(--admin-mobile-shell-mid) 48%,
|
||||
var(--admin-mobile-shell-end) 100%
|
||||
);
|
||||
overflow: auto;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 248, 240, 0.14);
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
margin: 0;
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
padding: 0 24px;
|
||||
background: rgba(255, 249, 242, 0.96);
|
||||
box-shadow: 0 10px 24px rgba(145, 102, 82, 0.08);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
.header-shell {
|
||||
width: 100%;
|
||||
max-width: var(--admin-content-max-width);
|
||||
margin: 0 auto;
|
||||
min-height: 64px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.trigger {
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.shop-hint,
|
||||
.shop-switcher,
|
||||
.shop-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-height: 40px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
background: var(--admin-mobile-surface-alt);
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.shop-hint {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.shop-switcher-label {
|
||||
font-size: 13px;
|
||||
color: var(--admin-mobile-muted);
|
||||
}
|
||||
|
||||
.shop-select {
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.shop-pill {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.user-dropdown {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 10px;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
.user-dropdown:hover {
|
||||
background: rgba(204, 123, 95, 0.1);
|
||||
}
|
||||
|
||||
.username {
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.content {
|
||||
margin-left: 240px;
|
||||
min-height: calc(100vh - 64px);
|
||||
padding: 24px;
|
||||
background:
|
||||
linear-gradient(180deg, #fbf6f0 0%, #f4e8dc 100%);
|
||||
transition: margin-left 0.2s;
|
||||
}
|
||||
|
||||
.content-shell {
|
||||
width: 100%;
|
||||
max-width: var(--admin-content-max-width);
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-layout-sider-collapsed) + .ant-layout .content {
|
||||
margin-left: 80px;
|
||||
}
|
||||
|
||||
.mobile-shell {
|
||||
min-height: 100vh;
|
||||
background:
|
||||
linear-gradient(180deg, var(--admin-mobile-shell-mid) 0 132px, var(--admin-mobile-surface) 132px 100%);
|
||||
}
|
||||
|
||||
.mobile-topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 120;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
|
||||
background: var(--admin-mobile-shell-glass);
|
||||
backdrop-filter: blur(16px);
|
||||
}
|
||||
|
||||
.mobile-icon-btn,
|
||||
.mobile-avatar-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 14px;
|
||||
background: var(--admin-mobile-shell-soft);
|
||||
color: #fff8f1;
|
||||
}
|
||||
|
||||
.mobile-title-block {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.mobile-eyebrow {
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
color: rgba(247, 242, 235, 0.68);
|
||||
}
|
||||
|
||||
.mobile-title {
|
||||
color: #f7f2eb;
|
||||
font-size: 18px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.mobile-context {
|
||||
padding: 0 16px 16px;
|
||||
color: #fff8f1;
|
||||
}
|
||||
|
||||
.mobile-context__primary {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.mobile-context__secondary {
|
||||
margin-top: 4px;
|
||||
color: rgba(255, 248, 241, 0.74);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.mobile-content {
|
||||
padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.mobile-tabbar {
|
||||
position: fixed;
|
||||
left: 12px;
|
||||
right: 12px;
|
||||
bottom: 12px;
|
||||
z-index: 130;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
padding: 10px;
|
||||
background: rgba(150, 103, 82, 0.92);
|
||||
border: 1px solid rgba(255, 248, 241, 0.16);
|
||||
border-radius: 24px;
|
||||
box-shadow: 0 16px 40px rgba(146, 103, 82, 0.24);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
|
||||
.mobile-tabbar__item {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: 6px;
|
||||
padding: 10px 4px;
|
||||
border: 0;
|
||||
border-radius: 18px;
|
||||
background: transparent;
|
||||
color: rgba(255, 248, 241, 0.68);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.mobile-tabbar__item.is-active {
|
||||
background: rgba(255, 248, 241, 0.16);
|
||||
color: #fff7ef;
|
||||
}
|
||||
|
||||
.mobile-tabbar__item :deep(.anticon) {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.drawer-account {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 18px;
|
||||
border-radius: 24px;
|
||||
color: #fff8f1;
|
||||
background:
|
||||
radial-gradient(circle at top right, rgba(255, 244, 232, 0.2), transparent 42%),
|
||||
radial-gradient(circle at left top, rgba(232, 195, 169, 0.22), transparent 44%),
|
||||
linear-gradient(
|
||||
160deg,
|
||||
var(--admin-mobile-shell-start) 0%,
|
||||
var(--admin-mobile-shell-mid) 58%,
|
||||
var(--admin-mobile-shell-end) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.drawer-account__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.drawer-account__title {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.drawer-account__meta {
|
||||
margin-top: 4px;
|
||||
font-size: 13px;
|
||||
color: rgba(255, 248, 241, 0.8);
|
||||
}
|
||||
|
||||
.drawer-shop-card {
|
||||
margin-top: 18px;
|
||||
padding: 18px;
|
||||
border-radius: 22px;
|
||||
background: var(--admin-mobile-card);
|
||||
border: 1px solid var(--admin-mobile-border);
|
||||
box-shadow: 0 12px 24px rgba(144, 103, 84, 0.08);
|
||||
}
|
||||
|
||||
.drawer-shop-card__label {
|
||||
font-size: 12px;
|
||||
color: var(--admin-mobile-muted);
|
||||
}
|
||||
|
||||
.drawer-shop-card__value {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: var(--admin-mobile-ink);
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.drawer-shop-card__desc {
|
||||
margin: 8px 0 14px;
|
||||
color: var(--admin-mobile-muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.drawer-section {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.drawer-section__title {
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
color: #6f594e;
|
||||
}
|
||||
|
||||
.drawer-link {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 0;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--admin-mobile-border);
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.drawer-link:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.drawer-link__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 14px;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
color: #9e5a44;
|
||||
}
|
||||
|
||||
.drawer-link__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.drawer-link__title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.drawer-link__meta {
|
||||
margin-top: 4px;
|
||||
color: var(--admin-mobile-muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.drawer-link__arrow {
|
||||
color: #b39384;
|
||||
}
|
||||
|
||||
.mobile-drawer :deep(.ant-drawer-body) {
|
||||
padding: calc(18px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
|
||||
background: var(--admin-mobile-surface);
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu),
|
||||
.sider :deep(.ant-menu-dark) {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu-item) {
|
||||
width: calc(100% - 24px);
|
||||
margin: 6px 12px;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu-dark .ant-menu-item),
|
||||
.sider :deep(.ant-menu-dark .ant-menu-submenu-title) {
|
||||
color: rgba(255, 248, 241, 0.8);
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu-dark .ant-menu-item:hover),
|
||||
.sider :deep(.ant-menu-dark .ant-menu-submenu-title:hover) {
|
||||
color: #fff8f1;
|
||||
background: rgba(255, 248, 241, 0.12);
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu-dark .ant-menu-item-selected) {
|
||||
color: #fff8f1;
|
||||
background: rgba(255, 248, 241, 0.18);
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-btn-primary) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, var(--admin-mobile-accent) 0%, var(--admin-mobile-accent-strong) 100%);
|
||||
box-shadow: 0 10px 20px rgba(185, 100, 73, 0.18);
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-btn-primary:hover),
|
||||
.admin-layout :deep(.ant-btn-primary:focus) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, #d4866c 0%, #c26e52 100%);
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-select:not(.ant-select-disabled):hover .ant-select-selector),
|
||||
.admin-layout :deep(.ant-input:hover),
|
||||
.admin-layout :deep(.ant-input-affix-wrapper:hover) {
|
||||
border-color: rgba(204, 123, 95, 0.45);
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-select-focused .ant-select-selector),
|
||||
.admin-layout :deep(.ant-input:focus),
|
||||
.admin-layout :deep(.ant-input-affix-wrapper-focused) {
|
||||
border-color: rgba(204, 123, 95, 0.6);
|
||||
box-shadow: 0 0 0 2px rgba(204, 123, 95, 0.12);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,458 @@
|
||||
<template>
|
||||
<div class="admin-login">
|
||||
<div class="login-container">
|
||||
<div class="login-header">
|
||||
<h1>后台管理系统</h1>
|
||||
<p>欢迎回来,请登录您的账户</p>
|
||||
</div>
|
||||
|
||||
<a-card class="login-card">
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
layout="vertical"
|
||||
@finish="handleLogin"
|
||||
>
|
||||
<a-alert
|
||||
v-if="loginShopMessage"
|
||||
:type="allowShoplessLogin || hasAvailableShops ? 'info' : 'warning'"
|
||||
show-icon
|
||||
:message="loginShopMessage"
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<a-form-item label="用户名" name="account">
|
||||
<a-input
|
||||
v-model:value="formState.account"
|
||||
size="large"
|
||||
placeholder="请输入用户名"
|
||||
:prefix-icon="UserOutlined"
|
||||
@input="handleAccountInput"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="formState.password"
|
||||
size="large"
|
||||
placeholder="请输入密码"
|
||||
:prefix-icon="LockOutlined"
|
||||
@pressEnter="handleLogin"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="登录店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
size="large"
|
||||
:placeholder="shopPlaceholder"
|
||||
:loading="shopLoading"
|
||||
:options="shopOptions"
|
||||
:disabled="shopLoading || (!hasAvailableShops && !allowShoplessLogin)"
|
||||
show-search
|
||||
:filter-option="filterShopOption"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
size="large"
|
||||
html-type="submit"
|
||||
:loading="loading"
|
||||
block
|
||||
>
|
||||
登录
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
|
||||
<div class="login-footer">
|
||||
<a @click="goToFrontend">返回前台</a>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
import { adminAuthApi, type LoginShopSelectionResponse } from '@/api/admin'
|
||||
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const shopLoading = ref(false)
|
||||
const shops = ref<Array<{ id: IdType; shopName: string }>>([])
|
||||
const allowShoplessLogin = ref(false)
|
||||
const loginShopMessage = ref('')
|
||||
const { loadUserPermissions } = usePermission()
|
||||
|
||||
const formState = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
shopId: undefined as string | undefined
|
||||
})
|
||||
let loginShopTimer: number | undefined
|
||||
|
||||
const handleAccountInput = () => {
|
||||
const normalized = sanitizeAccountInput(formState.account)
|
||||
if (normalized !== formState.account) {
|
||||
formState.account = normalized
|
||||
}
|
||||
}
|
||||
|
||||
const getShopIdValue = (shop: { id: IdType; shopName: string }) => String(shop.id ?? '')
|
||||
const getShopLabel = (shop: { id: IdType; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`)
|
||||
|
||||
const shopOptions = computed(() =>
|
||||
shops.value.map(shop => ({
|
||||
label: getShopLabel(shop),
|
||||
value: getShopIdValue(shop)
|
||||
}))
|
||||
)
|
||||
const hasAvailableShops = computed(() => shopOptions.value.length > 0)
|
||||
const shouldRequireShop = computed(() => hasAvailableShops.value && !allowShoplessLogin.value)
|
||||
const shopPlaceholder = computed(() => {
|
||||
if (allowShoplessLogin.value) {
|
||||
return '当前无需选择店铺'
|
||||
}
|
||||
if (shopLoading.value) {
|
||||
return '正在加载可登录店铺'
|
||||
}
|
||||
if (hasAvailableShops.value) {
|
||||
return '请选择登录店铺'
|
||||
}
|
||||
return '请先输入账号'
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
account: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
shopId: [{
|
||||
validator: async () => {
|
||||
if (!shouldRequireShop.value || formState.shopId) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return Promise.reject(new Error('请选择登录店铺'))
|
||||
},
|
||||
trigger: 'change'
|
||||
}]
|
||||
} as any
|
||||
|
||||
const filterShopOption = (input: string, option: { label?: string | number } | undefined) =>
|
||||
String(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
|
||||
const isLoginShopPrefetchUnsupported = (error: unknown) => {
|
||||
const status = (error as any)?.response?.status
|
||||
return status === 404
|
||||
}
|
||||
|
||||
const resetLoginShopTimer = () => {
|
||||
if (loginShopTimer !== undefined) {
|
||||
window.clearTimeout(loginShopTimer)
|
||||
loginShopTimer = undefined
|
||||
}
|
||||
}
|
||||
|
||||
const restoreLoginShop = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(cached)
|
||||
if (parsed?.shopId) {
|
||||
formState.shopId = String(parsed.shopId)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('恢复后台登录店铺失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const applyLoginShopSelection = (selection?: LoginShopSelectionResponse | null) => {
|
||||
shops.value = selection?.shops || []
|
||||
allowShoplessLogin.value = Boolean(selection?.allowShoplessLogin)
|
||||
loginShopMessage.value = selection?.message || ''
|
||||
|
||||
if (allowShoplessLogin.value) {
|
||||
formState.shopId = undefined
|
||||
return
|
||||
}
|
||||
|
||||
if (!shops.value.length) {
|
||||
formState.shopId = undefined
|
||||
return
|
||||
}
|
||||
|
||||
const matchedShop = shops.value.find(shop => getShopIdValue(shop) === formState.shopId)
|
||||
if (matchedShop) {
|
||||
return
|
||||
}
|
||||
|
||||
if (shops.value.length === 1) {
|
||||
formState.shopId = getShopIdValue(shops.value[0]!)
|
||||
return
|
||||
}
|
||||
|
||||
formState.shopId = undefined
|
||||
}
|
||||
|
||||
const loadLoginShops = async (account = formState.account) => {
|
||||
const trimmedAccount = account.trim()
|
||||
if (!trimmedAccount) {
|
||||
applyLoginShopSelection(null)
|
||||
return
|
||||
}
|
||||
|
||||
shopLoading.value = true
|
||||
try {
|
||||
const selection = await adminAuthApi.getLoginShops(trimmedAccount) as unknown as LoginShopSelectionResponse
|
||||
if (formState.account.trim() === trimmedAccount) {
|
||||
applyLoginShopSelection(selection)
|
||||
}
|
||||
} catch (error) {
|
||||
if (formState.account.trim() === trimmedAccount) {
|
||||
if (isLoginShopPrefetchUnsupported(error)) {
|
||||
applyLoginShopSelection({
|
||||
allowShoplessLogin: true,
|
||||
message: '当前环境暂未开放登录前店铺预加载,可直接登录。',
|
||||
shops: []
|
||||
})
|
||||
} else {
|
||||
applyLoginShopSelection(null)
|
||||
loginShopMessage.value = '登录店铺加载失败,请稍后重试'
|
||||
}
|
||||
}
|
||||
if (!isLoginShopPrefetchUnsupported(error)) {
|
||||
console.error('获取登录店铺列表失败:', error)
|
||||
}
|
||||
} finally {
|
||||
shopLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
loading.value = true
|
||||
|
||||
const res = await runWithGlobalLoading(() => adminAuthApi.login({
|
||||
account: formState.account,
|
||||
password: formState.password,
|
||||
shopId: formState.shopId
|
||||
}))
|
||||
|
||||
|
||||
const { accessToken, refreshToken, userInfo } = res as any
|
||||
|
||||
localStorage.setItem('adminAccessToken', accessToken)
|
||||
localStorage.setItem('adminRefreshToken', refreshToken)
|
||||
localStorage.setItem('adminUserInfo', JSON.stringify(userInfo))
|
||||
sessionStorage.setItem('adminAccessToken', accessToken)
|
||||
|
||||
|
||||
message.success('登录成功')
|
||||
|
||||
await runWithGlobalLoading(() => loadUserPermissions())
|
||||
|
||||
router.push('/admin').catch(err => {
|
||||
console.error('跳转到首页失败:', err)
|
||||
window.location.href = '/admin'
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('登录失败:', error)
|
||||
message.error(error.message || '登录失败,请检查用户名和密码')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
restoreLoginShop()
|
||||
})
|
||||
|
||||
watch(
|
||||
() => formState.account,
|
||||
value => {
|
||||
resetLoginShopTimer()
|
||||
const trimmedAccount = value.trim()
|
||||
if (!trimmedAccount) {
|
||||
applyLoginShopSelection(null)
|
||||
return
|
||||
}
|
||||
loginShopTimer = window.setTimeout(() => {
|
||||
loginShopTimer = undefined
|
||||
void loadLoginShops(trimmedAccount)
|
||||
}, 400)
|
||||
}
|
||||
)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
resetLoginShopTimer()
|
||||
})
|
||||
|
||||
const goToFrontend = () => {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/'
|
||||
}, 100)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-login {
|
||||
min-height: 100dvh;
|
||||
background:
|
||||
radial-gradient(circle at top right, rgba(255, 244, 232, 0.2), transparent 30%),
|
||||
radial-gradient(circle at left top, rgba(233, 193, 167, 0.18), transparent 38%),
|
||||
linear-gradient(
|
||||
160deg,
|
||||
var(--admin-mobile-shell-start) 0%,
|
||||
var(--admin-mobile-shell-mid) 56%,
|
||||
var(--admin-mobile-shell-end) 100%
|
||||
);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.login-container {
|
||||
width: 100%;
|
||||
max-width: 440px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 28px;
|
||||
color: #f7f2eb;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: clamp(28px, 4vw, 38px);
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
font-size: 14px;
|
||||
line-height: 1.7;
|
||||
opacity: 0.82;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
border-radius: 24px;
|
||||
border: 1px solid var(--admin-mobile-border);
|
||||
box-shadow: 0 24px 50px rgba(146, 103, 82, 0.18);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
text-align: center;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.login-footer a {
|
||||
color: #fff3ea;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.login-footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-card-body) {
|
||||
background: rgba(255, 250, 244, 0.98);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-btn-primary) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, var(--admin-mobile-accent) 0%, var(--admin-mobile-accent-strong) 100%);
|
||||
box-shadow: 0 10px 22px rgba(185, 100, 73, 0.18);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-btn-primary:hover),
|
||||
.login-card :deep(.ant-btn-primary:focus) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, #d4866c 0%, #c26e52 100%);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-input:hover),
|
||||
.login-card :deep(.ant-input-affix-wrapper:hover),
|
||||
.login-card :deep(.ant-select:not(.ant-select-disabled):hover .ant-select-selector) {
|
||||
border-color: rgba(204, 123, 95, 0.46);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-input:focus),
|
||||
.login-card :deep(.ant-input-affix-wrapper-focused),
|
||||
.login-card :deep(.ant-select-focused .ant-select-selector) {
|
||||
border-color: rgba(204, 123, 95, 0.62);
|
||||
box-shadow: 0 0 0 2px rgba(204, 123, 95, 0.12);
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.admin-login {
|
||||
align-items: flex-start;
|
||||
justify-content: stretch;
|
||||
padding: calc(22px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.login-container {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: left;
|
||||
margin-bottom: 18px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
max-width: 8em;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
border-radius: 26px;
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-card-body) {
|
||||
padding: 20px 18px 18px;
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-form-item) {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-btn-lg),
|
||||
.login-card :deep(.ant-input-affix-wrapper-lg),
|
||||
.login-card :deep(.ant-input-lg),
|
||||
.login-card :deep(.ant-select-single.ant-select-lg .ant-select-selector) {
|
||||
min-height: 48px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,821 @@
|
||||
<template>
|
||||
<div class="coupons">
|
||||
<a-page-header v-if="!isMobile" title="优惠券管理" sub-title="管理系统优惠券" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">优惠券管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">优惠券 {{ couponList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
优惠券列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索优惠券名称"
|
||||
:style="isMobile ? { width: '100%' } : { width: '260px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="!isMobile && hasPermission('coupon:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增优惠券
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="couponList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'shop'">
|
||||
{{ record.shopName || '未指定店铺' }}
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'couponType'">
|
||||
<a-tag :color="record.couponType === 1 ? 'blue' : 'green'">
|
||||
{{ record.couponTypeName || (record.couponType === 1 ? '折扣券' : '满减券') }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'couponScene'">
|
||||
<a-tag :color="record.couponScene === 'VIP_AUTO' ? 'gold' : 'default'">
|
||||
{{ getCouponSceneText(record.couponScene) }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'requiredVipLevel'">
|
||||
{{ record.requiredVipLevel || '-' }}
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'value'">
|
||||
<template v-if="record.couponType === 1">
|
||||
{{ record.discountValue }} 折
|
||||
</template>
|
||||
<template v-else>
|
||||
满 {{ record.minAmount }} 减 {{ record.reduceAmount }}
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="getStatusColor(record.status || 1)">
|
||||
{{ record.statusName || '未知' }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space wrap>
|
||||
<a-button v-if="hasPermission('coupon:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('coupon:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('coupon:assign') && !isVipAutoCoupon(record) && record.status === 1"
|
||||
type="link"
|
||||
size="small"
|
||||
@click="showDistributeModal(record)"
|
||||
>
|
||||
发放
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('coupon:delete') && record.status !== 2"
|
||||
type="link"
|
||||
size="small"
|
||||
danger
|
||||
@click="handleDelete(record)"
|
||||
>
|
||||
删除
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="couponList" empty-description="暂无优惠券数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.couponName }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || '未指定店铺' }}</div>
|
||||
</div>
|
||||
<a-tag :color="getStatusColor(item.status || 1)">
|
||||
{{ item.statusName || '未知' }}
|
||||
</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>类型</span>
|
||||
<strong>{{ item.couponType === 1 ? '折扣券' : '满减券' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>场景</span>
|
||||
<strong>{{ getCouponSceneText(item.couponScene) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>优惠值</span>
|
||||
<strong>{{ getCouponValueText(item) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>剩余数量</span>
|
||||
<strong>{{ item.remainingCount ?? '-' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button v-if="hasPermission('coupon:view')" size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('coupon:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('coupon:assign') && !isVipAutoCoupon(item) && item.status === 1"
|
||||
size="small"
|
||||
@click="showDistributeModal(item)"
|
||||
>
|
||||
发放
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('coupon:delete') && item.status !== 2"
|
||||
size="small"
|
||||
danger
|
||||
@click="handleDelete(item)"
|
||||
>
|
||||
删除
|
||||
</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑优惠券' : '新增优惠券'"
|
||||
:desktop-width="820"
|
||||
:confirm-loading="modalLoading"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="优惠券名称" name="couponName">
|
||||
<a-input v-model:value="formState.couponName" placeholder="请输入优惠券名称" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择所属店铺"
|
||||
:loading="loadingShops"
|
||||
:disabled="currentUserInfo?.type === 2"
|
||||
>
|
||||
<a-select-option v-for="shop in shops" :key="shop.id" :value="shop.id">
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="优惠券类型" name="couponType">
|
||||
<a-select v-model:value="formState.couponType" placeholder="请选择优惠券类型">
|
||||
<a-select-option :value="1">折扣券</a-select-option>
|
||||
<a-select-option :value="2">满减券</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="优惠场景" name="couponScene">
|
||||
<a-select v-model:value="formState.couponScene" placeholder="请选择优惠场景">
|
||||
<a-select-option value="GENERAL">普通券</a-select-option>
|
||||
<a-select-option value="VIP_AUTO">VIP 自动券</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="自动匹配">
|
||||
<a-switch :checked="formState.autoMatch === 1" @change="(checked: any) => handleAutoMatchChange(checked === true)" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="isVipAutoForm" label="所需 VIP 等级" name="requiredVipLevel">
|
||||
<a-select v-model:value="formState.requiredVipLevel" placeholder="请选择 VIP 等级">
|
||||
<a-select-option value="青铜">青铜</a-select-option>
|
||||
<a-select-option value="白银">白银</a-select-option>
|
||||
<a-select-option value="黄金">黄金</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="formState.couponType === 1" label="折扣值" name="discountValue">
|
||||
<a-input-number v-model:value="formState.discountValue" :min="0.1" :max="9.9" :step="0.1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="formState.couponType === 2" label="最低消费" name="minAmount">
|
||||
<a-input-number v-model:value="formState.minAmount" :min="0" :step="0.01" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="formState.couponType === 2" label="减免金额" name="reduceAmount">
|
||||
<a-input-number v-model:value="formState.reduceAmount" :min="0" :step="0.01" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="总数量" name="totalCount">
|
||||
<a-input-number v-model:value="formState.totalCount" :min="1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="开始时间" name="startTime">
|
||||
<a-date-picker v-model:value="formState.startTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="结束时间" name="endTime">
|
||||
<a-date-picker v-model:value="formState.endTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="可用标签" name="availableTagIds">
|
||||
<a-select v-model:value="formState.availableTagIds" mode="multiple" placeholder="请选择可用标签">
|
||||
<a-select-option v-for="tag in tagList" :key="tag.id" :value="tag.id">
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="不可用标签" name="unavailableTagIds">
|
||||
<a-select v-model:value="formState.unavailableTagIds" mode="multiple" placeholder="请选择不可用标签">
|
||||
<a-select-option v-for="tag in tagList" :key="tag.id" :value="tag.id">
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看优惠券详情"
|
||||
:footer="null"
|
||||
:desktop-width="760"
|
||||
@cancel="viewModalVisible = false"
|
||||
>
|
||||
<a-descriptions bordered :column="1" size="small">
|
||||
<a-descriptions-item label="优惠券名称">{{ currentCoupon?.couponName || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="所属店铺">{{ currentCoupon?.shopName || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠券类型">{{ currentCoupon?.couponType === 1 ? '折扣券' : '满减券' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠场景">{{ getCouponSceneText(currentCoupon?.couponScene) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="所需 VIP 等级">{{ currentCoupon?.requiredVipLevel || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="自动匹配">{{ currentCoupon?.autoMatch === 1 ? '是' : '否' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠信息">{{ getCouponValueText(currentCoupon) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="总数量">{{ currentCoupon?.totalCount ?? '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="已使用">{{ currentCoupon?.usedCount ?? '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="开始时间">{{ currentCoupon?.startTime || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="结束时间">{{ currentCoupon?.endTime || '-' }}</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="distributeModalVisible"
|
||||
title="发放优惠券"
|
||||
:desktop-width="760"
|
||||
:confirm-loading="distributeLoading"
|
||||
@ok="handleDistributeOk"
|
||||
@cancel="handleDistributeCancel"
|
||||
>
|
||||
<a-form
|
||||
ref="distributeFormRef"
|
||||
:model="distributeFormState"
|
||||
:rules="distributeFormRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="优惠券">
|
||||
<a-input v-model:value="distributeFormState.couponName" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="选择用户" name="userIds">
|
||||
<a-select
|
||||
v-model:value="distributeFormState.userIds"
|
||||
mode="multiple"
|
||||
placeholder="请选择要发放的用户"
|
||||
>
|
||||
<a-select-option v-for="user in userList" :key="user.id" :value="user.id">
|
||||
{{ user.nickname }}({{ user.account }})
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="发放数量" name="quantity">
|
||||
<a-input-number v-model:value="distributeFormState.quantity" :min="1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && hasPermission('coupon:create') && !modalVisible && !viewModalVisible && !distributeModalVisible"
|
||||
label="新增优惠券"
|
||||
@click="showAddModal"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import dayjs, { type Dayjs } from 'dayjs'
|
||||
import {
|
||||
adminCouponApi,
|
||||
adminShopApi,
|
||||
adminTagApi,
|
||||
adminUserApi,
|
||||
type Coupon,
|
||||
type Shop,
|
||||
type Tag,
|
||||
type UserVO
|
||||
} from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
const currentUserInfo = (() => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
return userInfoStr ? JSON.parse(userInfoStr) : null
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
return null
|
||||
}
|
||||
})()
|
||||
|
||||
interface CouponFormState {
|
||||
couponCode: string
|
||||
couponName: string
|
||||
couponType: number
|
||||
discountValue?: number
|
||||
minAmount?: number
|
||||
reduceAmount?: number
|
||||
totalCount: number
|
||||
startTime?: Dayjs
|
||||
endTime?: Dayjs
|
||||
availableTagIds: number[]
|
||||
unavailableTagIds: number[]
|
||||
shopId?: number
|
||||
couponScene: string
|
||||
requiredVipLevel?: string
|
||||
autoMatch: number
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const distributeFormRef = ref<FormInstance>()
|
||||
const currentCoupon = ref<Coupon | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
const couponList = ref<Coupon[]>([])
|
||||
const tagList = ref<Tag[]>([])
|
||||
const userList = ref<UserVO[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
|
||||
const distributeModalVisible = ref(false)
|
||||
const distributeLoading = ref(false)
|
||||
const currentDistributeCoupon = ref<Coupon | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive<CouponFormState>({
|
||||
couponCode: '',
|
||||
couponName: '',
|
||||
couponType: 1,
|
||||
discountValue: 9.5,
|
||||
minAmount: 100,
|
||||
reduceAmount: 20,
|
||||
totalCount: 100,
|
||||
startTime: dayjs(),
|
||||
endTime: dayjs().add(30, 'day'),
|
||||
availableTagIds: [],
|
||||
unavailableTagIds: [],
|
||||
shopId: undefined,
|
||||
couponScene: 'GENERAL',
|
||||
requiredVipLevel: undefined,
|
||||
autoMatch: 0
|
||||
})
|
||||
|
||||
const distributeFormState = reactive({
|
||||
couponName: '',
|
||||
userIds: [] as number[],
|
||||
quantity: 1
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
couponName: [{ required: true, message: '请输入优惠券名称', trigger: 'blur' }],
|
||||
couponType: [{ required: true, message: '请选择优惠券类型', trigger: 'change' }],
|
||||
couponScene: [{ required: true, message: '请选择优惠场景', trigger: 'change' }],
|
||||
requiredVipLevel: [{ required: true, message: '请选择所需 VIP 等级', trigger: 'change' }],
|
||||
totalCount: [{ required: true, message: '请输入优惠券总数量', trigger: 'blur' }],
|
||||
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
|
||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
const distributeFormRules = {
|
||||
userIds: [{ required: true, message: '请选择要发放的用户', trigger: 'change' }],
|
||||
quantity: [{ required: true, message: '请输入发放数量', trigger: 'blur' }]
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
||||
{ title: '所属店铺', key: 'shop', width: 140 },
|
||||
{ title: '类型', key: 'couponType', width: 100 },
|
||||
{ title: '场景', key: 'couponScene', width: 120 },
|
||||
{ title: '所需 VIP', key: 'requiredVipLevel', width: 110 },
|
||||
{ title: '优惠信息', key: 'value', width: 170 },
|
||||
{ title: '总数量', dataIndex: 'totalCount', key: 'totalCount', width: 90 },
|
||||
{ title: '已使用', dataIndex: 'usedCount', key: 'usedCount', width: 90 },
|
||||
{ title: '剩余', dataIndex: 'remainingCount', key: 'remainingCount', width: 90 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '操作', key: 'actions', width: 180, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const isVipAutoForm = computed(() => formState.couponScene === 'VIP_AUTO' || formState.autoMatch === 1)
|
||||
|
||||
const getStatusColor = (status: number) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return 'green'
|
||||
case 2:
|
||||
return 'red'
|
||||
case 3:
|
||||
return 'orange'
|
||||
default:
|
||||
return 'default'
|
||||
}
|
||||
}
|
||||
|
||||
const getCouponSceneText = (scene?: string) => {
|
||||
if (scene === 'VIP_AUTO') {
|
||||
return 'VIP 自动券'
|
||||
}
|
||||
return '普通券'
|
||||
}
|
||||
|
||||
const isVipAutoCoupon = (coupon: any) => coupon?.couponScene === 'VIP_AUTO' || coupon?.autoMatch === 1
|
||||
|
||||
const getCouponValueText = (coupon: Coupon | null) => {
|
||||
if (!coupon) {
|
||||
return '-'
|
||||
}
|
||||
return coupon.couponType === 1
|
||||
? `${coupon.discountValue} 折`
|
||||
: `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
|
||||
}
|
||||
|
||||
const resetFormState = () => {
|
||||
Object.assign(formState, {
|
||||
couponCode: '',
|
||||
couponName: '',
|
||||
couponType: 1,
|
||||
discountValue: 9.5,
|
||||
minAmount: 100,
|
||||
reduceAmount: 20,
|
||||
totalCount: 100,
|
||||
startTime: dayjs(),
|
||||
endTime: dayjs().add(30, 'day'),
|
||||
availableTagIds: [],
|
||||
unavailableTagIds: [],
|
||||
shopId: currentUserInfo?.shopId || undefined,
|
||||
couponScene: 'GENERAL',
|
||||
requiredVipLevel: undefined,
|
||||
autoMatch: 0
|
||||
})
|
||||
}
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-coupons', isEdit.value ? 'edit' : 'create', currentCoupon.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
couponCode: formState.couponCode,
|
||||
couponName: formState.couponName,
|
||||
couponType: formState.couponType,
|
||||
discountValue: formState.discountValue,
|
||||
minAmount: formState.minAmount,
|
||||
reduceAmount: formState.reduceAmount,
|
||||
totalCount: formState.totalCount,
|
||||
startTime: formState.startTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
endTime: formState.endTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
availableTagIds: [...formState.availableTagIds],
|
||||
unavailableTagIds: [...formState.unavailableTagIds],
|
||||
shopId: formState.shopId,
|
||||
couponScene: formState.couponScene,
|
||||
requiredVipLevel: formState.requiredVipLevel,
|
||||
autoMatch: formState.autoMatch
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
|
||||
Object.assign(formState, {
|
||||
...draft.payload,
|
||||
startTime: draft.payload.startTime ? dayjs(draft.payload.startTime) : undefined,
|
||||
endTime: draft.payload.endTime ? dayjs(draft.payload.endTime) : undefined
|
||||
})
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => formState.couponScene,
|
||||
value => {
|
||||
if (value === 'VIP_AUTO') {
|
||||
formState.autoMatch = 1
|
||||
if (!formState.requiredVipLevel) {
|
||||
formState.requiredVipLevel = '青铜'
|
||||
}
|
||||
} else {
|
||||
formState.autoMatch = 0
|
||||
formState.requiredVipLevel = undefined
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const handleAutoMatchChange = (checked: boolean) => {
|
||||
formState.autoMatch = checked ? 1 : 0
|
||||
formState.couponScene = checked ? 'VIP_AUTO' : 'GENERAL'
|
||||
}
|
||||
|
||||
const fetchCoupons = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const shopId = currentUserInfo?.shopId || undefined
|
||||
const coupons = await adminCouponApi.listAllCoupons(shopId) as unknown as Coupon[]
|
||||
const list = Array.isArray(coupons) ? coupons : []
|
||||
const keyword = searchText.value.trim()
|
||||
couponList.value = keyword
|
||||
? list.filter(item => (item.couponName || '').includes(keyword))
|
||||
: list
|
||||
pagination.total = couponList.value.length
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败:', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchTags = async () => {
|
||||
try {
|
||||
const tags = await adminTagApi.listAllTags() as unknown as Tag[]
|
||||
tagList.value = tags || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const shopList = await adminShopApi.listAllShops() as unknown as Shop[]
|
||||
shops.value = shopList || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUsers = async () => {
|
||||
try {
|
||||
const params: Record<string, unknown> = { page: 1, size: 200 }
|
||||
if (currentUserInfo?.shopId) {
|
||||
params.shopId = currentUserInfo.shopId
|
||||
}
|
||||
const result = await adminUserApi.listUsers(params as any)
|
||||
userList.value = result.list || []
|
||||
} catch (error) {
|
||||
console.error('获取用户列表失败:', error)
|
||||
userList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = async () => {
|
||||
pagination.current = 1
|
||||
await runWithGlobalLoading(() => fetchCoupons())
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current || 1
|
||||
pagination.pageSize = pag.pageSize || pagination.pageSize
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentCoupon.value = null
|
||||
resetFormState()
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: any) => {
|
||||
isEdit.value = true
|
||||
currentCoupon.value = record
|
||||
Object.assign(formState, {
|
||||
couponCode: record.couponCode || '',
|
||||
couponName: record.couponName || '',
|
||||
couponType: record.couponType || 1,
|
||||
discountValue: record.discountValue ? Number(record.discountValue) : 9.5,
|
||||
minAmount: record.minAmount ? Number(record.minAmount) : 100,
|
||||
reduceAmount: record.reduceAmount ? Number(record.reduceAmount) : 20,
|
||||
totalCount: record.totalCount || 100,
|
||||
startTime: record.startTime ? dayjs(record.startTime) : undefined,
|
||||
endTime: record.endTime ? dayjs(record.endTime) : undefined,
|
||||
availableTagIds: record.availableTags?.map((tag: Tag) => tag.id) || [],
|
||||
unavailableTagIds: record.unavailableTags?.map((tag: Tag) => tag.id) || [],
|
||||
shopId: record.shopId,
|
||||
couponScene: record.couponScene || 'GENERAL',
|
||||
requiredVipLevel: record.requiredVipLevel || undefined,
|
||||
autoMatch: record.autoMatch || 0
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = (record: any) => {
|
||||
currentCoupon.value = record
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const buildCouponPayload = () => ({
|
||||
couponCode: formState.couponCode,
|
||||
couponName: formState.couponName,
|
||||
couponType: formState.couponType,
|
||||
discountValue: formState.couponType === 1 ? formState.discountValue : undefined,
|
||||
minAmount: formState.couponType === 2 ? formState.minAmount : undefined,
|
||||
reduceAmount: formState.couponType === 2 ? formState.reduceAmount : undefined,
|
||||
totalCount: formState.totalCount,
|
||||
startTime: formState.startTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
endTime: formState.endTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
availableTagIds: formState.availableTagIds,
|
||||
unavailableTagIds: formState.unavailableTagIds,
|
||||
shopId: formState.shopId,
|
||||
couponScene: formState.couponScene,
|
||||
requiredVipLevel: isVipAutoForm.value ? formState.requiredVipLevel : undefined,
|
||||
autoMatch: isVipAutoForm.value ? 1 : 0
|
||||
})
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
await runWithGlobalLoading(async () => {
|
||||
const payload = buildCouponPayload()
|
||||
if (isEdit.value && currentCoupon.value) {
|
||||
await adminCouponApi.updateCoupon(currentCoupon.value.id, payload)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminCouponApi.createCoupon(payload)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
await fetchCoupons()
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('保存优惠券失败:', error)
|
||||
message.error(error.message || '操作失败')
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
resetFormState()
|
||||
}
|
||||
|
||||
const handleDelete = (record: any) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
content: `确定要删除优惠券 ${record.couponName} 吗?`,
|
||||
async onOk() {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminCouponApi.deleteCoupon(record.id)
|
||||
message.success('删除成功')
|
||||
await fetchCoupons()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('删除优惠券失败:', error)
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const showDistributeModal = async (record: any) => {
|
||||
currentDistributeCoupon.value = record
|
||||
distributeFormState.couponName = record.couponName
|
||||
distributeFormState.userIds = []
|
||||
distributeFormState.quantity = 1
|
||||
await runWithGlobalLoading(() => fetchUsers())
|
||||
distributeModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleDistributeOk = async () => {
|
||||
if (!currentDistributeCoupon.value) {
|
||||
return
|
||||
}
|
||||
const couponId = currentDistributeCoupon.value.id
|
||||
if (isVipAutoCoupon(currentDistributeCoupon.value)) {
|
||||
message.warning('VIP 自动券为系统模板券,不能手动发放')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await distributeFormRef.value?.validate()
|
||||
distributeLoading.value = true
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminCouponApi.distributeCoupon({
|
||||
couponId,
|
||||
userIds: distributeFormState.userIds,
|
||||
quantity: distributeFormState.quantity
|
||||
})
|
||||
message.success('发放成功')
|
||||
distributeModalVisible.value = false
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('发放优惠券失败:', error)
|
||||
message.error(error.message || '发放失败')
|
||||
} finally {
|
||||
distributeLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleDistributeCancel = () => {
|
||||
distributeModalVisible.value = false
|
||||
distributeFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
await Promise.all([fetchTags(), fetchShops(), fetchCoupons()])
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.coupons {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,313 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<a-page-header
|
||||
v-if="!isMobile"
|
||||
title="仪表盘"
|
||||
:sub-title="pageSubtitle"
|
||||
/>
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">工作台</span>
|
||||
<h1 class="admin-page-intro__title">仪表盘</h1>
|
||||
<p class="admin-page-intro__subtitle">{{ pageSubtitle }}</p>
|
||||
</section>
|
||||
|
||||
<a-row :gutter="[16, 16]" class="stat-cards">
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic title="用户数" :value="stats.totalUsers" :loading="loading">
|
||||
<template #prefix>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic title="作品数" :value="stats.totalProducts" :loading="loading">
|
||||
<template #prefix>
|
||||
<ShopOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
|
||||
<a-col v-if="isAdmin" :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic title="门店数" :value="stats.totalShops" :loading="loading">
|
||||
<template #prefix>
|
||||
<HomeOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic title="今日订单" :value="stats.todayOrders" :loading="loading">
|
||||
<template #prefix>
|
||||
<ShoppingOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-row :gutter="[16, 16]">
|
||||
<a-col :xs="24" :xl="14">
|
||||
<a-card title="经营提醒" class="insight-card">
|
||||
<a-spin :spinning="loading">
|
||||
<div class="insight-list">
|
||||
<div v-for="item in insightItems" :key="item.title" class="insight-item">
|
||||
<div class="insight-title">{{ item.title }}</div>
|
||||
<div class="insight-description">{{ item.description }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-spin>
|
||||
</a-card>
|
||||
</a-col>
|
||||
|
||||
<a-col :xs="24" :xl="10">
|
||||
<a-card title="热门作品" class="side-card">
|
||||
<a-spin :spinning="loading">
|
||||
<a-empty v-if="!stats.hotProducts.length" description="暂时还没有热门作品数据" />
|
||||
<div v-else class="hot-list">
|
||||
<div v-for="item in stats.hotProducts" :key="item.id" class="hot-item">
|
||||
<div>
|
||||
<div class="hot-name">{{ item.title }}</div>
|
||||
<div class="hot-meta">点赞 {{ item.likeCount || 0 }} · 收藏 {{ item.collectCount || 0 }}</div>
|
||||
</div>
|
||||
<div class="hot-price">¥{{ Number(item.price || 0).toFixed(2) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-spin>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-card title="最近动态" class="activity-card">
|
||||
<a-spin :spinning="loading">
|
||||
<a-empty v-if="!stats.recentActivities.length" description="暂时没有最近动态" />
|
||||
<a-timeline v-else>
|
||||
<a-timeline-item
|
||||
v-for="activity in stats.recentActivities"
|
||||
:key="activity.id"
|
||||
:color="activity.color || 'blue'"
|
||||
>
|
||||
<p class="activity-title">{{ activity.title || '系统动态' }}</p>
|
||||
<p class="activity-description">{{ activity.description }}</p>
|
||||
<p class="activity-time">{{ formatTime(activity.time) }}</p>
|
||||
</a-timeline-item>
|
||||
</a-timeline>
|
||||
</a-spin>
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { HomeOutlined, ShopOutlined, ShoppingOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { adminDashboardApi, type DashboardStats } from '@/api/admin'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const loading = ref(false)
|
||||
const stats = reactive<DashboardStats>({
|
||||
totalUsers: 0,
|
||||
totalProducts: 0,
|
||||
totalShops: 0,
|
||||
todayOrders: 0,
|
||||
hotProducts: [],
|
||||
recentActivities: []
|
||||
})
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const cache = localStorage.getItem('adminUserInfo')
|
||||
return cache ? JSON.parse(cache) : null
|
||||
} catch (error) {
|
||||
console.error('读取后台用户信息失败:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const currentUser = computed(() => getCurrentUserInfo())
|
||||
const isAdmin = computed(() => currentUser.value?.type === 4)
|
||||
const pageSubtitle = computed(() => {
|
||||
if (isAdmin.value) {
|
||||
return stats.totalShops > 0 ? '查看整体经营情况与各门店动态' : '当前还没有门店,先去店铺管理创建第一家门店'
|
||||
}
|
||||
return currentUser.value?.shopName ? `当前门店:${currentUser.value.shopName}` : '当前还没有选中门店'
|
||||
})
|
||||
|
||||
const insightItems = computed(() => {
|
||||
const items = []
|
||||
if (isAdmin.value && stats.totalShops === 0) {
|
||||
items.push({
|
||||
title: '先创建门店',
|
||||
description: '系统目前还没有门店,建议先在店铺管理里创建第一家门店,再继续配置作品、优惠券和员工。'
|
||||
})
|
||||
}
|
||||
if (stats.totalProducts === 0) {
|
||||
items.push({
|
||||
title: '还没有可售作品',
|
||||
description: '可以先补充几款基础作品,首页和前台作品页会更完整,也更方便测试完整下单流程。'
|
||||
})
|
||||
} else {
|
||||
items.push({
|
||||
title: '作品库已准备好',
|
||||
description: `当前共有 ${stats.totalProducts} 个作品,建议继续关注热门作品的收藏和点赞表现。`
|
||||
})
|
||||
}
|
||||
if (stats.todayOrders === 0) {
|
||||
items.push({
|
||||
title: '今日订单较安静',
|
||||
description: '可以检查首页推荐、优惠券配置或门店营业时间是否完整,减少用户下单前的犹豫。'
|
||||
})
|
||||
} else {
|
||||
items.push({
|
||||
title: '今日已有订单流入',
|
||||
description: `今天已产生 ${stats.todayOrders} 笔订单,建议优先关注订单状态推进和美甲师排期。`
|
||||
})
|
||||
}
|
||||
if (stats.totalUsers > 0) {
|
||||
items.push({
|
||||
title: '用户池正在积累',
|
||||
description: `当前共有 ${stats.totalUsers} 个用户,可继续结合收藏、优惠券和 VIP 规则提升复购。`
|
||||
})
|
||||
}
|
||||
return items
|
||||
})
|
||||
|
||||
const formatTime = (timeStr: string) => {
|
||||
if (!timeStr) return ''
|
||||
const time = new Date(timeStr)
|
||||
const now = new Date()
|
||||
const diff = now.getTime() - time.getTime()
|
||||
|
||||
const minutes = Math.floor(diff / 60000)
|
||||
const hours = Math.floor(diff / 3600000)
|
||||
const days = Math.floor(diff / 86400000)
|
||||
|
||||
if (minutes < 1) return '刚刚'
|
||||
if (minutes < 60) return `${minutes} 分钟前`
|
||||
if (hours < 24) return `${hours} 小时前`
|
||||
if (days < 7) return `${days} 天前`
|
||||
return time.toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
const fetchStats = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await adminDashboardApi.getStats()
|
||||
Object.assign(stats, data)
|
||||
} catch (error) {
|
||||
console.error('获取统计数据失败:', error)
|
||||
message.error('获取统计数据失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void fetchStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dashboard {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.stat-cards {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.insight-card,
|
||||
.side-card,
|
||||
.activity-card {
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.insight-list {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.insight-item {
|
||||
padding: 16px 18px;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(135deg, #fff8f1 0%, #f8ede1 100%);
|
||||
border: 1px solid #edd9ca;
|
||||
}
|
||||
|
||||
.insight-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.insight-description {
|
||||
margin-top: 6px;
|
||||
line-height: 1.7;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.hot-list {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.hot-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 14px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.hot-item:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.hot-name {
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.hot-meta,
|
||||
.activity-description,
|
||||
.activity-time {
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.hot-meta,
|
||||
.activity-time {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.hot-price {
|
||||
white-space: nowrap;
|
||||
font-weight: 700;
|
||||
color: #c4684b;
|
||||
}
|
||||
|
||||
.activity-card {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.activity-title {
|
||||
margin: 0 0 4px;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.activity-description,
|
||||
.activity-time {
|
||||
margin: 0;
|
||||
line-height: 1.7;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,451 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<template v-if="!isMobile">
|
||||
<a-page-header title="欢迎使用后台管理系统" :sub-title="welcomeMessage" />
|
||||
|
||||
<a-alert
|
||||
v-if="isBootstrapAdmin"
|
||||
class="bootstrap-alert"
|
||||
type="warning"
|
||||
show-icon
|
||||
message="当前处于建店引导状态"
|
||||
description="系统里还没有可用店铺。当前账号已允许登录后台先创建第一家店铺,其他后台模块会保持不可用,创建完成后请重新登录并选择店铺。"
|
||||
/>
|
||||
|
||||
<a-card class="time-card">
|
||||
<a-statistic title="当前时间" :value="currentTime" />
|
||||
</a-card>
|
||||
|
||||
<a-card class="info-card">
|
||||
<a-descriptions bordered>
|
||||
<a-descriptions-item label="用户信息">
|
||||
<div class="user-info">
|
||||
<a-avatar :size="64" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
<div class="user-details">
|
||||
<h3>{{ userInfo?.nickname || '管理员' }}</h3>
|
||||
<p>{{ getUserTypeText(userInfo?.type) }}</p>
|
||||
<p v-if="userInfo?.shopName">所属店铺:{{ userInfo?.shopName }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
</a-card>
|
||||
|
||||
<a-card class="permissions-card">
|
||||
<template #title>
|
||||
<div class="card-title">
|
||||
<SafetyCertificateOutlined class="title-icon" />
|
||||
<span>我的权限</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="permissions-content" v-if="userPermissions.length > 0">
|
||||
<div v-for="(group, groupName) in groupedPermissions" :key="groupName" class="permission-group">
|
||||
<div class="group-title">{{ groupName }}</div>
|
||||
<div class="permission-tags">
|
||||
<a-tag v-for="permission in group" :key="permission.id" color="blue" class="permission-tag">
|
||||
{{ permission.permissionName }}
|
||||
</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="no-permissions" v-else>
|
||||
暂无权限信息
|
||||
</div>
|
||||
</a-card>
|
||||
|
||||
<a-card class="quick-actions">
|
||||
<template #title>
|
||||
快捷操作
|
||||
</template>
|
||||
<a-grid :columns="3" :colGap="16" :rowGap="16">
|
||||
<a-grid-item v-for="item in quickActions" :key="item.key">
|
||||
<a-card hoverable @click="navigateTo(item.path, item.permissionCode)">
|
||||
<template #cover>
|
||||
<div class="action-icon">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
</template>
|
||||
<template #title>
|
||||
{{ item.title }}
|
||||
</template>
|
||||
</a-card>
|
||||
</a-grid-item>
|
||||
</a-grid>
|
||||
</a-card>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<section class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">{{ userInfo?.nickname || userInfo?.account || '后台账号' }}</span>
|
||||
<h1 class="admin-page-intro__title">{{ userInfo?.shopName || (isBootstrapAdmin ? '无门店工作台' : '游客模式') }}</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">{{ currentTime }}</span>
|
||||
<span class="admin-page-chip">{{ getUserTypeText(userInfo?.type) }}</span>
|
||||
<span v-if="isBootstrapAdmin" class="admin-page-chip">游客模式</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="isBootstrapAdmin" class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">先创建第一家店铺</div>
|
||||
<a-button type="primary" size="large" block @click="navigateTo('/admin/shops', 'shop:view')">进入店铺管理</a-button>
|
||||
</section>
|
||||
|
||||
<div class="admin-mobile-grid admin-mobile-grid--two">
|
||||
<section class="admin-mobile-stat">
|
||||
<div class="admin-mobile-stat__label">权限数量</div>
|
||||
<div class="admin-mobile-stat__value">{{ userPermissions.length }}</div>
|
||||
</section>
|
||||
<section class="admin-mobile-stat">
|
||||
<div class="admin-mobile-stat__label">快捷入口</div>
|
||||
<div class="admin-mobile-stat__value">{{ quickActions.length }}</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">快捷入口</div>
|
||||
<div class="mobile-actions">
|
||||
<button
|
||||
v-for="item in quickActions"
|
||||
:key="item.key"
|
||||
class="mobile-action"
|
||||
type="button"
|
||||
@click="navigateTo(item.path, item.permissionCode)"
|
||||
>
|
||||
<div class="mobile-action__icon">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
<div class="mobile-action__body">
|
||||
<div class="mobile-action__title">{{ item.title }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">权限分组</div>
|
||||
<div v-if="userPermissions.length > 0" class="mobile-permission-groups">
|
||||
<div v-for="(group, groupName) in groupedPermissions" :key="groupName" class="mobile-permission-group">
|
||||
<div class="mobile-permission-group__title">{{ groupName }}</div>
|
||||
<div class="permission-tags">
|
||||
<a-tag v-for="permission in group" :key="permission.id" color="blue" class="permission-tag">
|
||||
{{ permission.permissionName }}
|
||||
</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a-empty v-else description="暂无权限信息" />
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { DashboardOutlined, HomeOutlined, SafetyCertificateOutlined, ShopOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import { isBootstrapAdminUser } from './admin-helpers'
|
||||
|
||||
const router = useRouter()
|
||||
const { isMobile } = useAdminViewport()
|
||||
const currentTime = ref('')
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const userPermissions = ref<PermissionVO[]>([])
|
||||
let timer: number | null = null
|
||||
|
||||
const welcomeMessage = computed(() => {
|
||||
const hour = new Date().getHours()
|
||||
if (hour < 12) {
|
||||
return '早上好!'
|
||||
} else if (hour < 18) {
|
||||
return '下午好!'
|
||||
} else {
|
||||
return '晚上好!'
|
||||
}
|
||||
})
|
||||
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
|
||||
const groupedPermissions = computed(() => {
|
||||
const groups: Record<string, PermissionVO[]> = {}
|
||||
userPermissions.value.forEach(permission => {
|
||||
const groupName = permission.permissionGroup
|
||||
if (!groups[groupName]) {
|
||||
groups[groupName] = []
|
||||
}
|
||||
groups[groupName]!.push(permission)
|
||||
})
|
||||
return groups
|
||||
})
|
||||
|
||||
const quickActions = computed(() => {
|
||||
const actions = [
|
||||
{
|
||||
key: 'dashboard',
|
||||
title: '仪表盘',
|
||||
path: '/admin/dashboard',
|
||||
icon: DashboardOutlined,
|
||||
permissionCode: 'dashboard:view'
|
||||
},
|
||||
{
|
||||
key: 'users',
|
||||
title: '用户管理',
|
||||
path: '/admin/users',
|
||||
icon: UserOutlined,
|
||||
permissionCode: 'user:view'
|
||||
},
|
||||
{
|
||||
key: 'products',
|
||||
title: '作品管理',
|
||||
path: '/admin/products',
|
||||
icon: ShopOutlined,
|
||||
permissionCode: 'product:view'
|
||||
},
|
||||
{
|
||||
key: 'shops',
|
||||
title: '店铺管理',
|
||||
path: '/admin/shops',
|
||||
icon: HomeOutlined,
|
||||
permissionCode: 'shop:view'
|
||||
},
|
||||
{
|
||||
key: 'permissions',
|
||||
title: '权限管理',
|
||||
path: '/admin/permissions',
|
||||
icon: SafetyCertificateOutlined,
|
||||
permissionCode: 'permission:view'
|
||||
}
|
||||
]
|
||||
|
||||
const grantedPermissions = new Set(userPermissions.value.map(permission => permission.permissionCode))
|
||||
return actions.filter(item => grantedPermissions.has(item.permissionCode))
|
||||
})
|
||||
|
||||
const getUserTypeText = (type: number | undefined) => {
|
||||
switch (type) {
|
||||
case 4:
|
||||
return '平台管理员'
|
||||
case 2:
|
||||
return '店长'
|
||||
case 3:
|
||||
return '美甲师'
|
||||
default:
|
||||
return '后台账号'
|
||||
}
|
||||
}
|
||||
|
||||
const updateCurrentTime = () => {
|
||||
const now = new Date()
|
||||
currentTime.value = now.toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
})
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const adminUserInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (adminUserInfoStr) {
|
||||
userInfo.value = JSON.parse(adminUserInfoStr)
|
||||
} else {
|
||||
const res = await userApi.getUserInfo()
|
||||
userInfo.value = res as unknown as UserVO
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUserPermissions = async () => {
|
||||
try {
|
||||
const res = await permissionApi.getUserPermissions()
|
||||
userPermissions.value = res as unknown as PermissionVO[]
|
||||
} catch (error) {
|
||||
console.error('获取用户权限失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const navigateTo = (path: string, permissionCode?: string) => {
|
||||
if (permissionCode) {
|
||||
const hasPermission = userPermissions.value.some(p => p.permissionCode === permissionCode)
|
||||
if (!hasPermission) {
|
||||
message.warning('您没有该操作的权限')
|
||||
return
|
||||
}
|
||||
}
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
updateCurrentTime()
|
||||
timer = window.setInterval(updateCurrentTime, 1000)
|
||||
void fetchUserInfo()
|
||||
void fetchUserPermissions()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (timer !== null) {
|
||||
window.clearInterval(timer)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.home {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.time-card,
|
||||
.bootstrap-alert,
|
||||
.info-card,
|
||||
.permissions-card {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.user-details {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.user-details h3 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.user-details p {
|
||||
margin: 4px 0;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.title-icon {
|
||||
font-size: 20px;
|
||||
color: var(--admin-mobile-accent);
|
||||
}
|
||||
|
||||
.permissions-content,
|
||||
.mobile-permission-groups {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.permission-group,
|
||||
.mobile-permission-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.group-title,
|
||||
.mobile-permission-group__title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #a45d44;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.permission-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.permission-tag {
|
||||
font-size: 13px;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.no-permissions {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.quick-actions {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 80px;
|
||||
font-size: 32px;
|
||||
color: #b96449;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
}
|
||||
|
||||
.mobile-actions {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.mobile-action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 14px 0;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--admin-mobile-border);
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.mobile-action:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.mobile-action__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 14px;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
color: #9e5a44;
|
||||
}
|
||||
|
||||
.mobile-action__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.mobile-action__title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.mobile-action__meta {
|
||||
margin-top: 4px;
|
||||
color: #67727a;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,273 @@
|
||||
<template>
|
||||
<div class="admin-manage">
|
||||
<section class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">{{ currentShopName }}</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">{{ roleLabel }}</span>
|
||||
<span class="admin-page-chip">可见模块 {{ visibleModules.length }}</span>
|
||||
<span v-if="isBootstrapAdmin" class="admin-page-chip">游客模式</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="module-grid">
|
||||
<button
|
||||
v-for="module in visibleModules"
|
||||
:key="module.key"
|
||||
class="module-card"
|
||||
:class="{ 'is-disabled': !module.allowed }"
|
||||
type="button"
|
||||
@click="openModule(module)"
|
||||
>
|
||||
<div class="module-card__icon">
|
||||
<component :is="module.icon" />
|
||||
</div>
|
||||
<div class="module-card__body">
|
||||
<div class="module-card__head">
|
||||
<div class="module-card__title">{{ module.title }}</div>
|
||||
<span class="module-card__badge">
|
||||
{{ module.allowed ? '进入' : '受限' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="module-card__subtitle">{{ module.description }}</div>
|
||||
<div v-if="!module.allowed && module.disabledReason" class="module-card__hint">
|
||||
{{ module.disabledReason }}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
DashboardOutlined,
|
||||
GiftOutlined,
|
||||
HomeOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
ShopOutlined,
|
||||
TagOutlined,
|
||||
TeamOutlined,
|
||||
UserOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import {
|
||||
getAdminCurrentShopName,
|
||||
getAdminRoleLabel,
|
||||
isBootstrapAdminUser,
|
||||
loadCachedAdminUserInfo
|
||||
} from './admin-helpers'
|
||||
|
||||
const router = useRouter()
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const userInfo = computed(() => loadCachedAdminUserInfo())
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
|
||||
const visibleModules = computed(() => {
|
||||
const definitions = [
|
||||
{
|
||||
key: 'dashboard',
|
||||
title: '仪表盘',
|
||||
description: '查看经营概览、近期动态和重点提醒。',
|
||||
path: '/admin/dashboard',
|
||||
icon: DashboardOutlined,
|
||||
permissionCode: 'dashboard:view'
|
||||
},
|
||||
{
|
||||
key: 'users',
|
||||
title: '用户管理',
|
||||
description: '处理账号、资产、VIP 和店铺关系。',
|
||||
path: '/admin/users',
|
||||
icon: UserOutlined,
|
||||
permissionCode: 'user:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'products',
|
||||
title: '作品管理',
|
||||
description: '维护作品、标签、可预约美甲师和优惠券。',
|
||||
path: '/admin/products',
|
||||
icon: ShopOutlined,
|
||||
permissionCode: 'product:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'coupons',
|
||||
title: '优惠券',
|
||||
description: '管理券模板、场景和批量发放入口。',
|
||||
path: '/admin/coupons',
|
||||
icon: GiftOutlined,
|
||||
permissionCode: 'coupon:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'tags',
|
||||
title: '标签管理',
|
||||
description: '维护作品标签及颜色风格。',
|
||||
path: '/admin/tags',
|
||||
icon: TagOutlined,
|
||||
permissionCode: 'tag:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'artists',
|
||||
title: '美甲师',
|
||||
description: '查看状态、技能与作品挂载关系。',
|
||||
path: '/admin/nail-artists',
|
||||
icon: TeamOutlined,
|
||||
permissionCode: 'nail_artist:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'shops',
|
||||
title: '店铺管理',
|
||||
description: '创建门店、调整营业信息与图片素材。',
|
||||
path: '/admin/shops',
|
||||
icon: HomeOutlined,
|
||||
permissionCode: 'shop:view'
|
||||
},
|
||||
{
|
||||
key: 'permissions',
|
||||
title: '权限管理',
|
||||
description: '查看权限列表并给后台账号分配权限。',
|
||||
path: '/admin/permissions',
|
||||
icon: SafetyCertificateOutlined,
|
||||
permissionCode: 'permission:view'
|
||||
}
|
||||
]
|
||||
|
||||
return definitions
|
||||
.filter(module => !module.permissionCode || hasPermission(module.permissionCode))
|
||||
.map(module => {
|
||||
if (module.requireShopContext && isBootstrapAdmin.value) {
|
||||
return {
|
||||
...module,
|
||||
allowed: false,
|
||||
disabledReason: '当前没有门店上下文,先进入店铺管理完成初始化或切换门店。'
|
||||
}
|
||||
}
|
||||
return {
|
||||
...module,
|
||||
allowed: true,
|
||||
disabledReason: ''
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const openModule = (module: any) => {
|
||||
if (!module.allowed) {
|
||||
message.warning(module.disabledReason || '当前无法进入该模块')
|
||||
return
|
||||
}
|
||||
router.push(module.path)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadUserPermissions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-manage {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.module-grid {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.module-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 14px;
|
||||
padding: 18px;
|
||||
border: 1px solid var(--admin-mobile-border);
|
||||
border-radius: 24px;
|
||||
background: var(--admin-mobile-card);
|
||||
text-align: left;
|
||||
box-shadow: 0 12px 30px rgba(144, 103, 84, 0.08);
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.module-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 18px 36px rgba(144, 103, 84, 0.12);
|
||||
}
|
||||
|
||||
.module-card.is-disabled {
|
||||
opacity: 0.78;
|
||||
}
|
||||
|
||||
.module-card__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 18px;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
color: #9e5a44;
|
||||
flex-shrink: 0;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.module-card__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.module-card__head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.module-card__title {
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.module-card__badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 28px;
|
||||
padding: 0 10px;
|
||||
border-radius: 999px;
|
||||
background: rgba(215, 108, 84, 0.12);
|
||||
color: #9a412d;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.module-card__subtitle {
|
||||
margin-top: 8px;
|
||||
line-height: 1.6;
|
||||
color: #66727a;
|
||||
}
|
||||
|
||||
.module-card__hint {
|
||||
margin-top: 10px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 14px;
|
||||
background: rgba(204, 123, 95, 0.08);
|
||||
color: #725d51;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.module-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,550 @@
|
||||
<template>
|
||||
<div class="nail-artists">
|
||||
<a-page-header v-if="!isMobile" title="美甲师管理" sub-title="管理美甲师详细信息" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">美甲师管理</h1>
|
||||
<p class="admin-page-intro__subtitle">
|
||||
把状态、技能和作品挂载关系收成单列卡片,手机端可以直接查看和编辑。
|
||||
</p>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">美甲师 {{ nailArtistList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
美甲师列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索美甲师姓名"
|
||||
:style="isMobile ? { width: '100%' } : { width: '250px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="nailArtistList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="userId"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="getStatusColor(record.status)">
|
||||
{{ getStatusText(record.status) }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('nail_artist:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('nail_artist:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="nailArtistList" item-key="userId" empty-description="暂无美甲师数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.nickname }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || '未绑定店铺' }}</div>
|
||||
</div>
|
||||
<a-tag :color="getStatusColor(item.status)">{{ getStatusText(item.status) }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>身份</span>
|
||||
<strong>{{ item.identity || '--' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>从业年限</span>
|
||||
<strong>{{ item.experience ?? '--' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>评分</span>
|
||||
<strong>{{ item.rating || '--' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button v-if="hasPermission('nail_artist:view')" size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('nail_artist:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<!-- 编辑美甲师信息模态框 -->
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
title="编辑美甲师信息"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
:desktop-width="800"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="美甲师姓名" name="nickname">
|
||||
<a-input v-model:value="formState.nickname" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="身份" name="identity">
|
||||
<a-input
|
||||
v-model:value="formState.identity"
|
||||
placeholder="请输入身份"
|
||||
:disabled="!isShopOwner"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="从业年限" name="experience">
|
||||
<a-input-number
|
||||
v-model:value="formState.experience"
|
||||
:min="0"
|
||||
placeholder="请输入从业年限"
|
||||
:disabled="!isShopOwner"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="技能标签" name="skills">
|
||||
<a-select
|
||||
v-model:value="formState.skills"
|
||||
mode="multiple"
|
||||
placeholder="请选择技能标签"
|
||||
:loading="tagLoading"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="tag in tagList"
|
||||
:key="tag.id"
|
||||
:value="tag.id.toString()"
|
||||
>
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="状态" name="status">
|
||||
<a-select
|
||||
v-model:value="formState.status"
|
||||
placeholder="请选择状态"
|
||||
:disabled="!isShopOwner"
|
||||
>
|
||||
<a-select-option :value="1">营业中</a-select-option>
|
||||
<a-select-option :value="0">休息中</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="作品" name="portfolio">
|
||||
<a-select
|
||||
v-model:value="formState.portfolio"
|
||||
mode="multiple"
|
||||
placeholder="请选择作品作品"
|
||||
:loading="productLoading"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="product in productList"
|
||||
:key="product.id"
|
||||
:value="product.id.toString()"
|
||||
>
|
||||
{{ product.title }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="评分">
|
||||
<a-input v-model:value="formState.rating" :disabled="true" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<!-- 查看美甲师详情模态框 -->
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看美甲师详情"
|
||||
:footer="null"
|
||||
@cancel="handleViewModalCancel"
|
||||
:desktop-width="600"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="美甲师姓名">
|
||||
<a-input v-model:value="viewFormState.nickname" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺">
|
||||
<a-input v-model:value="viewFormState.shopName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="身份">
|
||||
<a-input v-model:value="viewFormState.identity" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="从业年限">
|
||||
<a-input v-model:value="viewFormState.experience" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="技能标签">
|
||||
<a-input v-model:value="viewFormState.skillsText" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="状态">
|
||||
<a-input v-model:value="viewFormState.statusText" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="评分">
|
||||
<a-input v-model:value="viewFormState.rating" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="作品">
|
||||
<a-input v-model:value="viewFormState.portfolioText" :disabled="true" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { adminNailArtistApi, type NailArtistInfoVO } from '@/api/admin'
|
||||
import { adminTagApi, type Tag } from '@/api/admin'
|
||||
import { adminProductApi, type Product } from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
isAdmin.value = userInfo.type === 4
|
||||
isShopOwner.value = userInfo.type === 2
|
||||
return userInfo
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const tagLoading = ref(false)
|
||||
const productLoading = ref(false)
|
||||
const searchText = ref('')
|
||||
const nailArtistList = ref<NailArtistInfoVO[]>([])
|
||||
const tagList = ref<Tag[]>([])
|
||||
const productList = ref<Product[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const isAdmin = ref(false)
|
||||
const isShopOwner = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentNailArtist = ref<NailArtistInfoVO | null>(null)
|
||||
const currentUserInfo = getCurrentUserInfo()
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const viewFormState = reactive({
|
||||
nickname: '',
|
||||
shopName: '',
|
||||
identity: '',
|
||||
experience: '',
|
||||
skillsText: '',
|
||||
statusText: '',
|
||||
rating: '',
|
||||
portfolioText: ''
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
userId: 0,
|
||||
identity: '',
|
||||
experience: 0,
|
||||
skills: [] as string[],
|
||||
rating: 0,
|
||||
status: 1,
|
||||
portfolio: [] as string[],
|
||||
nickname: ''
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-nail-artists', 'edit', currentNailArtist.value?.userId ?? formState.userId ?? 'unknown')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
identity: formState.identity,
|
||||
experience: formState.experience,
|
||||
skills: [...formState.skills],
|
||||
status: formState.status,
|
||||
portfolio: [...formState.portfolio]
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, {
|
||||
identity: draft.payload.identity ?? formState.identity,
|
||||
experience: typeof draft.payload.experience === 'number' ? draft.payload.experience : formState.experience,
|
||||
skills: Array.isArray(draft.payload.skills) ? draft.payload.skills : formState.skills,
|
||||
status: typeof draft.payload.status === 'number'
|
||||
? (draft.payload.status === 0 ? 0 : 1)
|
||||
: formState.status,
|
||||
portfolio: Array.isArray(draft.payload.portfolio) ? draft.payload.portfolio : formState.portfolio
|
||||
})
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const formRules = {
|
||||
identity: [{ required: true, message: '请输入身份', trigger: 'blur' }],
|
||||
experience: [{ required: true, message: '请输入从业年限', trigger: 'blur' }],
|
||||
skills: [{ required: true, message: '请选择技能标签', trigger: 'change' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
portfolio: [{ required: true, message: '请选择作品作品', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '美甲师姓名', dataIndex: 'nickname', key: 'nickname' },
|
||||
{ title: '所属店铺', dataIndex: 'shopName', key: 'shopName' },
|
||||
{ title: '身份', dataIndex: 'identity', key: 'identity' },
|
||||
{ title: '从业年限', dataIndex: 'experience', key: 'experience' },
|
||||
{ title: '评分', dataIndex: 'rating', key: 'rating' },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const getStatusText = (status: number) => {
|
||||
return status === 1 ? '营业中' : '休息中'
|
||||
}
|
||||
|
||||
const getStatusColor = (status: number) => {
|
||||
return status === 1 ? 'green' : 'default'
|
||||
}
|
||||
|
||||
const fetchTagList = async () => {
|
||||
tagLoading.value = true
|
||||
try {
|
||||
const res = await adminTagApi.listAllTags() as unknown as Tag[]
|
||||
tagList.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
} finally {
|
||||
tagLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchProductList = async () => {
|
||||
productLoading.value = true
|
||||
try {
|
||||
const params: any = {
|
||||
page: 1,
|
||||
size: 1000
|
||||
}
|
||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||
params.shopId = currentUserInfo.shopId
|
||||
}
|
||||
const res = await adminProductApi.listProducts(params) as unknown as { list: Product[] }
|
||||
productList.value = res.list || []
|
||||
} catch (error) {
|
||||
console.error('获取作品列表失败:', error)
|
||||
} finally {
|
||||
productLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchNailArtistList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await adminNailArtistApi.listNailArtists() as unknown as NailArtistInfoVO[]
|
||||
let filteredList = res || []
|
||||
|
||||
// 按搜索词过滤
|
||||
if (searchText.value) {
|
||||
filteredList = filteredList.filter((item: NailArtistInfoVO) =>
|
||||
item.nickname?.includes(searchText.value)
|
||||
)
|
||||
}
|
||||
|
||||
nailArtistList.value = filteredList
|
||||
pagination.total = filteredList.length || 0
|
||||
} catch (error) {
|
||||
message.error('获取美甲师列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = async () => {
|
||||
pagination.current = 1
|
||||
await runWithGlobalLoading(() => fetchNailArtistList())
|
||||
}
|
||||
|
||||
const handleTableChange = async (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchNailArtistList())
|
||||
}
|
||||
|
||||
const showEditModal = (record: Record<string, any>) => {
|
||||
currentNailArtist.value = record as NailArtistInfoVO
|
||||
const lockedFields = {
|
||||
userId: record.userId,
|
||||
rating: record.rating || 0,
|
||||
nickname: record.nickname || ''
|
||||
}
|
||||
Object.assign(formState, {
|
||||
identity: record.identity || '',
|
||||
experience: record.experience || 0,
|
||||
skills: record.skills ? record.skills.split(',').filter(Boolean) : [],
|
||||
status: record.status || 1,
|
||||
portfolio: record.portfolio ? record.portfolio.split(',').filter(Boolean) : [],
|
||||
...lockedFields
|
||||
})
|
||||
restoreDraft()
|
||||
Object.assign(formState, lockedFields)
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = (record: Record<string, any>) => {
|
||||
const nailArtist = record as NailArtistInfoVO
|
||||
// 构建技能标签文本
|
||||
const skillsArray = nailArtist.skills ? nailArtist.skills.split(',').filter(Boolean) : []
|
||||
const skillsText = skillsArray.map(skillId => {
|
||||
const tag = tagList.value.find(t => t.id.toString() === skillId)
|
||||
return tag ? tag.tagName : skillId
|
||||
}).join(', ')
|
||||
|
||||
// 构建作品文本
|
||||
const portfolioArray = nailArtist.portfolio ? nailArtist.portfolio.split(',').filter(Boolean) : []
|
||||
const portfolioText = portfolioArray.map(productId => {
|
||||
const product = productList.value.find(p => p.id.toString() === productId)
|
||||
return product ? product.title : productId
|
||||
}).join(', ')
|
||||
|
||||
Object.assign(viewFormState, {
|
||||
nickname: nailArtist.nickname || '',
|
||||
shopName: nailArtist.shopName || '',
|
||||
identity: nailArtist.identity || '',
|
||||
experience: (nailArtist.experience || 0).toString(),
|
||||
skillsText: skillsText,
|
||||
statusText: getStatusText(nailArtist.status || 1),
|
||||
rating: (nailArtist.rating || 0).toString(),
|
||||
portfolioText: portfolioText
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
|
||||
const targetUserId = currentNailArtist.value?.userId ?? formState.userId
|
||||
if (!targetUserId) {
|
||||
message.error('未获取到当前美甲师信息,请关闭弹窗后重试')
|
||||
return
|
||||
}
|
||||
|
||||
modalLoading.value = true
|
||||
|
||||
await runWithGlobalLoading(async () => {
|
||||
// 准备提交数据
|
||||
const submitData = {
|
||||
userId: targetUserId,
|
||||
identity: formState.identity,
|
||||
experience: formState.experience,
|
||||
rating: formState.rating,
|
||||
status: formState.status,
|
||||
skills: formState.skills.join(','),
|
||||
portfolio: formState.portfolio.join(',')
|
||||
}
|
||||
|
||||
await adminNailArtistApi.saveNailArtistInfo(submitData)
|
||||
message.success('保存成功')
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
await fetchNailArtistList()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
const errorMessage = (error as Error)?.message
|
||||
if (errorMessage) {
|
||||
message.error(errorMessage)
|
||||
return
|
||||
}
|
||||
message.error('操作失败')
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
currentNailArtist.value = null
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
fetchTagList()
|
||||
fetchProductList()
|
||||
fetchNailArtistList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.nail-artists {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,326 @@
|
||||
<template>
|
||||
<div class="orders">
|
||||
<a-page-header v-if="!isMobile" title="订单管理" sub-title="管理系统订单" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">订单</span>
|
||||
<h1 class="admin-page-intro__title">订单工作台</h1>
|
||||
<p class="admin-page-intro__subtitle">
|
||||
手机端不再默认展示横向大表格,而是把筛选、状态和处理按钮压到单列卡片里。
|
||||
</p>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">订单 {{ filteredOrders.length }}</span>
|
||||
<span class="admin-page-chip">{{ canProcessOrders ? '可处理订单' : '查看模式' }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
订单列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="keyword"
|
||||
class="admin-toolbar__grow"
|
||||
placeholder="搜索订单号、用户 ID 或优惠券"
|
||||
@search="noop"
|
||||
/>
|
||||
<a-select
|
||||
v-model:value="statusFilter"
|
||||
:options="statusOptions"
|
||||
:style="isMobile ? { width: '100%' } : { width: '160px' }"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table v-if="!isMobile" :columns="columns" :data-source="filteredOrders" :loading="loading" row-key="id">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="statusColor(record.status)">{{ record.statusText }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'totalAmount'">
|
||||
¥{{ record.totalAmount.toFixed(2) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actualAmount'">
|
||||
¥{{ record.actualAmount.toFixed(2) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="currentOrder = record">查看</a-button>
|
||||
<a-button
|
||||
v-if="record.status === 1 && canProcessOrders"
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="process(record.id, 2)"
|
||||
>
|
||||
确认完成
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="record.status === 1 && canProcessOrders && !isArtist"
|
||||
danger
|
||||
size="small"
|
||||
@click="process(record.id, 3)"
|
||||
>
|
||||
取消订单
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="filteredOrders" empty-description="暂无订单数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.orderNo }}</div>
|
||||
<div class="admin-mobile-card__subtitle">
|
||||
用户 {{ item.userId }} · {{ item.createTime }}
|
||||
</div>
|
||||
</div>
|
||||
<a-tag :color="statusColor(item.status)">{{ item.statusText }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>总金额</span>
|
||||
<strong>¥{{ item.totalAmount.toFixed(2) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>实付金额</span>
|
||||
<strong>¥{{ item.actualAmount.toFixed(2) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>优惠券</span>
|
||||
<strong>{{ item.couponName || '无' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>预约项目</span>
|
||||
<strong>{{ item.items?.length || 0 }} 个</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="currentOrder = item">查看详情</a-button>
|
||||
<a-button
|
||||
v-if="item.status === 1 && canProcessOrders"
|
||||
size="small"
|
||||
type="primary"
|
||||
@click="process(item.id, 2)"
|
||||
>
|
||||
完成
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="item.status === 1 && canProcessOrders && !isArtist"
|
||||
size="small"
|
||||
danger
|
||||
@click="process(item.id, 3)"
|
||||
>
|
||||
取消
|
||||
</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="detailVisible"
|
||||
title="订单详情"
|
||||
:desktop-width="860"
|
||||
@cancel="currentOrder = null"
|
||||
>
|
||||
<template v-if="currentOrder">
|
||||
<a-descriptions :column="isMobile ? 1 : 2" bordered size="small">
|
||||
<a-descriptions-item label="订单编号">{{ currentOrder.orderNo }}</a-descriptions-item>
|
||||
<a-descriptions-item label="用户ID">{{ currentOrder.userId }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单总额">¥{{ currentOrder.totalAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="实付金额">¥{{ currentOrder.actualAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠券">{{ currentOrder.couponName || '无' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单状态">{{ currentOrder.statusText }}</a-descriptions-item>
|
||||
<a-descriptions-item label="创建时间" :span="isMobile ? 1 : 2">{{ currentOrder.createTime }}</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
|
||||
<a-divider>订单项目</a-divider>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="itemColumns"
|
||||
:data-source="currentOrder.items"
|
||||
row-key="id"
|
||||
:pagination="false"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'price'">¥{{ record.price.toFixed(2) }}</template>
|
||||
<template v-else-if="column.key === 'totalPrice'">¥{{ (record.price * record.quantity).toFixed(2) }}</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<div v-else class="detail-items">
|
||||
<article v-for="item in currentOrder.items" :key="item.id" class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__title">{{ item.productTitle }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.artistName || '未指定美甲师' }}</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>预约时间</span>
|
||||
<strong>{{ item.appointmentTime || '--' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>单价</span>
|
||||
<strong>¥{{ item.price.toFixed(2) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>数量</span>
|
||||
<strong>{{ item.quantity }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>小计</span>
|
||||
<strong>¥{{ (item.price * item.quantity).toFixed(2) }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</template>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { orderApi } from '../../api/order'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { sameId } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const orders = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const currentOrder = ref<any | null>(null)
|
||||
const currentUserType = ref<number | null>(null)
|
||||
const keyword = ref('')
|
||||
const statusFilter = ref<'all' | string>('all')
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const detailVisible = computed({
|
||||
get: () => !!currentOrder.value,
|
||||
set: value => { if (!value) currentOrder.value = null }
|
||||
})
|
||||
const canProcessOrders = computed(() => hasPermission('order:process'))
|
||||
const isArtist = computed(() => currentUserType.value === 3)
|
||||
const statusOptions = [
|
||||
{ label: '全部状态', value: 'all' },
|
||||
{ label: '待处理', value: '1' },
|
||||
{ label: '已完成', value: '2' },
|
||||
{ label: '已取消', value: '3' }
|
||||
]
|
||||
|
||||
const filteredOrders = computed(() => {
|
||||
const keywordValue = keyword.value.trim().toLowerCase()
|
||||
return orders.value.filter(order => {
|
||||
const matchStatus = statusFilter.value === 'all' || String(order.status) === String(statusFilter.value)
|
||||
if (!matchStatus) {
|
||||
return false
|
||||
}
|
||||
if (!keywordValue) {
|
||||
return true
|
||||
}
|
||||
const haystack = [
|
||||
order.orderNo,
|
||||
order.userId,
|
||||
order.couponName,
|
||||
...(order.items || []).map((item: any) => `${item.productTitle || ''} ${item.artistName || ''}`)
|
||||
].join(' ').toLowerCase()
|
||||
return haystack.includes(keywordValue)
|
||||
})
|
||||
})
|
||||
|
||||
const columns = [
|
||||
{ title: '订单编号', dataIndex: 'orderNo', key: 'orderNo' },
|
||||
{ title: '用户ID', dataIndex: 'userId', key: 'userId', width: 100 },
|
||||
{ title: '订单总额', key: 'totalAmount', width: 120 },
|
||||
{ title: '实付金额', key: 'actualAmount', width: 120 },
|
||||
{ title: '优惠券', dataIndex: 'couponName', key: 'couponName', width: 140 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
|
||||
{ title: '操作', key: 'actions', width: 180 }
|
||||
]
|
||||
|
||||
const itemColumns = [
|
||||
{ title: '商品ID', dataIndex: 'productId', key: 'productId', width: 100 },
|
||||
{ title: '商品名称', dataIndex: 'productTitle', key: 'productTitle' },
|
||||
{ title: '美甲师', dataIndex: 'artistName', key: 'artistName', width: 120 },
|
||||
{ title: '预约时间', dataIndex: 'appointmentTime', key: 'appointmentTime', width: 180 },
|
||||
{ title: '单价', key: 'price', width: 100 },
|
||||
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 80 },
|
||||
{ title: '总价', key: 'totalPrice', width: 100 }
|
||||
]
|
||||
|
||||
const statusColor = (status: number) => {
|
||||
if (status === 1) return 'orange'
|
||||
if (status === 2) return 'green'
|
||||
if (status === 3) return 'red'
|
||||
return 'default'
|
||||
}
|
||||
|
||||
const resolveCurrentUserType = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo') || sessionStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
currentUserType.value = null
|
||||
return
|
||||
}
|
||||
try {
|
||||
currentUserType.value = JSON.parse(cached)?.type ?? null
|
||||
} catch {
|
||||
currentUserType.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
orders.value = await orderApi.getAllOrders() as unknown as any[]
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const process = async (orderId: IdType, status: number) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await orderApi.processOrder(orderId, status)
|
||||
await loadOrders()
|
||||
})
|
||||
message.success('操作成功')
|
||||
if (sameId(currentOrder.value?.id, orderId)) {
|
||||
currentOrder.value = orders.value.find(order => sameId(order.id, orderId)) || null
|
||||
}
|
||||
} catch {
|
||||
message.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const noop = () => {}
|
||||
|
||||
onMounted(async () => {
|
||||
resolveCurrentUserType()
|
||||
await loadUserPermissions()
|
||||
await loadOrders()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.orders {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.detail-items {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,734 @@
|
||||
<template>
|
||||
<div class="permissions">
|
||||
<a-page-header v-if="!isMobile" title="权限管理" sub-title="管理系统权限和用户权限分配" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">权限管理</h1>
|
||||
<p class="admin-page-intro__subtitle">
|
||||
手机端拆成“权限列表”和“用户权限”两段流程,先选人再分配,避免保留桌面双栏布局。
|
||||
</p>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">权限 {{ permissionList.length }}</span>
|
||||
<span class="admin-page-chip">用户 {{ filteredUserList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-tabs v-model:activeKey="activeTab">
|
||||
<a-tab-pane key="permissions" tab="权限列表">
|
||||
<div style="margin-bottom: 16px;" :style="isMobile ? {} : { textAlign: 'right' }">
|
||||
<a-button v-if="!isMobile && hasPermission('permission:create')" type="primary" @click="showAddPermissionModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增权限
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="permissionColumns"
|
||||
:data-source="permissionList"
|
||||
:loading="loading"
|
||||
:pagination="permissionPagination"
|
||||
:scroll="{ x: 1080 }"
|
||||
@change="handlePermissionTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'permissionGroup'">
|
||||
<a-tag color="purple">{{ record.permissionGroup }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'permissionCode'">
|
||||
<div style="max-width: 220px;">
|
||||
<TableEllipsisText :text="record.permissionCode" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'permissionName'">
|
||||
<div style="max-width: 180px;">
|
||||
<TableEllipsisText :text="record.permissionName" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'description'">
|
||||
<div style="max-width: 320px;">
|
||||
<TableEllipsisText :text="record.description" :lines="2" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('permission:edit')" type="link" size="small" @click="showEditPermissionModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('permission:delete')"
|
||||
title="确定要删除这个权限吗?"
|
||||
@confirm="handleDeletePermission(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="permissionList" empty-description="暂无权限数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.permissionName }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.permissionCode }}</div>
|
||||
</div>
|
||||
<a-tag color="purple">{{ item.permissionGroup }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__description">{{ item.description }}</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>创建时间</span>
|
||||
<strong>{{ item.createTime }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button v-if="hasPermission('permission:edit')" size="small" @click="showEditPermissionModal(item)">编辑</a-button>
|
||||
<a-button v-if="hasPermission('permission:delete')" size="small" danger @click="handleDeletePermission(item)">删除</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-tab-pane>
|
||||
|
||||
<a-tab-pane v-if="hasPermission('permission:assign')" key="user-permissions" tab="用户权限分配">
|
||||
<template v-if="!isMobile">
|
||||
<a-row :gutter="16">
|
||||
<a-col :span="8">
|
||||
<a-card title="选择用户" :bordered="false">
|
||||
<a-input-search
|
||||
v-model:value="userSearchText"
|
||||
placeholder="搜索用户"
|
||||
style="margin-bottom: 16px"
|
||||
@search="handleUserSearch"
|
||||
/>
|
||||
<a-list
|
||||
:data-source="filteredUserList"
|
||||
:loading="userLoading"
|
||||
item-layout="horizontal"
|
||||
size="small"
|
||||
>
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item
|
||||
:class="{ selected: sameId(selectedUser?.id, item.id) }"
|
||||
style="cursor: pointer;"
|
||||
@click="selectUser(item)"
|
||||
>
|
||||
<a-list-item-meta>
|
||||
<template #avatar>
|
||||
<a-avatar :src="item.avatar || DEFAULT_AVATAR" />
|
||||
</template>
|
||||
<template #title>{{ item.nickname }}</template>
|
||||
<template #description>{{ item.account }} - {{ getUserTypeText(item.type) }}</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="16">
|
||||
<a-card
|
||||
title="分配权限"
|
||||
:bordered="false"
|
||||
>
|
||||
<template #extra>
|
||||
<a-button v-if="selectedUser && hasPermission('permission:assign')" type="primary" @click="handleSaveUserPermissions">
|
||||
保存权限
|
||||
</a-button>
|
||||
</template>
|
||||
<template v-if="selectedUser">
|
||||
<a-alert
|
||||
:message="`当前用户: ${selectedUser.nickname}`"
|
||||
:description="`用户类型: ${getUserTypeText(selectedUser.type)}`"
|
||||
type="info"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
<a-alert
|
||||
v-if="disabledPermissionCount > 0"
|
||||
:message="`有 ${disabledPermissionCount} 项权限不在该角色可分配范围内,已禁止选择`"
|
||||
type="warning"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<a-spin :spinning="assignLoading">
|
||||
<a-checkbox-group v-model:value="selectedPermissions">
|
||||
<a-collapse v-model:activeKey="activeCollapseKeys">
|
||||
<a-collapse-panel
|
||||
v-for="(permissions, group) in groupedPermissions"
|
||||
:key="group"
|
||||
:header="group"
|
||||
>
|
||||
<a-space direction="vertical" style="width: 100%">
|
||||
<a-checkbox
|
||||
v-for="permission in permissions"
|
||||
:key="permission.id"
|
||||
:value="permission.id"
|
||||
:disabled="isPermissionDisabled(permission)"
|
||||
>
|
||||
{{ permission.permissionName }}
|
||||
<span style="color: #999; font-size: 12px; margin-left: 8px;">
|
||||
({{ permission.permissionCode }})
|
||||
</span>
|
||||
<span
|
||||
v-if="isPermissionDisabled(permission)"
|
||||
style="color: #ff4d4f; font-size: 12px; margin-left: 8px;"
|
||||
>
|
||||
不可分配
|
||||
</span>
|
||||
</a-checkbox>
|
||||
</a-space>
|
||||
</a-collapse-panel>
|
||||
</a-collapse>
|
||||
</a-checkbox-group>
|
||||
</a-spin>
|
||||
</template>
|
||||
<a-empty v-else description="请先选择一个用户" />
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="mobile-permission-flow">
|
||||
<template v-if="mobilePermissionStep === 'users' || !selectedUser">
|
||||
<a-input-search
|
||||
v-model:value="userSearchText"
|
||||
placeholder="搜索用户"
|
||||
style="margin-bottom: 16px"
|
||||
@search="handleUserSearch"
|
||||
/>
|
||||
<AdminMobileCardList :items="filteredUserList" empty-description="暂无可分配权限的用户">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card" @click="selectUser(item)">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="mobile-user-pick">
|
||||
<a-avatar :src="item.avatar || DEFAULT_AVATAR" />
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.nickname }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.account }} · {{ getUserTypeText(item.type) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<span class="admin-mobile-card__badge">选择</span>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="mobile-assign-actions">
|
||||
<a-button @click="mobilePermissionStep = 'users'">返回选用户</a-button>
|
||||
<a-button type="primary" @click="handleSaveUserPermissions">保存权限</a-button>
|
||||
</div>
|
||||
|
||||
<a-alert
|
||||
:message="`当前用户: ${selectedUser.nickname}`"
|
||||
:description="`用户类型: ${getUserTypeText(selectedUser.type)}`"
|
||||
type="info"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
<a-alert
|
||||
v-if="disabledPermissionCount > 0"
|
||||
:message="`有 ${disabledPermissionCount} 项权限不在该角色可分配范围内,已禁用`"
|
||||
type="warning"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<a-spin :spinning="assignLoading">
|
||||
<a-checkbox-group v-model:value="selectedPermissions" style="width: 100%">
|
||||
<a-collapse v-model:activeKey="activeCollapseKeys">
|
||||
<a-collapse-panel
|
||||
v-for="(permissions, group) in groupedPermissions"
|
||||
:key="group"
|
||||
:header="group"
|
||||
>
|
||||
<a-space direction="vertical" style="width: 100%">
|
||||
<a-checkbox
|
||||
v-for="permission in permissions"
|
||||
:key="permission.id"
|
||||
:value="permission.id"
|
||||
:disabled="isPermissionDisabled(permission)"
|
||||
>
|
||||
{{ permission.permissionName }}
|
||||
<span style="color: #999; font-size: 12px; margin-left: 8px;">
|
||||
({{ permission.permissionCode }})
|
||||
</span>
|
||||
</a-checkbox>
|
||||
</a-space>
|
||||
</a-collapse-panel>
|
||||
</a-collapse>
|
||||
</a-checkbox-group>
|
||||
</a-spin>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="permissionModalVisible"
|
||||
:title="isEditPermission ? '编辑权限' : '新增权限'"
|
||||
@ok="handlePermissionModalOk"
|
||||
@cancel="handlePermissionModalCancel"
|
||||
:confirmLoading="permissionModalLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="permissionFormRef"
|
||||
:model="permissionFormState"
|
||||
:rules="permissionFormRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="权限编码" name="permissionCode">
|
||||
<a-input v-model:value="permissionFormState.permissionCode" placeholder="例如:product:add" />
|
||||
</a-form-item>
|
||||
<a-form-item label="权限名称" name="permissionName">
|
||||
<a-input v-model:value="permissionFormState.permissionName" placeholder="例如:添加作品" />
|
||||
</a-form-item>
|
||||
<a-form-item label="权限分组" name="permissionGroup">
|
||||
<a-select v-model:value="permissionFormState.permissionGroup" placeholder="请选择权限分组">
|
||||
<a-select-option value="作品管理">作品管理</a-select-option>
|
||||
<a-select-option value="店铺管理">店铺管理</a-select-option>
|
||||
<a-select-option value="用户管理">用户管理</a-select-option>
|
||||
<a-select-option value="权限管理">权限管理</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="权限描述" name="description">
|
||||
<a-textarea
|
||||
v-model:value="permissionFormState.description"
|
||||
placeholder="请输入权限描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && activeTab === 'permissions' && hasPermission('permission:create') && !permissionModalVisible"
|
||||
label="鏂板鏉冮檺"
|
||||
@click="showAddPermissionModal"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed, onMounted, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import TableEllipsisText from '@/components/TableEllipsisText.vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { sameId } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
const activeTab = ref('permissions')
|
||||
const loading = ref(false)
|
||||
const permissionList = ref<PermissionVO[]>([])
|
||||
const permissionModalVisible = ref(false)
|
||||
const permissionModalLoading = ref(false)
|
||||
const isEditPermission = ref(false)
|
||||
const permissionFormRef = ref<FormInstance>()
|
||||
const currentPermission = ref<PermissionVO | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const permissionPagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 20,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const permissionFormState = reactive({
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-permissions', isEditPermission.value ? 'edit' : 'create', currentPermission.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
permissionCode: permissionFormState.permissionCode,
|
||||
permissionName: permissionFormState.permissionName,
|
||||
permissionGroup: permissionFormState.permissionGroup,
|
||||
description: permissionFormState.description
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(permissionFormState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const permissionFormRules: Record<string, Rule[]> = {
|
||||
permissionCode: [{ required: true, message: '请输入权限编码', trigger: 'blur' }],
|
||||
permissionName: [{ required: true, message: '请输入权限名称', trigger: 'blur' }],
|
||||
permissionGroup: [{ required: true, message: '请选择权限分组', trigger: 'change' }],
|
||||
description: [{ required: true, message: '请输入权限描述', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const permissionColumns = [
|
||||
{ title: '权限编码', dataIndex: 'permissionCode', key: 'permissionCode' },
|
||||
{ title: '权限名称', dataIndex: 'permissionName', key: 'permissionName' },
|
||||
{ title: '权限分组', key: 'permissionGroup', width: 120 },
|
||||
{ title: '权限描述', dataIndex: 'description', key: 'description' },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const userLoading = ref(false)
|
||||
const userSearchText = ref('')
|
||||
const userList = ref<UserVO[]>([])
|
||||
const selectedUser = ref<UserVO | null>(null)
|
||||
const assignLoading = ref(false)
|
||||
const selectedPermissions = ref<IdType[]>([])
|
||||
const assignablePermissionIds = ref<IdType[]>([])
|
||||
const activeCollapseKeys = ref<string[]>(['作品管理', '店铺管理', '用户管理', '权限管理'])
|
||||
const currentLoginUser = ref<UserVO | null>(null)
|
||||
const mobilePermissionStep = ref<'users' | 'assign'>('users')
|
||||
|
||||
// 权限 ID 同样可能以字符串形式返回,所以这里统一转成字符串集合做包含判断。
|
||||
const assignablePermissionIdSet = computed(() => new Set(assignablePermissionIds.value.map(id => String(id))))
|
||||
const disabledPermissionCount = computed(() =>
|
||||
permissionList.value.filter(permission => !assignablePermissionIdSet.value.has(String(permission.id))).length
|
||||
)
|
||||
|
||||
const groupedPermissions = computed(() => {
|
||||
const groups: Record<string, PermissionVO[]> = {}
|
||||
permissionList.value.forEach(p => {
|
||||
const groupName = p.permissionGroup
|
||||
if (!groups[groupName]) {
|
||||
groups[groupName] = []
|
||||
}
|
||||
groups[groupName]!.push(p)
|
||||
})
|
||||
return groups
|
||||
})
|
||||
|
||||
const getUserTypeText = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: '用户',
|
||||
2: '店长',
|
||||
3: '美甲师',
|
||||
4: '管理员'
|
||||
}
|
||||
return map[type] || '未知'
|
||||
}
|
||||
|
||||
const filteredUserList = computed(() => {
|
||||
if (!currentLoginUser.value) return []
|
||||
|
||||
const currentUserId = currentLoginUser.value.id
|
||||
|
||||
// 管理员可以看到所有用户(除了普通用户和自己)
|
||||
if (currentLoginUser.value.type === 4) {
|
||||
return userList.value.filter(user => user.type !== 0 && !sameId(user.id, currentUserId))
|
||||
}
|
||||
|
||||
// 店长只能看到美甲师(除了自己)
|
||||
if (currentLoginUser.value.type === 2) {
|
||||
return userList.value.filter(user => user.type === 3 && !sameId(user.id, currentUserId))
|
||||
}
|
||||
|
||||
// 其他用户类型(如美甲师)不能管理权限
|
||||
return []
|
||||
})
|
||||
|
||||
const isPermissionDisabled = (permission: PermissionVO) => {
|
||||
if (!selectedUser.value) {
|
||||
return true
|
||||
}
|
||||
return !assignablePermissionIdSet.value.has(String(permission.id))
|
||||
}
|
||||
|
||||
const resolveRequestErrorMessage = (error: any, fallback: string) => {
|
||||
return error?.response?.data?.message || error?.message || fallback
|
||||
}
|
||||
|
||||
const fetchCurrentUser = async () => {
|
||||
try {
|
||||
// 尝试从API获取用户信息
|
||||
try {
|
||||
const res = await userApi.getUserInfo()
|
||||
currentLoginUser.value = res as unknown as UserVO
|
||||
} catch (apiError) {
|
||||
// 如果API调用失败,尝试从本地存储获取
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
try {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
currentLoginUser.value = userInfo as UserVO
|
||||
} catch (parseError) {
|
||||
console.error('解析本地存储的用户信息失败:', parseError)
|
||||
}
|
||||
} else {
|
||||
console.error('获取当前用户信息失败,本地存储也没有用户信息')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchPermissionList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await permissionApi.listAllPermissions() as unknown as PermissionVO[]
|
||||
permissionList.value = res || []
|
||||
permissionPagination.total = res?.length || 0
|
||||
} catch (error) {
|
||||
message.error('获取权限列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUserList = async () => {
|
||||
userLoading.value = true
|
||||
try {
|
||||
const params: any = {
|
||||
page: 1,
|
||||
size: 100,
|
||||
keyword: userSearchText.value
|
||||
}
|
||||
|
||||
// 如果当前用户不是管理员,只获取当前店铺的用户
|
||||
if (currentLoginUser.value && currentLoginUser.value.type !== 4 && currentLoginUser.value.shopId) {
|
||||
params.shopId = currentLoginUser.value.shopId
|
||||
}
|
||||
|
||||
const res = await userApi.listUsers(params) as unknown as { list: UserVO[] }
|
||||
userList.value = res.list || []
|
||||
} catch (error) {
|
||||
message.error('获取用户列表失败')
|
||||
} finally {
|
||||
userLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handlePermissionTableChange = async (pag: any) => {
|
||||
permissionPagination.current = pag.current
|
||||
permissionPagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchPermissionList())
|
||||
}
|
||||
|
||||
const handleUserSearch = async () => {
|
||||
await runWithGlobalLoading(() => fetchUserList())
|
||||
}
|
||||
|
||||
const selectUser = async (user: UserVO) => {
|
||||
selectedUser.value = user
|
||||
assignLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
// 已分配权限和“当前角色允许分配的权限”需要分开拿,前端只保留交集,避免保存时越权。
|
||||
const [assignedPermissions, allowedIds] = await Promise.all([
|
||||
permissionApi.getUserPermissions(user.id) as unknown as Promise<PermissionVO[]>,
|
||||
permissionApi.getAssignablePermissionIds(user.id) as unknown as Promise<IdType[]>
|
||||
])
|
||||
assignablePermissionIds.value = allowedIds || []
|
||||
const allowedIdSet = new Set(assignablePermissionIds.value.map(id => String(id)))
|
||||
const assignedIds = (assignedPermissions || []).map((p: PermissionVO) => p.id)
|
||||
selectedPermissions.value = assignedIds.filter(id => allowedIdSet.has(String(id)))
|
||||
const trimmedCount = assignedIds.length - selectedPermissions.value.length
|
||||
if (trimmedCount > 0) {
|
||||
message.warning(`已自动排除 ${trimmedCount} 项超出当前角色允许范围的权限`)
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
message.error(resolveRequestErrorMessage(error, '获取用户权限失败'))
|
||||
assignablePermissionIds.value = []
|
||||
selectedPermissions.value = []
|
||||
} finally {
|
||||
assignLoading.value = false
|
||||
if (isMobile.value) {
|
||||
mobilePermissionStep.value = 'assign'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleSaveUserPermissions = async () => {
|
||||
if (!selectedUser.value) return
|
||||
const userId = selectedUser.value.id
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await permissionApi.assignUserPermissions(userId, selectedPermissions.value)
|
||||
message.success('权限保存成功')
|
||||
// 重新加载当前用户的权限
|
||||
await loadUserPermissions()
|
||||
})
|
||||
} catch (error: any) {
|
||||
message.error(resolveRequestErrorMessage(error, '权限保存失败'))
|
||||
}
|
||||
}
|
||||
|
||||
const showAddPermissionModal = () => {
|
||||
isEditPermission.value = false
|
||||
currentPermission.value = null
|
||||
Object.assign(permissionFormState, {
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
})
|
||||
restoreDraft()
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditPermissionModal = (record: Record<string, any>) => {
|
||||
isEditPermission.value = true
|
||||
currentPermission.value = record as PermissionVO
|
||||
Object.assign(permissionFormState, {
|
||||
permissionCode: record.permissionCode,
|
||||
permissionName: record.permissionName,
|
||||
permissionGroup: record.permissionGroup,
|
||||
description: record.description
|
||||
})
|
||||
restoreDraft()
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
const handlePermissionModalOk = async () => {
|
||||
try {
|
||||
await permissionFormRef.value?.validate()
|
||||
permissionModalLoading.value = true
|
||||
|
||||
await runWithGlobalLoading(async () => {
|
||||
if (isEditPermission.value && currentPermission.value) {
|
||||
await permissionApi.updatePermission(currentPermission.value.id, permissionFormState)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await permissionApi.createPermission(permissionFormState)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
permissionModalVisible.value = false
|
||||
await fetchPermissionList()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
permissionModalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handlePermissionModalCancel = () => {
|
||||
permissionModalVisible.value = false
|
||||
permissionFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDeletePermission = async (record: Record<string, any>) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await permissionApi.deletePermission((record as PermissionVO).id)
|
||||
message.success('删除成功')
|
||||
await fetchPermissionList()
|
||||
})
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchCurrentUser()
|
||||
await loadUserPermissions()
|
||||
fetchPermissionList()
|
||||
// 确保在获取当前用户信息后再获取用户列表
|
||||
setTimeout(() => {
|
||||
fetchUserList()
|
||||
}, 100)
|
||||
})
|
||||
|
||||
watch(
|
||||
() => activeTab.value,
|
||||
value => {
|
||||
if (value !== 'user-permissions') {
|
||||
mobilePermissionStep.value = 'users'
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.permissions {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.selected {
|
||||
background: rgba(204, 123, 95, 0.12) !important;
|
||||
border-left: 3px solid #cc7b5f;
|
||||
}
|
||||
|
||||
.mobile-permission-flow {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.mobile-user-pick {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.mobile-assign-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,26 +1,38 @@
|
||||
<template>
|
||||
<div class="products">
|
||||
<a-page-header title="作品管理" sub-title="管理美甲作品" />
|
||||
<a-page-header v-if="!isMobile" title="作品管理" sub-title="管理美甲作品" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">作品管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">作品 {{ productList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
作品列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<a-space>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索作品名称"
|
||||
style="width: 250px"
|
||||
:style="isMobile ? { width: '100%' } : { width: '250px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="hasPermission('product:create')" type="primary" @click="showAddModal">
|
||||
<a-button v-if="!isMobile && hasPermission('product:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增作品
|
||||
</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="productList"
|
||||
:loading="loading"
|
||||
@@ -91,12 +103,47 @@
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="productList" empty-description="暂无作品数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<a-image
|
||||
class="admin-mobile-card__cover admin-mobile-card__cover--wide"
|
||||
:src="getProductImages(item)[0] || DEFAULT_PRODUCT_IMAGE"
|
||||
:preview="false"
|
||||
/>
|
||||
<div class="admin-mobile-card__head" style="margin-top: 14px">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.title }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || getShopName(item.shopId) }}</div>
|
||||
</div>
|
||||
<span class="admin-mobile-card__badge">¥{{ item.price }}</span>
|
||||
</div>
|
||||
<div class="admin-mobile-card__description">{{ item.description || '暂无描述' }}</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>预计时长</span>
|
||||
<strong>{{ item.approximateDuration || '--' }} 分钟</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>互动数据</span>
|
||||
<strong>赞 {{ item.likeCount || 0 }} / 藏 {{ item.collectCount || 0 }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('product:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
<a-button v-if="hasPermission('product:delete')" size="small" danger @click="handleDelete(item)">删除</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑作品' : '新增作品'"
|
||||
width="700px"
|
||||
:desktop-width="700"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
@@ -302,13 +349,13 @@
|
||||
</a-form-item>
|
||||
</template>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<!-- 查看作品详情模态框 -->
|
||||
<a-modal
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看作品详情"
|
||||
width="700px"
|
||||
:desktop-width="700"
|
||||
@cancel="handleViewModalCancel"
|
||||
>
|
||||
<a-form
|
||||
@@ -427,7 +474,13 @@
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && hasPermission('product:create') && !modalVisible && !viewModalVisible"
|
||||
label="新增作品"
|
||||
@click="showAddModal"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -446,8 +499,13 @@ import { MAX_IMAGE_UPLOAD_SIZE, compressImageIfNeeded, formatFileSize } from '@/
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { sameId } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const productList = ref<Product[]>([])
|
||||
@@ -477,6 +535,20 @@ const uploadTaskMap = new Map<string, ChunkUploadTask<any>>()
|
||||
const activeUploadCount = ref(0)
|
||||
const isUploadPending = computed(() => activeUploadCount.value > 0)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
const requestTokens = reactive({
|
||||
shops: 0,
|
||||
tags: 0,
|
||||
artists: 0,
|
||||
coupons: 0,
|
||||
products: 0
|
||||
})
|
||||
|
||||
const nextRequestToken = (key: keyof typeof requestTokens) => {
|
||||
requestTokens[key] += 1
|
||||
return requestTokens[key]
|
||||
}
|
||||
|
||||
const isLatestRequestToken = (key: keyof typeof requestTokens, token: number) => requestTokens[key] === token
|
||||
|
||||
const viewFormState = reactive({
|
||||
shopId: undefined,
|
||||
@@ -593,6 +665,7 @@ const canManageAvailableCoupons = () => {
|
||||
const isCouponSelectionDisabled = computed(() => !canManageAvailableCoupons())
|
||||
|
||||
const fetchShops = async () => {
|
||||
const requestToken = nextRequestToken('shops')
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
@@ -600,11 +673,16 @@ const fetchShops = async () => {
|
||||
// 检查用户类型和权限
|
||||
if (currentUser && currentUser.type === 3 && currentUser.shopId) {
|
||||
// 美甲师直接使用自己的店铺ID,不需要获取店铺列表
|
||||
shops.value = []
|
||||
formState.shopId = currentUser.shopId
|
||||
if (isLatestRequestToken('shops', requestToken)) {
|
||||
shops.value = []
|
||||
formState.shopId = currentUser.shopId
|
||||
}
|
||||
} else {
|
||||
const response = await adminShopApi.listAllShops() as any
|
||||
const res = response || []
|
||||
if (!isLatestRequestToken('shops', requestToken)) {
|
||||
return
|
||||
}
|
||||
// 根据用户权限控制店铺列表的显示
|
||||
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
||||
// 如果是店长,只显示用户所属的店铺
|
||||
@@ -620,11 +698,14 @@ const fetchShops = async () => {
|
||||
// 权限不足时不显示错误提示
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
if (isLatestRequestToken('shops', requestToken)) {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchTags = async (shopId?: IdType) => {
|
||||
const requestToken = nextRequestToken('tags')
|
||||
loadingTags.value = true
|
||||
try {
|
||||
let response
|
||||
@@ -633,25 +714,36 @@ const fetchTags = async (shopId?: IdType) => {
|
||||
} else {
|
||||
response = await adminTagApi.listAllTags() as any
|
||||
}
|
||||
if (!isLatestRequestToken('tags', requestToken)) {
|
||||
return
|
||||
}
|
||||
tags.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败', error)
|
||||
message.error('获取标签列表失败')
|
||||
} finally {
|
||||
loadingTags.value = false
|
||||
if (isLatestRequestToken('tags', requestToken)) {
|
||||
loadingTags.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchArtists = async (shopId?: IdType) => {
|
||||
const requestToken = nextRequestToken('artists')
|
||||
loadingArtists.value = true
|
||||
try {
|
||||
const response = await adminArtistApi.listArtists(shopId) as any
|
||||
if (!isLatestRequestToken('artists', requestToken)) {
|
||||
return
|
||||
}
|
||||
artists.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取美甲师列表失败', error)
|
||||
message.error('获取美甲师列表失败')
|
||||
} finally {
|
||||
loadingArtists.value = false
|
||||
if (isLatestRequestToken('artists', requestToken)) {
|
||||
loadingArtists.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,26 +759,34 @@ const syncAvailableCouponSelection = () => {
|
||||
|
||||
const fetchCoupons = async (shopId?: IdType) => {
|
||||
if (!shopId) {
|
||||
nextRequestToken('coupons')
|
||||
coupons.value = []
|
||||
formState.availableCoupons = []
|
||||
return
|
||||
}
|
||||
|
||||
const requestToken = nextRequestToken('coupons')
|
||||
loadingCoupons.value = true
|
||||
try {
|
||||
const response = await adminCouponApi.listAllCoupons(shopId)
|
||||
const res = typeof response === 'object' && 'data' in response ? response.data : response
|
||||
if (!isLatestRequestToken('coupons', requestToken)) {
|
||||
return
|
||||
}
|
||||
coupons.value = (res as any[]) || []
|
||||
syncAvailableCouponSelection()
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
loadingCoupons.value = false
|
||||
if (isLatestRequestToken('coupons', requestToken)) {
|
||||
loadingCoupons.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchProductList = async () => {
|
||||
const requestToken = nextRequestToken('products')
|
||||
loading.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
@@ -701,24 +801,40 @@ const fetchProductList = async () => {
|
||||
}
|
||||
|
||||
const response = await adminProductApi.listProducts(params) as any
|
||||
productList.value = response?.list || []
|
||||
if (!isLatestRequestToken('products', requestToken)) {
|
||||
return
|
||||
}
|
||||
const nextProducts = response?.list || []
|
||||
productList.value = nextProducts
|
||||
pagination.total = response?.total || 0
|
||||
|
||||
await loadImageUrls(response?.list || [])
|
||||
|
||||
const nextImageUrls = await loadImageUrls(nextProducts, requestToken)
|
||||
if (nextImageUrls && isLatestRequestToken('products', requestToken)) {
|
||||
imageUrls.value = nextImageUrls
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取作品列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (isLatestRequestToken('products', requestToken)) {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const loadImageUrls = async (products: Product[]) => {
|
||||
const loadImageUrls = async (products: Product[], requestToken?: number) => {
|
||||
const nextImageUrls: Record<string, string[]> = {}
|
||||
for (const product of products) {
|
||||
if (requestToken && !isLatestRequestToken('products', requestToken)) {
|
||||
return null
|
||||
}
|
||||
if (product.imageFileIds) {
|
||||
const ids = product.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (requestToken && !isLatestRequestToken('products', requestToken)) {
|
||||
return null
|
||||
}
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
@@ -735,14 +851,15 @@ const loadImageUrls = async (products: Product[]) => {
|
||||
}
|
||||
|
||||
if (product.id) {
|
||||
imageUrls.value[String(product.id)] = urls
|
||||
nextImageUrls[String(product.id)] = urls
|
||||
}
|
||||
} else {
|
||||
if (product.id) {
|
||||
imageUrls.value[String(product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
nextImageUrls[String(product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
}
|
||||
}
|
||||
return nextImageUrls
|
||||
}
|
||||
|
||||
const getProductImages = (product: Product | Record<string, any>): string[] => {
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
<template>
|
||||
<div class="admin-profile">
|
||||
<section class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">{{ userInfo?.account || '后台账号' }}</span>
|
||||
<h1 class="admin-page-intro__title">{{ userInfo?.nickname || '未设置昵称' }}</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">权限 {{ permissionCount }}</span>
|
||||
<span class="admin-page-chip">门店 {{ shopOptions.length || 0 }}</span>
|
||||
<span class="admin-page-chip">{{ roleLabel }}</span>
|
||||
<span v-if="currentShopName === '游客模式'" class="admin-page-chip">游客模式</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="admin-mobile-grid admin-mobile-grid--two">
|
||||
<section class="admin-mobile-stat">
|
||||
<div class="admin-mobile-stat__label">当前门店</div>
|
||||
<div class="admin-mobile-stat__value">{{ currentShopName }}</div>
|
||||
</section>
|
||||
<section class="admin-mobile-stat">
|
||||
<div class="admin-mobile-stat__label">角色</div>
|
||||
<div class="admin-mobile-stat__value">{{ roleLabel }}</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">账号信息</div>
|
||||
<div class="profile-meta-list">
|
||||
<div class="profile-meta-list__row">
|
||||
<span>账号</span>
|
||||
<strong>{{ userInfo?.account || '--' }}</strong>
|
||||
</div>
|
||||
<div class="profile-meta-list__row">
|
||||
<span>昵称</span>
|
||||
<strong>{{ userInfo?.nickname || '--' }}</strong>
|
||||
</div>
|
||||
<div class="profile-meta-list__row">
|
||||
<span>权限数量</span>
|
||||
<strong>{{ permissionCount }}</strong>
|
||||
</div>
|
||||
<div class="profile-meta-list__row">
|
||||
<span>可登录门店</span>
|
||||
<strong>{{ shopScopeText }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">门店切换</div>
|
||||
<a-select
|
||||
v-if="shopOptions.length > 1"
|
||||
v-model:value="selectedShopId"
|
||||
class="profile-shop-select"
|
||||
:options="shopSelectOptions"
|
||||
:loading="shopSwitchLoading"
|
||||
@change="handleShopChange"
|
||||
/>
|
||||
<div v-else class="profile-static-shop">
|
||||
{{ currentShopName }}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">常用入口</div>
|
||||
<div class="profile-actions">
|
||||
<a-button type="default" size="large" block @click="router.push('/admin/orders')">查看订单</a-button>
|
||||
<a-button type="default" size="large" block @click="router.push('/admin/manage')">进入经营模块</a-button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">退出登录</div>
|
||||
<a-button danger size="large" block @click="handleLogout">退出当前账号</a-button>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { adminAuthApi } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import {
|
||||
getAdminCurrentShopName,
|
||||
getAdminRoleLabel,
|
||||
getAdminShopOptions,
|
||||
loadCachedAdminUserInfo
|
||||
} from './admin-helpers'
|
||||
|
||||
const router = useRouter()
|
||||
const { userPermissions, loadUserPermissions, clearPermissions } = usePermission()
|
||||
|
||||
const userInfo = ref(loadCachedAdminUserInfo())
|
||||
const selectedShopId = ref(userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined)
|
||||
const shopSwitchLoading = ref(false)
|
||||
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
const shopOptions = computed(() => getAdminShopOptions(userInfo.value))
|
||||
const shopSelectOptions = computed(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
|
||||
const permissionCount = computed(() => userPermissions.value.length)
|
||||
const shopScopeText = computed(() => {
|
||||
if (!shopOptions.value.length) {
|
||||
return '游客模式'
|
||||
}
|
||||
return shopOptions.value.map(item => item.name).join(' / ')
|
||||
})
|
||||
|
||||
const persistAdminSession = (payload: any) => {
|
||||
localStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
localStorage.setItem('adminRefreshToken', payload.refreshToken)
|
||||
localStorage.setItem('adminUserInfo', JSON.stringify(payload.userInfo))
|
||||
sessionStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
}
|
||||
|
||||
const refreshLocalUserInfo = () => {
|
||||
userInfo.value = loadCachedAdminUserInfo()
|
||||
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
|
||||
}
|
||||
|
||||
const handleShopChange = async (shopId: unknown) => {
|
||||
if (typeof shopId !== 'string' && typeof shopId !== 'number') {
|
||||
return
|
||||
}
|
||||
const normalizedShopId = String(shopId)
|
||||
if (!normalizedShopId || normalizedShopId === String(userInfo.value?.shopId || '')) {
|
||||
return
|
||||
}
|
||||
shopSwitchLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
const response = await adminAuthApi.switchShop(normalizedShopId)
|
||||
persistAdminSession(response as any)
|
||||
refreshLocalUserInfo()
|
||||
await loadUserPermissions()
|
||||
})
|
||||
message.success('门店切换成功')
|
||||
window.location.reload()
|
||||
} catch (error: any) {
|
||||
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
|
||||
message.error(error?.message || '切换门店失败')
|
||||
} finally {
|
||||
shopSwitchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出登录',
|
||||
content: '退出后需要重新登录后台。',
|
||||
okText: '确认',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
await runWithGlobalLoading(async () => {
|
||||
try {
|
||||
await adminAuthApi.logout()
|
||||
} catch (error) {
|
||||
console.error('退出失败:', error)
|
||||
} finally {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
clearPermissions()
|
||||
message.success('已退出登录')
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
refreshLocalUserInfo()
|
||||
await loadUserPermissions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-profile {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.profile-meta-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.profile-meta-list__row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
color: #64707a;
|
||||
}
|
||||
|
||||
.profile-meta-list__row strong {
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.profile-shop-select {
|
||||
width: 100%;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.profile-static-shop {
|
||||
margin-top: 14px;
|
||||
min-height: 46px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 14px;
|
||||
border-radius: 16px;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.profile-actions {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,537 @@
|
||||
<template>
|
||||
<div class="tags">
|
||||
<a-page-header v-if="!isMobile" title="标签管理" sub-title="管理系统标签" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">标签管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">标签 {{ tagList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
标签列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索标签名称"
|
||||
:style="isMobile ? { width: '100%' } : { width: '250px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="!isMobile && hasPermission('tag:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增标签
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="tagList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'color'">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: record.bgColor,
|
||||
color: record.textColor,
|
||||
borderColor: record.borderColor
|
||||
}"
|
||||
>
|
||||
{{ record.tagName }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shop'">
|
||||
<span>{{ record.shopName || getShopName(record.shopId) }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('tag:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('tag:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('tag:delete')" type="link" size="small" danger @click="handleDelete(record)">
|
||||
删除
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="tagList" empty-description="暂无标签数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.tagName }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || getShopName(item.shopId) || '未关联店铺' }}</div>
|
||||
</div>
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{ backgroundColor: item.bgColor, color: item.textColor, borderColor: item.borderColor }"
|
||||
>
|
||||
{{ item.tagName }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>创建时间</span>
|
||||
<strong>{{ item.createTime || '--' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button v-if="hasPermission('tag:view')" size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('tag:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
<a-button v-if="hasPermission('tag:delete')" size="small" danger @click="handleDelete(item)">删除</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑标签' : '新增标签'"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
:desktop-width="600"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="标签名称" name="tagName">
|
||||
<a-input v-model:value="formState.tagName" placeholder="请输入标签名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择所属店铺"
|
||||
style="width: 100%"
|
||||
:loading="loadingShops"
|
||||
:disabled="getCurrentUserInfo()?.type === 2"
|
||||
>
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
disabled
|
||||
value=""
|
||||
>
|
||||
暂无店铺数据
|
||||
</a-select-option>
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="文字颜色" name="textColor">
|
||||
<el-color-picker v-model="formState.textColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="背景颜色" name="bgColor">
|
||||
<el-color-picker v-model="formState.bgColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="边框颜色" name="borderColor">
|
||||
<el-color-picker v-model="formState.borderColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="预览">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: formState.bgColor,
|
||||
color: formState.textColor,
|
||||
borderColor: formState.borderColor
|
||||
}"
|
||||
>
|
||||
{{ formState.tagName }}
|
||||
</span>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<!-- 查看标签详情模态框 -->
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看标签详情"
|
||||
:footer="null"
|
||||
@cancel="handleViewModalCancel"
|
||||
:desktop-width="600"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="标签名称">
|
||||
<a-input v-model:value="viewFormState.tagName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺">
|
||||
<a-select v-model:value="viewFormState.shopId" :disabled="true">
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="文字颜色">
|
||||
<el-color-picker v-model="viewFormState.textColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="背景颜色">
|
||||
<el-color-picker v-model="viewFormState.bgColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="边框颜色">
|
||||
<el-color-picker v-model="viewFormState.borderColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="预览">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: viewFormState.bgColor,
|
||||
color: viewFormState.textColor,
|
||||
borderColor: viewFormState.borderColor
|
||||
}"
|
||||
>
|
||||
{{ viewFormState.tagName }}
|
||||
</span>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && hasPermission('tag:create') && !modalVisible && !viewModalVisible"
|
||||
label="新增标签"
|
||||
@click="showAddModal"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { adminTagApi, adminShopApi, type Shop } from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
return userInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentTag = ref<any>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
// 查看标签相关状态
|
||||
const viewFormState = reactive({
|
||||
tagName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
|
||||
const tagList = ref<any[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
const loadingShops = ref(false)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
tagName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-tags', isEdit.value ? 'edit' : 'create', currentTag.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
tagName: formState.tagName,
|
||||
shopId: formState.shopId,
|
||||
textColor: formState.textColor,
|
||||
bgColor: formState.bgColor,
|
||||
borderColor: formState.borderColor
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const formRules = {
|
||||
tagName: [{ required: true, message: '请输入标签名称', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '标签名称', dataIndex: 'tagName', key: 'tagName' },
|
||||
{ title: '所属店铺', key: 'shop', width: 150 },
|
||||
{ title: '预览', key: 'color', width: 150 },
|
||||
{ title: '文字颜色', dataIndex: 'textColor', key: 'textColor', width: 120 },
|
||||
{ title: '背景颜色', dataIndex: 'bgColor', key: 'bgColor', width: 120 },
|
||||
{ title: '边框颜色', dataIndex: 'borderColor', key: 'borderColor', width: 120 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const fetchTags = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
let tags
|
||||
if (shopId) {
|
||||
tags = await adminTagApi.listTagsByShopId(shopId) as unknown as any[]
|
||||
} else {
|
||||
tags = await adminTagApi.listAllTags() as unknown as any[]
|
||||
}
|
||||
tagList.value = tags || []
|
||||
pagination.total = tagList.value.length
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
message.error('获取标签列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const res = await adminShopApi.listAllShops() as unknown as any[]
|
||||
shops.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeShopIdValue = (value: string | number | undefined | null) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return ''
|
||||
}
|
||||
return String(value)
|
||||
}
|
||||
|
||||
const getShopName = (shopId: IdType | undefined) => {
|
||||
const normalizedShopId = normalizeShopIdValue(shopId)
|
||||
const shop = shops.value.find(s => normalizeShopIdValue(s.id) === normalizedShopId)
|
||||
return shop ? shop.shopName : '未知店铺'
|
||||
}
|
||||
|
||||
const handleSearch = async () => {
|
||||
pagination.current = 1
|
||||
await runWithGlobalLoading(() => fetchTags())
|
||||
}
|
||||
|
||||
const handleTableChange = async (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchTags())
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentTag.value = null
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
Object.assign(formState, {
|
||||
tagName: '',
|
||||
shopId: shopId,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: any) => {
|
||||
isEdit.value = true
|
||||
currentTag.value = record
|
||||
Object.assign(formState, {
|
||||
tagName: record.tagName,
|
||||
shopId: record.shopId,
|
||||
textColor: record.textColor,
|
||||
bgColor: record.bgColor,
|
||||
borderColor: record.borderColor
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = (record: any) => {
|
||||
Object.assign(viewFormState, {
|
||||
tagName: record.tagName,
|
||||
shopId: record.shopId,
|
||||
textColor: record.textColor,
|
||||
bgColor: record.bgColor,
|
||||
borderColor: record.borderColor
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
await runWithGlobalLoading(async () => {
|
||||
const requestData = {
|
||||
tagName: formState.tagName,
|
||||
shopId: formState.shopId,
|
||||
textColor: formState.textColor,
|
||||
bgColor: formState.bgColor,
|
||||
borderColor: formState.borderColor
|
||||
}
|
||||
|
||||
if (isEdit.value && currentTag.value) {
|
||||
await adminTagApi.updateTag(currentTag.value.id, requestData)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminTagApi.createTag(requestData)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
await fetchTags()
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('Error:', error)
|
||||
message.error(error?.message || (isEdit.value ? '更新失败' : '创建失败'))
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDelete = (record: any) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
content: `确定要删除标签 ${record.tagName} 吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminTagApi.deleteTag(record.id)
|
||||
message.success('删除成功')
|
||||
await fetchTags()
|
||||
})
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
await fetchShops()
|
||||
await fetchTags()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tags {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.tag-preview {
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
import { loadCachedAdminUserInfo, isBootstrapAdminUser, type AdminCachedUserInfo } from '@/utils/admin-session'
|
||||
|
||||
export { loadCachedAdminUserInfo, isBootstrapAdminUser }
|
||||
export type { AdminCachedUserInfo }
|
||||
|
||||
export const getAdminRoleLabel = (type?: number) => {
|
||||
switch (type) {
|
||||
case 4:
|
||||
return '平台管理员'
|
||||
case 2:
|
||||
return '店长'
|
||||
case 3:
|
||||
return '美甲师'
|
||||
default:
|
||||
return '后台账号'
|
||||
}
|
||||
}
|
||||
|
||||
export const getAdminShopOptions = (userInfo?: AdminCachedUserInfo | null) => {
|
||||
const ids = userInfo?.shopIds || []
|
||||
const names = userInfo?.shopNames || []
|
||||
return ids.map((id, index) => ({
|
||||
id: String(id),
|
||||
name: names[index] || `门店 ${id}`
|
||||
}))
|
||||
}
|
||||
|
||||
export const getAdminCurrentShopName = (userInfo?: AdminCachedUserInfo | null) =>
|
||||
userInfo?.shopName || '游客模式'
|
||||
Reference in New Issue
Block a user