功能:完善多店铺登录与首次部署SQL
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
>
|
||||
<div class="logo">
|
||||
<h1 v-if="!collapsed">后台管理</h1>
|
||||
<h1 v-else>管</h1>
|
||||
<h1 v-else>后台</h1>
|
||||
</div>
|
||||
<a-menu
|
||||
:selectedKeys="selectedKeys"
|
||||
@@ -29,21 +29,36 @@
|
||||
</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"
|
||||
/>
|
||||
<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>
|
||||
@@ -53,11 +68,11 @@
|
||||
</a>
|
||||
<template #overlay>
|
||||
<a-menu>
|
||||
<a-menu-item key="profile" @click="goToProfile">
|
||||
<a-menu-item key="home" @click="router.push('/admin')">
|
||||
<template #icon>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
个人中心
|
||||
工作台
|
||||
</a-menu-item>
|
||||
<a-menu-divider />
|
||||
<a-menu-item key="logout" @click="handleLogout">
|
||||
@@ -72,6 +87,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</a-layout-header>
|
||||
|
||||
<a-layout-content class="content">
|
||||
<div class="content-shell">
|
||||
<router-view />
|
||||
@@ -83,26 +99,25 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, watch } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
DashboardOutlined,
|
||||
DownOutlined,
|
||||
GiftOutlined,
|
||||
HomeOutlined,
|
||||
LogoutOutlined,
|
||||
MenuFoldOutlined,
|
||||
MenuUnfoldOutlined,
|
||||
DashboardOutlined,
|
||||
UserOutlined,
|
||||
ShopOutlined,
|
||||
HomeOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
DownOutlined,
|
||||
LogoutOutlined,
|
||||
GiftOutlined,
|
||||
TagOutlined,
|
||||
ShopOutlined,
|
||||
ShoppingOutlined,
|
||||
TeamOutlined
|
||||
TagOutlined,
|
||||
TeamOutlined,
|
||||
UserOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { adminAuthApi, type UserVO } from '@/api/admin'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
@@ -111,86 +126,52 @@ const route = useRoute()
|
||||
|
||||
const collapsed = 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 = [
|
||||
{
|
||||
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'
|
||||
}
|
||||
{ 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 selectedKeys = ref<string[]>([route.path])
|
||||
const isBootstrapAdmin = computed(() => userInfo.value?.type === 4 && !userInfo.value?.shopId)
|
||||
const shopOptions = computed(() => {
|
||||
const ids = userInfo.value?.shopIds || []
|
||||
const names = userInfo.value?.shopNames || []
|
||||
return ids.map((id, index) => ({
|
||||
id: String(id),
|
||||
name: names[index] || `门店 ${id}`
|
||||
}))
|
||||
})
|
||||
const shopSelectOptions = computed(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
|
||||
const currentShopName = computed(() => userInfo.value?.shopName || '未选择门店')
|
||||
|
||||
const filteredMenuItems = computed(() => {
|
||||
// 访问 userPermissions 以建立依赖关系
|
||||
userPermissions.value
|
||||
// 所有用户类型都根据实际权限过滤菜单
|
||||
return menuItems.filter(item => {
|
||||
// 空权限码的菜单项(如首页)总是可见
|
||||
if (!item.permissionCode) {
|
||||
return true
|
||||
}
|
||||
return hasPermission(item.permissionCode)
|
||||
})
|
||||
let visibleItems = menuItems.filter(item => !item.permissionCode || hasPermission(item.permissionCode))
|
||||
if (isBootstrapAdmin.value) {
|
||||
visibleItems = visibleItems.filter(item => item.key === '/admin' || item.key === '/admin/shops')
|
||||
}
|
||||
return visibleItems
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
@@ -199,20 +180,17 @@ const handleMenuClick = (info: any) => {
|
||||
router.push(info.key)
|
||||
}
|
||||
|
||||
const goToProfile = () => {
|
||||
router.push('/profile')
|
||||
}
|
||||
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出',
|
||||
content: '确定要退出登录吗?',
|
||||
title: '确认退出登录',
|
||||
content: '退出后需要重新登录后台。',
|
||||
okText: '确认',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
try {
|
||||
// 尝试调用登出API
|
||||
await authApi.logout()
|
||||
await adminAuthApi.logout()
|
||||
} catch (error) {
|
||||
console.error('登出失败:', error)
|
||||
console.error('退出失败:', error)
|
||||
} finally {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
@@ -232,21 +210,51 @@ const handleLogout = () => {
|
||||
|
||||
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
|
||||
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)
|
||||
console.error('获取后台用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => route.path, (newPath) => {
|
||||
selectedKeys.value = [newPath]
|
||||
}, { immediate: true })
|
||||
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 {
|
||||
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 = [newPath]
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchUserInfo()
|
||||
@@ -275,51 +283,76 @@ onMounted(async () => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
margin: 0;
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(.ant-menu) {
|
||||
border-right: none;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: white;
|
||||
padding: 0 24px;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
padding: 0 24px;
|
||||
background: white;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.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;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.trigger:hover {
|
||||
color: #1890ff;
|
||||
.shop-hint,
|
||||
.shop-switcher,
|
||||
.shop-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-height: 40px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
background: #f5f7fb;
|
||||
color: #334155;
|
||||
}
|
||||
|
||||
.shop-hint {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.shop-switcher-label {
|
||||
font-size: 13px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.shop-select {
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.shop-pill {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
@@ -331,29 +364,25 @@ onMounted(async () => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
cursor: pointer;
|
||||
padding: 8px 12px;
|
||||
border-radius: 8px;
|
||||
transition: background 0.3s;
|
||||
border-radius: 10px;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
.user-dropdown:hover {
|
||||
background: #f5f5f5;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin-left: 240px;
|
||||
min-height: calc(100vh - 64px);
|
||||
padding: 24px;
|
||||
background: #f0f2f5;
|
||||
min-height: calc(100vh - 64px);
|
||||
transition: margin-left 0.2s;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.content-shell {
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
@finish="handleLogin"
|
||||
>
|
||||
<a-alert
|
||||
v-if="!shopLoading && !hasAvailableShops"
|
||||
type="warning"
|
||||
v-if="loginShopMessage"
|
||||
:type="allowShoplessLogin || hasAvailableShops ? 'info' : 'warning'"
|
||||
show-icon
|
||||
message="当前暂无可选店铺"
|
||||
description="如果你使用的是平台管理员账号,可以直接登录后台先创建第一家店铺;其他后台账号仍需先绑定店铺。"
|
||||
:message="loginShopMessage"
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
@@ -46,10 +45,10 @@
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
size="large"
|
||||
:placeholder="hasAvailableShops ? '请选择登录店铺' : '当前暂无可选店铺'"
|
||||
:placeholder="shopPlaceholder"
|
||||
:loading="shopLoading"
|
||||
:options="shopOptions"
|
||||
:disabled="shopLoading || !hasAvailableShops"
|
||||
:disabled="shopLoading || (!hasAvailableShops && !allowShoplessLogin)"
|
||||
show-search
|
||||
:filter-option="filterShopOption"
|
||||
/>
|
||||
@@ -77,20 +76,21 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
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 } from '@/api/admin'
|
||||
import { shopApi, type ShopSimpleVO } from '@/api/shop'
|
||||
import { adminAuthApi, type LoginShopSelectionResponse } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const shopLoading = ref(false)
|
||||
const shops = ref<ShopSimpleVO[]>([])
|
||||
const shops = ref<Array<{ id: number | string; shopName: string }>>([])
|
||||
const allowShoplessLogin = ref(false)
|
||||
const loginShopMessage = ref('')
|
||||
const { loadUserPermissions } = usePermission()
|
||||
|
||||
const formState = reactive({
|
||||
@@ -98,9 +98,10 @@ const formState = reactive({
|
||||
password: '',
|
||||
shopId: undefined as string | undefined
|
||||
})
|
||||
let loginShopTimer: number | undefined
|
||||
|
||||
const getShopIdValue = (shop: ShopSimpleVO) => String(shop.id ?? '')
|
||||
const getShopLabel = (shop: ShopSimpleVO) => String(shop.shopName || shop.name || `店铺 ${shop.id}`)
|
||||
const getShopIdValue = (shop: { id: number | string; shopName: string }) => String(shop.id ?? '')
|
||||
const getShopLabel = (shop: { id: number | string; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`)
|
||||
|
||||
const shopOptions = computed(() =>
|
||||
shops.value.map(shop => ({
|
||||
@@ -109,6 +110,19 @@ const shopOptions = computed(() =>
|
||||
}))
|
||||
)
|
||||
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: [
|
||||
@@ -118,7 +132,7 @@ const formRules = {
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
shopId: [{
|
||||
validator: async () => {
|
||||
if (!hasAvailableShops.value || formState.shopId) {
|
||||
if (!shouldRequireShop.value || formState.shopId) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return Promise.reject(new Error('请选择登录店铺'))
|
||||
@@ -130,6 +144,18 @@ const formRules = {
|
||||
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) {
|
||||
@@ -145,32 +171,63 @@ const restoreLoginShop = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadShops = async () => {
|
||||
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 {
|
||||
shops.value = await shopApi.getShopsSimple() as unknown as ShopSimpleVO[]
|
||||
if (!shops.value.length) {
|
||||
formState.shopId = undefined
|
||||
return
|
||||
const selection = await adminAuthApi.getLoginShops(trimmedAccount) as unknown as LoginShopSelectionResponse
|
||||
if (formState.account.trim() === trimmedAccount) {
|
||||
applyLoginShopSelection(selection)
|
||||
}
|
||||
|
||||
const hasMatchedShop = shopOptions.value.some(option => option.value === formState.shopId)
|
||||
if (hasMatchedShop) {
|
||||
return
|
||||
}
|
||||
|
||||
if (shops.value.length === 1) {
|
||||
const [onlyShop] = shops.value
|
||||
if (onlyShop) {
|
||||
formState.shopId = getShopIdValue(onlyShop)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
formState.shopId = undefined
|
||||
} catch (error) {
|
||||
console.error('获取登录店铺列表失败:', error)
|
||||
message.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
|
||||
}
|
||||
@@ -214,7 +271,26 @@ const handleLogin = async () => {
|
||||
|
||||
onMounted(() => {
|
||||
restoreLoginShop()
|
||||
loadShops()
|
||||
})
|
||||
|
||||
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 = () => {
|
||||
|
||||
@@ -1,58 +1,44 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<a-page-header title="仪表盘" sub-title="欢迎使用后台管理系统" />
|
||||
|
||||
<a-row :gutter="16" class="stat-cards">
|
||||
<a-col :span="6">
|
||||
<a-page-header
|
||||
title="仪表盘"
|
||||
:sub-title="pageSubtitle"
|
||||
/>
|
||||
|
||||
<a-row :gutter="[16, 16]" class="stat-cards">
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="总用户数"
|
||||
:value="stats.totalUsers"
|
||||
:value-style="{ color: '#3f8600' }"
|
||||
:loading="loading"
|
||||
>
|
||||
<a-statistic title="用户数" :value="stats.totalUsers" :loading="loading">
|
||||
<template #prefix>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="6">
|
||||
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="作品总数"
|
||||
:value="stats.totalProducts"
|
||||
:value-style="{ color: '#1890ff' }"
|
||||
:loading="loading"
|
||||
>
|
||||
<a-statistic title="作品数" :value="stats.totalProducts" :loading="loading">
|
||||
<template #prefix>
|
||||
<ShopOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="6" v-if="isAdmin">
|
||||
|
||||
<a-col v-if="isAdmin" :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="店铺数量"
|
||||
:value="stats.totalShops"
|
||||
:value-style="{ color: '#722ed1' }"
|
||||
:loading="loading"
|
||||
>
|
||||
<a-statistic title="门店数" :value="stats.totalShops" :loading="loading">
|
||||
<template #prefix>
|
||||
<HomeOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="6">
|
||||
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="今日订单"
|
||||
:value="stats.todayOrders"
|
||||
:value-style="{ color: '#cf1322' }"
|
||||
:loading="loading"
|
||||
>
|
||||
<a-statistic title="今日订单" :value="stats.todayOrders" :loading="loading">
|
||||
<template #prefix>
|
||||
<ShoppingOutlined />
|
||||
</template>
|
||||
@@ -61,47 +47,50 @@
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-row :gutter="16" class="charts-section">
|
||||
<a-col :span="16">
|
||||
<a-card title="订单趋势" :bordered="false" class="chart-card">
|
||||
<div class="chart-placeholder">
|
||||
<BarChartOutlined :style="{ fontSize: '64px', color: '#d9d9d9' }" />
|
||||
<p>订单趋势图表</p>
|
||||
</div>
|
||||
<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 :span="8">
|
||||
<a-card title="热门作品" :bordered="false" class="chart-card">
|
||||
|
||||
<a-col :xs="24" :xl="10">
|
||||
<a-card title="热门作品" class="side-card">
|
||||
<a-spin :spinning="loading">
|
||||
<a-list :data-source="stats.hotProducts" size="small">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item>
|
||||
<a-list-item-meta>
|
||||
<template #title>
|
||||
<a href="#">{{ item.title }}</a>
|
||||
</template>
|
||||
<template #description>
|
||||
点赞: {{ item.likeCount }} | 收藏: {{ item.collectCount || 0 }}
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
<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="最近活动" :bordered="false" class="activity-card">
|
||||
<a-card title="最近动态" class="activity-card">
|
||||
<a-spin :spinning="loading">
|
||||
<a-timeline>
|
||||
<a-timeline-item
|
||||
v-for="activity in stats.recentActivities"
|
||||
<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"
|
||||
:color="activity.color || 'blue'"
|
||||
>
|
||||
<p>{{ activity.description }}</p>
|
||||
<p style="font-size: 12px; color: #999;">{{ formatTime(activity.time) }}</p>
|
||||
<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>
|
||||
@@ -110,15 +99,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import {
|
||||
UserOutlined,
|
||||
ShopOutlined,
|
||||
HomeOutlined,
|
||||
ShoppingOutlined,
|
||||
BarChartOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { HomeOutlined, ShopOutlined, ShoppingOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { adminDashboardApi, type DashboardStats } from '@/api/admin'
|
||||
|
||||
const loading = ref(false)
|
||||
@@ -131,24 +114,62 @@ const stats = reactive<DashboardStats>({
|
||||
recentActivities: []
|
||||
})
|
||||
|
||||
// 获取当前用户信息
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
return userInfo
|
||||
}
|
||||
const cache = localStorage.getItem('adminUserInfo')
|
||||
return cache ? JSON.parse(cache) : null
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
console.error('读取后台用户信息失败:', error)
|
||||
return null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// 判断是否为管理员
|
||||
const isAdmin = computed(() => {
|
||||
const userInfo = getCurrentUserInfo()
|
||||
return userInfo?.type === 4
|
||||
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) => {
|
||||
@@ -156,22 +177,21 @@ const formatTime = (timeStr: string) => {
|
||||
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}天前`
|
||||
|
||||
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 {
|
||||
loading.value = true
|
||||
const data = await adminDashboardApi.getStats()
|
||||
Object.assign(stats, data)
|
||||
} catch (error) {
|
||||
@@ -183,7 +203,7 @@ const fetchStats = async () => {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchStats()
|
||||
void fetchStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -196,29 +216,89 @@ onMounted(() => {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.charts-section {
|
||||
margin-bottom: 24px;
|
||||
.insight-card,
|
||||
.side-card,
|
||||
.activity-card {
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
height: 400px;
|
||||
.insight-list {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.chart-placeholder {
|
||||
.insight-item {
|
||||
padding: 16px 18px;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(135deg, #f8fbff 0%, #f5f7ff 100%);
|
||||
border: 1px solid #edf2ff;
|
||||
}
|
||||
|
||||
.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;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 300px;
|
||||
color: #999;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 14px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.chart-placeholder p {
|
||||
margin-top: 16px;
|
||||
font-size: 14px;
|
||||
.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: #ff4d4f;
|
||||
}
|
||||
|
||||
.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>
|
||||
|
||||
@@ -64,6 +64,15 @@
|
||||
<span v-if="getShopBannerImages(record).length === 0" class="no-banner">暂无Banner</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-switch
|
||||
:checked="record.status !== 0"
|
||||
:disabled="!hasPermission('shop:edit') || !isAdmin"
|
||||
checked-children="启用"
|
||||
un-checked-children="停用"
|
||||
@change="(checked: any) => handleStatusChange(record, checked === true)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('shop:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
@@ -298,6 +307,7 @@ const viewFormState = reactive({
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
status: 1,
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
@@ -316,6 +326,7 @@ const formState = reactive({
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
status: 1,
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
@@ -345,6 +356,7 @@ const columns = [
|
||||
{ title: '店铺描述', dataIndex: 'description', key: 'description' },
|
||||
{ title: '店铺地址', dataIndex: 'address', key: 'address' },
|
||||
{ title: '营业时间', dataIndex: 'businessHours', key: 'businessHours' },
|
||||
{ title: '状态', key: 'status', width: 120 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
@@ -600,6 +612,7 @@ const showAddModal = () => {
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
status: 1,
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
@@ -619,6 +632,7 @@ const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
description: 'description' in record ? record.description : (record as any).description,
|
||||
address: 'address' in record ? record.address : (record as any).address,
|
||||
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
|
||||
status: 'status' in record ? (record.status ?? 1) : ((record as any).status ?? 1),
|
||||
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
@@ -707,6 +721,7 @@ const showViewModal = async (record: Shop | Record<string, any>) => {
|
||||
description: 'description' in record ? record.description : (record as any).description,
|
||||
address: 'address' in record ? record.address : (record as any).address,
|
||||
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
|
||||
status: 'status' in record ? (record.status ?? 1) : ((record as any).status ?? 1),
|
||||
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
@@ -812,6 +827,17 @@ const handleDelete = async (record: Shop | Record<string, any>) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleStatusChange = async (record: Shop | Record<string, any>, enabled: boolean) => {
|
||||
try {
|
||||
const shopId = 'id' in record ? record.id : (record as any).id
|
||||
await adminShopApi.updateShopStatus(shopId, enabled ? 1 : 0)
|
||||
;(record as any).status = enabled ? 1 : 0
|
||||
message.success(`店铺已${enabled ? '启用' : '停用'}`)
|
||||
} catch (error) {
|
||||
message.error('店铺状态更新失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
fetchShopList()
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'shopName'">
|
||||
{{ record.shopName || getShopNameById(record.shopId) || '-' }}
|
||||
{{ getShopDisplay(record) || '-' }}
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'type'">
|
||||
@@ -83,7 +83,7 @@
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('user:delete') && record.type !== 4"
|
||||
title="确定要删除这个用户吗?"
|
||||
title="确定要将这个用户从当前店铺移除吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
@@ -128,10 +128,11 @@
|
||||
<a-form-item v-if="!isEdit" label="密码" name="password">
|
||||
<a-input-password v-model:value="formState.password" placeholder="请输入密码" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺" name="shopId">
|
||||
<a-form-item label="所属店铺" name="shopIds">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择店铺"
|
||||
v-model:value="formState.shopIds"
|
||||
mode="multiple"
|
||||
:placeholder="currentUserInfo?.type === 4 ? '请选择一个或多个店铺' : '请选择店铺'"
|
||||
:loading="shopLoading"
|
||||
:disabled="currentUserInfo?.type !== 4 && !!currentUserInfo?.shopId"
|
||||
>
|
||||
@@ -169,7 +170,7 @@
|
||||
<a-descriptions-item label="账号">{{ viewRecord?.account || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="昵称">{{ viewRecord?.nickname || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="手机号">{{ viewRecord?.phone || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="所属店铺">{{ viewRecord?.shopName || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="所属店铺">{{ getShopDisplay(viewRecord) || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="用户类型">{{ getUserTypeText(viewRecord?.type || 0) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="VIP 等级">{{ viewRecord?.level || '普通' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="状态">{{ viewRecord?.status === 1 ? '正常' : '禁用' }}</a-descriptions-item>
|
||||
@@ -188,7 +189,7 @@
|
||||
<div v-if="assetTargetUser" class="asset-modal">
|
||||
<a-alert
|
||||
:message="`${assetTargetUser.nickname}(${assetTargetUser.account})`"
|
||||
:description="assetTargetUser.shopName ? `所属店铺:${assetTargetUser.shopName}` : '未绑定店铺'"
|
||||
:description="getShopDisplay(assetTargetUser) ? `所属店铺:${getShopDisplay(assetTargetUser)}` : '未绑定店铺'"
|
||||
type="info"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
@@ -423,7 +424,7 @@ const formState = reactive({
|
||||
phone: '',
|
||||
password: '',
|
||||
type: 0,
|
||||
shopId: undefined as string | undefined
|
||||
shopIds: [] as string[]
|
||||
})
|
||||
|
||||
const balanceForm = reactive<AdminUserBalanceChangeRequest>({
|
||||
@@ -459,7 +460,15 @@ const formRules = {
|
||||
}
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
shopIds: [{
|
||||
validator: async (_rule: unknown, value: string[]) => {
|
||||
if (Array.isArray(value) && value.length > 0) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return Promise.reject('请选择至少一个店铺')
|
||||
},
|
||||
trigger: 'change'
|
||||
}],
|
||||
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
@@ -561,12 +570,41 @@ const getShopNameById = (shopId?: string | number | null) => {
|
||||
return matchedShop?.shopName || ''
|
||||
}
|
||||
|
||||
const resolveEditableShopId = (shopId?: string | number | null) => {
|
||||
const targetShopId = normalizeShopId(shopId)
|
||||
if (targetShopId && shopList.value.some(shop => getShopOptionValue(shop) === targetShopId)) {
|
||||
return targetShopId
|
||||
const getShopDisplay = (user?: Partial<UserVO> | Record<string, any> | null) => {
|
||||
if (!user) {
|
||||
return ''
|
||||
}
|
||||
return shopList.value.length === 1 ? getShopOptionValue(shopList.value[0]!) : undefined
|
||||
const names = (user.shopNames || []).filter(Boolean)
|
||||
if (names.length) {
|
||||
return names.join('、')
|
||||
}
|
||||
if (user.shopName) {
|
||||
return user.shopName
|
||||
}
|
||||
if (user.shopIds?.length) {
|
||||
return (user.shopIds as Array<string | number>)
|
||||
.map((id: string | number) => getShopNameById(id) || `店铺 ${id}`)
|
||||
.join('、')
|
||||
}
|
||||
return getShopNameById(user.shopId) || ''
|
||||
}
|
||||
|
||||
const resolveEditableShopIds = (user?: UserVO | null) => {
|
||||
const sourceIds = user?.shopIds?.length
|
||||
? user.shopIds
|
||||
: (user?.shopId ? [user.shopId] : [])
|
||||
const normalizedIds = sourceIds
|
||||
.map(id => normalizeShopId(id))
|
||||
.filter((id): id is string => Boolean(id))
|
||||
.filter(id => shopList.value.some(shop => getShopOptionValue(shop) === id))
|
||||
|
||||
if (normalizedIds.length) {
|
||||
return normalizedIds
|
||||
}
|
||||
|
||||
return currentUserInfo?.type !== 4 && currentUserInfo?.shopId
|
||||
? [normalizeShopId(currentUserInfo.shopId)!]
|
||||
: []
|
||||
}
|
||||
|
||||
const fetchShopList = async () => {
|
||||
@@ -575,7 +613,7 @@ const fetchShopList = async () => {
|
||||
const shops = await adminShopApi.listAllShops() as unknown as Shop[]
|
||||
shopList.value = shops || []
|
||||
if (currentUserInfo?.type !== 4 && currentUserInfo?.shopId) {
|
||||
formState.shopId = normalizeShopId(currentUserInfo.shopId)
|
||||
formState.shopIds = [normalizeShopId(currentUserInfo.shopId)!]
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
@@ -593,7 +631,7 @@ const fetchUserList = async () => {
|
||||
keyword: searchText.value || undefined
|
||||
}
|
||||
|
||||
if (currentUserInfo?.type !== 4 && currentUserInfo?.shopId) {
|
||||
if (currentUserInfo?.shopId) {
|
||||
params.shopId = currentUserInfo.shopId
|
||||
}
|
||||
|
||||
@@ -616,9 +654,9 @@ const resetFormState = () => {
|
||||
phone: '',
|
||||
password: '',
|
||||
type: 0,
|
||||
shopId: currentUserInfo?.type !== 4 && currentUserInfo?.shopId
|
||||
? normalizeShopId(currentUserInfo.shopId)
|
||||
: undefined
|
||||
shopIds: currentUserInfo?.type !== 4 && currentUserInfo?.shopId
|
||||
? [normalizeShopId(currentUserInfo.shopId)!]
|
||||
: []
|
||||
})
|
||||
}
|
||||
|
||||
@@ -649,7 +687,7 @@ const showEditModal = (record: any) => {
|
||||
phone: record.phone || '',
|
||||
password: '',
|
||||
type: record.type,
|
||||
shopId: resolveEditableShopId(record.shopId)
|
||||
shopIds: resolveEditableShopIds(record)
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
@@ -713,15 +751,21 @@ const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
const requestData = {
|
||||
const requestData: Record<string, unknown> = {
|
||||
account: formState.account.trim(),
|
||||
nickname: formState.nickname.trim(),
|
||||
phone: formState.phone.trim(),
|
||||
type: formState.type,
|
||||
shopId: formState.shopId || undefined,
|
||||
shopIds: formState.shopIds,
|
||||
shopId: formState.shopIds.length ? formState.shopIds[0] : undefined,
|
||||
...(formState.password.trim() ? { password: formState.password.trim() } : {})
|
||||
}
|
||||
|
||||
if (isEdit.value && currentUserInfo?.type !== 4) {
|
||||
delete requestData.shopIds
|
||||
delete requestData.shopId
|
||||
}
|
||||
|
||||
if (isEdit.value && currentUser.value) {
|
||||
await adminUserApi.updateUser(currentUser.value.id, requestData)
|
||||
message.success('更新成功')
|
||||
@@ -751,7 +795,7 @@ const handleStatusChange = async (record: any, checked: boolean) => {
|
||||
try {
|
||||
await adminUserApi.updateUserStatus(record.id, checked ? 1 : 0)
|
||||
record.status = checked ? 1 : 0
|
||||
message.success('状态更新成功')
|
||||
message.success(`已${checked ? '启用' : '停用'}当前店铺下的用户访问`)
|
||||
} catch (error) {
|
||||
console.error('状态更新失败:', error)
|
||||
message.error('状态更新失败')
|
||||
@@ -780,15 +824,8 @@ const handleDelete = async (record: any) => {
|
||||
message.warning('管理员账号无法被删除')
|
||||
return
|
||||
}
|
||||
|
||||
const timestamp = Date.now()
|
||||
await adminUserApi.updateUser(record.id, {
|
||||
account: `${record.account}_deleted_${timestamp}`,
|
||||
phone: record.phone ? `${record.phone}_deleted_${timestamp}` : undefined
|
||||
})
|
||||
|
||||
await adminUserApi.deleteUser(record.id)
|
||||
message.success('删除成功')
|
||||
message.success('已移除当前店铺下的用户绑定')
|
||||
await fetchUserList()
|
||||
} catch (error) {
|
||||
console.error('删除用户失败:', error)
|
||||
|
||||
Reference in New Issue
Block a user