后台管理页面初版
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>
|
||||
Reference in New Issue
Block a user