后台管理页面初版
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import axios, { AxiosError } from 'axios'
|
||||
import router from '../router'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const adminApi = axios.create({
|
||||
baseURL: 'http://wcy111.top:8088/api',
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
adminApi.interceptors.request.use(
|
||||
config => {
|
||||
let token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
adminApi.interceptors.response.use(
|
||||
response => {
|
||||
return response.data.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'
|
||||
}
|
||||
}
|
||||
|
||||
console.error('Admin API Error:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export interface AdminLoginRequest {
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export interface AdminLoginResponse {
|
||||
accessToken: string
|
||||
refreshToken: string
|
||||
userInfo: any
|
||||
}
|
||||
|
||||
export const adminAuthApi = {
|
||||
login: (data: AdminLoginRequest) => {
|
||||
return adminApi.post<AdminLoginResponse>('/admin/auth/login', data)
|
||||
},
|
||||
|
||||
logout: () => {
|
||||
return adminApi.post('/admin/auth/logout')
|
||||
}
|
||||
}
|
||||
|
||||
export default adminApi
|
||||
@@ -0,0 +1,54 @@
|
||||
import api from './index'
|
||||
|
||||
export interface PermissionVO {
|
||||
id: number
|
||||
permissionCode: string
|
||||
permissionName: string
|
||||
permissionGroup: string
|
||||
description: string
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface CreatePermissionRequest {
|
||||
permissionCode: string
|
||||
permissionName: string
|
||||
permissionGroup: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface UpdatePermissionRequest {
|
||||
permissionCode?: string
|
||||
permissionName?: string
|
||||
permissionGroup?: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export const permissionApi = {
|
||||
getUserPermissions: (userId?: number) => {
|
||||
if (userId) {
|
||||
return api.get<PermissionVO[]>(`/admin/permission/user/${userId}`)
|
||||
}
|
||||
return api.get<PermissionVO[]>('/permission/list/user/current')
|
||||
},
|
||||
|
||||
listAllPermissions: () => {
|
||||
return api.get<PermissionVO[]>('/permission/list/all')
|
||||
},
|
||||
|
||||
createPermission: (data: CreatePermissionRequest) => {
|
||||
return api.post('/admin/permission/create', data)
|
||||
},
|
||||
|
||||
updatePermission: (id: number, data: UpdatePermissionRequest) => {
|
||||
return api.put(`/admin/permission/update/${id}`, data)
|
||||
},
|
||||
|
||||
deletePermission: (id: number) => {
|
||||
return api.delete(`/admin/permission/delete/${id}`)
|
||||
},
|
||||
|
||||
assignUserPermissions: (userId: number, permissionIds: number[]) => {
|
||||
return api.post(`/admin/permission/assign/${userId}`, { permissionIds })
|
||||
}
|
||||
}
|
||||
+40
-26
@@ -2,34 +2,44 @@ import api from './index'
|
||||
|
||||
export interface ProductVO {
|
||||
id: number
|
||||
shopId: number
|
||||
shopName: string
|
||||
title: string
|
||||
shopId: number | null
|
||||
name: string
|
||||
description: string
|
||||
imageFileIds: string
|
||||
imageUrls: string[]
|
||||
image: string
|
||||
price: number
|
||||
tags: string
|
||||
tagList: string[]
|
||||
likeCount: number
|
||||
collectCount: number
|
||||
approximateDuration: string
|
||||
bookableArtists: string
|
||||
availableCoupons: string
|
||||
estimatedTime: number
|
||||
category: string
|
||||
status: number
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface ProductDTO {
|
||||
shopId: number
|
||||
title: string
|
||||
export interface ListProductsParams {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export interface CreateProductRequest {
|
||||
name: string
|
||||
description: string
|
||||
imageFileIds: string
|
||||
image: string
|
||||
price: number
|
||||
tags: string
|
||||
approximateDuration: string
|
||||
bookableArtists: string
|
||||
availableCoupons: string
|
||||
estimatedTime: number
|
||||
category: string
|
||||
status: number
|
||||
shopId: number | null
|
||||
}
|
||||
|
||||
export interface UpdateProductRequest {
|
||||
name?: string
|
||||
description?: string
|
||||
image?: string
|
||||
price?: number
|
||||
estimatedTime?: number
|
||||
category?: string
|
||||
status?: number
|
||||
shopId?: number | null
|
||||
}
|
||||
|
||||
export const productApi = {
|
||||
@@ -45,15 +55,19 @@ export const productApi = {
|
||||
return api.get<ProductVO[]>(`/product/list/tag/${tag}`)
|
||||
},
|
||||
|
||||
createProduct: (data: ProductDTO) => {
|
||||
return api.post<ProductVO>('/product/add', data)
|
||||
listProducts: (params: ListProductsParams) => {
|
||||
return api.get<any>('/admin/product/list', { params })
|
||||
},
|
||||
|
||||
updateProduct: (id: number, data: ProductDTO) => {
|
||||
return api.put<ProductVO>(`/product/update/${id}`, data)
|
||||
createProduct: (data: CreateProductRequest) => {
|
||||
return api.post('/admin/product/create', data)
|
||||
},
|
||||
|
||||
updateProduct: (id: number, data: UpdateProductRequest) => {
|
||||
return api.put(`/admin/product/update/${id}`, data)
|
||||
},
|
||||
|
||||
deleteProduct: (id: number) => {
|
||||
return api.delete(`/product/delete/${id}`)
|
||||
return api.delete(`/admin/product/delete/${id}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,46 @@ import api from './index'
|
||||
|
||||
export interface ShopVO {
|
||||
id: number
|
||||
shopName: string
|
||||
address: string
|
||||
phone: string
|
||||
businessHours: string
|
||||
name: string
|
||||
description: string
|
||||
image: string
|
||||
phone: string
|
||||
address: string
|
||||
businessHours: string
|
||||
status: number
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface ShopSimpleVO {
|
||||
id: number
|
||||
shopName: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface ListShopsParams {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export interface CreateShopRequest {
|
||||
name: string
|
||||
description: string
|
||||
image: string
|
||||
phone: string
|
||||
address: string
|
||||
businessHours: string
|
||||
status: number
|
||||
}
|
||||
|
||||
export interface UpdateShopRequest {
|
||||
name?: string
|
||||
description?: string
|
||||
image?: string
|
||||
phone?: string
|
||||
address?: string
|
||||
businessHours?: string
|
||||
status?: number
|
||||
}
|
||||
|
||||
export const shopApi = {
|
||||
@@ -27,5 +55,21 @@ export const shopApi = {
|
||||
|
||||
getShopById: (id: number) => {
|
||||
return api.get<ShopVO>(`/shop/get/${id}`)
|
||||
},
|
||||
|
||||
listShops: (params: ListShopsParams) => {
|
||||
return api.get<any>('/admin/shop/list', { params })
|
||||
},
|
||||
|
||||
createShop: (data: CreateShopRequest) => {
|
||||
return api.post('/admin/shop/create', data)
|
||||
},
|
||||
|
||||
updateShop: (id: number, data: UpdateShopRequest) => {
|
||||
return api.put(`/admin/shop/update/${id}`, data)
|
||||
},
|
||||
|
||||
deleteShop: (id: number) => {
|
||||
return api.delete(`/admin/shop/delete/${id}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,50 @@ export interface UpdateUserInfoRequest {
|
||||
signature?: string
|
||||
}
|
||||
|
||||
export interface ListUsersParams {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export interface CreateUserRequest {
|
||||
username: string
|
||||
nickname: string
|
||||
phone: string
|
||||
password: string
|
||||
userType: number
|
||||
}
|
||||
|
||||
export interface UpdateUserRequest {
|
||||
username?: string
|
||||
nickname?: string
|
||||
phone?: string
|
||||
userType?: number
|
||||
}
|
||||
|
||||
export const userApi = {
|
||||
getUserInfo: () => {
|
||||
return api.get<UserVO>('/user/info')
|
||||
},
|
||||
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
||||
return api.put('/user/info', data)
|
||||
},
|
||||
listUsers: (params: ListUsersParams) => {
|
||||
return api.get<any>('/admin/user/list', { params })
|
||||
},
|
||||
createUser: (data: CreateUserRequest) => {
|
||||
return api.post('/admin/user/create', data)
|
||||
},
|
||||
updateUser: (id: number, data: UpdateUserRequest) => {
|
||||
return api.put(`/admin/user/update/${id}`, data)
|
||||
},
|
||||
updateUserStatus: (id: number, status: number) => {
|
||||
return api.put(`/admin/user/status/${id}`, { status })
|
||||
},
|
||||
resetPassword: (id: number) => {
|
||||
return api.post(`/admin/user/reset-password/${id}`)
|
||||
},
|
||||
deleteUser: (id: number) => {
|
||||
return api.delete(`/admin/user/delete/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
export const DEFAULT_AVATAR = 'https://api.dicebear.com/7.x/avataaars/svg?seed=default'
|
||||
export const DEFAULT_PRODUCT_IMAGE = 'https://via.placeholder.com/200x200?text=Product'
|
||||
export const DEFAULT_SHOP_IMAGE = 'https://via.placeholder.com/200x200?text=Shop'
|
||||
|
||||
@@ -7,65 +7,127 @@ const router = createRouter({
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: () => import('../views/HomeView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
meta: { requiresAuth: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/auth',
|
||||
name: 'auth',
|
||||
component: () => import('../views/AuthView.vue'),
|
||||
meta: { requiresAuth: false, hideNav: true }
|
||||
meta: { requiresAuth: false, hideNav: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/products',
|
||||
name: 'products',
|
||||
component: () => import('../views/ProductListView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
meta: { requiresAuth: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/product/:id',
|
||||
name: 'product-detail',
|
||||
component: () => import('../views/ProductDetailView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true }
|
||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/cart',
|
||||
name: 'cart',
|
||||
component: () => import('../views/CartView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
meta: { requiresAuth: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/profile',
|
||||
name: 'profile',
|
||||
component: () => import('../views/ProfileView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
meta: { requiresAuth: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/wishlist',
|
||||
name: 'wishlist',
|
||||
component: () => import('../views/WishlistView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
meta: { requiresAuth: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/settings',
|
||||
name: 'settings',
|
||||
component: () => import('../views/SettingsView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true }
|
||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/admin/login',
|
||||
name: 'admin-login',
|
||||
component: () => import('../views/admin/AdminLoginView.vue'),
|
||||
meta: { requiresAuth: false, isAdmin: true }
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
name: 'admin',
|
||||
component: () => import('../views/admin/AdminLayout.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: true },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
redirect: '/admin/dashboard'
|
||||
},
|
||||
{
|
||||
path: 'dashboard',
|
||||
name: 'admin-dashboard',
|
||||
component: () => import('../views/admin/DashboardView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: true }
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
name: 'admin-users',
|
||||
component: () => import('../views/admin/UsersView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: true }
|
||||
},
|
||||
{
|
||||
path: 'products',
|
||||
name: 'admin-products',
|
||||
component: () => import('../views/admin/ProductsView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: true }
|
||||
},
|
||||
{
|
||||
path: 'shops',
|
||||
name: 'admin-shops',
|
||||
component: () => import('../views/admin/ShopsView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: true }
|
||||
},
|
||||
{
|
||||
path: 'permissions',
|
||||
name: 'admin-permissions',
|
||||
component: () => import('../views/admin/PermissionsView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: true }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const token = localStorage.getItem('accessToken')
|
||||
const isAdminRoute = to.meta.isAdmin as boolean
|
||||
const requiresAuth = to.meta.requiresAuth as boolean
|
||||
|
||||
if (requiresAuth && !token) {
|
||||
next('/auth')
|
||||
} else if (to.path === '/auth' && token) {
|
||||
next('/')
|
||||
} else if (to.path === '/' && !token) {
|
||||
next('/auth')
|
||||
if (isAdminRoute) {
|
||||
const adminToken = localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken')
|
||||
|
||||
if (requiresAuth && !adminToken) {
|
||||
next('/admin/login')
|
||||
} else if (to.path === '/admin/login' && adminToken) {
|
||||
next('/admin/dashboard')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
const token = localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')
|
||||
|
||||
if (requiresAuth && !token) {
|
||||
next('/auth')
|
||||
} else if (to.path === '/auth' && token) {
|
||||
next('/')
|
||||
} else if (to.path === '/' && !token) {
|
||||
next('/auth')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
+130
-30
@@ -30,23 +30,34 @@
|
||||
|
||||
<!-- 商品图片 -->
|
||||
<div class="item-image" :style="{ backgroundColor: item.bgColor }">
|
||||
<span>{{ item.name[0] }}</span>
|
||||
<span>{{ item.title[0] }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 商品详情 -->
|
||||
<div class="item-details">
|
||||
<h3 class="item-name">{{ item.name }}</h3>
|
||||
<p class="item-price">${{ item.price }}</p>
|
||||
<h3 class="item-name">{{ item.title }}</h3>
|
||||
<p class="item-price">¥{{ item.price.toFixed(2) }}</p>
|
||||
<p class="item-duration">预计耗时: {{ item.approximateDuration }}</p>
|
||||
|
||||
<!-- 数量控制和删除按钮 -->
|
||||
<div class="item-actions">
|
||||
<a-input-number
|
||||
v-model:value="item.quantity"
|
||||
:min="1"
|
||||
:max="99"
|
||||
size="small"
|
||||
@change="(val: number | null) => handleQuantityChange(item, val)"
|
||||
/>
|
||||
<div class="quantity-control">
|
||||
<a-button
|
||||
size="small"
|
||||
:disabled="item.quantity <= 1"
|
||||
@click="handleDecreaseQuantity(item)"
|
||||
>
|
||||
-
|
||||
</a-button>
|
||||
<span class="quantity-value">{{ item.quantity }}</span>
|
||||
<a-button
|
||||
size="small"
|
||||
:disabled="item.quantity >= 99"
|
||||
@click="handleIncreaseQuantity(item)"
|
||||
>
|
||||
+
|
||||
</a-button>
|
||||
</div>
|
||||
<a-popconfirm
|
||||
title="确定要删除这个商品吗?"
|
||||
ok-text="确定"
|
||||
@@ -71,15 +82,15 @@
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span>小计</span>
|
||||
<span>${{ subtotal }}</span>
|
||||
<span>¥{{ subtotal.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span>运费</span>
|
||||
<span>${{ shipping }}</span>
|
||||
<span>预计消耗时间</span>
|
||||
<span class="duration">{{ totalDuration }}</span>
|
||||
</div>
|
||||
<div class="summary-row total">
|
||||
<span>总计</span>
|
||||
<span class="total-price">${{ total }}</span>
|
||||
<span class="total-price">¥{{ subtotal.toFixed(2) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -105,19 +116,54 @@ import {
|
||||
DeleteOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { ProductVO } from '@/api/product'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 购物车商品数据
|
||||
const cartItems = ref([
|
||||
{ id: 1, name: 'Watch', price: 40, bgColor: '#ffe4d6', quantity: 1, selected: true },
|
||||
{ id: 2, name: 'Nike Shoes', price: 430, bgColor: '#d6eaff', quantity: 2, selected: true },
|
||||
{ id: 3, name: 'Airpods', price: 333, bgColor: '#e2ffd6', quantity: 1, selected: false }
|
||||
// 购物车商品数据(模拟真实产品数据结构)
|
||||
const cartItems = ref<Array<{
|
||||
id: number
|
||||
productId: number
|
||||
title: string
|
||||
price: number
|
||||
imageUrl?: string
|
||||
bgColor: string
|
||||
quantity: number
|
||||
selected: boolean
|
||||
approximateDuration: string
|
||||
}>>([
|
||||
{
|
||||
id: 1,
|
||||
productId: 1,
|
||||
title: '经典美甲',
|
||||
price: 99,
|
||||
bgColor: '#ffe4d6',
|
||||
quantity: 1,
|
||||
selected: true,
|
||||
approximateDuration: '30分钟'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
productId: 2,
|
||||
title: '法式美甲',
|
||||
price: 168,
|
||||
bgColor: '#d6eaff',
|
||||
quantity: 2,
|
||||
selected: true,
|
||||
approximateDuration: '45分钟'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
productId: 3,
|
||||
title: '光疗美甲',
|
||||
price: 238,
|
||||
bgColor: '#e2ffd6',
|
||||
quantity: 1,
|
||||
selected: false,
|
||||
approximateDuration: '60分钟'
|
||||
}
|
||||
])
|
||||
|
||||
// 运费
|
||||
const shipping = 10
|
||||
|
||||
// 计算选中的商品数量
|
||||
const selectedCount = computed(() => {
|
||||
return cartItems.value.filter(item => item.selected).length
|
||||
@@ -135,9 +181,31 @@ const subtotal = computed(() => {
|
||||
.reduce((sum, item) => sum + (item.price * item.quantity), 0)
|
||||
})
|
||||
|
||||
// 计算总价
|
||||
const total = computed(() => {
|
||||
return subtotal.value + shipping
|
||||
// 计算预计总消耗时间
|
||||
const totalDuration = computed(() => {
|
||||
const selectedItems = cartItems.value.filter(item => item.selected)
|
||||
if (selectedItems.length === 0) return '0分钟'
|
||||
|
||||
let totalMinutes = 0
|
||||
selectedItems.forEach(item => {
|
||||
const durationStr = item.approximateDuration
|
||||
const match = durationStr.match(/(\d+)/)
|
||||
if (match) {
|
||||
totalMinutes += parseInt(match[1]) * item.quantity
|
||||
}
|
||||
})
|
||||
|
||||
if (totalMinutes < 60) {
|
||||
return `${totalMinutes}分钟`
|
||||
} else {
|
||||
const hours = Math.floor(totalMinutes / 60)
|
||||
const minutes = totalMinutes % 60
|
||||
if (minutes === 0) {
|
||||
return `${hours}小时`
|
||||
} else {
|
||||
return `${hours}小时${minutes}分钟`
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 处理返回按钮点击
|
||||
@@ -156,9 +224,18 @@ const handleSelectChange = () => {
|
||||
console.log('选择状态改变')
|
||||
}
|
||||
|
||||
// 处理数量变化
|
||||
const handleQuantityChange = (item: any, val: number | null) => {
|
||||
console.log('商品数量改变:', item.name, val)
|
||||
// 处理减少数量
|
||||
const handleDecreaseQuantity = (item: any) => {
|
||||
if (item.quantity > 1) {
|
||||
item.quantity--
|
||||
}
|
||||
}
|
||||
|
||||
// 处理增加数量
|
||||
const handleIncreaseQuantity = (item: any) => {
|
||||
if (item.quantity < 99) {
|
||||
item.quantity++
|
||||
}
|
||||
}
|
||||
|
||||
// 处理删除商品
|
||||
@@ -186,8 +263,7 @@ const handleCheckout = () => {
|
||||
console.log('结算购物车:', {
|
||||
items: selectedItems,
|
||||
subtotal: subtotal.value,
|
||||
shipping: shipping,
|
||||
total: total.value
|
||||
totalDuration: totalDuration.value
|
||||
})
|
||||
message.success('正在跳转到结算页面...')
|
||||
}
|
||||
@@ -286,6 +362,12 @@ const handleCheckout = () => {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.item-duration {
|
||||
color: #666;
|
||||
font-size: 13px;
|
||||
margin: 4px 0 0 0;
|
||||
}
|
||||
|
||||
.item-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -293,6 +375,19 @@ const handleCheckout = () => {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.quantity-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.quantity-value {
|
||||
min-width: 30px;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.summary {
|
||||
margin: 0 15px 15px;
|
||||
padding: 16px;
|
||||
@@ -322,6 +417,11 @@ const handleCheckout = () => {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.duration {
|
||||
color: #667eea;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.checkout-section {
|
||||
position: fixed;
|
||||
bottom: 60px;
|
||||
|
||||
@@ -38,6 +38,26 @@
|
||||
</a-button>
|
||||
</a-card>
|
||||
</div>
|
||||
<div class="permissions-section" v-if="userPermissions.length > 0">
|
||||
<a-card :bordered="false" class="permissions-card">
|
||||
<template #title>
|
||||
<div class="card-title">
|
||||
<SafetyCertificateOutlined class="title-icon" />
|
||||
<span>我的权限</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="permissions-content">
|
||||
<div v-for="(group, groupName) in groupedPermissions" :key="groupName" class="permission-group">
|
||||
<div class="group-title">{{ groupName }}</div>
|
||||
<div class="permission-tags">
|
||||
<a-tag v-for="permission in group" :key="permission.id" color="blue" class="permission-tag">
|
||||
{{ permission.permissionName }}
|
||||
</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
<div class="stats-section">
|
||||
<a-card :bordered="false" class="stats-card">
|
||||
<a-row :gutter="16">
|
||||
@@ -136,7 +156,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
SettingOutlined,
|
||||
@@ -147,13 +167,15 @@ import {
|
||||
CreditCardOutlined,
|
||||
BellOutlined,
|
||||
QuestionCircleOutlined,
|
||||
ShopOutlined
|
||||
ShopOutlined,
|
||||
SafetyCertificateOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { UploadProps } from 'ant-design-vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { fileApi } from '@/api/file'
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -166,7 +188,21 @@ const userInfo = ref<UserVO>({
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
const userPermissions = ref<PermissionVO[]>([])
|
||||
|
||||
const hasNotification = ref(true)
|
||||
|
||||
const groupedPermissions = computed(() => {
|
||||
const groups: Record<string, PermissionVO[]> = {}
|
||||
userPermissions.value.forEach(permission => {
|
||||
if (!groups[permission.permissionGroup]) {
|
||||
groups[permission.permissionGroup] = []
|
||||
}
|
||||
groups[permission.permissionGroup].push(permission)
|
||||
})
|
||||
return groups
|
||||
})
|
||||
|
||||
const editModalVisible = ref(false)
|
||||
const saving = ref(false)
|
||||
const uploading = ref(false)
|
||||
@@ -230,6 +266,18 @@ const fetchUserInfo = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUserPermissions = async () => {
|
||||
try {
|
||||
console.log('开始获取用户权限...')
|
||||
const res = await permissionApi.getUserPermissions()
|
||||
console.log('获取到的用户权限:', res)
|
||||
userPermissions.value = res as unknown as PermissionVO[]
|
||||
console.log('设置后的 userPermissions:', userPermissions.value)
|
||||
} catch (error) {
|
||||
console.error('获取用户权限失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleEditProfile = () => {
|
||||
editForm.value = {
|
||||
nickname: userInfo.value.nickname || '',
|
||||
@@ -355,6 +403,7 @@ const handleSettingsClick = () => {
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
fetchUserPermissions()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -411,6 +460,73 @@ onMounted(() => {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.permissions-section {
|
||||
padding: 0 15px 15px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.permissions-card {
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.permissions-card :deep(.ant-card-head) {
|
||||
border-bottom: none;
|
||||
padding: 16px 20px 12px;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.title-icon {
|
||||
font-size: 20px;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.permissions-card :deep(.ant-card-body) {
|
||||
padding: 0 20px 20px;
|
||||
}
|
||||
|
||||
.permissions-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.permission-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.group-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #667eea;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.permission-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.permission-tag {
|
||||
font-size: 13px;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
@@ -629,6 +745,8 @@ onMounted(() => {
|
||||
justify-content: center;
|
||||
font-size: 20px;
|
||||
color: white;
|
||||
opacity: 1;
|
||||
filter: none;
|
||||
}
|
||||
|
||||
.menu-item :deep(.ant-list-item-meta-title) {
|
||||
@@ -652,10 +770,12 @@ onMounted(() => {
|
||||
.logout-section :deep(.ant-btn-dangerous) {
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
font-size: 17px;
|
||||
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
|
||||
border: none;
|
||||
box-shadow: 0 4px 15px rgba(238, 90, 111, 0.3);
|
||||
color: white !important;
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
<template>
|
||||
<div class="admin-layout">
|
||||
<a-layout>
|
||||
<a-layout-sider
|
||||
v-model:collapsed="collapsed"
|
||||
:trigger="null"
|
||||
collapsible
|
||||
class="sider"
|
||||
width="240"
|
||||
>
|
||||
<div class="logo">
|
||||
<h1 v-if="!collapsed">后台管理</h1>
|
||||
<h1 v-else>管</h1>
|
||||
</div>
|
||||
<a-menu
|
||||
v-model:selectedKeys="selectedKeys"
|
||||
mode="inline"
|
||||
theme="dark"
|
||||
@click="handleMenuClick"
|
||||
>
|
||||
<a-menu-item key="/admin/dashboard">
|
||||
<template #icon>
|
||||
<DashboardOutlined />
|
||||
</template>
|
||||
<span>仪表盘</span>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/admin/users">
|
||||
<template #icon>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
<span>用户管理</span>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/admin/products">
|
||||
<template #icon>
|
||||
<ShopOutlined />
|
||||
</template>
|
||||
<span>商品管理</span>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/admin/shops">
|
||||
<template #icon>
|
||||
<HomeOutlined />
|
||||
</template>
|
||||
<span>店铺管理</span>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/admin/permissions">
|
||||
<template #icon>
|
||||
<SafetyCertificateOutlined />
|
||||
</template>
|
||||
<span>权限管理</span>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</a-layout-sider>
|
||||
<a-layout>
|
||||
<a-layout-header class="header">
|
||||
<div class="header-left">
|
||||
<MenuUnfoldOutlined
|
||||
v-if="collapsed"
|
||||
class="trigger"
|
||||
@click="toggleCollapsed"
|
||||
/>
|
||||
<MenuFoldOutlined
|
||||
v-else
|
||||
class="trigger"
|
||||
@click="toggleCollapsed"
|
||||
/>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<a-dropdown>
|
||||
<a class="user-dropdown" @click.prevent>
|
||||
<a-avatar :size="32" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
<span class="username">{{ userInfo?.nickname || '管理员' }}</span>
|
||||
<DownOutlined />
|
||||
</a>
|
||||
<template #overlay>
|
||||
<a-menu>
|
||||
<a-menu-item key="profile" @click="goToProfile">
|
||||
<template #icon>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
个人中心
|
||||
</a-menu-item>
|
||||
<a-menu-divider />
|
||||
<a-menu-item key="logout" @click="handleLogout">
|
||||
<template #icon>
|
||||
<LogoutOutlined />
|
||||
</template>
|
||||
退出登录
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</template>
|
||||
</a-dropdown>
|
||||
</div>
|
||||
</a-layout-header>
|
||||
<a-layout-content class="content">
|
||||
<router-view />
|
||||
</a-layout-content>
|
||||
</a-layout>
|
||||
</a-layout>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import {
|
||||
MenuFoldOutlined,
|
||||
MenuUnfoldOutlined,
|
||||
DashboardOutlined,
|
||||
UserOutlined,
|
||||
ShopOutlined,
|
||||
HomeOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
DownOutlined,
|
||||
LogoutOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const collapsed = ref(false)
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
|
||||
const selectedKeys = computed(() => [route.path])
|
||||
|
||||
const toggleCollapsed = () => {
|
||||
collapsed.value = !collapsed.value
|
||||
}
|
||||
|
||||
const handleMenuClick = ({ key }: { key: string }) => {
|
||||
router.push(key)
|
||||
}
|
||||
|
||||
const goToProfile = () => {
|
||||
router.push('/profile')
|
||||
}
|
||||
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出',
|
||||
content: '确定要退出登录吗?',
|
||||
onOk: async () => {
|
||||
try {
|
||||
await authApi.logout()
|
||||
} catch (error) {
|
||||
console.error('登出失败:', error)
|
||||
} finally {
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
message.success('已退出登录')
|
||||
router.push('/auth')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const res = await userApi.getUserInfo()
|
||||
userInfo.value = res as unknown as UserVO
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-layout {
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.sider {
|
||||
background: #001529;
|
||||
overflow: auto;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(.ant-menu) {
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: white;
|
||||
padding: 0 24px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.trigger {
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.trigger:hover {
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.user-dropdown {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
cursor: pointer;
|
||||
padding: 8px 12px;
|
||||
border-radius: 8px;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.user-dropdown:hover {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin-left: 240px;
|
||||
padding: 24px;
|
||||
background: #f0f2f5;
|
||||
min-height: calc(100vh - 64px);
|
||||
transition: margin-left 0.2s;
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-layout-sider-collapsed) + .ant-layout .content {
|
||||
margin-left: 80px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,163 @@
|
||||
<template>
|
||||
<div class="admin-login">
|
||||
<div class="login-container">
|
||||
<div class="login-header">
|
||||
<h1>后台管理系统</h1>
|
||||
<p>欢迎回来,请登录您的账户</p>
|
||||
</div>
|
||||
|
||||
<a-card class="login-card">
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
layout="vertical"
|
||||
@finish="handleLogin"
|
||||
>
|
||||
<a-form-item label="用户名" name="username">
|
||||
<a-input
|
||||
v-model:value="formState.username"
|
||||
size="large"
|
||||
placeholder="请输入用户名"
|
||||
:prefix-icon="UserOutlined"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="formState.password"
|
||||
size="large"
|
||||
placeholder="请输入密码"
|
||||
:prefix-icon="LockOutlined"
|
||||
@pressEnter="handleLogin"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
size="large"
|
||||
html-type="submit"
|
||||
:loading="loading"
|
||||
block
|
||||
>
|
||||
登录
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
|
||||
<div class="login-footer">
|
||||
<a @click="goToFrontend">返回前台</a>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } 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'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
|
||||
const formState = reactive({
|
||||
username: '',
|
||||
password: ''
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
loading.value = true
|
||||
|
||||
const res = await adminAuthApi.login({
|
||||
username: formState.username,
|
||||
password: formState.password
|
||||
})
|
||||
|
||||
const { accessToken, refreshToken, userInfo } = res as any
|
||||
|
||||
localStorage.setItem('adminAccessToken', accessToken)
|
||||
localStorage.setItem('adminRefreshToken', refreshToken)
|
||||
localStorage.setItem('adminUserInfo', JSON.stringify(userInfo))
|
||||
sessionStorage.setItem('adminAccessToken', accessToken)
|
||||
|
||||
message.success('登录成功')
|
||||
router.push('/admin/dashboard')
|
||||
} catch (error: any) {
|
||||
console.error('登录失败:', error)
|
||||
message.error(error.message || '登录失败,请检查用户名和密码')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const goToFrontend = () => {
|
||||
router.push('/')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-login {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 32px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 32px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
font-size: 14px;
|
||||
opacity: 0.9;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
text-align: center;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.login-footer a {
|
||||
color: #1890ff;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.login-footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,165 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<a-page-header title="仪表盘" sub-title="欢迎使用后台管理系统" />
|
||||
|
||||
<a-row :gutter="16" class="stat-cards">
|
||||
<a-col :span="6">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="总用户数"
|
||||
:value="128"
|
||||
:value-style="{ color: '#3f8600' }"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="6">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="商品总数"
|
||||
:value="56"
|
||||
:value-style="{ color: '#1890ff' }"
|
||||
>
|
||||
<template #prefix>
|
||||
<ShopOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="6">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="店铺数量"
|
||||
:value="8"
|
||||
:value-style="{ color: '#722ed1' }"
|
||||
>
|
||||
<template #prefix>
|
||||
<HomeOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="6">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="今日订单"
|
||||
:value="24"
|
||||
:value-style="{ color: '#cf1322' }"
|
||||
>
|
||||
<template #prefix>
|
||||
<ShoppingOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</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-card>
|
||||
</a-col>
|
||||
<a-col :span="8">
|
||||
<a-card title="热门商品" :bordered="false" class="chart-card">
|
||||
<a-list :data-source="hotProducts" size="small">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item>
|
||||
<a-list-item-meta>
|
||||
<template #title>
|
||||
<a href="#">{{ item.name }}</a>
|
||||
</template>
|
||||
<template #description>
|
||||
销量: {{ item.sales }}
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-card title="最近活动" :bordered="false" class="activity-card">
|
||||
<a-timeline>
|
||||
<a-timeline-item color="green">
|
||||
<p>用户张三完成了订单 #1024</p>
|
||||
<p style="font-size: 12px; color: #999;">2小时前</p>
|
||||
</a-timeline-item>
|
||||
<a-timeline-item color="blue">
|
||||
<p>新品"星空美甲"已上架</p>
|
||||
<p style="font-size: 12px; color: #999;">5小时前</p>
|
||||
</a-timeline-item>
|
||||
<a-timeline-item color="red">
|
||||
<p>店铺"时尚美甲店"信息已更新</p>
|
||||
<p style="font-size: 12px; color: #999;">昨天</p>
|
||||
</a-timeline-item>
|
||||
<a-timeline-item>
|
||||
<p>新用户李四注册成功</p>
|
||||
<p style="font-size: 12px; color: #999;">2天前</p>
|
||||
</a-timeline-item>
|
||||
</a-timeline>
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import {
|
||||
UserOutlined,
|
||||
ShopOutlined,
|
||||
HomeOutlined,
|
||||
ShoppingOutlined,
|
||||
BarChartOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
|
||||
const hotProducts = ref([
|
||||
{ name: '法式美甲', sales: 156 },
|
||||
{ name: '星空美甲', sales: 132 },
|
||||
{ name: '渐变美甲', sales: 98 },
|
||||
{ name: '贴钻美甲', sales: 87 },
|
||||
{ name: '纯色美甲', sales: 65 }
|
||||
])
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dashboard {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.stat-cards {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.charts-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
.chart-placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 300px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.chart-placeholder p {
|
||||
margin-top: 16px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.activity-card {
|
||||
margin-top: 24px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,392 @@
|
||||
<template>
|
||||
<div class="permissions">
|
||||
<a-page-header title="权限管理" sub-title="管理系统权限和用户权限分配" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-tabs v-model:activeKey="activeTab">
|
||||
<a-tab-pane key="permissions" tab="权限列表">
|
||||
<template #extra>
|
||||
<a-button type="primary" @click="showAddPermissionModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增权限
|
||||
</a-button>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
:columns="permissionColumns"
|
||||
:data-source="permissionList"
|
||||
:loading="loading"
|
||||
:pagination="permissionPagination"
|
||||
@change="handlePermissionTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-else-if="column.key === 'permissionGroup'">
|
||||
<a-tag color="purple">{{ record.permissionGroup }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showEditPermissionModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
title="确定要删除这个权限吗?"
|
||||
@confirm="handleDeletePermission(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-tab-pane>
|
||||
|
||||
<a-tab-pane key="user-permissions" tab="用户权限分配">
|
||||
<a-row :gutter="16">
|
||||
<a-col :span="8">
|
||||
<a-card title="选择用户" :bordered="false">
|
||||
<a-input-search
|
||||
v-model:value="userSearchText"
|
||||
placeholder="搜索用户"
|
||||
style="margin-bottom: 16px"
|
||||
@search="handleUserSearch"
|
||||
/>
|
||||
<a-list
|
||||
:data-source="userList"
|
||||
:loading="userLoading"
|
||||
item-layout="horizontal"
|
||||
size="small"
|
||||
@click="selectUser"
|
||||
>
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item
|
||||
:class="{ selected: selectedUser?.id === item.id }"
|
||||
style="cursor: pointer;"
|
||||
@click="selectUser(item)"
|
||||
>
|
||||
<a-list-item-meta>
|
||||
<template #avatar>
|
||||
<a-avatar :src="item.avatar || DEFAULT_AVATAR" />
|
||||
</template>
|
||||
<template #title>{{ item.nickname }}</template>
|
||||
<template #description>{{ item.username }}</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="16">
|
||||
<a-card
|
||||
title="分配权限"
|
||||
:bordered="false"
|
||||
:extra="selectedUser ? [
|
||||
<a-button type='primary' key='save' @click='handleSaveUserPermissions'>
|
||||
保存权限
|
||||
</a-button>
|
||||
] : []"
|
||||
>
|
||||
<template v-if="selectedUser">
|
||||
<a-alert
|
||||
message="当前用户: {{ selectedUser.nickname }}"
|
||||
description="用户类型: {{ getUserTypeText(selectedUser.userType) }}"
|
||||
type="info"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<a-spin :spinning="assignLoading">
|
||||
<a-collapse v-model:activeKey="activeCollapseKeys">
|
||||
<a-collapse-panel
|
||||
v-for="(permissions, group) in groupedPermissions"
|
||||
:key="group"
|
||||
:header="group"
|
||||
>
|
||||
<a-checkbox-group v-model:value="selectedPermissions">
|
||||
<a-space direction="vertical" style="width: 100%">
|
||||
<a-checkbox
|
||||
v-for="permission in permissions"
|
||||
:key="permission.id"
|
||||
:value="permission.id"
|
||||
>
|
||||
{{ permission.permissionName }}
|
||||
<span style="color: #999; font-size: 12px; margin-left: 8px;">
|
||||
({{ permission.permissionCode }})
|
||||
</span>
|
||||
</a-checkbox>
|
||||
</a-space>
|
||||
</a-checkbox-group>
|
||||
</a-collapse-panel>
|
||||
</a-collapse>
|
||||
</a-spin>
|
||||
</template>
|
||||
<a-empty v-else description="请先选择一个用户" />
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
v-model:open="permissionModalVisible"
|
||||
:title="isEditPermission ? '编辑权限' : '新增权限'"
|
||||
@ok="handlePermissionModalOk"
|
||||
@cancel="handlePermissionModalCancel"
|
||||
:confirmLoading="permissionModalLoading"
|
||||
>
|
||||
<a-form
|
||||
ref="permissionFormRef"
|
||||
:model="permissionFormState"
|
||||
:rules="permissionFormRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="权限编码" name="permissionCode">
|
||||
<a-input v-model:value="permissionFormState.permissionCode" placeholder="例如:product:add" />
|
||||
</a-form-item>
|
||||
<a-form-item label="权限名称" name="permissionName">
|
||||
<a-input v-model:value="permissionFormState.permissionName" placeholder="例如:添加商品" />
|
||||
</a-form-item>
|
||||
<a-form-item label="权限分组" name="permissionGroup">
|
||||
<a-select v-model:value="permissionFormState.permissionGroup" placeholder="请选择权限分组">
|
||||
<a-select-option value="商品管理">商品管理</a-select-option>
|
||||
<a-select-option value="店铺管理">店铺管理</a-select-option>
|
||||
<a-select-option value="用户管理">用户管理</a-select-option>
|
||||
<a-select-option value="权限管理">权限管理</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="权限描述" name="description">
|
||||
<a-textarea
|
||||
v-model:value="permissionFormState.description"
|
||||
placeholder="请输入权限描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
|
||||
const activeTab = ref('permissions')
|
||||
const loading = ref(false)
|
||||
const permissionList = ref<PermissionVO[]>([])
|
||||
const permissionModalVisible = ref(false)
|
||||
const permissionModalLoading = ref(false)
|
||||
const isEditPermission = ref(false)
|
||||
const permissionFormRef = ref<FormInstance>()
|
||||
const currentPermission = ref<PermissionVO | null>(null)
|
||||
|
||||
const permissionPagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 20,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const permissionFormState = reactive({
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
const permissionFormRules = {
|
||||
permissionCode: [{ required: true, message: '请输入权限编码', trigger: 'blur' }],
|
||||
permissionName: [{ required: true, message: '请输入权限名称', trigger: 'blur' }],
|
||||
permissionGroup: [{ required: true, message: '请选择权限分组', trigger: 'change' }],
|
||||
description: [{ required: true, message: '请输入权限描述', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const permissionColumns = [
|
||||
{ title: '权限编码', dataIndex: 'permissionCode', key: 'permissionCode' },
|
||||
{ title: '权限名称', dataIndex: 'permissionName', key: 'permissionName' },
|
||||
{ title: '权限分组', key: 'permissionGroup', width: 120 },
|
||||
{ title: '权限描述', dataIndex: 'description', key: 'description' },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const userLoading = ref(false)
|
||||
const userSearchText = ref('')
|
||||
const userList = ref<UserVO[]>([])
|
||||
const selectedUser = ref<UserVO | null>(null)
|
||||
const assignLoading = ref(false)
|
||||
const selectedPermissions = ref<number[]>([])
|
||||
const activeCollapseKeys = ref<string[]>(['商品管理', '店铺管理', '用户管理', '权限管理'])
|
||||
|
||||
const groupedPermissions = computed(() => {
|
||||
const groups: Record<string, PermissionVO[]> = {}
|
||||
permissionList.value.forEach(p => {
|
||||
if (!groups[p.permissionGroup]) {
|
||||
groups[p.permissionGroup] = []
|
||||
}
|
||||
groups[p.permissionGroup].push(p)
|
||||
})
|
||||
return groups
|
||||
})
|
||||
|
||||
const getUserTypeText = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: '用户',
|
||||
2: '店长',
|
||||
3: '美甲师',
|
||||
4: '管理员'
|
||||
}
|
||||
return map[type] || '未知'
|
||||
}
|
||||
|
||||
const fetchPermissionList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await permissionApi.listAllPermissions()
|
||||
permissionList.value = res || []
|
||||
permissionPagination.total = res?.length || 0
|
||||
} catch (error) {
|
||||
message.error('获取权限列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUserList = async () => {
|
||||
userLoading.value = true
|
||||
try {
|
||||
const res = await userApi.listUsers({
|
||||
page: 1,
|
||||
size: 100,
|
||||
keyword: userSearchText.value
|
||||
})
|
||||
userList.value = res.list || []
|
||||
} catch (error) {
|
||||
message.error('获取用户列表失败')
|
||||
} finally {
|
||||
userLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handlePermissionTableChange = (pag: any) => {
|
||||
permissionPagination.current = pag.current
|
||||
permissionPagination.pageSize = pag.pageSize
|
||||
fetchPermissionList()
|
||||
}
|
||||
|
||||
const handleUserSearch = () => {
|
||||
fetchUserList()
|
||||
}
|
||||
|
||||
const selectUser = async (user: UserVO) => {
|
||||
selectedUser.value = user
|
||||
assignLoading.value = true
|
||||
try {
|
||||
const res = await permissionApi.getUserPermissions(user.id)
|
||||
selectedPermissions.value = res.map(p => p.id)
|
||||
} catch (error) {
|
||||
message.error('获取用户权限失败')
|
||||
selectedPermissions.value = []
|
||||
} finally {
|
||||
assignLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSaveUserPermissions = async () => {
|
||||
if (!selectedUser.value) return
|
||||
try {
|
||||
await permissionApi.assignUserPermissions(selectedUser.value.id, selectedPermissions.value)
|
||||
message.success('权限保存成功')
|
||||
} catch (error) {
|
||||
message.error('权限保存失败')
|
||||
}
|
||||
}
|
||||
|
||||
const showAddPermissionModal = () => {
|
||||
isEditPermission.value = false
|
||||
Object.assign(permissionFormState, {
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
})
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditPermissionModal = (record: PermissionVO) => {
|
||||
isEditPermission.value = true
|
||||
currentPermission.value = record
|
||||
Object.assign(permissionFormState, {
|
||||
permissionCode: record.permissionCode,
|
||||
permissionName: record.permissionName,
|
||||
permissionGroup: record.permissionGroup,
|
||||
description: record.description
|
||||
})
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
const handlePermissionModalOk = async () => {
|
||||
try {
|
||||
await permissionFormRef.value?.validate()
|
||||
permissionModalLoading.value = true
|
||||
|
||||
if (isEditPermission.value && currentPermission.value) {
|
||||
await permissionApi.updatePermission(currentPermission.value.id, permissionFormState)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await permissionApi.createPermission(permissionFormState)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
permissionModalVisible.value = false
|
||||
fetchPermissionList()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
permissionModalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handlePermissionModalCancel = () => {
|
||||
permissionModalVisible.value = false
|
||||
permissionFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDeletePermission = async (record: PermissionVO) => {
|
||||
try {
|
||||
await permissionApi.deletePermission(record.id)
|
||||
message.success('删除成功')
|
||||
fetchPermissionList()
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchPermissionList()
|
||||
fetchUserList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.permissions {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.selected {
|
||||
background: #e6f7ff !important;
|
||||
border-left: 3px solid #1890ff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,295 @@
|
||||
<template>
|
||||
<div class="products">
|
||||
<a-page-header title="商品管理" sub-title="管理美甲商品" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #extra>
|
||||
<a-space>
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索商品名称"
|
||||
style="width: 250px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增商品
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="productList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'image'">
|
||||
<a-image
|
||||
:width="60"
|
||||
:height="60"
|
||||
:src="record.image || DEFAULT_PRODUCT_IMAGE"
|
||||
style="object-fit: cover; border-radius: 4px;"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'price'">
|
||||
<span style="color: #cf1322; font-weight: 600;">
|
||||
¥{{ record.price }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 1 ? 'green' : 'default'">
|
||||
{{ record.status === 1 ? '上架' : '下架' }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
title="确定要删除这个商品吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑商品' : '新增商品'"
|
||||
width="600px"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 5 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<a-form-item label="商品名称" name="name">
|
||||
<a-input v-model:value="formState.name" placeholder="请输入商品名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="商品描述" name="description">
|
||||
<a-textarea
|
||||
v-model:value="formState.description"
|
||||
placeholder="请输入商品描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品图片" name="image">
|
||||
<a-input v-model:value="formState.image" placeholder="请输入图片URL" />
|
||||
</a-form-item>
|
||||
<a-form-item label="价格" name="price">
|
||||
<a-input-number
|
||||
v-model:value="formState.price"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
placeholder="请输入价格"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="预计时长(分钟)" name="estimatedTime">
|
||||
<a-input-number
|
||||
v-model:value="formState.estimatedTime"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
placeholder="请输入预计时长"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="分类" name="category">
|
||||
<a-select v-model:value="formState.category" placeholder="请选择分类">
|
||||
<a-select-option value="美甲">美甲</a-select-option>
|
||||
<a-select-option value="美睫">美睫</a-select-option>
|
||||
<a-select-option value="手足护理">手足护理</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="状态" name="status">
|
||||
<a-switch v-model:checked="formState.status" checked-children="上架" un-checked-children="下架" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const productList = ref<ProductVO[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentProduct = ref<ProductVO | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
name: '',
|
||||
description: '',
|
||||
image: '',
|
||||
price: 0,
|
||||
estimatedTime: 30,
|
||||
category: '美甲',
|
||||
status: true,
|
||||
shopId: null as number | null
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
name: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '请输入商品描述', trigger: 'blur' }],
|
||||
price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
|
||||
estimatedTime: [{ required: true, message: '请输入预计时长', trigger: 'blur' }],
|
||||
category: [{ required: true, message: '请选择分类', trigger: 'change' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '图片', key: 'image', width: 100 },
|
||||
{ title: '商品名称', dataIndex: 'name', key: 'name' },
|
||||
{ title: '分类', dataIndex: 'category', key: 'category', width: 100 },
|
||||
{ title: '价格', key: 'price', width: 100 },
|
||||
{ title: '预计时长', dataIndex: 'estimatedTime', key: 'estimatedTime', width: 120, customRender: ({ text }: { text: number }) => `${text}分钟` },
|
||||
{ title: '状态', key: 'status', width: 80 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const fetchProductList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await productApi.listProducts({
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize,
|
||||
keyword: searchText.value
|
||||
})
|
||||
productList.value = res.list || []
|
||||
pagination.total = res.total || 0
|
||||
} catch (error) {
|
||||
message.error('获取商品列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
pagination.current = 1
|
||||
fetchProductList()
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
fetchProductList()
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
Object.assign(formState, {
|
||||
name: '',
|
||||
description: '',
|
||||
image: '',
|
||||
price: 0,
|
||||
estimatedTime: 30,
|
||||
category: '美甲',
|
||||
status: true,
|
||||
shopId: null
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: ProductVO) => {
|
||||
isEdit.value = true
|
||||
currentProduct.value = record
|
||||
Object.assign(formState, {
|
||||
name: record.name,
|
||||
description: record.description,
|
||||
image: record.image,
|
||||
price: record.price,
|
||||
estimatedTime: record.estimatedTime,
|
||||
category: record.category,
|
||||
status: record.status === 1,
|
||||
shopId: record.shopId
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
const data = {
|
||||
...formState,
|
||||
status: formState.status ? 1 : 0
|
||||
}
|
||||
|
||||
if (isEdit.value && currentProduct.value) {
|
||||
await productApi.updateProduct(currentProduct.value.id, data)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await productApi.createProduct(data)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
modalVisible.value = false
|
||||
fetchProductList()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDelete = async (record: ProductVO) => {
|
||||
try {
|
||||
await productApi.deleteProduct(record.id)
|
||||
message.success('删除成功')
|
||||
fetchProductList()
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchProductList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.products {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,272 @@
|
||||
<template>
|
||||
<div class="shops">
|
||||
<a-page-header title="店铺管理" sub-title="管理美甲店铺" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #extra>
|
||||
<a-space>
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索店铺名称"
|
||||
style="width: 250px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增店铺
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="shopList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'image'">
|
||||
<a-image
|
||||
:width="60"
|
||||
:height="60"
|
||||
:src="record.image || DEFAULT_SHOP_IMAGE"
|
||||
style="object-fit: cover; border-radius: 4px;"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 1 ? 'green' : 'default'">
|
||||
{{ record.status === 1 ? '营业中' : '已关闭' }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
title="确定要删除这个店铺吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑店铺' : '新增店铺'"
|
||||
width="600px"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 5 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<a-form-item label="店铺名称" name="name">
|
||||
<a-input v-model:value="formState.name" placeholder="请输入店铺名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺描述" name="description">
|
||||
<a-textarea
|
||||
v-model:value="formState.description"
|
||||
placeholder="请输入店铺描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺图片" name="image">
|
||||
<a-input v-model:value="formState.image" placeholder="请输入图片URL" />
|
||||
</a-form-item>
|
||||
<a-form-item label="联系电话" name="phone">
|
||||
<a-input v-model:value="formState.phone" placeholder="请输入联系电话" />
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺地址" name="address">
|
||||
<a-input v-model:value="formState.address" placeholder="请输入店铺地址" />
|
||||
</a-form-item>
|
||||
<a-form-item label="营业时间" name="businessHours">
|
||||
<a-input v-model:value="formState.businessHours" placeholder="例如:09:00-21:00" />
|
||||
</a-form-item>
|
||||
<a-form-item label="状态" name="status">
|
||||
<a-switch v-model:checked="formState.status" checked-children="营业中" un-checked-children="已关闭" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_SHOP_IMAGE } from '@/constants'
|
||||
import { shopApi, type ShopVO } from '@/api/shop'
|
||||
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const shopList = ref<ShopVO[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentShop = ref<ShopVO | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
name: '',
|
||||
description: '',
|
||||
image: '',
|
||||
phone: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
status: true
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '请输入店铺描述', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
|
||||
address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
|
||||
businessHours: [{ required: true, message: '请输入营业时间', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '图片', key: 'image', width: 100 },
|
||||
{ title: '店铺名称', dataIndex: 'name', key: 'name' },
|
||||
{ title: '联系电话', dataIndex: 'phone', key: 'phone' },
|
||||
{ title: '店铺地址', dataIndex: 'address', key: 'address' },
|
||||
{ title: '营业时间', dataIndex: 'businessHours', key: 'businessHours' },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const fetchShopList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await shopApi.listShops({
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize,
|
||||
keyword: searchText.value
|
||||
})
|
||||
shopList.value = res.list || []
|
||||
pagination.total = res.total || 0
|
||||
} catch (error) {
|
||||
message.error('获取店铺列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
pagination.current = 1
|
||||
fetchShopList()
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
fetchShopList()
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
Object.assign(formState, {
|
||||
name: '',
|
||||
description: '',
|
||||
image: '',
|
||||
phone: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
status: true
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: ShopVO) => {
|
||||
isEdit.value = true
|
||||
currentShop.value = record
|
||||
Object.assign(formState, {
|
||||
name: record.name,
|
||||
description: record.description,
|
||||
image: record.image,
|
||||
phone: record.phone,
|
||||
address: record.address,
|
||||
businessHours: record.businessHours,
|
||||
status: record.status === 1
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
const data = {
|
||||
...formState,
|
||||
status: formState.status ? 1 : 0
|
||||
}
|
||||
|
||||
if (isEdit.value && currentShop.value) {
|
||||
await shopApi.updateShop(currentShop.value.id, data)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await shopApi.createShop(data)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
modalVisible.value = false
|
||||
fetchShopList()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDelete = async (record: ShopVO) => {
|
||||
try {
|
||||
await shopApi.deleteShop(record.id)
|
||||
message.success('删除成功')
|
||||
fetchShopList()
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchShopList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.shops {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,305 @@
|
||||
<template>
|
||||
<div class="users">
|
||||
<a-page-header title="用户管理" sub-title="管理系统用户" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #extra>
|
||||
<a-space>
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索用户名或手机号"
|
||||
style="width: 250px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增用户
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="userList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'avatar'">
|
||||
<a-avatar :size="40" :src="record.avatar || DEFAULT_AVATAR" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'userType'">
|
||||
<a-tag :color="getUserTypeColor(record.userType)">
|
||||
{{ getUserTypeText(record.userType) }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-switch
|
||||
:checked="record.status === 1"
|
||||
@change="(checked) => handleStatusChange(record, checked)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button type="link" size="small" @click="handleResetPassword(record)">
|
||||
重置密码
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
title="确定要删除这个用户吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑用户' : '新增用户'"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="用户名" name="username">
|
||||
<a-input v-model:value="formState.username" placeholder="请输入用户名" />
|
||||
</a-form-item>
|
||||
<a-form-item label="昵称" name="nickname">
|
||||
<a-input v-model:value="formState.nickname" placeholder="请输入昵称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="手机号" name="phone">
|
||||
<a-input v-model:value="formState.phone" placeholder="请输入手机号" />
|
||||
</a-form-item>
|
||||
<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="userType">
|
||||
<a-select v-model:value="formState.userType" placeholder="请选择用户类型">
|
||||
<a-select-option :value="0">用户</a-select-option>
|
||||
<a-select-option :value="2">店长</a-select-option>
|
||||
<a-select-option :value="3">美甲师</a-select-option>
|
||||
<a-select-option :value="4">管理员</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const userList = ref<UserVO[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentUser = ref<UserVO | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
username: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
userType: 0
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
userType: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '头像', key: 'avatar', width: 80 },
|
||||
{ title: '用户名', dataIndex: 'username', key: 'username' },
|
||||
{ title: '昵称', dataIndex: 'nickname', key: 'nickname' },
|
||||
{ title: '手机号', dataIndex: 'phone', key: 'phone' },
|
||||
{ title: '用户类型', key: 'userType', width: 120 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 200, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const getUserTypeText = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: '用户',
|
||||
2: '店长',
|
||||
3: '美甲师',
|
||||
4: '管理员'
|
||||
}
|
||||
return map[type] || '未知'
|
||||
}
|
||||
|
||||
const getUserTypeColor = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: 'default',
|
||||
2: 'blue',
|
||||
3: 'green',
|
||||
4: 'purple'
|
||||
}
|
||||
return map[type] || 'default'
|
||||
}
|
||||
|
||||
const fetchUserList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await userApi.listUsers({
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize,
|
||||
keyword: searchText.value
|
||||
})
|
||||
userList.value = res.list || []
|
||||
pagination.total = res.total || 0
|
||||
} catch (error) {
|
||||
message.error('获取用户列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
pagination.current = 1
|
||||
fetchUserList()
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
fetchUserList()
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
Object.assign(formState, {
|
||||
username: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
userType: 0
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: UserVO) => {
|
||||
isEdit.value = true
|
||||
currentUser.value = record
|
||||
Object.assign(formState, {
|
||||
username: record.username,
|
||||
nickname: record.nickname,
|
||||
phone: record.phone,
|
||||
password: '',
|
||||
userType: record.userType
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
if (isEdit.value && currentUser.value) {
|
||||
await userApi.updateUser(currentUser.value.id, formState)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await userApi.createUser(formState)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
modalVisible.value = false
|
||||
fetchUserList()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleStatusChange = async (record: UserVO, checked: boolean) => {
|
||||
try {
|
||||
await userApi.updateUserStatus(record.id, checked ? 1 : 0)
|
||||
message.success('状态更新成功')
|
||||
fetchUserList()
|
||||
} catch (error) {
|
||||
message.error('状态更新失败')
|
||||
record.status = record.status === 1 ? 0 : 1
|
||||
}
|
||||
}
|
||||
|
||||
const handleResetPassword = (record: UserVO) => {
|
||||
Modal.confirm({
|
||||
title: '确认重置密码',
|
||||
content: `确定要将用户 ${record.nickname} 的密码重置为 88888888 吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
await userApi.resetPassword(record.id)
|
||||
message.success('密码重置成功')
|
||||
} catch (error) {
|
||||
message.error('密码重置失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleDelete = async (record: UserVO) => {
|
||||
try {
|
||||
await userApi.deleteUser(record.id)
|
||||
message.success('删除成功')
|
||||
fetchUserList()
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.users {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -133,6 +133,18 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- AOP -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Validation -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.xiaowang.yuminailcore.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RequirePermission {
|
||||
|
||||
String value() default "";
|
||||
|
||||
int requireUserType() default -1;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.xiaowang.yuminailcore.aspect;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.service.PermissionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionAspect {
|
||||
|
||||
private final PermissionService permissionService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@Around("@annotation(com.xiaowang.yuminailcore.annotation.RequirePermission)")
|
||||
public Object checkPermission(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes == null) {
|
||||
return Result.error(403, "无法获取请求信息");
|
||||
}
|
||||
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
|
||||
if (userId == null) {
|
||||
return Result.error(401, "未登录");
|
||||
}
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
RequirePermission requirePermission = method.getAnnotation(RequirePermission.class);
|
||||
|
||||
if (requirePermission == null) {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
return Result.error(404, "用户不存在");
|
||||
}
|
||||
|
||||
String permissionCode = requirePermission.value();
|
||||
int requireUserType = requirePermission.requireUserType();
|
||||
|
||||
boolean hasPermission = true;
|
||||
|
||||
if (!permissionCode.isEmpty()) {
|
||||
hasPermission = permissionService.hasPermission(userId, permissionCode);
|
||||
}
|
||||
|
||||
if (hasPermission && requireUserType >= 0) {
|
||||
hasPermission = permissionService.hasPermissionByType(userDO.getType(), requireUserType);
|
||||
}
|
||||
|
||||
if (!hasPermission) {
|
||||
return Result.error(403, "权限不足");
|
||||
}
|
||||
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.PermissionDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
||||
import com.xiaowang.yuminailcore.service.PermissionService;
|
||||
import com.xiaowang.yuminailcore.vo.PermissionVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统权限表 Controller
|
||||
* 对应数据库表 t_permission
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/permission")
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionController {
|
||||
|
||||
private final PermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 创建权限
|
||||
*
|
||||
* @param permissionDTO 权限DTO
|
||||
* @return 权限ID
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
public Result<Long> createPermission(@RequestBody PermissionDTO permissionDTO) {
|
||||
Long id = permissionService.createPermission(permissionDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @param permissionDTO 权限DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
public Result<Boolean> updatePermission(@PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
|
||||
boolean success = permissionService.updatePermission(id, permissionDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除权限
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result<Boolean> deletePermission(@PathVariable Long id) {
|
||||
boolean success = permissionService.deletePermission(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询权限
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @return 权限VO
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
public Result<PermissionVO> getPermissionById(@PathVariable Long id) {
|
||||
PermissionVO permissionVO = permissionService.getPermissionById(id);
|
||||
return Result.success(permissionVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有权限
|
||||
*
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
public Result<List<PermissionVO>> listAllPermissions() {
|
||||
List<PermissionVO> permissionVOs = permissionService.listAllPermissions();
|
||||
return Result.success(permissionVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限分组查询权限
|
||||
*
|
||||
* @param permissionGroup 权限分组
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
@GetMapping("/list/group/{permissionGroup}")
|
||||
public Result<List<PermissionVO>> listPermissionsByGroup(@PathVariable String permissionGroup) {
|
||||
List<PermissionVO> permissionVOs = permissionService.listPermissionsByGroup(permissionGroup);
|
||||
return Result.success(permissionVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户的权限列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
@GetMapping("/list/user/{userId}")
|
||||
public Result<List<PermissionVO>> listUserPermissions(@PathVariable Long userId) {
|
||||
List<PermissionVO> permissionVOs = permissionService.listUserPermissions(userId);
|
||||
return Result.success(permissionVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配权限给用户
|
||||
*
|
||||
* @param userPermissionDTO 用户权限分配DTO
|
||||
* @return 是否分配成功
|
||||
*/
|
||||
@PostMapping("/assign")
|
||||
public Result<Boolean> assignPermissions(HttpServletRequest request, @RequestBody UserPermissionDTO userPermissionDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
boolean success = permissionService.assignPermissions(userPermissionDTO, userId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的权限列表
|
||||
*
|
||||
* @return 权限列表
|
||||
*/
|
||||
@GetMapping("/list/user/current")
|
||||
public Result<List<PermissionVO>> getCurrentUserPermissions(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
List<PermissionVO> permissions = permissionService.listUserPermissions(userId);
|
||||
return Result.success(permissions);
|
||||
}
|
||||
}
|
||||
+5
-50
@@ -1,21 +1,15 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||
import com.xiaowang.yuminailcore.service.ProductService;
|
||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品信息表 Controller
|
||||
* 对应数据库表 t_product
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/product")
|
||||
@RequiredArgsConstructor
|
||||
@@ -23,84 +17,45 @@ public class ProductController {
|
||||
|
||||
private final ProductService productService;
|
||||
|
||||
/**
|
||||
* 创建商品
|
||||
*
|
||||
* @param productDTO 商品DTO
|
||||
* @return 商品ID
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("product:create")
|
||||
public Result<Long> createProduct(@RequestBody ProductDTO productDTO) {
|
||||
Long id = productService.createProduct(productDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品
|
||||
*
|
||||
* @param id 商品ID
|
||||
* @param productDTO 商品DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("product:update")
|
||||
public Result<Boolean> updateProduct(@PathVariable Long id, @RequestBody ProductDTO productDTO) {
|
||||
boolean success = productService.updateProduct(id, productDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*
|
||||
* @param id 商品ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("product:delete")
|
||||
public Result<Boolean> deleteProduct(@PathVariable Long id) {
|
||||
boolean success = productService.deleteProduct(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询商品
|
||||
*
|
||||
* @param id 商品ID
|
||||
* @return 商品VO
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
public Result<ProductVO> getProductById(@PathVariable Long id) {
|
||||
ProductVO productVO = productService.getProductById(id);
|
||||
return Result.success(productVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有商品
|
||||
*
|
||||
* @return 商品VO列表
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
public Result<List<ProductVO>> listAllProducts() {
|
||||
List<ProductVO> productVOs = productService.listAllProducts();
|
||||
return Result.success(productVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据店铺ID查询商品
|
||||
*
|
||||
* @param shopId 店铺ID
|
||||
* @return 商品VO列表
|
||||
*/
|
||||
@GetMapping("/list/shop/{shopId}")
|
||||
public Result<List<ProductVO>> listProductsByShopId(@PathVariable Long shopId) {
|
||||
List<ProductVO> productVOs = productService.listProductsByShopId(shopId);
|
||||
return Result.success(productVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签查询商品
|
||||
*
|
||||
* @param tag 标签
|
||||
* @return 商品VO列表
|
||||
*/
|
||||
@GetMapping("/list/tag/{tag}")
|
||||
public Result<List<ProductVO>> listProductsByTag(@PathVariable String tag) {
|
||||
List<ProductVO> productVOs = productService.listProductsByTag(tag);
|
||||
|
||||
+5
-48
@@ -1,5 +1,6 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.ShopDTO;
|
||||
import com.xiaowang.yuminailcore.service.ShopService;
|
||||
@@ -11,13 +12,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 店铺信息表 Controller
|
||||
* 对应数据库表 t_shop
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/shop")
|
||||
@RequiredArgsConstructor
|
||||
@@ -25,83 +19,46 @@ public class ShopController {
|
||||
|
||||
private final ShopService shopService;
|
||||
|
||||
/**
|
||||
* 创建店铺
|
||||
*
|
||||
* @param shopDTO 店铺DTO
|
||||
* @return 店铺ID
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("shop:create")
|
||||
public Result<Long> createShop(@RequestBody ShopDTO shopDTO) {
|
||||
Long id = shopService.createShop(shopDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新店铺
|
||||
*
|
||||
* @param id 店铺ID
|
||||
* @param shopDTO 店铺DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("shop:update")
|
||||
public Result<Boolean> updateShop(@PathVariable Long id, @RequestBody ShopDTO shopDTO) {
|
||||
boolean success = shopService.updateShop(id, shopDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除店铺
|
||||
*
|
||||
* @param id 店铺ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("shop:delete")
|
||||
public Result<Boolean> deleteShop(@PathVariable Long id) {
|
||||
boolean success = shopService.deleteShop(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询店铺
|
||||
*
|
||||
* @param id 店铺ID
|
||||
* @return 店铺VO
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
public Result<ShopVO> getShopById(@PathVariable Long id) {
|
||||
ShopVO shopVO = shopService.getShopById(id);
|
||||
return Result.success(shopVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有店铺
|
||||
*
|
||||
* @return 店铺VO列表
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("shop:view")
|
||||
public Result<List<ShopVO>> listAllShops() {
|
||||
List<ShopVO> shopVOs = shopService.listAllShops();
|
||||
return Result.success(shopVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据店铺名称查询店铺
|
||||
*
|
||||
* @param shopName 店铺名称
|
||||
* @return 店铺VO列表
|
||||
*/
|
||||
@GetMapping("/list/shopName/{shopName}")
|
||||
public Result<List<ShopVO>> listShopsByShopName(@PathVariable String shopName) {
|
||||
List<ShopVO> shopVOs = shopService.listShopsByShopName(shopName);
|
||||
return Result.success(shopVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有店铺(仅ID和名称,用于注册页面)
|
||||
*
|
||||
* @return 店铺简单信息列表
|
||||
*/
|
||||
@GetMapping("/list/simple")
|
||||
public Result<List<ShopSimpleVO>> listShopsSimple() {
|
||||
List<ShopVO> shopVOs = shopService.listAllShops();
|
||||
|
||||
@@ -239,4 +239,17 @@ public class UserController {
|
||||
String avatarUrl = "https://api.dicebear.com/7.x/avataaars/svg?seed=" + fileName;
|
||||
return Result.success(avatarUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置用户密码为88888888
|
||||
*
|
||||
* @param userId 目标用户ID
|
||||
* @return 是否重置成功
|
||||
*/
|
||||
@PostMapping("/reset-password/{userId}")
|
||||
public Result<Boolean> resetPassword(HttpServletRequest request, @PathVariable Long userId) {
|
||||
Long currentUserId = (Long) request.getAttribute("userId");
|
||||
boolean success = userService.resetPassword(userId, currentUserId);
|
||||
return Result.success(success);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 系统权限表 DTO
|
||||
* 用于权限信息的传输
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@Data
|
||||
public class PermissionDTO {
|
||||
|
||||
/**
|
||||
* 权限编码(唯一标识)
|
||||
*/
|
||||
private String permissionCode;
|
||||
|
||||
/**
|
||||
* 权限名称
|
||||
*/
|
||||
private String permissionName;
|
||||
|
||||
/**
|
||||
* 权限分组(商品管理、用户管理等)
|
||||
*/
|
||||
private String permissionGroup;
|
||||
|
||||
/**
|
||||
* 权限描述
|
||||
*/
|
||||
private String description;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户权限分配 DTO
|
||||
* 用于给用户分配权限
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@Data
|
||||
public class UserPermissionDTO {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 权限ID列表
|
||||
*/
|
||||
private List<Long> permissionIds;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 系统权限表 DO
|
||||
* 对应数据库表 t_permission
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_permission")
|
||||
public class PermissionDO extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 权限编码(唯一标识)
|
||||
*/
|
||||
@TableField("permission_code")
|
||||
private String permissionCode;
|
||||
|
||||
/**
|
||||
* 权限名称
|
||||
*/
|
||||
@TableField("permission_name")
|
||||
private String permissionName;
|
||||
|
||||
/**
|
||||
* 权限分组(商品管理、用户管理等)
|
||||
*/
|
||||
@TableField("permission_group")
|
||||
private String permissionGroup;
|
||||
|
||||
/**
|
||||
* 权限描述
|
||||
*/
|
||||
@TableField("description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 逻辑删除:0-未删,1-已删
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 用户权限关联表 DO
|
||||
* 对应数据库表 t_user_permission
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_user_permission")
|
||||
public class UserPermissionDO extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
*/
|
||||
@TableField("permission_id")
|
||||
private Long permissionId;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.PermissionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 系统权限表 Mapper
|
||||
* 对应数据库表 t_permission
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@Mapper
|
||||
public interface PermissionMapper extends BaseMapper<PermissionDO> {
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.UserPermissionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户权限关联表 Mapper
|
||||
* 对应数据库表 t_user_permission
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserPermissionMapper extends BaseMapper<UserPermissionDO> {
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.xiaowang.yuminailcore.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xiaowang.yuminailcore.dto.PermissionDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
||||
import com.xiaowang.yuminailcore.entity.PermissionDO;
|
||||
import com.xiaowang.yuminailcore.vo.PermissionVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统权限表 Service
|
||||
* 对应数据库表 t_permission
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
public interface PermissionService extends IService<PermissionDO> {
|
||||
|
||||
/**
|
||||
* 创建权限
|
||||
*
|
||||
* @param permissionDTO 权限DTO
|
||||
* @return 权限ID
|
||||
*/
|
||||
Long createPermission(PermissionDTO permissionDTO);
|
||||
|
||||
/**
|
||||
* 更新权限
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @param permissionDTO 权限DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
boolean updatePermission(Long id, PermissionDTO permissionDTO);
|
||||
|
||||
/**
|
||||
* 删除权限
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean deletePermission(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID查询权限
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @return 权限VO
|
||||
*/
|
||||
PermissionVO getPermissionById(Long id);
|
||||
|
||||
/**
|
||||
* 查询所有权限
|
||||
*
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
List<PermissionVO> listAllPermissions();
|
||||
|
||||
/**
|
||||
* 根据权限分组查询权限
|
||||
*
|
||||
* @param permissionGroup 权限分组
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
List<PermissionVO> listPermissionsByGroup(String permissionGroup);
|
||||
|
||||
/**
|
||||
* 查询用户的权限列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
List<PermissionVO> listUserPermissions(Long userId);
|
||||
|
||||
/**
|
||||
* 给用户分配权限
|
||||
*
|
||||
* @param userPermissionDTO 用户权限分配DTO
|
||||
* @param currentUserId 当前操作人ID
|
||||
* @return 是否分配成功
|
||||
*/
|
||||
boolean assignPermissions(UserPermissionDTO userPermissionDTO, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 检查用户是否有指定权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param permissionCode 权限编码
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasPermission(Long userId, String permissionCode);
|
||||
|
||||
/**
|
||||
* 根据用户类型判断是否有权限(基于用户级别)
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param requireType 需要的最低用户类型
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasPermissionByType(Integer userType, Integer requireType);
|
||||
}
|
||||
@@ -1,143 +1,48 @@
|
||||
package com.xiaowang.yuminailcore.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.dto.BindEmailRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindEmailRequestDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户信息表 Service
|
||||
* 对应数据库表 t_user
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
public interface UserService extends IService<UserDO> {
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*
|
||||
* @param userDTO 用户DTO
|
||||
* @return 用户ID
|
||||
*/
|
||||
Long createUser(UserDTO userDTO);
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @param userDTO 用户DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
boolean updateUser(Long id, UserDTO userDTO);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean deleteUser(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID查询用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return 用户VO
|
||||
*/
|
||||
UserVO getUserById(Long id);
|
||||
|
||||
/**
|
||||
* 查询所有用户
|
||||
*
|
||||
* @return 用户VO列表
|
||||
*/
|
||||
List<UserVO> listAllUsers();
|
||||
|
||||
/**
|
||||
* 根据店铺ID查询用户
|
||||
*
|
||||
* @param shopId 店铺ID
|
||||
* @return 用户VO列表
|
||||
*/
|
||||
List<UserVO> listUsersByShopId(Long shopId);
|
||||
|
||||
/**
|
||||
* 根据用户类型查询用户
|
||||
*
|
||||
* @param type 用户类型
|
||||
* @return 用户VO列表
|
||||
*/
|
||||
List<UserVO> listUsersByType(Integer type);
|
||||
|
||||
/**
|
||||
* 根据账号查询用户
|
||||
*
|
||||
* @param account 账号
|
||||
* @return 用户VO
|
||||
*/
|
||||
UserVO getUserByAccount(String account);
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @param loginRequestDTO 登录请求DTO
|
||||
* @return 登录响应VO
|
||||
*/
|
||||
LoginResponseVO login(LoginRequestDTO loginRequestDTO);
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param registerRequestDTO 注册请求DTO
|
||||
* @return 是否注册成功
|
||||
*/
|
||||
boolean register(RegisterRequestDTO registerRequestDTO);
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
*
|
||||
* @param refreshToken 刷新Token
|
||||
* @return 新的Token
|
||||
*/
|
||||
LoginResponseVO refreshToken(String refreshToken);
|
||||
|
||||
/**
|
||||
* 用户登出
|
||||
*
|
||||
* @return 是否登出成功
|
||||
*/
|
||||
boolean logout();
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
*
|
||||
* @return 用户VO
|
||||
*/
|
||||
UserVO getCurrentUserInfo();
|
||||
|
||||
/**
|
||||
* 绑定手机号
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param bindPhoneRequestDTO 绑定手机号请求DTO
|
||||
* @return 是否绑定成功
|
||||
*/
|
||||
boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO);
|
||||
|
||||
/**
|
||||
* 绑定邮箱
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param bindEmailRequestDTO 绑定邮箱请求DTO
|
||||
* @return 是否绑定成功
|
||||
*/
|
||||
boolean bindEmail(Long userId, BindEmailRequestDTO bindEmailRequestDTO);
|
||||
|
||||
boolean resetPassword(Long targetUserId, Long currentUserId);
|
||||
}
|
||||
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.dto.PermissionDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
||||
import com.xiaowang.yuminailcore.entity.PermissionDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserPermissionDO;
|
||||
import com.xiaowang.yuminailcore.mapper.PermissionMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserPermissionMapper;
|
||||
import com.xiaowang.yuminailcore.service.PermissionService;
|
||||
import com.xiaowang.yuminailcore.vo.PermissionVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统权限表 Service 实现
|
||||
* 对应数据库表 t_permission
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionDO> implements PermissionService {
|
||||
|
||||
private final PermissionMapper permissionMapper;
|
||||
private final UserPermissionMapper userPermissionMapper;
|
||||
|
||||
@Override
|
||||
public Long createPermission(PermissionDTO permissionDTO) {
|
||||
PermissionDO permissionDO = new PermissionDO();
|
||||
permissionDO.setPermissionCode(permissionDTO.getPermissionCode());
|
||||
permissionDO.setPermissionName(permissionDTO.getPermissionName());
|
||||
permissionDO.setPermissionGroup(permissionDTO.getPermissionGroup());
|
||||
permissionDO.setDescription(permissionDTO.getDescription());
|
||||
permissionDO.setIsDelete(0);
|
||||
permissionMapper.insert(permissionDO);
|
||||
return permissionDO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePermission(Long id, PermissionDTO permissionDTO) {
|
||||
PermissionDO permissionDO = permissionMapper.selectById(id);
|
||||
if (permissionDO == null) {
|
||||
return false;
|
||||
}
|
||||
if (permissionDTO.getPermissionCode() != null) {
|
||||
permissionDO.setPermissionCode(permissionDTO.getPermissionCode());
|
||||
}
|
||||
if (permissionDTO.getPermissionName() != null) {
|
||||
permissionDO.setPermissionName(permissionDTO.getPermissionName());
|
||||
}
|
||||
if (permissionDTO.getPermissionGroup() != null) {
|
||||
permissionDO.setPermissionGroup(permissionDTO.getPermissionGroup());
|
||||
}
|
||||
if (permissionDTO.getDescription() != null) {
|
||||
permissionDO.setDescription(permissionDTO.getDescription());
|
||||
}
|
||||
permissionDO.setUpdateTime(LocalDateTime.now());
|
||||
return permissionMapper.updateById(permissionDO) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePermission(Long id) {
|
||||
PermissionDO permissionDO = permissionMapper.selectById(id);
|
||||
if (permissionDO == null) {
|
||||
return false;
|
||||
}
|
||||
permissionDO.setIsDelete(1);
|
||||
return permissionMapper.updateById(permissionDO) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionVO getPermissionById(Long id) {
|
||||
PermissionDO permissionDO = permissionMapper.selectById(id);
|
||||
if (permissionDO == null) {
|
||||
return null;
|
||||
}
|
||||
return convertToVO(permissionDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermissionVO> listAllPermissions() {
|
||||
List<PermissionDO> permissionDOs = permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
);
|
||||
return permissionDOs.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermissionVO> listPermissionsByGroup(String permissionGroup) {
|
||||
List<PermissionDO> permissionDOs = permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getPermissionGroup, permissionGroup)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
);
|
||||
return permissionDOs.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermissionVO> listUserPermissions(Long userId) {
|
||||
List<UserPermissionDO> userPermissions = userPermissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(UserPermissionDO.class)
|
||||
.eq(UserPermissionDO::getUserId, userId)
|
||||
);
|
||||
|
||||
if (userPermissions.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<Long> permissionIds = userPermissions.stream()
|
||||
.map(UserPermissionDO::getPermissionId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<PermissionDO> permissionDOs = permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.in(PermissionDO::getId, permissionIds)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
);
|
||||
|
||||
return permissionDOs.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean assignPermissions(UserPermissionDTO userPermissionDTO, Long currentUserId) {
|
||||
Long userId = userPermissionDTO.getUserId();
|
||||
List<Long> permissionIds = userPermissionDTO.getPermissionIds();
|
||||
|
||||
userPermissionMapper.delete(
|
||||
Wrappers.lambdaQuery(UserPermissionDO.class)
|
||||
.eq(UserPermissionDO::getUserId, userId)
|
||||
);
|
||||
|
||||
if (permissionIds != null && !permissionIds.isEmpty()) {
|
||||
for (Long permissionId : permissionIds) {
|
||||
UserPermissionDO userPermissionDO = new UserPermissionDO();
|
||||
userPermissionDO.setUserId(userId);
|
||||
userPermissionDO.setPermissionId(permissionId);
|
||||
userPermissionDO.setCreateBy(currentUserId);
|
||||
userPermissionMapper.insert(userPermissionDO);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Long userId, String permissionCode) {
|
||||
List<UserPermissionDO> userPermissions = userPermissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(UserPermissionDO.class)
|
||||
.eq(UserPermissionDO::getUserId, userId)
|
||||
);
|
||||
|
||||
if (userPermissions.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Long> permissionIds = userPermissions.stream()
|
||||
.map(UserPermissionDO::getPermissionId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PermissionDO permissionDO = permissionMapper.selectOne(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getPermissionCode, permissionCode)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
);
|
||||
|
||||
if (permissionDO == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return permissionIds.contains(permissionDO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermissionByType(Integer userType, Integer requireType) {
|
||||
if (userType == null || requireType == null) {
|
||||
return false;
|
||||
}
|
||||
return userType >= requireType;
|
||||
}
|
||||
|
||||
private PermissionVO convertToVO(PermissionDO permissionDO) {
|
||||
PermissionVO permissionVO = new PermissionVO();
|
||||
permissionVO.setId(permissionDO.getId());
|
||||
permissionVO.setPermissionCode(permissionDO.getPermissionCode());
|
||||
permissionVO.setPermissionName(permissionDO.getPermissionName());
|
||||
permissionVO.setPermissionGroup(permissionDO.getPermissionGroup());
|
||||
permissionVO.setDescription(permissionDO.getDescription());
|
||||
permissionVO.setCreateTime(permissionDO.getCreateTime());
|
||||
permissionVO.setUpdateTime(permissionDO.getUpdateTime());
|
||||
return permissionVO;
|
||||
}
|
||||
}
|
||||
+29
@@ -316,4 +316,33 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resetPassword(Long targetUserId, Long currentUserId) {
|
||||
UserDO targetUser = userMapper.selectById(targetUserId);
|
||||
if (targetUser == null) {
|
||||
throw new RuntimeException("目标用户不存在");
|
||||
}
|
||||
|
||||
UserDO currentUser = userMapper.selectById(currentUserId);
|
||||
if (currentUser == null) {
|
||||
throw new RuntimeException("当前用户不存在");
|
||||
}
|
||||
|
||||
Integer currentUserType = currentUser.getType();
|
||||
Integer targetUserType = targetUser.getType();
|
||||
|
||||
if (currentUserType == null || targetUserType == null) {
|
||||
throw new RuntimeException("用户类型错误");
|
||||
}
|
||||
|
||||
if (currentUserType <= targetUserType) {
|
||||
throw new RuntimeException("权限不足,只能重置比自己级别低的用户密码");
|
||||
}
|
||||
|
||||
targetUser.setPassword("88888888");
|
||||
targetUser.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
return userMapper.updateById(targetUser) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 系统权限表 VO
|
||||
* 用于前端展示权限信息
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@Data
|
||||
public class PermissionVO {
|
||||
|
||||
/**
|
||||
* 权限唯一主键ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 权限编码(唯一标识)
|
||||
*/
|
||||
private String permissionCode;
|
||||
|
||||
/**
|
||||
* 权限名称
|
||||
*/
|
||||
private String permissionName;
|
||||
|
||||
/**
|
||||
* 权限分组(商品管理、用户管理等)
|
||||
*/
|
||||
private String permissionGroup;
|
||||
|
||||
/**
|
||||
* 权限描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -65,6 +65,7 @@ CREATE TABLE `t_user` (
|
||||
`nickname` VARCHAR(50) NOT NULL COMMENT '用户昵称',
|
||||
`account` VARCHAR(50) NOT NULL COMMENT '用户账号(登录用)',
|
||||
`password` VARCHAR(100) NOT NULL COMMENT '用户密码(加密存储)',
|
||||
`avatar` VARCHAR(512) NOT NULL COMMENT '头像',
|
||||
`signature` VARCHAR(200) DEFAULT '' COMMENT '用户签名',
|
||||
`level` VARCHAR(20) DEFAULT '普通' COMMENT '用户等级',
|
||||
`type` tinyint NOT NULL COMMENT '用户类型,(0-用户,2-店长,3-美甲师,4-管理员)',
|
||||
@@ -195,4 +196,47 @@ CREATE TABLE `t_comment` (
|
||||
INDEX `idx_shop_id` (`shop_id`) COMMENT '按店铺查询评论的索引',
|
||||
INDEX `idx_product_id` (`product_id`) COMMENT '按商品查询评论的索引',
|
||||
INDEX `idx_parent_comment_id` (`parent_comment_id`) COMMENT '按父级评论查询回复的索引'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户评论信息表';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户评论信息表';
|
||||
|
||||
|
||||
|
||||
-- 创建权限表
|
||||
CREATE TABLE IF NOT EXISTS t_permission (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT COMMENT '权限唯一主键ID' PRIMARY KEY,
|
||||
permission_code VARCHAR(100) NOT NULL COMMENT '权限编码(唯一标识)',
|
||||
permission_name VARCHAR(100) NOT NULL COMMENT '权限名称',
|
||||
permission_group VARCHAR(50) NOT NULL COMMENT '权限分组(商品管理、用户管理等)',
|
||||
description VARCHAR(255) NULL COMMENT '权限描述',
|
||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间',
|
||||
update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
is_delete TINYINT UNSIGNED DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删',
|
||||
CONSTRAINT uk_permission_code UNIQUE (permission_code) COMMENT '权限编码唯一索引'
|
||||
) COMMENT '系统权限表';
|
||||
|
||||
-- 创建用户权限关联表
|
||||
CREATE TABLE IF NOT EXISTS t_user_permission (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT COMMENT '关联ID' PRIMARY KEY,
|
||||
user_id BIGINT UNSIGNED NOT NULL COMMENT '用户ID',
|
||||
permission_id BIGINT UNSIGNED NOT NULL COMMENT '权限ID',
|
||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间',
|
||||
create_by BIGINT UNSIGNED NULL COMMENT '创建人ID',
|
||||
CONSTRAINT uk_user_permission UNIQUE (user_id, permission_id) COMMENT '用户-权限唯一索引',
|
||||
INDEX idx_user_id (user_id) COMMENT '用户ID索引',
|
||||
INDEX idx_permission_id (permission_id) COMMENT '权限ID索引'
|
||||
) COMMENT '用户权限关联表';
|
||||
|
||||
-- 插入默认权限数据
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description) VALUES
|
||||
-- 商品管理权限
|
||||
('product:view', '查看商品', '商品管理', '查看商品列表和详情'),
|
||||
('product:create', '新增商品', '商品管理', '新增商品'),
|
||||
('product:update', '编辑商品', '商品管理', '编辑商品信息'),
|
||||
('product:delete', '删除商品', '商品管理', '删除商品'),
|
||||
-- 用户管理权限
|
||||
('user:view', '查看用户', '用户管理', '查看用户列表和详情'),
|
||||
('user:create', '新增用户', '用户管理', '新增用户'),
|
||||
('user:disable', '停用用户', '用户管理', '停用/启用用户'),
|
||||
('user:reset_password', '重置密码', '用户管理', '重置用户密码'),
|
||||
-- 权限管理权限
|
||||
('permission:view', '查看权限', '权限管理', '查看权限列表'),
|
||||
('permission:assign', '分配权限', '权限管理', '给用户分配权限');
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
-- 为用户表添加手机号和邮箱字段
|
||||
ALTER TABLE `t_user`
|
||||
ADD COLUMN `phone` VARCHAR(20) DEFAULT NULL COMMENT '手机号' AFTER `account`,
|
||||
ADD COLUMN `email` VARCHAR(100) DEFAULT NULL COMMENT '邮箱' AFTER `phone`,
|
||||
ADD COLUMN `phone_verified` TINYINT UNSIGNED DEFAULT 0 COMMENT '手机号是否已验证:0-未验证,1-已验证' AFTER `email`,
|
||||
ADD COLUMN `email_verified` TINYINT UNSIGNED DEFAULT 0 COMMENT '邮箱是否已验证:0-未验证,1-已验证' AFTER `phone_verified`;
|
||||
|
||||
-- 添加索引
|
||||
ALTER TABLE `t_user`
|
||||
ADD INDEX `idx_phone` (`phone`) COMMENT '按手机号查询的索引',
|
||||
ADD INDEX `idx_email` (`email`) COMMENT '按邮箱查询的索引';
|
||||
@@ -1,55 +0,0 @@
|
||||
-- 1. 创建标签表
|
||||
CREATE TABLE IF NOT EXISTS `t_tag` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`tag_name` varchar(50) NOT NULL COMMENT '标签名称',
|
||||
`text_color` varchar(20) NOT NULL DEFAULT '#FFFFFF' COMMENT '标签文字颜色(16进制)',
|
||||
`bg_color` varchar(20) NOT NULL DEFAULT '#1890FF' COMMENT '标签背景颜色(16进制)',
|
||||
`border_color` varchar(20) NOT NULL DEFAULT '#1890FF' COMMENT '标签边框颜色(16进制)',
|
||||
`is_delete` int NOT NULL DEFAULT '0' COMMENT '逻辑删除:0-未删,1-已删',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='系统标签信息表';
|
||||
|
||||
-- 2. 插入标签数据
|
||||
INSERT INTO `t_tag` (`id`, `tag_name`, `text_color`, `bg_color`, `border_color`) VALUES
|
||||
(0, '精选', '#FFFFFF', '#FF4D4F', '#FF4D4F'),
|
||||
(1, '热门', '#FFFFFF', '#FAAD14', '#FAAD14'),
|
||||
(2, '美甲', '#FFFFFF', '#1890FF', '#1890FF'),
|
||||
(3, '美睫', '#FFFFFF', '#52C41A', '#52C41A'),
|
||||
(4, '手足护理', '#FFFFFF', '#722ED1', '#722ED1'),
|
||||
(5, '纹绣', '#FFFFFF', '#EB2F96', '#EB2F96'),
|
||||
(6, '基础', '#333333', '#F0F0F0', '#F0F0F0'),
|
||||
(7, '法式', '#333333', '#E6F7FF', '#91D5FF'),
|
||||
(8, '光疗', '#333333', '#F6FFED', '#B7EB8F'),
|
||||
(9, '手绘', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(10, '钻饰', '#333333', '#FFF0F5', '#FFB3C6'),
|
||||
(11, '脚部', '#333333', '#F9F0FF', '#D3ADF7'),
|
||||
(12, '新娘', '#333333', '#E8F5FF', '#91D5FF'),
|
||||
(13, '儿童', '#333333', '#E6FFFB', '#67C23A'),
|
||||
(14, '定制', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(15, '持久', '#333333', '#F6FFED', '#B7EB8F');
|
||||
|
||||
-- 3. 修改产品表的标签字段(如果需要)
|
||||
-- 注意:如果已经存在 t_product 表,需要执行以下修改
|
||||
ALTER TABLE `t_product` MODIFY COLUMN `tags` varchar(255) COMMENT '标签ID集合,多个ID以分号分隔';
|
||||
|
||||
-- 4. 更新测试商品的标签为标签ID
|
||||
-- 请将下面的 shop_id 替换为实际的店铺ID
|
||||
INSERT INTO `t_product` (`shop_id`, `title`, `description`, `price`, `tags`, `like_count`, `collect_count`, `approximate_duration`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
(1, '基础美甲套餐', '包含基础修甲、抛光、上色', 88.00, '2;6', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '法式美甲', '经典法式美甲,优雅大方', 128.00, '2;7', 0, 0, '45分钟', 0, NOW(), NOW()),
|
||||
(1, '光疗甲', '持久光疗甲,不易脱落', 168.00, '2;8;15', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '手绘美甲', '创意手绘图案,个性定制', 198.00, '2;9;14', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '钻饰美甲', '镶嵌钻饰,闪亮夺目', 228.00, '2;10', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '脚部美甲', '脚部护理+美甲', 158.00, '2;11', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '新娘美甲', '婚礼专用美甲套餐', 298.00, '0;2;12;14', 0, 0, '120分钟', 0, NOW(), NOW()),
|
||||
(1, '儿童美甲', '无毒无害,专为儿童设计', 68.00, '2;13', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '美睫套餐', '自然浓密美睫', 198.00, '1;3', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '手足护理套餐', '深层护理,滋润保湿', 168.00, '4', 0, 0, '120分钟', 0, NOW(), NOW());
|
||||
|
||||
-- 5. 查看标签数据
|
||||
SELECT * FROM `t_tag` ORDER BY `id`;
|
||||
|
||||
-- 6. 查看商品数据
|
||||
SELECT `id`, `shop_id`, `title`, `price`, `tags` FROM `t_product` WHERE `is_delete` = 0;
|
||||
@@ -1,24 +0,0 @@
|
||||
# 数据库连接配置
|
||||
sspring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/yumi_nail?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
# 连接池配置
|
||||
druid:
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
max-wait: 60000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
filters: stat,wall
|
||||
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
@@ -1,51 +0,0 @@
|
||||
-- 插入标签数据
|
||||
INSERT INTO `t_tag` (`id`, `tag_name`, `text_color`, `bg_color`, `border_color`) VALUES
|
||||
(0, '精选', '#FFFFFF', '#FF4D4F', '#FF4D4F'),
|
||||
(1, '热门', '#FFFFFF', '#FAAD14', '#FAAD14'),
|
||||
(2, '美甲', '#333333', '#E6F7FF', '#91D5FF'),
|
||||
(3, '美睫', '#333333', '#F6FFED', '#B7EB8F'),
|
||||
(4, '手足护理', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(5, '纹绣', '#333333', '#FFF0F5', '#FFB3C6'),
|
||||
(6, '基础', '#333333', '#F0F0F0', '#F0F0F0'),
|
||||
(7, '法式', '#333333', '#F9F0FF', '#D3ADF7'),
|
||||
(8, '光疗', '#333333', '#E6FFFB', '#67C23A'),
|
||||
(9, '手绘', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(10, '钻饰', '#333333', '#FFF0F5', '#FFB3C6'),
|
||||
(11, '脚部', '#333333', '#E8F5FF', '#91D5FF'),
|
||||
(12, '新娘', '#333333', '#F0F5FF', '#91D5FF'),
|
||||
(13, '儿童', '#333333', '#F6FFED', '#B7EB8F'),
|
||||
(14, '定制', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(15, '持久', '#333333', '#F6FFED', '#B7EB8F'),
|
||||
(16, '快速', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(17, '优惠', '#FFFFFF', '#52C41A', '#52C41A'),
|
||||
(18, '新品', '#FFFFFF', '#1890FF', '#1890FF');
|
||||
|
||||
-- 更新商品标签为标签ID(假设商品表已存在)
|
||||
-- 请将下面的 shop_id 替换为实际的店铺ID
|
||||
INSERT INTO `t_product` (`shop_id`, `title`, `description`, `price`, `tags`, `like_count`, `collect_count`, `approximate_duration`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
(1, '基础美甲套餐', '包含基础修甲、抛光、上色', 88.00, '2;6', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '法式美甲', '经典法式美甲,优雅大方', 128.00, '2;7', 0, 0, '45分钟', 0, NOW(), NOW()),
|
||||
(1, '光疗甲', '持久光疗甲,不易脱落', 168.00, '2;8;15', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '手绘美甲', '创意手绘图案,个性定制', 198.00, '2;9;14', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '钻饰美甲', '镶嵌钻饰,闪亮夺目', 228.00, '0;2;10', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '脚部美甲', '脚部护理+美甲', 158.00, '2;11', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '新娘美甲', '婚礼专用美甲套餐', 298.00, '0;2;12;14', 0, 0, '120分钟', 0, NOW(), NOW()),
|
||||
(1, '儿童美甲', '无毒无害,专为儿童设计', 68.00, '2;13', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '美睫套餐', '自然浓密美睫', 198.00, '1;3', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '手足护理套餐', '深层护理,滋润保湿', 168.00, '1;4', 0, 0, '120分钟', 0, NOW(), NOW());
|
||||
|
||||
-- 查看标签数据
|
||||
SELECT * FROM `t_tag` ORDER BY `id`;
|
||||
|
||||
-- 查看商品数据
|
||||
SELECT `id`, `shop_id`, `title`, `price`, `tags` FROM `t_product` WHERE `is_delete` = 0;
|
||||
|
||||
-- 查看精选商品(包含标签0)
|
||||
SELECT p.`id`, p.`title`, p.`price`, p.`tags`
|
||||
FROM `t_product` p
|
||||
WHERE p.`is_delete` = 0 AND p.`tags` LIKE '%0%';
|
||||
|
||||
-- 查看热门商品(包含标签1)
|
||||
SELECT p.`id`, p.`title`, p.`price`, p.`tags`
|
||||
FROM `t_product` p
|
||||
WHERE p.`is_delete` = 0 AND p.`tags` LIKE '%1%';
|
||||
@@ -1,17 +0,0 @@
|
||||
-- 查询店铺信息
|
||||
SELECT `id`, `shop_name`, `address` FROM `t_shop` WHERE `is_delete` = 0;
|
||||
|
||||
-- 插入测试商品数据(修正版)
|
||||
-- 请将下面的 shop_id 替换为上面查询到的 "美甲工作室 - 中心店" 的 ID
|
||||
INSERT INTO `t_product` (`shop_id`, `title`, `description`, `price`, `tags`, `like_count`, `collect_count`, `approximate_duration`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
(1, '基础美甲套餐', '包含基础修甲、抛光、上色', 88.00, '美甲,基础', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '法式美甲', '经典法式美甲,优雅大方', 128.00, '美甲,法式', 0, 0, '45分钟', 0, NOW(), NOW()),
|
||||
(1, '光疗甲', '持久光疗甲,不易脱落', 168.00, '美甲,光疗', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '手绘美甲', '创意手绘图案,个性定制', 198.00, '美甲,手绘,定制', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '钻饰美甲', '镶嵌钻饰,闪亮夺目', 228.00, '美甲,钻饰', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '脚部美甲', '脚部护理+美甲', 158.00, '美甲,脚部', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '新娘美甲', '婚礼专用美甲套餐', 298.00, '美甲,新娘,定制', 0, 0, '120分钟', 0, NOW(), NOW()),
|
||||
(1, '儿童美甲', '无毒无害,专为儿童设计', 68.00, '美甲,儿童', 0, 0, '30分钟', 0, NOW(), NOW());
|
||||
|
||||
-- 查看插入结果
|
||||
SELECT `id`, `shop_id`, `title`, `price`, `tags` FROM `t_product` WHERE `is_delete` = 0 AND `shop_id` = 1;
|
||||
@@ -1,10 +0,0 @@
|
||||
-- 插入测试店铺数据
|
||||
INSERT INTO `t_shop` (`shop_name`, `address`, `phone`, `business_hours`, `description`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
('美甲工作室 - 中心店', '北京市朝阳区建国路88号', '13812345678', '10:00-21:00', '专业美甲服务,使用进口产品', 0, NOW(), NOW()),
|
||||
('Yumi Nail - 国贸店', '北京市朝阳区国贸CBD', '13987654321', '09:30-20:30', '高端美甲沙龙,提供定制服务', 0, NOW(), NOW()),
|
||||
('指尖艺术 - 三里屯店', '北京市朝阳区三里屯SOHO', '13756789012', '10:00-22:00', '创意美甲,流行款式', 0, NOW(), NOW()),
|
||||
('Pretty Nails - 望京店', '北京市朝阳区望京SOHO', '13623456789', '10:00-21:00', '温馨舒适的美甲环境', 0, NOW(), NOW()),
|
||||
('指甲花 - 西单店', '北京市西城区西单商业街', '13587654321', '10:00-21:30', '实惠价格,优质服务', 0, NOW(), NOW());
|
||||
|
||||
-- 查看插入结果
|
||||
SELECT `id`, `shop_name`, `address`, `phone` FROM `t_shop` WHERE `is_delete` = 0;
|
||||
@@ -1,10 +0,0 @@
|
||||
-- 插入测试店铺数据(修正版)
|
||||
INSERT INTO `t_shop` (`shop_name`, `address`, `business_hours`, `description`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
('美甲工作室 - 中心店', '北京市朝阳区建国路88号', '10:00-21:00', '专业美甲服务,使用进口产品', 0, NOW(), NOW()),
|
||||
('Yumi Nail - 国贸店', '北京市朝阳区国贸CBD', '09:30-20:30', '高端美甲沙龙,提供定制服务', 0, NOW(), NOW()),
|
||||
('指尖艺术 - 三里屯店', '北京市朝阳区三里屯SOHO', '10:00-22:00', '创意美甲,流行款式', 0, NOW(), NOW()),
|
||||
('Pretty Nails - 望京店', '北京市朝阳区望京SOHO', '10:00-21:00', '温馨舒适的美甲环境', 0, NOW(), NOW()),
|
||||
('指甲花 - 西单店', '北京市西城区西单商业街', '10:00-21:30', '实惠价格,优质服务', 0, NOW(), NOW());
|
||||
|
||||
-- 查看插入结果
|
||||
SELECT `id`, `shop_name`, `address`, `business_hours` FROM `t_shop` WHERE `is_delete` = 0;
|
||||
Reference in New Issue
Block a user