用户管理一些问题修复
This commit is contained in:
+45
-19
@@ -2,6 +2,11 @@ import axios, { AxiosError } from 'axios'
|
||||
import router from '../router'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
// 防重复提示标志
|
||||
let lastErrorTime = 0
|
||||
let lastErrorMessage = ''
|
||||
const ERROR_DEBOUNCE_TIME = 1000 // 1秒内不重复显示相同错误
|
||||
|
||||
const adminApi = axios.create({
|
||||
baseURL: 'http://wcy111.top:8088/api',
|
||||
timeout: 10000,
|
||||
@@ -30,30 +35,51 @@ adminApi.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
if (res.code !== 200) {
|
||||
message.error(res.message || '请求失败')
|
||||
return Promise.reject(new Error(res.message || '请求失败'))
|
||||
// 检查是否是权限不足的错误
|
||||
const errorMsg = res.message || '请求失败'
|
||||
if (!errorMsg.includes('权限') && !errorMsg.includes('permission')) {
|
||||
message.error(errorMsg)
|
||||
} else {
|
||||
console.error('权限不足:', errorMsg)
|
||||
}
|
||||
return Promise.reject(new Error(errorMsg))
|
||||
}
|
||||
return res.data
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
message.error('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/admin/login').catch(err => {
|
||||
console.error('跳转到登录页失败:', err)
|
||||
window.location.href = '/admin/login'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/admin/login'
|
||||
// 防抖处理错误提示
|
||||
const showError = (msg: string) => {
|
||||
const now = Date.now()
|
||||
if (now - lastErrorTime > ERROR_DEBOUNCE_TIME || msg !== lastErrorMessage) {
|
||||
lastErrorTime = now
|
||||
lastErrorMessage = msg
|
||||
message.error(msg)
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
// 登录过期,只提示一次
|
||||
if (Date.now() - lastErrorTime > ERROR_DEBOUNCE_TIME || lastErrorMessage !== '登录已过期,请重新登录') {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
showError('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/admin/login').catch(err => {
|
||||
console.error('跳转到登录页失败:', err)
|
||||
window.location.href = '/admin/login'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
}
|
||||
} else if (error.response?.status !== 403) { // 403权限不足不提示
|
||||
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
||||
message.error(errorMsg)
|
||||
showError(errorMsg)
|
||||
} else {
|
||||
console.error('权限不足:', error)
|
||||
}
|
||||
|
||||
console.error('Admin API Error:', error)
|
||||
@@ -250,7 +276,7 @@ export const userApi = {
|
||||
getUserInfo: () => {
|
||||
return adminApi.get<UserVO>('/user/info')
|
||||
},
|
||||
listUsers: (params: { page: number; size: number; keyword?: string; shopId?: number }) => {
|
||||
listUsers: (params: { page: number; size: number; keyword?: string; shopId?: number; status?: number }) => {
|
||||
return adminApi.get<UserListResponse>('/admin/user/list', { params })
|
||||
},
|
||||
createUser: (data: CreateUserRequest) => {
|
||||
|
||||
+43
-17
@@ -3,6 +3,11 @@ import { authApi } from './auth'
|
||||
import router from '../router'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
// 防重复提示标志
|
||||
let lastErrorTime = 0
|
||||
let lastErrorMessage = ''
|
||||
const ERROR_DEBOUNCE_TIME = 1000 // 1秒内不重复显示相同错误
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'http://wcy111.top:8088/api',
|
||||
timeout: 10000,
|
||||
@@ -28,21 +33,34 @@ const processQueue = (error: any, token: string | null = null) => {
|
||||
failedQueue = []
|
||||
}
|
||||
|
||||
// 防抖处理错误提示
|
||||
const showError = (msg: string) => {
|
||||
const now = Date.now()
|
||||
if (now - lastErrorTime > ERROR_DEBOUNCE_TIME || msg !== lastErrorMessage) {
|
||||
lastErrorTime = now
|
||||
lastErrorMessage = msg
|
||||
message.error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
const handleTokenExpired = () => {
|
||||
console.log('Token 过期,清理本地存储并跳转到登录页')
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
message.error('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/auth').catch(err => {
|
||||
console.error('跳转到登录页失败:', err)
|
||||
// 登录过期,只提示一次
|
||||
if (Date.now() - lastErrorTime > ERROR_DEBOUNCE_TIME || lastErrorMessage !== '登录已过期,请重新登录') {
|
||||
console.log('Token 过期,清理本地存储并跳转到登录页')
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
showError('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/auth').catch(err => {
|
||||
console.error('跳转到登录页失败:', err)
|
||||
window.location.href = '/auth'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/auth'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/auth'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +84,14 @@ api.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
if (res.code !== 200) {
|
||||
message.error(res.message || '请求失败')
|
||||
return Promise.reject(new Error(res.message || '请求失败'))
|
||||
// 检查是否是权限不足的错误
|
||||
const errorMsg = res.message || '请求失败'
|
||||
if (!errorMsg.includes('权限') && !errorMsg.includes('permission')) {
|
||||
showError(errorMsg)
|
||||
} else {
|
||||
console.error('权限不足:', errorMsg)
|
||||
}
|
||||
return Promise.reject(new Error(errorMsg))
|
||||
}
|
||||
return res.data
|
||||
},
|
||||
@@ -128,9 +152,11 @@ api.interceptors.response.use(
|
||||
handleTokenExpired()
|
||||
return Promise.reject(error)
|
||||
}
|
||||
} else {
|
||||
} else if (error.response?.status !== 403) { // 403权限不足不提示
|
||||
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
||||
message.error(errorMsg)
|
||||
showError(errorMsg)
|
||||
} else {
|
||||
console.error('权限不足:', error)
|
||||
}
|
||||
|
||||
console.error('API Error:', error)
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { permissionApi } from '@/api/admin'
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
const userPermissions = ref<string[]>([])
|
||||
const loadingPermissions = ref(false)
|
||||
|
||||
export const usePermission = () => {
|
||||
const hasPermission = (permissionCode: string) => {
|
||||
return userPermissions.value.includes(permissionCode)
|
||||
}
|
||||
|
||||
const hasAnyPermission = (permissionCodes: string[]) => {
|
||||
return permissionCodes.some(code => userPermissions.value.includes(code))
|
||||
}
|
||||
|
||||
const hasAllPermissions = (permissionCodes: string[]) => {
|
||||
return permissionCodes.every(code => userPermissions.value.includes(code))
|
||||
}
|
||||
|
||||
const loadUserPermissions = async () => {
|
||||
loadingPermissions.value = true
|
||||
try {
|
||||
const permissions = await permissionApi.getUserPermissions()
|
||||
userPermissions.value = permissions && Array.isArray(permissions) ? permissions.map(p => p.permissionCode) : []
|
||||
// 存储权限到本地存储,供路由守卫使用
|
||||
localStorage.setItem('userPermissions', JSON.stringify(userPermissions.value))
|
||||
} catch (error) {
|
||||
console.error('加载用户权限失败:', error)
|
||||
userPermissions.value = []
|
||||
localStorage.setItem('userPermissions', JSON.stringify([]))
|
||||
} finally {
|
||||
loadingPermissions.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const clearPermissions = () => {
|
||||
userPermissions.value = []
|
||||
localStorage.removeItem('userPermissions')
|
||||
}
|
||||
|
||||
return {
|
||||
userPermissions: computed(() => userPermissions.value),
|
||||
loadingPermissions: computed(() => loadingPermissions.value),
|
||||
hasPermission,
|
||||
hasAnyPermission,
|
||||
hasAllPermissions,
|
||||
loadUserPermissions,
|
||||
clearPermissions
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<template>
|
||||
<div class="shop-detail">
|
||||
<div class="header-bg"></div>
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>店铺详情</h1>
|
||||
<div class="header-placeholder"></div>
|
||||
</header>
|
||||
<div class="shop-content">
|
||||
<a-card :bordered="false" class="shop-card">
|
||||
<div class="shop-info">
|
||||
<div class="shop-header">
|
||||
<div class="shop-icon-wrapper">
|
||||
<ShopOutlined class="shop-icon" />
|
||||
</div>
|
||||
<div class="shop-header-content">
|
||||
<h2 class="shop-name">{{ shopInfo.shopName }}</h2>
|
||||
<p class="shop-address">{{ shopInfo.address }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shop-details">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">营业时间</div>
|
||||
<div class="detail-value">{{ shopInfo.businessHours }}</div>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">店铺描述</div>
|
||||
<div class="detail-value">{{ shopInfo.description }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shop-images" v-if="shopImages.length > 0">
|
||||
<h3 class="section-title">店铺图片</h3>
|
||||
<div class="image-grid">
|
||||
<a-image
|
||||
v-for="(url, index) in shopImages"
|
||||
:key="index"
|
||||
:width="100"
|
||||
:height="100"
|
||||
:src="url"
|
||||
style="object-fit: cover; border-radius: 4px; margin: 4px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { LeftOutlined, ShopOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { shopApi, type ShopVO } from '@/api/shop'
|
||||
import { fileApi } from '@/api/index'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const shopInfo = ref<ShopVO>({
|
||||
id: 0,
|
||||
shopName: '',
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
|
||||
const shopImages = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
const loadShopImages = async () => {
|
||||
if (shopInfo.value.imageFileIds) {
|
||||
const ids = shopInfo.value.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shopImages.value = urls
|
||||
}
|
||||
}
|
||||
|
||||
const fetchShopDetail = async () => {
|
||||
try {
|
||||
// 从路由参数或本地存储获取店铺ID
|
||||
const shopId = route.params.id || localStorage.getItem('userShopId')
|
||||
if (!shopId) {
|
||||
message.error('店铺ID不存在')
|
||||
router.back()
|
||||
return
|
||||
}
|
||||
|
||||
const res = await shopApi.getShopById(Number(shopId))
|
||||
shopInfo.value = res as unknown as ShopVO
|
||||
|
||||
// 加载店铺图片
|
||||
await loadShopImages()
|
||||
} catch (error) {
|
||||
console.error('获取店铺详情失败:', error)
|
||||
message.error('获取店铺详情失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchShopDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.shop-detail {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.header-bg {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 120px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: transparent;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.header-placeholder {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.shop-content {
|
||||
padding: 100px 15px 20px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.shop-card {
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.shop-card :deep(.ant-card-body) {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.shop-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.shop-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.shop-icon-wrapper {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.shop-icon {
|
||||
font-size: 36px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.shop-header-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.shop-name {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px 0;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.shop-address {
|
||||
font-size: 14px;
|
||||
color: #8b8b9a;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.shop-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.detail-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
font-size: 13px;
|
||||
color: #8b8b9a;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
font-size: 16px;
|
||||
color: #1a1a2e;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,207 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<a-page-header title="欢迎使用后台管理系统" :sub-title="welcomeMessage" />
|
||||
|
||||
<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="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)">
|
||||
<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>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { DashboardOutlined, UserOutlined, ShopOutlined, SafetyCertificateOutlined, HomeOutlined } from '@ant-design/icons-vue'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
|
||||
const router = useRouter()
|
||||
const currentTime = ref('')
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
|
||||
const welcomeMessage = computed(() => {
|
||||
const hour = new Date().getHours()
|
||||
if (hour < 12) {
|
||||
return '早上好!'
|
||||
} else if (hour < 18) {
|
||||
return '下午好!'
|
||||
} else {
|
||||
return '晚上好!'
|
||||
}
|
||||
})
|
||||
|
||||
const quickActions = computed(() => {
|
||||
const actions = [
|
||||
{
|
||||
key: 'dashboard',
|
||||
title: '仪表盘',
|
||||
path: '/admin/dashboard',
|
||||
icon: DashboardOutlined
|
||||
},
|
||||
{
|
||||
key: 'users',
|
||||
title: '用户管理',
|
||||
path: '/admin/users',
|
||||
icon: UserOutlined
|
||||
},
|
||||
{
|
||||
key: 'products',
|
||||
title: '商品管理',
|
||||
path: '/admin/products',
|
||||
icon: ShopOutlined
|
||||
},
|
||||
{
|
||||
key: 'shops',
|
||||
title: '店铺管理',
|
||||
path: '/admin/shops',
|
||||
icon: HomeOutlined
|
||||
},
|
||||
{
|
||||
key: 'permissions',
|
||||
title: '权限管理',
|
||||
path: '/admin/permissions',
|
||||
icon: SafetyCertificateOutlined
|
||||
}
|
||||
]
|
||||
|
||||
// 根据用户类型过滤操作
|
||||
if (userInfo.value?.type === 3) { // 美甲师
|
||||
return actions.filter(item => ['products', 'users'].includes(item.key))
|
||||
}
|
||||
|
||||
return actions
|
||||
})
|
||||
|
||||
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 navigateTo = (path: string) => {
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
updateCurrentTime()
|
||||
setInterval(updateCurrentTime, 1000)
|
||||
fetchUserInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.home {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.time-card {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.info-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;
|
||||
}
|
||||
|
||||
.quick-actions {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 80px;
|
||||
font-size: 32px;
|
||||
color: #1890ff;
|
||||
background: #f0f2f5;
|
||||
}
|
||||
</style>
|
||||
@@ -334,22 +334,29 @@ const getCurrentUserInfo = () => {
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const res = await adminShopApi.listAllShops()
|
||||
const currentUser = getCurrentUserInfo()
|
||||
|
||||
// 根据用户权限控制店铺列表的显示
|
||||
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
||||
// 如果是店长,只显示用户所属的店铺
|
||||
shops.value = res?.filter(shop => shop.id === currentUser.shopId) || []
|
||||
// 默认选择用户所属的店铺,并且不可修改
|
||||
// 检查用户类型和权限
|
||||
if (currentUser && currentUser.type === 3 && currentUser.shopId) {
|
||||
// 美甲师直接使用自己的店铺ID,不需要获取店铺列表
|
||||
shops.value = []
|
||||
formState.shopId = currentUser.shopId
|
||||
} else {
|
||||
// 如果是管理员,显示所有店铺
|
||||
shops.value = res || []
|
||||
const res = await adminShopApi.listAllShops()
|
||||
// 根据用户权限控制店铺列表的显示
|
||||
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
||||
// 如果是店长,只显示用户所属的店铺
|
||||
shops.value = res?.filter(shop => shop.id === currentUser.shopId) || []
|
||||
// 默认选择用户所属的店铺,并且不可修改
|
||||
formState.shopId = currentUser.shopId
|
||||
} else {
|
||||
// 如果是管理员,显示所有店铺
|
||||
shops.value = res || []
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败', error)
|
||||
message.error('获取店铺列表失败')
|
||||
// 权限不足时不显示错误提示
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
重置密码
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('user:delete')"
|
||||
v-if="hasPermission('user:delete') && record.type !== 4"
|
||||
title="确定要删除这个用户吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
@@ -240,13 +240,21 @@ const getUserTypeColor = (type: number) => {
|
||||
const fetchShopList = async () => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
const res = await adminShopApi.listAllShops()
|
||||
shopList.value = res || []
|
||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||
// 检查用户类型和权限
|
||||
if (currentUserInfo && currentUserInfo.type === 3 && currentUserInfo.shopId) {
|
||||
// 美甲师直接使用自己的店铺ID,不需要获取店铺列表
|
||||
shopList.value = []
|
||||
formState.shopId = currentUserInfo.shopId
|
||||
} else {
|
||||
const res = await adminShopApi.listAllShops()
|
||||
shopList.value = res || []
|
||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||
formState.shopId = currentUserInfo.shopId
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取店铺列表失败')
|
||||
// 权限不足时不显示错误提示
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
shopLoading.value = false
|
||||
}
|
||||
@@ -258,7 +266,8 @@ const fetchUserList = async () => {
|
||||
const params: any = {
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize,
|
||||
keyword: searchText.value
|
||||
keyword: searchText.value,
|
||||
status: 1 // 只获取未被删除的用户
|
||||
}
|
||||
|
||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||
@@ -313,23 +322,75 @@ const showEditModal = (record: UserVO) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const checkAccountExists = async (account: string) => {
|
||||
try {
|
||||
const res = await userApi.listUsers({ page: 1, size: 1000, keyword: account, status: 1 })
|
||||
console.log('检查账号是否存在:', account, res.list)
|
||||
// 只检查未被删除的账号(status为1表示正常,0表示删除)
|
||||
return res.list?.some(user => user.account === account)
|
||||
} catch (error) {
|
||||
console.error('检查账号是否存在失败:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
|
||||
// 新增用户时检查账号是否已存在
|
||||
if (!isEdit.value) {
|
||||
const accountExists = await checkAccountExists(formState.account)
|
||||
if (accountExists) {
|
||||
message.error('账号已存在,请使用其他账号')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
modalLoading.value = true
|
||||
|
||||
if (isEdit.value && currentUser.value) {
|
||||
await userApi.updateUser(currentUser.value.id, formState)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await userApi.createUser(formState)
|
||||
message.success('创建成功')
|
||||
try {
|
||||
await userApi.createUser(formState)
|
||||
message.success('创建成功')
|
||||
} catch (createError: any) {
|
||||
// 检查是否为账号重复错误
|
||||
if (createError.response?.data?.message?.includes('账号重复') ||
|
||||
createError.message?.includes('账号重复')) {
|
||||
// 尝试恢复已删除的账号
|
||||
const deletedUser = await userApi.listUsers({
|
||||
page: 1,
|
||||
size: 1000,
|
||||
keyword: formState.account,
|
||||
status: 0 // 只查询已删除的用户
|
||||
})
|
||||
|
||||
if (deletedUser.list && deletedUser.list.length > 0) {
|
||||
// 找到已删除的账号,恢复它
|
||||
const user = deletedUser.list[0]
|
||||
await userApi.updateUserStatus(user.id, 1)
|
||||
message.success('账号已恢复')
|
||||
} else {
|
||||
message.error('账号已存在,请使用其他账号')
|
||||
}
|
||||
} else {
|
||||
throw createError
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
modalVisible.value = false
|
||||
fetchUserList()
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error(error)
|
||||
if (error.message?.includes('账号重复')) {
|
||||
message.error('账号已存在,请使用其他账号')
|
||||
} else {
|
||||
message.error('操作失败')
|
||||
}
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
@@ -368,6 +429,22 @@ const handleResetPassword = (record: UserVO) => {
|
||||
|
||||
const handleDelete = async (record: UserVO) => {
|
||||
try {
|
||||
if (record.type === 4) {
|
||||
message.warning('管理员账号无法被删除')
|
||||
return
|
||||
}
|
||||
|
||||
// 在删除前先重命名账号,添加删除时间戳
|
||||
const timestamp = new Date().getTime()
|
||||
const newAccount = `${record.account}_deleted_${timestamp}`
|
||||
|
||||
try {
|
||||
await userApi.updateUser(record.id, { account: newAccount })
|
||||
} catch (renameError) {
|
||||
console.error('重命名账号失败:', renameError)
|
||||
// 重命名失败也继续删除流程
|
||||
}
|
||||
|
||||
await userApi.deleteUser(record.id)
|
||||
message.success('删除成功')
|
||||
fetchUserList()
|
||||
|
||||
Reference in New Issue
Block a user