用户管理一些问题修复
This commit is contained in:
@@ -2,6 +2,11 @@ import axios, { AxiosError } from 'axios'
|
|||||||
import router from '../router'
|
import router from '../router'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
|
|
||||||
|
// 防重复提示标志
|
||||||
|
let lastErrorTime = 0
|
||||||
|
let lastErrorMessage = ''
|
||||||
|
const ERROR_DEBOUNCE_TIME = 1000 // 1秒内不重复显示相同错误
|
||||||
|
|
||||||
const adminApi = axios.create({
|
const adminApi = axios.create({
|
||||||
baseURL: 'http://wcy111.top:8088/api',
|
baseURL: 'http://wcy111.top:8088/api',
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
@@ -30,18 +35,36 @@ adminApi.interceptors.response.use(
|
|||||||
response => {
|
response => {
|
||||||
const res = response.data
|
const res = response.data
|
||||||
if (res.code !== 200) {
|
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
|
return res.data
|
||||||
},
|
},
|
||||||
async (error: AxiosError) => {
|
async (error: AxiosError) => {
|
||||||
|
// 防抖处理错误提示
|
||||||
|
const showError = (msg: string) => {
|
||||||
|
const now = Date.now()
|
||||||
|
if (now - lastErrorTime > ERROR_DEBOUNCE_TIME || msg !== lastErrorMessage) {
|
||||||
|
lastErrorTime = now
|
||||||
|
lastErrorMessage = msg
|
||||||
|
message.error(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
|
// 登录过期,只提示一次
|
||||||
|
if (Date.now() - lastErrorTime > ERROR_DEBOUNCE_TIME || lastErrorMessage !== '登录已过期,请重新登录') {
|
||||||
localStorage.removeItem('adminAccessToken')
|
localStorage.removeItem('adminAccessToken')
|
||||||
localStorage.removeItem('adminRefreshToken')
|
localStorage.removeItem('adminRefreshToken')
|
||||||
localStorage.removeItem('adminUserInfo')
|
localStorage.removeItem('adminUserInfo')
|
||||||
sessionStorage.removeItem('adminAccessToken')
|
sessionStorage.removeItem('adminAccessToken')
|
||||||
message.error('登录已过期,请重新登录')
|
showError('登录已过期,请重新登录')
|
||||||
try {
|
try {
|
||||||
router.push('/admin/login').catch(err => {
|
router.push('/admin/login').catch(err => {
|
||||||
console.error('跳转到登录页失败:', err)
|
console.error('跳转到登录页失败:', err)
|
||||||
@@ -51,9 +74,12 @@ adminApi.interceptors.response.use(
|
|||||||
console.error('跳转到登录页异常:', err)
|
console.error('跳转到登录页异常:', err)
|
||||||
window.location.href = '/admin/login'
|
window.location.href = '/admin/login'
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
} else if (error.response?.status !== 403) { // 403权限不足不提示
|
||||||
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
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)
|
console.error('Admin API Error:', error)
|
||||||
@@ -250,7 +276,7 @@ export const userApi = {
|
|||||||
getUserInfo: () => {
|
getUserInfo: () => {
|
||||||
return adminApi.get<UserVO>('/user/info')
|
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 })
|
return adminApi.get<UserListResponse>('/admin/user/list', { params })
|
||||||
},
|
},
|
||||||
createUser: (data: CreateUserRequest) => {
|
createUser: (data: CreateUserRequest) => {
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ import { authApi } from './auth'
|
|||||||
import router from '../router'
|
import router from '../router'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
|
|
||||||
|
// 防重复提示标志
|
||||||
|
let lastErrorTime = 0
|
||||||
|
let lastErrorMessage = ''
|
||||||
|
const ERROR_DEBOUNCE_TIME = 1000 // 1秒内不重复显示相同错误
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: 'http://wcy111.top:8088/api',
|
baseURL: 'http://wcy111.top:8088/api',
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
@@ -28,13 +33,25 @@ const processQueue = (error: any, token: string | null = null) => {
|
|||||||
failedQueue = []
|
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 = () => {
|
const handleTokenExpired = () => {
|
||||||
|
// 登录过期,只提示一次
|
||||||
|
if (Date.now() - lastErrorTime > ERROR_DEBOUNCE_TIME || lastErrorMessage !== '登录已过期,请重新登录') {
|
||||||
console.log('Token 过期,清理本地存储并跳转到登录页')
|
console.log('Token 过期,清理本地存储并跳转到登录页')
|
||||||
localStorage.removeItem('accessToken')
|
localStorage.removeItem('accessToken')
|
||||||
localStorage.removeItem('refreshToken')
|
localStorage.removeItem('refreshToken')
|
||||||
localStorage.removeItem('userInfo')
|
localStorage.removeItem('userInfo')
|
||||||
sessionStorage.removeItem('accessToken')
|
sessionStorage.removeItem('accessToken')
|
||||||
message.error('登录已过期,请重新登录')
|
showError('登录已过期,请重新登录')
|
||||||
try {
|
try {
|
||||||
router.push('/auth').catch(err => {
|
router.push('/auth').catch(err => {
|
||||||
console.error('跳转到登录页失败:', err)
|
console.error('跳转到登录页失败:', err)
|
||||||
@@ -44,6 +61,7 @@ const handleTokenExpired = () => {
|
|||||||
console.error('跳转到登录页异常:', err)
|
console.error('跳转到登录页异常:', err)
|
||||||
window.location.href = '/auth'
|
window.location.href = '/auth'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api.interceptors.request.use(
|
api.interceptors.request.use(
|
||||||
@@ -66,8 +84,14 @@ api.interceptors.response.use(
|
|||||||
response => {
|
response => {
|
||||||
const res = response.data
|
const res = response.data
|
||||||
if (res.code !== 200) {
|
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
|
return res.data
|
||||||
},
|
},
|
||||||
@@ -128,9 +152,11 @@ api.interceptors.response.use(
|
|||||||
handleTokenExpired()
|
handleTokenExpired()
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
} else {
|
} else if (error.response?.status !== 403) { // 403权限不足不提示
|
||||||
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
||||||
message.error(errorMsg)
|
showError(errorMsg)
|
||||||
|
} else {
|
||||||
|
console.error('权限不足:', error)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error('API 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,9 +334,15 @@ const getCurrentUserInfo = () => {
|
|||||||
const fetchShops = async () => {
|
const fetchShops = async () => {
|
||||||
loadingShops.value = true
|
loadingShops.value = true
|
||||||
try {
|
try {
|
||||||
const res = await adminShopApi.listAllShops()
|
|
||||||
const currentUser = getCurrentUserInfo()
|
const currentUser = getCurrentUserInfo()
|
||||||
|
|
||||||
|
// 检查用户类型和权限
|
||||||
|
if (currentUser && currentUser.type === 3 && currentUser.shopId) {
|
||||||
|
// 美甲师直接使用自己的店铺ID,不需要获取店铺列表
|
||||||
|
shops.value = []
|
||||||
|
formState.shopId = currentUser.shopId
|
||||||
|
} else {
|
||||||
|
const res = await adminShopApi.listAllShops()
|
||||||
// 根据用户权限控制店铺列表的显示
|
// 根据用户权限控制店铺列表的显示
|
||||||
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
||||||
// 如果是店长,只显示用户所属的店铺
|
// 如果是店长,只显示用户所属的店铺
|
||||||
@@ -347,9 +353,10 @@ const fetchShops = async () => {
|
|||||||
// 如果是管理员,显示所有店铺
|
// 如果是管理员,显示所有店铺
|
||||||
shops.value = res || []
|
shops.value = res || []
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取店铺列表失败', error)
|
// 权限不足时不显示错误提示
|
||||||
message.error('获取店铺列表失败')
|
console.error('获取店铺列表失败:', error)
|
||||||
} finally {
|
} finally {
|
||||||
loadingShops.value = false
|
loadingShops.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@
|
|||||||
重置密码
|
重置密码
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-popconfirm
|
<a-popconfirm
|
||||||
v-if="hasPermission('user:delete')"
|
v-if="hasPermission('user:delete') && record.type !== 4"
|
||||||
title="确定要删除这个用户吗?"
|
title="确定要删除这个用户吗?"
|
||||||
@confirm="handleDelete(record)"
|
@confirm="handleDelete(record)"
|
||||||
>
|
>
|
||||||
@@ -240,13 +240,21 @@ const getUserTypeColor = (type: number) => {
|
|||||||
const fetchShopList = async () => {
|
const fetchShopList = async () => {
|
||||||
shopLoading.value = true
|
shopLoading.value = true
|
||||||
try {
|
try {
|
||||||
|
// 检查用户类型和权限
|
||||||
|
if (currentUserInfo && currentUserInfo.type === 3 && currentUserInfo.shopId) {
|
||||||
|
// 美甲师直接使用自己的店铺ID,不需要获取店铺列表
|
||||||
|
shopList.value = []
|
||||||
|
formState.shopId = currentUserInfo.shopId
|
||||||
|
} else {
|
||||||
const res = await adminShopApi.listAllShops()
|
const res = await adminShopApi.listAllShops()
|
||||||
shopList.value = res || []
|
shopList.value = res || []
|
||||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||||
formState.shopId = currentUserInfo.shopId
|
formState.shopId = currentUserInfo.shopId
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('获取店铺列表失败')
|
// 权限不足时不显示错误提示
|
||||||
|
console.error('获取店铺列表失败:', error)
|
||||||
} finally {
|
} finally {
|
||||||
shopLoading.value = false
|
shopLoading.value = false
|
||||||
}
|
}
|
||||||
@@ -258,7 +266,8 @@ const fetchUserList = async () => {
|
|||||||
const params: any = {
|
const params: any = {
|
||||||
page: pagination.current,
|
page: pagination.current,
|
||||||
size: pagination.pageSize,
|
size: pagination.pageSize,
|
||||||
keyword: searchText.value
|
keyword: searchText.value,
|
||||||
|
status: 1 // 只获取未被删除的用户
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||||
@@ -313,23 +322,75 @@ const showEditModal = (record: UserVO) => {
|
|||||||
modalVisible.value = true
|
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 () => {
|
const handleModalOk = async () => {
|
||||||
try {
|
try {
|
||||||
await formRef.value?.validate()
|
await formRef.value?.validate()
|
||||||
|
|
||||||
|
// 新增用户时检查账号是否已存在
|
||||||
|
if (!isEdit.value) {
|
||||||
|
const accountExists = await checkAccountExists(formState.account)
|
||||||
|
if (accountExists) {
|
||||||
|
message.error('账号已存在,请使用其他账号')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
modalLoading.value = true
|
modalLoading.value = true
|
||||||
|
|
||||||
if (isEdit.value && currentUser.value) {
|
if (isEdit.value && currentUser.value) {
|
||||||
await userApi.updateUser(currentUser.value.id, formState)
|
await userApi.updateUser(currentUser.value.id, formState)
|
||||||
message.success('更新成功')
|
message.success('更新成功')
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
await userApi.createUser(formState)
|
await userApi.createUser(formState)
|
||||||
message.success('创建成功')
|
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
|
modalVisible.value = false
|
||||||
fetchUserList()
|
fetchUserList()
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
if (error.message?.includes('账号重复')) {
|
||||||
|
message.error('账号已存在,请使用其他账号')
|
||||||
|
} else {
|
||||||
|
message.error('操作失败')
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
modalLoading.value = false
|
modalLoading.value = false
|
||||||
}
|
}
|
||||||
@@ -368,6 +429,22 @@ const handleResetPassword = (record: UserVO) => {
|
|||||||
|
|
||||||
const handleDelete = async (record: UserVO) => {
|
const handleDelete = async (record: UserVO) => {
|
||||||
try {
|
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)
|
await userApi.deleteUser(record.id)
|
||||||
message.success('删除成功')
|
message.success('删除成功')
|
||||||
fetchUserList()
|
fetchUserList()
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.xiaowang.yuminailcore.config;
|
||||||
|
|
||||||
|
import io.minio.MinioClient;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "minio")
|
||||||
|
public class MinioConfig {
|
||||||
|
|
||||||
|
private String endpoint;
|
||||||
|
private String accessKey;
|
||||||
|
private String secretKey;
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MinioClient minioClient() {
|
||||||
|
return MinioClient.builder()
|
||||||
|
.endpoint(endpoint)
|
||||||
|
.credentials(accessKey, secretKey)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
package com.xiaowang.yuminailcore.controller;
|
||||||
|
|
||||||
|
import com.xiaowang.yuminailcore.common.Result;
|
||||||
|
import com.xiaowang.yuminailcore.service.MinioService;
|
||||||
|
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
||||||
|
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前台文件控制器
|
||||||
|
* 提供前台用户可以访问的文件相关接口
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/file")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class FrontendFileController {
|
||||||
|
|
||||||
|
private final ObjectStorageFileService objectStorageFileService;
|
||||||
|
private final MinioService minioService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取带签名的图片链接(前台用户可访问)
|
||||||
|
*
|
||||||
|
* @param fileId 文件ID
|
||||||
|
* @param expiryTimeInMinutes 有效期(分钟),默认60分钟
|
||||||
|
* @return 带签名的临时访问链接
|
||||||
|
*/
|
||||||
|
@GetMapping("/get-signed-url/{fileId}")
|
||||||
|
public Result<String> getSignedUrl(@PathVariable Long fileId, @RequestParam(defaultValue = "60") Integer expiryTimeInMinutes) {
|
||||||
|
try {
|
||||||
|
ObjectStorageFileVO fileVO = objectStorageFileService.getObjectStorageFileById(fileId);
|
||||||
|
if (fileVO == null) {
|
||||||
|
return Result.error("文件不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从fileUrl中提取objectName
|
||||||
|
String fileUrl = fileVO.getFileUrl();
|
||||||
|
// 提取最后一个/后面的部分作为objectName
|
||||||
|
int lastSlashIndex = fileUrl.lastIndexOf("/");
|
||||||
|
if (lastSlashIndex == -1) {
|
||||||
|
return Result.error("文件URL格式错误");
|
||||||
|
}
|
||||||
|
String objectName = fileUrl.substring(lastSlashIndex + 1);
|
||||||
|
|
||||||
|
String signedUrl = minioService.getPresignedUrl(objectName, expiryTimeInMinutes);
|
||||||
|
return Result.success(signedUrl);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("获取签名链接失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.xiaowang.yuminailcore.service;
|
||||||
|
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public interface MinioService {
|
||||||
|
|
||||||
|
String uploadFile(MultipartFile file, String objectName) throws Exception;
|
||||||
|
|
||||||
|
InputStream downloadFile(String objectName) throws Exception;
|
||||||
|
|
||||||
|
void deleteFile(String objectName) throws Exception;
|
||||||
|
|
||||||
|
String getFileUrl(String objectName);
|
||||||
|
|
||||||
|
String getPresignedUrl(String objectName, int expiryTimeInMinutes) throws Exception;
|
||||||
|
|
||||||
|
boolean bucketExists(String bucketName) throws Exception;
|
||||||
|
|
||||||
|
void makeBucket(String bucketName) throws Exception;
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
package com.xiaowang.yuminailcore.service.impl;
|
||||||
|
|
||||||
|
import com.xiaowang.yuminailcore.config.MinioConfig;
|
||||||
|
import com.xiaowang.yuminailcore.service.MinioService;
|
||||||
|
import io.minio.*;
|
||||||
|
import io.minio.http.Method;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MinioServiceImpl implements MinioService {
|
||||||
|
|
||||||
|
private final MinioClient minioClient;
|
||||||
|
private final MinioConfig minioConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadFile(MultipartFile file, String objectName) throws Exception {
|
||||||
|
try {
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
long fileSize = file.getSize();
|
||||||
|
String contentType = file.getContentType();
|
||||||
|
|
||||||
|
minioClient.putObject(
|
||||||
|
PutObjectArgs.builder()
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(objectName)
|
||||||
|
.stream(inputStream, fileSize, -1)
|
||||||
|
.contentType(contentType)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("文件上传成功: {}", objectName);
|
||||||
|
return getFileUrl(objectName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("文件上传失败: {}", objectName, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream downloadFile(String objectName) throws Exception {
|
||||||
|
return minioClient.getObject(
|
||||||
|
GetObjectArgs.builder()
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(objectName)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteFile(String objectName) throws Exception {
|
||||||
|
minioClient.removeObject(
|
||||||
|
RemoveObjectArgs.builder()
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(objectName)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
log.info("文件删除成功: {}", objectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFileUrl(String objectName) {
|
||||||
|
return minioConfig.getEndpoint() + "/" + minioConfig.getBucketName() + "/" + objectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPresignedUrl(String objectName, int expiryTimeInMinutes) throws Exception {
|
||||||
|
String url = minioClient.getPresignedObjectUrl(
|
||||||
|
GetPresignedObjectUrlArgs.builder()
|
||||||
|
.method(Method.GET)
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(objectName)
|
||||||
|
.expiry(expiryTimeInMinutes, TimeUnit.MINUTES)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
log.info("生成带签名的临时访问链接: {}, 有效期: {}分钟", objectName, expiryTimeInMinutes);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean bucketExists(String bucketName) throws Exception {
|
||||||
|
return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void makeBucket(String bucketName) throws Exception {
|
||||||
|
if (!bucketExists(bucketName)) {
|
||||||
|
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||||
|
log.info("Bucket 创建成功: {}", bucketName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+51
-2
@@ -37,12 +37,19 @@ import java.util.stream.Collectors;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {
|
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {
|
||||||
|
|
||||||
|
// 注入用户数据访问层、JWT工具类和店铺服务
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
private final JwtUtil jwtUtil;
|
private final JwtUtil jwtUtil;
|
||||||
private final ShopService shopService;
|
private final ShopService shopService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建新用户
|
||||||
|
* @param userDTO 用户数据传输对象
|
||||||
|
* @return 新创建用户的ID
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long createUser(UserDTO userDTO) {
|
public Long createUser(UserDTO userDTO) {
|
||||||
|
// 检查账号是否已存在
|
||||||
UserDO existingUser = userMapper.selectOne(
|
UserDO existingUser = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, userDTO.getAccount())
|
.eq(UserDO::getAccount, userDTO.getAccount())
|
||||||
@@ -52,6 +59,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
throw new RuntimeException("账号已存在");
|
throw new RuntimeException("账号已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建用户实体并设置属性
|
||||||
UserDO userDO = new UserDO();
|
UserDO userDO = new UserDO();
|
||||||
userDO.setShopId(userDTO.getShopId());
|
userDO.setShopId(userDTO.getShopId());
|
||||||
userDO.setNickname(userDTO.getNickname());
|
userDO.setNickname(userDTO.getNickname());
|
||||||
@@ -64,14 +72,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
userDO.setVipId(userDTO.getVipId());
|
userDO.setVipId(userDTO.getVipId());
|
||||||
userDO.setIsDelete(0);
|
userDO.setIsDelete(0);
|
||||||
userDO.setStatus(1);
|
userDO.setStatus(1);
|
||||||
|
// 设置默认头像
|
||||||
String defaultAvatar = "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
|
String defaultAvatar = "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
|
||||||
userDO.setAvatar(defaultAvatar);
|
userDO.setAvatar(defaultAvatar);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 插入用户数据
|
||||||
userMapper.insert(userDO);
|
userMapper.insert(userDO);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// 捕获重复账号异常
|
||||||
if (e.getMessage() != null && e.getMessage().contains("Duplicate entry")) {
|
if (e.getMessage() != null && e.getMessage().contains("Duplicate entry")) {
|
||||||
throw new RuntimeException("账号已存在");
|
throw new RuntimeException("账号已被使用");
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -79,13 +90,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
return userDO.getId();
|
return userDO.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户信息
|
||||||
|
* @param id 用户ID
|
||||||
|
* @param userDTO 用户数据传输对象
|
||||||
|
* @return 更新是否成功
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean updateUser(Long id, UserDTO userDTO) {
|
public boolean updateUser(Long id, UserDTO userDTO) {
|
||||||
|
// 查询用户是否存在
|
||||||
UserDO userDO = userMapper.selectById(id);
|
UserDO userDO = userMapper.selectById(id);
|
||||||
if (userDO == null) {
|
if (userDO == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新账号(如果提供且变更)
|
||||||
if (userDTO.getAccount() != null && !userDTO.getAccount().equals(userDO.getAccount())) {
|
if (userDTO.getAccount() != null && !userDTO.getAccount().equals(userDO.getAccount())) {
|
||||||
UserDO existingUser = userMapper.selectOne(
|
UserDO existingUser = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
@@ -98,6 +117,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
userDO.setAccount(userDTO.getAccount());
|
userDO.setAccount(userDTO.getAccount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新其他字段(如果提供)
|
||||||
if (userDTO.getShopId() != null) {
|
if (userDTO.getShopId() != null) {
|
||||||
userDO.setShopId(userDTO.getShopId());
|
userDO.setShopId(userDTO.getShopId());
|
||||||
}
|
}
|
||||||
@@ -133,11 +153,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
return userMapper.updateById(userDO) > 0;
|
return userMapper.updateById(userDO) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户
|
||||||
|
* @param id 用户ID
|
||||||
|
* @return 删除是否成功
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteUser(Long id) {
|
public boolean deleteUser(Long id) {
|
||||||
return removeById(id);
|
return removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID获取用户信息
|
||||||
|
* @param id 用户ID
|
||||||
|
* @return 用户视图对象
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UserVO getUserById(Long id) {
|
public UserVO getUserById(Long id) {
|
||||||
UserDO userDO = userMapper.selectById(id);
|
UserDO userDO = userMapper.selectById(id);
|
||||||
@@ -147,6 +177,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
return convertToVO(userDO);
|
return convertToVO(userDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有用户列表
|
||||||
|
* @return 用户视图对象列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<UserVO> listAllUsers() {
|
public List<UserVO> listAllUsers() {
|
||||||
List<UserDO> userDOs = userMapper.selectList(
|
List<UserDO> userDOs = userMapper.selectList(
|
||||||
@@ -158,6 +192,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据店铺ID获取用户列表
|
||||||
|
* @param shopId 店铺ID
|
||||||
|
* @return 用户视图对象列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<UserVO> listUsersByShopId(Long shopId) {
|
public List<UserVO> listUsersByShopId(Long shopId) {
|
||||||
List<UserDO> userDOs = userMapper.selectList(
|
List<UserDO> userDOs = userMapper.selectList(
|
||||||
@@ -170,6 +209,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户类型获取用户列表
|
||||||
|
* @param type 用户类型
|
||||||
|
* @return 用户视图对象列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<UserVO> listUsersByType(Integer type) {
|
public List<UserVO> listUsersByType(Integer type) {
|
||||||
List<UserDO> userDOs = userMapper.selectList(
|
List<UserDO> userDOs = userMapper.selectList(
|
||||||
@@ -182,6 +226,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据账号获取用户信息
|
||||||
|
* @param account 用户账号
|
||||||
|
* @return 用户视图对象
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UserVO getUserByAccount(String account) {
|
public UserVO getUserByAccount(String account) {
|
||||||
UserDO userDO = userMapper.selectOne(
|
UserDO userDO = userMapper.selectOne(
|
||||||
@@ -196,7 +245,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 DO 转换为 VO
|
* 将 DO 转换为 VO
|
||||||
*
|
* @param userDO 用户DO
|
||||||
* @param userDO 用户DO
|
* @param userDO 用户DO
|
||||||
* @return 用户VO
|
* @return 用户VO
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
-- 为t_user表添加status字段
|
||||||
|
-- 执行时间:2026-02-25
|
||||||
|
|
||||||
|
ALTER TABLE `t_user`
|
||||||
|
ADD COLUMN `status` TINYINT UNSIGNED DEFAULT 1 COMMENT '用户状态:1-正常,0-禁用'
|
||||||
|
AFTER `is_delete`;
|
||||||
|
|
||||||
|
-- 为现有用户设置默认状态为正常(1)
|
||||||
|
UPDATE `t_user` SET `status` = 1 WHERE `status` IS NULL;
|
||||||
Reference in New Issue
Block a user