后台管理功能进行一些优化
This commit is contained in:
@@ -22,7 +22,8 @@ const route = useRoute()
|
||||
|
||||
const isHiddenNav = computed(() => {
|
||||
// 检查当前路由及其所有父路由是否有 hideNav: true
|
||||
const result = route.matched.some(r => r.meta.hideNav)
|
||||
// 或者检查是否是后台页面
|
||||
const result = route.matched.some(r => r.meta.hideNav) || route.matched.some(r => r.meta.isAdmin)
|
||||
console.log('isHiddenNav:', result, 'matched routes:', route.matched)
|
||||
return result
|
||||
})
|
||||
|
||||
+66
-19
@@ -43,23 +43,44 @@ const showError = (msg: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleTokenExpired = () => {
|
||||
const handleTokenExpired = (isAdmin = false) => {
|
||||
// 登录过期,只提示一次
|
||||
if (Date.now() - lastErrorTime > ERROR_DEBOUNCE_TIME || lastErrorMessage !== '登录已过期,请重新登录') {
|
||||
console.log('Token 过期,清理本地存储并跳转到登录页')
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
showError('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/').catch(err => {
|
||||
console.error('跳转到登录页失败:', err)
|
||||
|
||||
if (isAdmin) {
|
||||
// 清理后台管理的token
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
showError('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/admin/login').catch(err => {
|
||||
console.error('跳转到后台登录页失败:', err)
|
||||
window.location.href = '/admin/login'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到后台登录页异常:', err)
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
} else {
|
||||
// 清理前台的token
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
showError('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/').catch(err => {
|
||||
console.error('跳转到登录页失败:', err)
|
||||
window.location.href = '/'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +91,15 @@ api.interceptors.request.use(
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('accessToken')
|
||||
}
|
||||
|
||||
// 检查是否是后台管理的API请求
|
||||
if (!token && (config.url?.includes('/admin/') || config.url?.includes('/order/admin/'))) {
|
||||
token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
}
|
||||
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
@@ -107,6 +137,9 @@ api.interceptors.response.use(
|
||||
}
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
// 检查是否是后台管理的API请求
|
||||
const isAdminRequest = originalRequest.url?.includes('/admin/') || originalRequest.url?.includes('/order/admin/')
|
||||
|
||||
if (!originalRequest._retry && !isWhitelistedPath(originalRequest.url)) {
|
||||
if (isRefreshing) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -125,18 +158,32 @@ api.interceptors.response.use(
|
||||
isRefreshing = true
|
||||
|
||||
try {
|
||||
const refreshToken = localStorage.getItem('refreshToken')
|
||||
let refreshToken
|
||||
if (isAdminRequest) {
|
||||
refreshToken = localStorage.getItem('adminRefreshToken')
|
||||
} else {
|
||||
refreshToken = localStorage.getItem('refreshToken')
|
||||
}
|
||||
|
||||
if (!refreshToken) {
|
||||
throw new Error('No refresh token available')
|
||||
}
|
||||
|
||||
// 这里需要根据是否是后台请求调用不同的refreshToken API
|
||||
// 暂时使用同一个API,实际项目中可能需要分开
|
||||
const response = await authApi.refreshToken({ refreshToken })
|
||||
const newToken = (response as any).accessToken
|
||||
const newRefreshToken = (response as any).refreshToken
|
||||
|
||||
localStorage.setItem('accessToken', newToken)
|
||||
localStorage.setItem('refreshToken', newRefreshToken)
|
||||
sessionStorage.setItem('accessToken', newToken)
|
||||
if (isAdminRequest) {
|
||||
localStorage.setItem('adminAccessToken', newToken)
|
||||
localStorage.setItem('adminRefreshToken', newRefreshToken)
|
||||
sessionStorage.setItem('adminAccessToken', newToken)
|
||||
} else {
|
||||
localStorage.setItem('accessToken', newToken)
|
||||
localStorage.setItem('refreshToken', newRefreshToken)
|
||||
sessionStorage.setItem('accessToken', newToken)
|
||||
}
|
||||
|
||||
processQueue(null, newToken)
|
||||
|
||||
@@ -144,13 +191,13 @@ api.interceptors.response.use(
|
||||
return api(originalRequest)
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null)
|
||||
handleTokenExpired()
|
||||
handleTokenExpired(isAdminRequest)
|
||||
return Promise.reject(refreshError)
|
||||
} finally {
|
||||
isRefreshing = false
|
||||
}
|
||||
} else {
|
||||
handleTokenExpired()
|
||||
handleTokenExpired(isAdminRequest)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
} else if (error.response?.status !== 403) { // 403权限不足不提示
|
||||
|
||||
@@ -2,6 +2,7 @@ import api from './index'
|
||||
|
||||
interface CreateOrderRequest {
|
||||
couponId?: number
|
||||
artistId?: number
|
||||
}
|
||||
|
||||
export const orderApi = {
|
||||
|
||||
Vendored
+1
@@ -24,6 +24,7 @@ declare module 'vue' {
|
||||
ADatePicker: typeof import('ant-design-vue/es')['DatePicker']
|
||||
ADescriptions: typeof import('ant-design-vue/es')['Descriptions']
|
||||
ADescriptionsItem: typeof import('ant-design-vue/es')['DescriptionsItem']
|
||||
ADivider: typeof import('ant-design-vue/es')['Divider']
|
||||
ADropdown: typeof import('ant-design-vue/es')['Dropdown']
|
||||
AEmpty: typeof import('ant-design-vue/es')['Empty']
|
||||
AForm: typeof import('ant-design-vue/es')['Form']
|
||||
|
||||
@@ -45,19 +45,40 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, ref, onMounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { HomeOutlined, ShoppingOutlined, ShoppingCartOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { cartApi } from '../api/cart'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
// 购物车商品数量(示例数据)
|
||||
const cartCount = ref(3)
|
||||
// 购物车商品数量
|
||||
const cartCount = ref(0)
|
||||
|
||||
// 是否有未读通知
|
||||
const hasNotification = ref(true)
|
||||
|
||||
// 加载购物车数量
|
||||
const loadCartCount = async () => {
|
||||
try {
|
||||
const data = await cartApi.getCartList()
|
||||
cartCount.value = data.reduce((sum: number, item: any) => sum + item.quantity, 0)
|
||||
} catch (error) {
|
||||
console.error('获取购物车数量失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时获取购物车数量
|
||||
onMounted(() => {
|
||||
// 检查当前是否是后台页面,如果是则不加载购物车数据
|
||||
const isAdminPage = window.location.pathname.startsWith('/admin')
|
||||
if (!isAdminPage) {
|
||||
loadCartCount()
|
||||
}
|
||||
})
|
||||
|
||||
// 根据当前路由判断激活的导航项
|
||||
const currentRoute = computed(() => {
|
||||
const path = route.path
|
||||
|
||||
@@ -145,14 +145,21 @@ router.beforeEach((to, _from, next) => {
|
||||
|
||||
if (isAdminRoute) {
|
||||
const adminToken = localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken')
|
||||
const adminUserInfoStr = localStorage.getItem('adminUserInfo')
|
||||
|
||||
console.log('Admin route check:', { to: to.path, adminToken: !!adminToken, requiresAuth })
|
||||
console.log('Admin route check:', { to: to.path, adminToken: !!adminToken, adminUserInfo: !!adminUserInfoStr, requiresAuth })
|
||||
|
||||
if (requiresAuth && !adminToken) {
|
||||
console.log('No token, redirecting to login')
|
||||
if (requiresAuth && (!adminToken || !adminUserInfoStr)) {
|
||||
console.log('No token or user info, redirecting to login')
|
||||
// 清除可能存在的过期信息
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
next('/admin/login')
|
||||
} else if (to.path === '/admin/login' && adminToken) {
|
||||
console.log('Token exists, redirecting from login to dashboard')
|
||||
} else if (to.path === '/admin/login' && adminToken && adminUserInfoStr) {
|
||||
console.log('Token and user info exist, redirecting from login to dashboard')
|
||||
next('/admin/dashboard')
|
||||
} else {
|
||||
// 检查用户权限
|
||||
@@ -206,13 +213,14 @@ router.beforeEach((to, _from, next) => {
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse user info:', parseError)
|
||||
// 解析失败,允许访问首页临时,直到权限加载完成
|
||||
if (to.path === '/admin') {
|
||||
console.log('Allowing access to home due to parse error')
|
||||
next()
|
||||
} else {
|
||||
next('/admin')
|
||||
}
|
||||
// 解析失败,重定向到登录页
|
||||
console.log('User info parse error, redirecting to login')
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
next('/admin/login')
|
||||
}
|
||||
} else {
|
||||
console.log('No user info found, redirecting to login')
|
||||
@@ -221,13 +229,14 @@ router.beforeEach((to, _from, next) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('解析用户信息失败:', error)
|
||||
// 解析失败,允许访问首页临时,直到权限加载完成
|
||||
if (to.path === '/admin') {
|
||||
console.log('Allowing access to home due to error')
|
||||
next()
|
||||
} else {
|
||||
next('/admin')
|
||||
}
|
||||
// 解析失败,重定向到登录页
|
||||
console.log('Error parsing user info, redirecting to login')
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
next('/admin/login')
|
||||
}
|
||||
} else {
|
||||
// 没有权限要求,直接通过
|
||||
|
||||
@@ -153,15 +153,42 @@
|
||||
<div class="coupon-time">
|
||||
{{ coupon.startTime }} 至 {{ coupon.endTime }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="coupon-select" v-if="selectedCoupon && selectedCoupon.id === coupon.id">
|
||||
<CheckCircleOutlined />
|
||||
<div class="coupon-select" v-if="selectedCoupon && selectedCoupon.id === coupon.id">
|
||||
<CheckCircleOutlined />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</a-modal>
|
||||
|
||||
<!-- 美甲师选择弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="showArtistModal"
|
||||
title="选择美甲师"
|
||||
width="90%"
|
||||
@ok="selectArtistAndCheckout"
|
||||
@cancel="closeArtistModal"
|
||||
>
|
||||
<div class="artist-modal-content">
|
||||
<a-empty v-if="availableArtists.length === 0" description="暂无可用美甲师" />
|
||||
<div v-else class="artist-list">
|
||||
<a-radio-group v-model:value="selectedArtist" name="artist">
|
||||
<a-radio
|
||||
v-for="artist in availableArtists"
|
||||
:key="artist.id"
|
||||
:value="artist"
|
||||
class="artist-item"
|
||||
>
|
||||
<div class="artist-info">
|
||||
<span class="artist-name">{{ artist.name }}</span>
|
||||
</div>
|
||||
</a-radio>
|
||||
</a-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -397,6 +424,26 @@ const selectCoupon = (coupon: UserCoupon) => {
|
||||
showCouponModal.value = false
|
||||
}
|
||||
|
||||
// 美甲师选择相关状态
|
||||
const showArtistModal = ref(false)
|
||||
const selectedArtist = ref<{id: number, name: string} | null>(null)
|
||||
const availableArtists = ref<{id: number, name: string}[]>([])
|
||||
|
||||
// 加载可用美甲师
|
||||
const loadAvailableArtists = async () => {
|
||||
try {
|
||||
// 这里需要根据商品ID获取可用的美甲师
|
||||
// 暂时使用模拟数据
|
||||
availableArtists.value = [
|
||||
{ id: 1, name: '美甲师1' },
|
||||
{ id: 2, name: '美甲师2' },
|
||||
{ id: 3, name: '美甲师3' }
|
||||
]
|
||||
} catch (error) {
|
||||
console.error('获取美甲师列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理结算
|
||||
const handleCheckout = async () => {
|
||||
const selectedItems = cartItems.value.filter(item => item.selected)
|
||||
@@ -405,17 +452,39 @@ const handleCheckout = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
// 加载可用美甲师
|
||||
await loadAvailableArtists()
|
||||
|
||||
// 显示美甲师选择弹窗
|
||||
showArtistModal.value = true
|
||||
}
|
||||
|
||||
// 选择美甲师并创建订单
|
||||
const selectArtistAndCheckout = async () => {
|
||||
if (!selectedArtist.value) {
|
||||
message.warning('请选择美甲师')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const order = await orderApi.createOrder({
|
||||
couponId: selectedCoupon.value ? selectedCoupon.value.id : undefined
|
||||
couponId: selectedCoupon.value ? selectedCoupon.value.id : undefined,
|
||||
artistId: selectedArtist.value.id
|
||||
})
|
||||
message.success('订单创建成功')
|
||||
showArtistModal.value = false
|
||||
router.push('/profile')
|
||||
} catch (error) {
|
||||
message.error('创建订单失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭美甲师选择弹窗
|
||||
const closeArtistModal = () => {
|
||||
showArtistModal.value = false
|
||||
selectedArtist.value = null
|
||||
}
|
||||
|
||||
// 监听选中商品变化,重新加载可用优惠券
|
||||
watch(
|
||||
() => cartItems.value.map(item => ({ id: item.id, selected: item.selected, quantity: item.quantity })),
|
||||
@@ -745,4 +814,37 @@ onMounted(() => {
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 美甲师选择弹窗样式 */
|
||||
.artist-modal-content {
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.artist-list {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.artist-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.artist-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.artist-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.artist-name {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
</style>
|
||||
+166
-13
@@ -6,11 +6,11 @@
|
||||
<!-- 用户信息区域 -->
|
||||
<div class="user-info" @click="handleUserClick">
|
||||
<div class="avatar">
|
||||
<a-avatar :size="40" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" />
|
||||
<a-avatar :size="40" :src="userInfo.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />
|
||||
</div>
|
||||
<div class="welcome">
|
||||
<p class="greeting">Hello!</p>
|
||||
<p class="username">昵称</p>
|
||||
<p class="username">{{ userInfo.nickname || '用户' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 通知按钮 -->
|
||||
@@ -102,12 +102,25 @@
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
<!-- 加载状态 -->
|
||||
<div v-if="loading" class="loading-more">
|
||||
<a-spin size="small" />
|
||||
<span style="margin-left: 8px;">加载中...</span>
|
||||
</div>
|
||||
<!-- 暂无更多商品 -->
|
||||
<div v-else-if="!hasMore && popularItems.length > 0" class="no-more">
|
||||
暂无更多商品推荐
|
||||
</div>
|
||||
<!-- 无商品时的提示 -->
|
||||
<div v-else-if="popularItems.length === 0 && !loading" class="no-products">
|
||||
暂无热门商品
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
BellOutlined,
|
||||
@@ -115,25 +128,142 @@ import {
|
||||
FilterOutlined,
|
||||
RightOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { userApi, type UserVO } from '../api/user'
|
||||
import { productApi } from '../api/product'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 用户信息
|
||||
const userInfo = ref<UserVO>({
|
||||
id: 0,
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
// 搜索关键词
|
||||
const searchQuery = ref('')
|
||||
|
||||
// 精选商品数据
|
||||
const featuredItems = ref([
|
||||
{ id: 1, name: 'Watch', price: 40, bgColor: '#ffe4d6' },
|
||||
{ id: 2, name: 'Nike Shoes', price: 430, bgColor: '#d6eaff' },
|
||||
{ id: 3, name: 'Airpods', price: 333, bgColor: '#e2ffd6' }
|
||||
])
|
||||
const featuredItems = ref<any[]>([])
|
||||
|
||||
// 热门商品数据
|
||||
const popularItems = ref([
|
||||
{ id: 4, name: 'LG TV', price: 330, bgColor: '#f0d6ff' },
|
||||
{ id: 5, name: 'Hoodie', price: 50, bgColor: '#ffd6e2' },
|
||||
{ id: 6, name: 'Jacket', price: 400, bgColor: '#d6fff0' }
|
||||
])
|
||||
const popularItems = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const hasMore = ref(true)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(10)
|
||||
|
||||
// 加载用户信息
|
||||
const loadUserInfo = async () => {
|
||||
try {
|
||||
const data = await userApi.getUserInfo()
|
||||
userInfo.value = data as unknown as UserVO
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载精选商品
|
||||
const loadFeaturedProducts = async () => {
|
||||
try {
|
||||
const data = await productApi.getProductsByTag('精选')
|
||||
// 随机选择5个商品
|
||||
const shuffled = data.sort(() => 0.5 - Math.random())
|
||||
featuredItems.value = shuffled.slice(0, 5).map(item => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
bgColor: getRandomColor()
|
||||
}))
|
||||
} catch (error) {
|
||||
console.error('获取精选商品失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载热门商品
|
||||
const loadPopularProducts = async (loadMore = false) => {
|
||||
if (loading.value || !hasMore.value) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await productApi.getProductsByTag('热门')
|
||||
|
||||
if (loadMore) {
|
||||
// 模拟分页,实际应该在API中实现
|
||||
const start = (page.value - 1) * pageSize.value
|
||||
const end = start + pageSize.value
|
||||
const newItems = data.slice(start, end)
|
||||
|
||||
if (newItems.length < pageSize.value) {
|
||||
hasMore.value = false
|
||||
}
|
||||
|
||||
popularItems.value = [...popularItems.value, ...newItems.map(item => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
bgColor: getRandomColor()
|
||||
}))]
|
||||
} else {
|
||||
// 初始加载
|
||||
popularItems.value = data.slice(0, pageSize.value).map(item => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
bgColor: getRandomColor()
|
||||
}))
|
||||
|
||||
if (data.length <= pageSize.value) {
|
||||
hasMore.value = false
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取热门商品失败:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理滚动事件,实现懒加载
|
||||
const handleScroll = () => {
|
||||
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
|
||||
const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight
|
||||
const clientHeight = document.documentElement.clientHeight
|
||||
|
||||
if (scrollTop + clientHeight >= scrollHeight - 100 && !loading.value && hasMore.value) {
|
||||
page.value++
|
||||
loadPopularProducts(true)
|
||||
}
|
||||
}
|
||||
|
||||
// 添加滚动监听
|
||||
onMounted(() => {
|
||||
loadUserInfo()
|
||||
loadFeaturedProducts()
|
||||
loadPopularProducts()
|
||||
window.addEventListener('scroll', handleScroll)
|
||||
})
|
||||
|
||||
// 移除滚动监听
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('scroll', handleScroll)
|
||||
})
|
||||
|
||||
// 生成随机颜色
|
||||
const getRandomColor = () => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
// 页面加载时获取数据
|
||||
onMounted(() => {
|
||||
loadUserInfo()
|
||||
loadFeaturedProducts()
|
||||
loadPopularProducts()
|
||||
})
|
||||
|
||||
// 处理用户头像点击
|
||||
const handleUserClick = () => {
|
||||
@@ -419,4 +549,27 @@ const handleProductClick = (item: any) => {
|
||||
.popular-section {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.loading-more {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px 0;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.no-more {
|
||||
text-align: center;
|
||||
padding: 20px 0;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.no-products {
|
||||
text-align: center;
|
||||
padding: 40px 0;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -58,11 +58,11 @@
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="8">
|
||||
<div class="stat-item">
|
||||
<div class="stat-item" @click="handleCouponClick" style="cursor: pointer;">
|
||||
<div class="stat-icon" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
|
||||
<CreditCardOutlined />
|
||||
</div>
|
||||
<a-statistic title="优惠券" :value="3" />
|
||||
<a-statistic title="优惠券" :value="couponCount" />
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
@@ -252,6 +252,7 @@ const orders = ref<any[]>([])
|
||||
const coupons = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const orderCount = ref(0)
|
||||
const couponCount = ref(0)
|
||||
|
||||
const editForm = ref({
|
||||
nickname: '',
|
||||
@@ -411,6 +412,7 @@ const loadCoupons = async () => {
|
||||
try {
|
||||
const data = await couponApi.listUserCoupons()
|
||||
coupons.value = data
|
||||
couponCount.value = data.length
|
||||
} catch (error) {
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
@@ -418,6 +420,12 @@ const loadCoupons = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理优惠券点击
|
||||
const handleCouponClick = () => {
|
||||
activeTab.value = 'coupons'
|
||||
loadCoupons()
|
||||
}
|
||||
|
||||
// 处理取消订单
|
||||
const handleCancelOrder = async (orderId: number) => {
|
||||
Modal.confirm({
|
||||
@@ -500,6 +508,7 @@ const getRandomColor = () => {
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
loadOrders()
|
||||
loadCoupons()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -92,7 +92,8 @@ import {
|
||||
DownOutlined,
|
||||
LogoutOutlined,
|
||||
GiftOutlined,
|
||||
TagOutlined
|
||||
TagOutlined,
|
||||
ShoppingOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { userApi, type UserVO, adminAuthApi } from '@/api/admin'
|
||||
@@ -154,6 +155,12 @@ const menuItems = [
|
||||
icon: TagOutlined,
|
||||
label: '标签管理',
|
||||
permissionCode: 'tag:view'
|
||||
},
|
||||
{
|
||||
key: '/admin/orders',
|
||||
icon: ShoppingOutlined,
|
||||
label: '订单管理',
|
||||
permissionCode: 'order:view'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -52,7 +52,10 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showEditModal(record)">
|
||||
<a-button v-if="hasPermission('coupon:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('coupon:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('coupon:assign') && record.status === 1" type="link" size="small" @click="showDistributeModal(record)">
|
||||
@@ -199,6 +202,86 @@
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 查看优惠券详情模态框 -->
|
||||
<a-modal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看优惠券详情"
|
||||
@cancel="handleViewModalCancel"
|
||||
width="800px"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="优惠券编码">
|
||||
<a-input v-model:value="viewFormState.couponCode" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="优惠券名称">
|
||||
<a-input v-model:value="viewFormState.couponName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺">
|
||||
<a-select v-model:value="viewFormState.shopId" :disabled="true">
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="优惠券类型">
|
||||
<a-select v-model:value="viewFormState.couponType" :disabled="true">
|
||||
<a-select-option :value="1">折扣券</a-select-option>
|
||||
<a-select-option :value="2">满减券</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item v-if="viewFormState.couponType === 1" label="折扣值">
|
||||
<a-input-number v-model:value="viewFormState.discountValue" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item v-if="viewFormState.couponType === 2" label="最低消费">
|
||||
<a-input-number v-model:value="viewFormState.minAmount" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item v-if="viewFormState.couponType === 2" label="减免金额">
|
||||
<a-input-number v-model:value="viewFormState.reduceAmount" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="总数量">
|
||||
<a-input-number v-model:value="viewFormState.totalCount" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="开始时间">
|
||||
<a-date-picker v-model:value="viewFormState.startTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="结束时间">
|
||||
<a-date-picker v-model:value="viewFormState.endTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="可用标签">
|
||||
<a-select
|
||||
v-model:value="viewFormState.availableTagIds"
|
||||
mode="multiple"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option v-for="tag in tagList" :key="tag.id" :value="tag.id">
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="不可用标签">
|
||||
<a-select
|
||||
v-model:value="viewFormState.unavailableTagIds"
|
||||
mode="multiple"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option v-for="tag in tagList" :key="tag.id" :value="tag.id">
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -255,6 +338,7 @@ const getCurrentUserInfo = () => {
|
||||
|
||||
const loading = ref(false)
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const searchText = ref('')
|
||||
@@ -267,6 +351,22 @@ const distributeLoading = ref(false)
|
||||
const distributeFormRef = ref<FormInstance>()
|
||||
const currentDistributeCoupon = ref<Coupon | null>(null)
|
||||
|
||||
// 查看优惠券相关状态
|
||||
const viewFormState = reactive({
|
||||
couponCode: '',
|
||||
couponName: '',
|
||||
couponType: 1,
|
||||
discountValue: 9.5,
|
||||
minAmount: 100,
|
||||
reduceAmount: 20,
|
||||
totalCount: 100,
|
||||
startTime: undefined,
|
||||
endTime: undefined,
|
||||
availableTagIds: [] as number[],
|
||||
unavailableTagIds: [] as number[],
|
||||
shopId: undefined as number | undefined
|
||||
})
|
||||
|
||||
const couponList = ref<Coupon[]>([])
|
||||
const tagList = ref<TagVO[]>([])
|
||||
const userList = ref<any[]>([])
|
||||
@@ -453,6 +553,37 @@ const showEditModal = (record: Coupon) => {
|
||||
}
|
||||
}
|
||||
|
||||
const showViewModal = (record: Coupon) => {
|
||||
if (!record) {
|
||||
message.error('优惠券数据不存在')
|
||||
return
|
||||
}
|
||||
try {
|
||||
Object.assign(viewFormState, {
|
||||
couponCode: record.couponCode || '',
|
||||
couponName: record.couponName || '',
|
||||
couponType: record.couponType || 1,
|
||||
discountValue: record.discountValue || 0,
|
||||
minAmount: record.minAmount || 0,
|
||||
reduceAmount: record.reduceAmount || 0,
|
||||
totalCount: record.totalCount || 0,
|
||||
startTime: record.startTime ? dayjs(record.startTime) : undefined,
|
||||
endTime: record.endTime ? dayjs(record.endTime) : undefined,
|
||||
availableTagIds: record.availableTags ? record.availableTags.map(tag => tag.id) : [],
|
||||
unavailableTagIds: record.unavailableTags ? record.unavailableTags.map(tag => tag.id) : [],
|
||||
shopId: record.shopId
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
} catch (error) {
|
||||
console.error('Error in showViewModal:', error)
|
||||
message.error('打开查看模态框失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
@@ -525,8 +656,14 @@ const handleModalOk = async () => {
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
message.confirm({
|
||||
title: '确认关闭',
|
||||
content: '确定要关闭编辑模态框吗?未保存的更改将会丢失。',
|
||||
onOk: () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleDelete = (record: Coupon) => {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="6">
|
||||
<a-col :span="6" v-if="isAdmin">
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="店铺数量"
|
||||
@@ -110,7 +110,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import {
|
||||
UserOutlined,
|
||||
@@ -131,6 +131,26 @@ const stats = reactive<DashboardStats>({
|
||||
recentActivities: []
|
||||
})
|
||||
|
||||
// 获取当前用户信息
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
return userInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// 判断是否为管理员
|
||||
const isAdmin = computed(() => {
|
||||
const userInfo = getCurrentUserInfo()
|
||||
return userInfo?.type === 4
|
||||
})
|
||||
|
||||
const formatTime = (timeStr: string) => {
|
||||
if (!timeStr) return ''
|
||||
const time = new Date(timeStr)
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showOrderDetail(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="record.status === 1" type="primary" size="small" @click="processOrder(record.id, 2)">
|
||||
确认完成
|
||||
</a-button>
|
||||
@@ -40,6 +43,38 @@
|
||||
</a-table>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 订单详情模态框 -->
|
||||
<a-modal
|
||||
v-model:open="detailModalVisible"
|
||||
title="订单详情"
|
||||
@cancel="handleDetailModalCancel"
|
||||
width="800px"
|
||||
>
|
||||
<div v-if="currentOrder">
|
||||
<a-descriptions :column="2">
|
||||
<a-descriptions-item label="订单编号">{{ currentOrder.orderNo }}</a-descriptions-item>
|
||||
<a-descriptions-item label="用户ID">{{ currentOrder.userId }}</a-descriptions-item>
|
||||
<a-descriptions-item label="总金额">¥{{ currentOrder.totalAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="实际金额">¥{{ currentOrder.actualAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠券">{{ currentOrder.couponName || '无' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单状态">{{ currentOrder.statusText }}</a-descriptions-item>
|
||||
<a-descriptions-item label="创建时间" :span="2">{{ currentOrder.createTime }}</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
|
||||
<a-divider>订单商品</a-divider>
|
||||
<a-table :columns="orderItemColumns" :data-source="currentOrder.items" row-key="id">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'price'">
|
||||
¥{{ record.price.toFixed(2) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'totalPrice'">
|
||||
¥{{ (record.price * record.quantity).toFixed(2) }}
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -64,6 +99,8 @@ interface Order {
|
||||
const orders = ref<Order[]>([])
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const detailModalVisible = ref(false)
|
||||
const currentOrder = ref<Order | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -74,6 +111,14 @@ const pagination = reactive({
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const orderItemColumns = [
|
||||
{ title: '商品ID', dataIndex: 'productId', key: 'productId' },
|
||||
{ title: '商品名称', dataIndex: 'productTitle', key: 'productTitle' },
|
||||
{ title: '单价', key: 'price', width: 100 },
|
||||
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 100 },
|
||||
{ title: '总价', key: 'totalPrice', width: 100 }
|
||||
]
|
||||
|
||||
const columns = [
|
||||
{ title: '订单编号', dataIndex: 'orderNo', key: 'orderNo' },
|
||||
{ title: '用户ID', dataIndex: 'userId', key: 'userId' },
|
||||
@@ -138,6 +183,16 @@ const processOrder = async (orderId: number, status: number) => {
|
||||
}
|
||||
}
|
||||
|
||||
const showOrderDetail = (order: Order) => {
|
||||
currentOrder.value = order
|
||||
detailModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleDetailModalCancel = () => {
|
||||
detailModalVisible.value = false
|
||||
currentOrder.value = null
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadOrders()
|
||||
})
|
||||
|
||||
@@ -256,13 +256,43 @@ const getUserTypeText = (type: number) => {
|
||||
|
||||
const filteredUserList = computed(() => {
|
||||
if (!currentLoginUser.value) return []
|
||||
return userList.value.filter(user => user.type < currentLoginUser.value!.type && user.type !== 0)
|
||||
|
||||
// 管理员可以看到所有用户(除了普通用户和自己)
|
||||
if (currentLoginUser.value.type === 4) {
|
||||
return userList.value.filter(user => user.type !== 0 && user.id !== currentLoginUser.value!.id)
|
||||
}
|
||||
|
||||
// 店长只能看到美甲师(除了自己)
|
||||
if (currentLoginUser.value.type === 2) {
|
||||
return userList.value.filter(user => user.type === 3 && user.id !== currentLoginUser.value!.id)
|
||||
}
|
||||
|
||||
// 其他用户类型(如美甲师)不能管理权限
|
||||
return []
|
||||
})
|
||||
|
||||
const fetchCurrentUser = async () => {
|
||||
try {
|
||||
const res = await userApi.getUserInfo()
|
||||
currentLoginUser.value = res as unknown as UserVO
|
||||
// 尝试从API获取用户信息
|
||||
try {
|
||||
const res = await userApi.getUserInfo()
|
||||
currentLoginUser.value = res as unknown as UserVO
|
||||
console.log('从API获取当前用户信息:', currentLoginUser.value)
|
||||
} catch (apiError) {
|
||||
// 如果API调用失败,尝试从本地存储获取
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
try {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
currentLoginUser.value = userInfo as UserVO
|
||||
console.log('从本地存储获取当前用户信息:', currentLoginUser.value)
|
||||
} catch (parseError) {
|
||||
console.error('解析本地存储的用户信息失败:', parseError)
|
||||
}
|
||||
} else {
|
||||
console.error('获取当前用户信息失败,本地存储也没有用户信息')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败:', error)
|
||||
}
|
||||
@@ -284,11 +314,18 @@ const fetchPermissionList = async () => {
|
||||
const fetchUserList = async () => {
|
||||
userLoading.value = true
|
||||
try {
|
||||
const res = await userApi.listUsers({
|
||||
const params: any = {
|
||||
page: 1,
|
||||
size: 100,
|
||||
keyword: userSearchText.value
|
||||
})
|
||||
}
|
||||
|
||||
// 如果当前用户不是管理员,只获取当前店铺的用户
|
||||
if (currentLoginUser.value && currentLoginUser.value.type !== 4 && currentLoginUser.value.shopId) {
|
||||
params.shopId = currentLoginUser.value.shopId
|
||||
}
|
||||
|
||||
const res = await userApi.listUsers(params)
|
||||
userList.value = res.list || []
|
||||
} catch (error) {
|
||||
message.error('获取用户列表失败')
|
||||
@@ -397,7 +434,10 @@ onMounted(async () => {
|
||||
await fetchCurrentUser()
|
||||
await loadUserPermissions()
|
||||
fetchPermissionList()
|
||||
fetchUserList()
|
||||
// 确保在获取当前用户信息后再获取用户列表
|
||||
setTimeout(() => {
|
||||
fetchUserList()
|
||||
}, 100)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -61,6 +61,9 @@
|
||||
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('product:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
@@ -241,6 +244,117 @@
|
||||
</template>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 查看商品详情模态框 -->
|
||||
<a-modal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看商品详情"
|
||||
width="700px"
|
||||
@cancel="handleViewModalCancel"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 5 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<a-form-item label="商品名称">
|
||||
<a-input v-model:value="viewFormState.title" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="商品描述">
|
||||
<a-textarea
|
||||
v-model:value="viewFormState.description"
|
||||
:rows="3"
|
||||
:disabled="true"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺">
|
||||
<a-select v-model:value="viewFormState.shopId" :disabled="true">
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品图片">
|
||||
<div class="product-images">
|
||||
<a-image
|
||||
v-for="(url, index) in viewImageUrls"
|
||||
:key="index"
|
||||
:width="80"
|
||||
:height="80"
|
||||
:src="url"
|
||||
style="object-fit: cover; border-radius: 4px; margin-right: 8px; margin-bottom: 8px;"
|
||||
:preview="false"
|
||||
/>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="价格">
|
||||
<a-input-number
|
||||
v-model:value="viewFormState.price"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="预计时长">
|
||||
<a-input-number
|
||||
v-model:value="viewFormState.approximateDuration"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="标签">
|
||||
<a-select
|
||||
v-model:value="viewFormState.tags"
|
||||
mode="multiple"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="tag in tags"
|
||||
:key="tag.id"
|
||||
:value="tag.id.toString()"
|
||||
>
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="可预约美甲师">
|
||||
<a-select
|
||||
v-model:value="viewFormState.bookableArtists"
|
||||
mode="multiple"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="artist in artists"
|
||||
:key="artist.id"
|
||||
:value="artist.id.toString()"
|
||||
>
|
||||
{{ artist.nickname }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="可用优惠券">
|
||||
<a-select
|
||||
v-model:value="viewFormState.availableCoupons"
|
||||
mode="multiple"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="coupon in coupons"
|
||||
:key="coupon?.id"
|
||||
:value="coupon?.id?.toString()"
|
||||
>
|
||||
{{ coupon?.couponName || '' }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -258,6 +372,7 @@ const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const productList = ref<Product[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const currentProduct = ref<Product | null>(null)
|
||||
@@ -274,10 +389,23 @@ const previewImage = ref('')
|
||||
const imageFileList = ref<any[]>([])
|
||||
const uploadedFileIds = ref<string[]>([])
|
||||
const imageUrls = ref<Record<number, string[]>>({})
|
||||
const viewImageUrls = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const isAdmin = ref(false)
|
||||
const formRef = ref<any>(null)
|
||||
|
||||
const viewFormState = reactive({
|
||||
shopId: undefined,
|
||||
title: '',
|
||||
description: '',
|
||||
imageFileIds: '',
|
||||
price: 0,
|
||||
tags: [] as string[],
|
||||
approximateDuration: undefined,
|
||||
bookableArtists: [] as string[],
|
||||
availableCoupons: [] as string[]
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
@@ -585,6 +713,64 @@ const showEditModal = async (record: Product) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = async (record: Product) => {
|
||||
// 处理标签
|
||||
const tagsArray = record.tags ? record.tags.split(';').filter(tag => tag) : []
|
||||
// 处理美甲师
|
||||
const artistsArray = record.bookableArtists ? record.bookableArtists.split(',').filter(artist => artist) : []
|
||||
// 处理优惠券
|
||||
const couponsArray = record.availableCoupons ? record.availableCoupons.split(',').filter(coupon => coupon) : []
|
||||
// 处理预计时长,将字符串转换为数字
|
||||
const durationNumber = record.approximateDuration ? parseInt(record.approximateDuration.replace('分钟', '')) : undefined
|
||||
|
||||
Object.assign(viewFormState, {
|
||||
shopId: record.shopId,
|
||||
title: record.title,
|
||||
description: record.description,
|
||||
imageFileIds: record.imageFileIds,
|
||||
price: record.price,
|
||||
tags: tagsArray,
|
||||
approximateDuration: durationNumber,
|
||||
bookableArtists: artistsArray,
|
||||
availableCoupons: couponsArray
|
||||
})
|
||||
|
||||
// 加载图片URL
|
||||
if (record.imageFileIds) {
|
||||
const ids = record.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
urls.push(DEFAULT_PRODUCT_IMAGE)
|
||||
}
|
||||
}
|
||||
viewImageUrls.value = urls
|
||||
} else {
|
||||
viewImageUrls.value = [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
// 获取该店铺的美甲师列表
|
||||
if (record.shopId) {
|
||||
await fetchArtists(record.shopId)
|
||||
}
|
||||
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
viewImageUrls.value = []
|
||||
}
|
||||
|
||||
const beforeUpload = (file: File) => {
|
||||
const isImage = file.type.startsWith('image/')
|
||||
if (!isImage) {
|
||||
|
||||
@@ -52,6 +52,9 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('shop:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('shop:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
@@ -122,6 +125,50 @@
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 查看店铺详情模态框 -->
|
||||
<a-modal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看店铺详情"
|
||||
width="600px"
|
||||
@cancel="handleViewModalCancel"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 5 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<a-form-item label="店铺名称">
|
||||
<a-input v-model:value="viewFormState.shopName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺描述">
|
||||
<a-textarea
|
||||
v-model:value="viewFormState.description"
|
||||
:rows="3"
|
||||
:disabled="true"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺地址">
|
||||
<a-input v-model:value="viewFormState.address" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="营业时间">
|
||||
<a-input v-model:value="viewFormState.businessHours" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺图片">
|
||||
<div class="shop-images">
|
||||
<a-image
|
||||
v-for="(url, index) in viewImageUrls"
|
||||
:key="index"
|
||||
:width="80"
|
||||
:height="80"
|
||||
:src="url"
|
||||
style="object-fit: cover; border-radius: 4px; margin-right: 8px; margin-bottom: 8px;"
|
||||
:preview="false"
|
||||
/>
|
||||
</div>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -140,6 +187,7 @@ const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const shopList = ref<Shop[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
@@ -151,9 +199,19 @@ const imageFileList = ref<any[]>([])
|
||||
const uploadedFileIds = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const shopImageUrls = ref<Record<number, string[]>>({})
|
||||
const viewImageUrls = ref<string[]>([])
|
||||
const previewVisible = ref(false)
|
||||
const previewImage = ref('')
|
||||
|
||||
// 查看店铺相关状态
|
||||
const viewFormState = reactive({
|
||||
shopName: '',
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
@@ -387,6 +445,46 @@ const showEditModal = async (record: Shop) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = async (record: Shop) => {
|
||||
Object.assign(viewFormState, {
|
||||
shopName: record.shopName,
|
||||
description: record.description,
|
||||
address: record.address,
|
||||
businessHours: record.businessHours,
|
||||
imageFileIds: record.imageFileIds
|
||||
})
|
||||
|
||||
// 加载图片URL
|
||||
if (record.imageFileIds) {
|
||||
const ids = record.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
urls.push(DEFAULT_SHOP_IMAGE)
|
||||
}
|
||||
}
|
||||
viewImageUrls.value = urls
|
||||
} else {
|
||||
viewImageUrls.value = [DEFAULT_SHOP_IMAGE]
|
||||
}
|
||||
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
viewImageUrls.value = []
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
|
||||
@@ -0,0 +1,427 @@
|
||||
<template>
|
||||
<div class="tags">
|
||||
<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 v-if="hasPermission('tag:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增标签
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="tagList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'color'">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: record.bgColor,
|
||||
color: record.textColor,
|
||||
borderColor: record.borderColor
|
||||
}"
|
||||
>
|
||||
{{ record.tagName }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shop'">
|
||||
<span>{{ getShopName(record.shopId) }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('tag:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('tag:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('tag:delete')" type="link" size="small" danger @click="handleDelete(record)">
|
||||
删除
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑标签' : '新增标签'"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
width="600px"
|
||||
>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="标签名称" name="tagName">
|
||||
<a-input v-model:value="formState.tagName" placeholder="请输入标签名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择所属店铺"
|
||||
style="width: 100%"
|
||||
:loading="loadingShops"
|
||||
:disabled="getCurrentUserInfo()?.type === 2"
|
||||
>
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
disabled
|
||||
value=""
|
||||
>
|
||||
暂无店铺数据
|
||||
</a-select-option>
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="文字颜色" name="textColor">
|
||||
<el-color-picker v-model="formState.textColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="背景颜色" name="bgColor">
|
||||
<el-color-picker v-model="formState.bgColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="边框颜色" name="borderColor">
|
||||
<el-color-picker v-model="formState.borderColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="预览">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: formState.bgColor,
|
||||
color: formState.textColor,
|
||||
borderColor: formState.borderColor
|
||||
}"
|
||||
>
|
||||
{{ formState.tagName }}
|
||||
</span>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 查看标签详情模态框 -->
|
||||
<a-modal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看标签详情"
|
||||
@cancel="handleViewModalCancel"
|
||||
width="600px"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="标签名称">
|
||||
<a-input v-model:value="viewFormState.tagName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺">
|
||||
<a-select v-model:value="viewFormState.shopId" :disabled="true">
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="文字颜色">
|
||||
<el-color-picker v-model="viewFormState.textColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="背景颜色">
|
||||
<el-color-picker v-model="viewFormState.bgColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="边框颜色">
|
||||
<el-color-picker v-model="viewFormState.borderColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="预览">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: viewFormState.bgColor,
|
||||
color: viewFormState.textColor,
|
||||
borderColor: viewFormState.borderColor
|
||||
}"
|
||||
>
|
||||
{{ viewFormState.tagName }}
|
||||
</span>
|
||||
</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 { adminTagApi, adminShopApi, type Shop } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
return userInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentTag = ref<any>(null)
|
||||
|
||||
// 查看标签相关状态
|
||||
const viewFormState = reactive({
|
||||
tagName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
|
||||
const tagList = ref<any[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
const loadingShops = ref(false)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
tagName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
tagName: [{ required: true, message: '请输入标签名称', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '标签名称', dataIndex: 'tagName', key: 'tagName' },
|
||||
{ title: '所属店铺', key: 'shop', width: 150 },
|
||||
{ title: '预览', key: 'color', width: 150 },
|
||||
{ title: '文字颜色', dataIndex: 'textColor', key: 'textColor', width: 120 },
|
||||
{ title: '背景颜色', dataIndex: 'bgColor', key: 'bgColor', width: 120 },
|
||||
{ title: '边框颜色', dataIndex: 'borderColor', key: 'borderColor', width: 120 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
const fetchTags = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
let tags
|
||||
if (shopId) {
|
||||
tags = await adminTagApi.listTagsByShopId(shopId)
|
||||
} else {
|
||||
tags = await adminTagApi.listAllTags()
|
||||
}
|
||||
console.log('Tags data:', tags)
|
||||
tagList.value = tags || []
|
||||
pagination.total = tagList.value.length
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
message.error('获取标签列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const res = await adminShopApi.listAllShops()
|
||||
shops.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const getShopName = (shopId: number) => {
|
||||
const shop = shops.value.find(s => s.id === shopId)
|
||||
return shop ? shop.shopName : '未知店铺'
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
pagination.current = 1
|
||||
fetchTags()
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
fetchTags()
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
Object.assign(formState, {
|
||||
tagName: '',
|
||||
shopId: shopId,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: any) => {
|
||||
console.log('Edit record:', record)
|
||||
isEdit.value = true
|
||||
currentTag.value = record
|
||||
Object.assign(formState, {
|
||||
tagName: record.tagName,
|
||||
shopId: record.shopId,
|
||||
textColor: record.textColor,
|
||||
bgColor: record.bgColor,
|
||||
borderColor: record.borderColor
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = (record: any) => {
|
||||
Object.assign(viewFormState, {
|
||||
tagName: record.tagName,
|
||||
shopId: record.shopId,
|
||||
textColor: record.textColor,
|
||||
bgColor: record.bgColor,
|
||||
borderColor: record.borderColor
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
const requestData = {
|
||||
tagName: formState.tagName,
|
||||
shopId: formState.shopId,
|
||||
textColor: formState.textColor,
|
||||
bgColor: formState.bgColor,
|
||||
borderColor: formState.borderColor
|
||||
}
|
||||
|
||||
console.log('Request data:', requestData)
|
||||
console.log('Current tag:', currentTag.value)
|
||||
|
||||
if (isEdit.value && currentTag.value) {
|
||||
console.log('Updating tag with id:', currentTag.value.id)
|
||||
await adminTagApi.updateTag(currentTag.value.id, requestData)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminTagApi.createTag(requestData)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
modalVisible.value = false
|
||||
fetchTags()
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDelete = (record: any) => {
|
||||
message.confirm({
|
||||
title: '确认删除',
|
||||
content: `确定要删除标签 ${record.tagName} 吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
await adminTagApi.deleteTag(record.id)
|
||||
message.success('删除成功')
|
||||
fetchTags()
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
await fetchShops()
|
||||
await fetchTags()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tags {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.tag-preview {
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -48,6 +48,9 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('user:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('user:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
@@ -128,12 +131,66 @@
|
||||
</a-form-item>
|
||||
<a-form-item label="用户类型" name="type">
|
||||
<a-select v-model:value="formState.type" placeholder="请选择用户类型">
|
||||
<!-- 管理员可以新建所有类型 -->
|
||||
<a-select-option v-if="currentUserInfo?.type === 4" :value="0">用户</a-select-option>
|
||||
<a-select-option v-if="currentUserInfo?.type === 4" :value="2">店长</a-select-option>
|
||||
<a-select-option v-if="currentUserInfo?.type === 4" :value="3">美甲师</a-select-option>
|
||||
<a-select-option v-if="currentUserInfo?.type === 4" :value="4">管理员</a-select-option>
|
||||
|
||||
<!-- 店长可以新建美甲师和用户 -->
|
||||
<a-select-option v-else-if="currentUserInfo?.type === 2" :value="0">用户</a-select-option>
|
||||
<a-select-option v-else-if="currentUserInfo?.type === 2" :value="3">美甲师</a-select-option>
|
||||
|
||||
<!-- 美甲师只能新建用户 -->
|
||||
<a-select-option v-else-if="currentUserInfo?.type === 3" :value="0">用户</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 查看用户详情模态框 -->
|
||||
<a-modal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看用户详情"
|
||||
@cancel="handleViewModalCancel"
|
||||
width="600px"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="账号">
|
||||
<a-input v-model:value="viewFormState.account" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="昵称">
|
||||
<a-input v-model:value="viewFormState.nickname" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="手机号">
|
||||
<a-input v-model:value="viewFormState.phone" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺">
|
||||
<a-select v-model:value="viewFormState.shopId" :disabled="true">
|
||||
<a-select-option
|
||||
v-for="shop in shopList"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="用户类型">
|
||||
<a-select v-model:value="viewFormState.type" :disabled="true">
|
||||
<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-item label="创建时间">
|
||||
<a-input v-model:value="viewFormState.createTime" :disabled="true" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
@@ -172,12 +229,22 @@ const userList = ref<UserVO[]>([])
|
||||
const shopList = ref<Shop[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const isAdmin = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentUser = ref<UserVO | null>(null)
|
||||
const currentUserInfo = getCurrentUserInfo()
|
||||
|
||||
const viewFormState = reactive({
|
||||
account: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
shopId: undefined as number | undefined,
|
||||
type: 0,
|
||||
createTime: ''
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
@@ -339,6 +406,22 @@ const showEditModal = (record: UserVO) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = (record: UserVO) => {
|
||||
Object.assign(viewFormState, {
|
||||
account: record.account,
|
||||
nickname: record.nickname,
|
||||
phone: record.phone,
|
||||
shopId: record.shopId,
|
||||
type: record.type,
|
||||
createTime: record.createTime
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
const checkAccountExists = async (account: string) => {
|
||||
try {
|
||||
const res = await userApi.listUsers({ page: 1, size: 1000, keyword: account, status: 1 })
|
||||
|
||||
+106
-16
@@ -3,9 +3,13 @@ package com.xiaowang.yuminailcore.controller;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.entity.CommentDO;
|
||||
import com.xiaowang.yuminailcore.entity.OrderDO;
|
||||
import com.xiaowang.yuminailcore.entity.OrderItemDO;
|
||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.CommentMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.OrderItemMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.OrderMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
@@ -16,10 +20,12 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@@ -31,14 +37,47 @@ public class DashboardController {
|
||||
private final ProductMapper productMapper;
|
||||
private final ShopMapper shopMapper;
|
||||
private final CommentMapper commentMapper;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
|
||||
@GetMapping("/stats")
|
||||
public Result<DashboardStatsVO> getDashboardStats() {
|
||||
public Result<DashboardStatsVO> getDashboardStats(HttpServletRequest request) {
|
||||
DashboardStatsVO stats = new DashboardStatsVO();
|
||||
stats.setTotalUsers(userMapper.selectCount(null));
|
||||
stats.setTotalProducts(productMapper.selectCount(null));
|
||||
stats.setTotalShops(shopMapper.selectCount(null));
|
||||
stats.setTodayOrders(0L);
|
||||
|
||||
// 获取当前用户信息
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
UserDO currentUser = userMapper.selectById(userId);
|
||||
|
||||
if (currentUser != null) {
|
||||
// 根据用户类型显示不同的数据
|
||||
if (currentUser.getType() == 4) { // 管理员
|
||||
stats.setTotalUsers(userMapper.selectCount(null));
|
||||
stats.setTotalProducts(productMapper.selectCount(null));
|
||||
stats.setTotalShops(shopMapper.selectCount(null));
|
||||
stats.setTodayOrders(getTodayOrders(null));
|
||||
} else { // 店长或美甲师
|
||||
Long shopId = currentUser.getShopId();
|
||||
if (shopId != null) {
|
||||
// 只显示当前店铺的数据
|
||||
stats.setTotalUsers(userMapper.selectCount(new LambdaQueryWrapper<UserDO>().eq(UserDO::getShopId, shopId)));
|
||||
stats.setTotalProducts(productMapper.selectCount(new LambdaQueryWrapper<ProductDO>().eq(ProductDO::getShopId, shopId)));
|
||||
stats.setTotalShops(0L); // 非管理员不显示店铺数量
|
||||
stats.setTodayOrders(getTodayOrders(shopId));
|
||||
} else {
|
||||
// 没有店铺ID的情况
|
||||
stats.setTotalUsers(0L);
|
||||
stats.setTotalProducts(0L);
|
||||
stats.setTotalShops(0L);
|
||||
stats.setTodayOrders(0L);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 无法获取用户信息的情况
|
||||
stats.setTotalUsers(0L);
|
||||
stats.setTotalProducts(0L);
|
||||
stats.setTotalShops(0L);
|
||||
stats.setTodayOrders(0L);
|
||||
}
|
||||
|
||||
stats.setHotProducts(getHotProducts());
|
||||
stats.setRecentActivities(getRecentActivities());
|
||||
@@ -46,18 +85,69 @@ public class DashboardController {
|
||||
return Result.success(stats);
|
||||
}
|
||||
|
||||
private List<HotProductVO> getHotProducts() {
|
||||
LambdaQueryWrapper<ProductDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByDesc(ProductDO::getLikeCount)
|
||||
.last("LIMIT 5");
|
||||
List<ProductDO> products = productMapper.selectList(wrapper);
|
||||
private Long getTodayOrders(Long shopId) {
|
||||
// 获取今天的开始时间
|
||||
LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
String todayStartStr = todayStart.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
System.out.println("Today start time: " + todayStartStr);
|
||||
|
||||
return products.stream().map(product -> {
|
||||
HotProductVO vo = new HotProductVO();
|
||||
BeanUtils.copyProperties(product, vo);
|
||||
vo.setLikeCount(product.getLikeCount() != null ? product.getLikeCount() : 0);
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
if (shopId != null) {
|
||||
// 非管理员只查询自己店铺的订单,通过订单商品关联到商品,再关联到店铺
|
||||
java.util.Map<String, Object> result = orderItemMapper.countTodayOrdersByShopId(shopId, todayStartStr);
|
||||
Long count = result != null && result.get("count") != null ? Long.valueOf(result.get("count").toString()) : 0L;
|
||||
System.out.println("Shop ID: " + shopId + ", Order count: " + count);
|
||||
return count;
|
||||
} else {
|
||||
// 管理员查询所有订单
|
||||
java.util.Map<String, Object> result = orderItemMapper.countTodayOrders(todayStartStr);
|
||||
Long count = result != null && result.get("count") != null ? Long.valueOf(result.get("count").toString()) : 0L;
|
||||
System.out.println("Admin order count: " + count);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
private List<HotProductVO> getHotProducts() {
|
||||
// 通过订单商品表统计每个商品的订单数量,按订单数量排序
|
||||
// 使用SQL查询获取商品及其订单数量
|
||||
List<Map<String, Object>> productOrderCounts = orderItemMapper.selectMaps(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<OrderItemDO>()
|
||||
.select("product_id, COUNT(*) as order_count")
|
||||
.groupBy("product_id")
|
||||
.orderByDesc("order_count")
|
||||
.last("LIMIT 5")
|
||||
);
|
||||
|
||||
List<HotProductVO> hotProducts = new ArrayList<>();
|
||||
|
||||
// 遍历查询结果,获取商品详情
|
||||
for (Map<String, Object> map : productOrderCounts) {
|
||||
Long productId = Long.valueOf(map.get("product_id").toString());
|
||||
ProductDO product = productMapper.selectById(productId);
|
||||
|
||||
if (product != null) {
|
||||
HotProductVO vo = new HotProductVO();
|
||||
BeanUtils.copyProperties(product, vo);
|
||||
vo.setLikeCount(product.getLikeCount() != null ? product.getLikeCount() : 0);
|
||||
hotProducts.add(vo);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果按订单数量查询没有结果,使用点赞数作为备选
|
||||
if (hotProducts.isEmpty()) {
|
||||
LambdaQueryWrapper<ProductDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByDesc(ProductDO::getLikeCount)
|
||||
.last("LIMIT 5");
|
||||
List<ProductDO> products = productMapper.selectList(wrapper);
|
||||
|
||||
hotProducts = products.stream().map(product -> {
|
||||
HotProductVO vo = new HotProductVO();
|
||||
BeanUtils.copyProperties(product, vo);
|
||||
vo.setLikeCount(product.getLikeCount() != null ? product.getLikeCount() : 0);
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return hotProducts;
|
||||
}
|
||||
|
||||
private List<RecentActivityVO> getRecentActivities() {
|
||||
|
||||
@@ -6,10 +6,20 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderItemMapper extends BaseMapper<OrderItemDO> {
|
||||
@Select("SELECT * FROM t_order_item WHERE order_id = #{orderId}")
|
||||
List<OrderItemDO> selectByOrderId(@Param("orderId") Long orderId);
|
||||
|
||||
@Select("SELECT COUNT(DISTINCT oi.order_id) as count FROM t_order_item oi " +
|
||||
"JOIN t_product p ON oi.product_id = p.id " +
|
||||
"JOIN t_order o ON oi.order_id = o.id " +
|
||||
"WHERE p.shop_id = #{shopId} AND o.create_time >= STR_TO_DATE(#{todayStart}, '%Y-%m-%d %H:%i:%s') AND o.is_delete = 0")
|
||||
java.util.Map<String, Object> countTodayOrdersByShopId(@Param("shopId") Long shopId, @Param("todayStart") String todayStart);
|
||||
|
||||
@Select("SELECT COUNT(DISTINCT order_id) as count FROM t_order WHERE create_time >= STR_TO_DATE(#{todayStart}, '%Y-%m-%d %H:%i:%s') AND is_delete = 0")
|
||||
java.util.Map<String, Object> countTodayOrders(@Param("todayStart") String todayStart);
|
||||
}
|
||||
+2
-3
@@ -568,8 +568,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
|
||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
||||
wrapper.eq(UserDO::getIsDelete, 0);
|
||||
// 过滤掉普通用户(type为0)
|
||||
wrapper.ne(UserDO::getType, 0);
|
||||
// 不再过滤普通用户,由前端根据用户角色进行过滤
|
||||
if (StringUtils.hasText(keyword)) {
|
||||
wrapper.and(w -> w.like(UserDO::getAccount, keyword)
|
||||
.or().like(UserDO::getNickname, keyword)
|
||||
@@ -578,7 +577,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
if (shopId != null && shopId > 0) {
|
||||
wrapper.eq(UserDO::getShopId, shopId);
|
||||
}
|
||||
if (type != null && type > 0) {
|
||||
if (type != null) {
|
||||
wrapper.eq(UserDO::getType, type);
|
||||
}
|
||||
wrapper.orderByDesc(UserDO::getCreateTime);
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
-- 清空现有数据
|
||||
DELETE FROM t_user_permission WHERE 1=1;
|
||||
DELETE FROM t_permission WHERE 1=1;
|
||||
DELETE FROM t_user WHERE 1=1;
|
||||
|
||||
-- 插入完整的系统权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
-- 首页权限
|
||||
('home:view', '查看首页', '首页', '查看系统首页', NOW(), NOW(), 0),
|
||||
|
||||
-- 仪表盘权限
|
||||
('dashboard:view', '查看仪表盘', '仪表盘', '查看系统仪表盘', NOW(), NOW(), 0),
|
||||
|
||||
-- 用户管理权限
|
||||
('user:view', '查看用户', '用户管理', '查看用户列表和详情', NOW(), NOW(), 0),
|
||||
('user:create', '新增用户', '用户管理', '新增用户', NOW(), NOW(), 0),
|
||||
('user:edit', '编辑用户', '用户管理', '编辑用户信息', NOW(), NOW(), 0),
|
||||
('user:reset_password', '重置密码', '用户管理', '重置用户密码', NOW(), NOW(), 0),
|
||||
('user:delete', '删除用户', '用户管理', '删除用户', NOW(), NOW(), 0),
|
||||
|
||||
-- 商品管理权限
|
||||
('product:view', '查看商品', '商品管理', '查看商品列表和详情', NOW(), NOW(), 0),
|
||||
('product:create', '新增商品', '商品管理', '新增商品', NOW(), NOW(), 0),
|
||||
('product:edit', '编辑商品', '商品管理', '编辑商品信息', NOW(), NOW(), 0),
|
||||
('product:delete', '删除商品', '商品管理', '删除商品', NOW(), NOW(), 0),
|
||||
('product:category:manage', '管理商品分类', '商品管理', '管理商品分类', NOW(), NOW(), 0),
|
||||
|
||||
-- 店铺管理权限
|
||||
('shop:view', '查看店铺', '店铺管理', '查看店铺列表和详情', NOW(), NOW(), 0),
|
||||
('shop:create', '新增店铺', '店铺管理', '新增店铺', NOW(), NOW(), 0),
|
||||
('shop:edit', '编辑店铺', '店铺管理', '编辑店铺信息', NOW(), NOW(), 0),
|
||||
('shop:delete', '删除店铺', '店铺管理', '删除店铺', NOW(), NOW(), 0),
|
||||
('shop:staff:manage', '管理店铺员工', '店铺管理', '管理店铺员工', NOW(), NOW(), 0),
|
||||
|
||||
-- 权限管理权限
|
||||
('permission:view', '查看权限', '权限管理', '查看权限列表', NOW(), NOW(), 0),
|
||||
('permission:create', '新增权限', '权限管理', '新增系统权限', NOW(), NOW(), 0),
|
||||
('permission:edit', '编辑权限', '权限管理', '编辑系统权限', NOW(), NOW(), 0),
|
||||
('permission:delete', '删除权限', '权限管理', '删除系统权限', NOW(), NOW(), 0),
|
||||
('permission:assign', '分配权限', '权限管理', '为用户分配权限', NOW(), NOW(), 0),
|
||||
|
||||
-- 标签管理权限
|
||||
('tag:view', '查看标签', '标签管理', '查看标签列表和详情', NOW(), NOW(), 0),
|
||||
('tag:create', '新增标签', '标签管理', '新增标签', NOW(), NOW(), 0),
|
||||
('tag:edit', '编辑标签', '标签管理', '编辑标签信息', NOW(), NOW(), 0),
|
||||
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0),
|
||||
('tag:assign', '分配标签', '标签管理', '为商品分配标签', NOW(), NOW(), 0),
|
||||
|
||||
-- 优惠券管理权限
|
||||
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券列表和详情', NOW(), NOW(), 0),
|
||||
('coupon:create', '新增优惠券', '优惠券管理', '新增优惠券', NOW(), NOW(), 0),
|
||||
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券信息', NOW(), NOW(), 0),
|
||||
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券', NOW(), NOW(), 0),
|
||||
('coupon:assign', '分配优惠券', '优惠券管理', '为用户分配优惠券', NOW(), NOW(), 0),
|
||||
|
||||
-- 订单管理权限
|
||||
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
|
||||
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
|
||||
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
|
||||
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
|
||||
|
||||
-- 初始化admin用户,密码为123456
|
||||
-- 密码使用BCrypt加密,123456的加密值为:$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW
|
||||
INSERT INTO t_user (id, shop_id, nickname, account, password, type, status, create_time, update_time, is_delete) VALUES
|
||||
(1, 0, '管理员', 'admin', '$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW', 4, 1, NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员分配权限
|
||||
-- 首页的全部权限
|
||||
-- 仪表盘的全部权限
|
||||
-- 所有店铺的用户管理的全部权限
|
||||
-- 所有店铺的商品管理的查看权限,无新增编辑删除管理商品分类权限
|
||||
-- 所有店铺的店铺管理的全部权限
|
||||
-- 所有店铺的权限管理的全部权限
|
||||
-- 所有店铺的标签管理的查看权限
|
||||
-- 所有店铺的优惠券管理的查看权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by)
|
||||
SELECT
|
||||
1 as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time,
|
||||
1 as create_by
|
||||
FROM t_permission p
|
||||
WHERE p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:edit',
|
||||
'user:reset_password',
|
||||
'user:delete',
|
||||
'product:view',
|
||||
'shop:view',
|
||||
'shop:create',
|
||||
'shop:edit',
|
||||
'shop:delete',
|
||||
'shop:staff:manage',
|
||||
'permission:view',
|
||||
'permission:create',
|
||||
'permission:edit',
|
||||
'permission:delete',
|
||||
'permission:assign',
|
||||
'tag:view',
|
||||
'coupon:view'
|
||||
);
|
||||
|
||||
-- 注意:店长和美甲师的权限需要在系统中手动分配,因为需要关联具体的店铺
|
||||
-- 这里只初始化管理员的权限
|
||||
@@ -0,0 +1,600 @@
|
||||
# 项目架构分析
|
||||
|
||||
## 1. 项目结构
|
||||
|
||||
### 1.1 目录结构
|
||||
|
||||
```
|
||||
├── Frontend/ # 前端项目
|
||||
│ ├── src/
|
||||
│ │ ├── api/ # API请求封装
|
||||
│ │ ├── router/ # 路由配置
|
||||
│ │ ├── utils/ # 工具函数
|
||||
│ │ └── views/ # 页面组件
|
||||
├── YumiNail-Gateway/ # 网关服务
|
||||
│ └── src/main/java/com/xiaowang/yumitailgateway/
|
||||
│ ├── filter/ # 全局过滤器
|
||||
│ └── config/ # 网关配置
|
||||
├── YumiNail-Core/ # 核心业务服务
|
||||
│ └── src/main/java/com/xiaowang/yuminailcore/
|
||||
│ ├── config/ # 配置类
|
||||
│ ├── controller/ # 控制器
|
||||
│ ├── service/ # 业务逻辑
|
||||
│ └── utils/ # 工具类
|
||||
└── MessageHub/ # 消息推送服务
|
||||
```
|
||||
|
||||
## 2. 前后端交互逻辑
|
||||
|
||||
### 2.1 前端请求流程
|
||||
|
||||
1. **API请求封装**:
|
||||
- 前端使用axios创建API实例,配置baseURL为`http://wcy111.top:8088/api`
|
||||
- 请求拦截器会在请求头中添加Authorization token
|
||||
- 响应拦截器会处理错误和token过期逻辑
|
||||
|
||||
2. **Token管理**:
|
||||
- 前端使用双token模式:accessToken(2小时过期)和refreshToken(7天过期)
|
||||
- Token存储在localStorage和sessionStorage中
|
||||
- 当accessToken过期时,会自动使用refreshToken刷新
|
||||
|
||||
3. **路由守卫**:
|
||||
- 前端路由守卫会检查用户是否登录
|
||||
- 对于管理员路由,会检查adminAccessToken
|
||||
- 对于需要权限的页面,会检查用户是否拥有对应权限
|
||||
|
||||
### 2.2 后端处理流程
|
||||
|
||||
1. **网关过滤**:
|
||||
- 网关的AuthGlobalFilter会首先检查请求是否在白名单中
|
||||
- 对于非白名单请求,会检查Authorization header
|
||||
- 网关只做基本的token格式检查,具体验证由核心服务处理
|
||||
|
||||
2. **核心服务验证**:
|
||||
- AuthInterceptor会进一步验证token的有效性
|
||||
- 验证token是否过期、是否为accessToken类型
|
||||
- 从token中提取用户信息并设置到请求属性中
|
||||
|
||||
3. **权限控制**:
|
||||
- 后端使用@RequirePermission注解进行权限控制
|
||||
- 权限验证由PermissionAspect切面处理
|
||||
|
||||
## 3. 白名单逻辑
|
||||
|
||||
### 3.1 前端白名单
|
||||
|
||||
在`Frontend/src/api/index.ts`中定义:
|
||||
|
||||
```typescript
|
||||
const isWhitelistedPath = (url: string) => {
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/shop/list/simple') ||
|
||||
url?.includes('/admin/login')
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 网关白名单
|
||||
|
||||
在`YumiNail-Gateway/src/main/java/com/xiaowang/yumitailgateway/filter/AuthGlobalFilter.java`中定义:
|
||||
|
||||
```java
|
||||
private boolean isWhitelist(String path) {
|
||||
return path.equals("/api/user/login") ||
|
||||
path.equals("/api/user/register") ||
|
||||
path.equals("/api/user/refresh-token") ||
|
||||
path.equals("/api/shop/list/simple") ||
|
||||
path.equals("/api/admin/auth/login") ||
|
||||
path.equals("/admin/api/auth/login") ||
|
||||
path.startsWith("/api/user/get/account") ||
|
||||
path.startsWith("/api/health");
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 核心服务白名单
|
||||
|
||||
在`YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/config/AuthInterceptor.java`中定义:
|
||||
|
||||
```java
|
||||
private boolean isWhitelistedPath(String path) {
|
||||
return path.contains("/user/login") ||
|
||||
path.contains("/user/register") ||
|
||||
path.contains("/user/refresh-token") ||
|
||||
path.contains("/user/get/account") ||
|
||||
path.contains("/shop/list/simple") ||
|
||||
path.contains("/admin/auth/login") ||
|
||||
path.contains("/admin/object-storage-file/upload") ||
|
||||
path.contains("/health") ||
|
||||
path.contains("/error");
|
||||
}
|
||||
```
|
||||
|
||||
## 4. 权限控制体系
|
||||
|
||||
### 4.1 前端权限控制
|
||||
|
||||
1. **权限加载**:
|
||||
- 使用`usePermission` composable加载用户权限
|
||||
- 权限信息存储在localStorage中
|
||||
|
||||
2. **路由权限检查**:
|
||||
- 路由守卫会检查用户是否拥有对应权限
|
||||
- 对于没有权限的用户,会重定向到管理员首页
|
||||
|
||||
3. **页面权限控制**:
|
||||
- 使用`hasPermission`等方法检查用户权限
|
||||
- 基于权限控制页面元素的显示/隐藏
|
||||
|
||||
### 4.2 后端权限控制
|
||||
|
||||
1. **注解式权限控制**:
|
||||
- 使用`@RequirePermission`注解标记需要权限的方法
|
||||
- 权限检查由PermissionAspect切面处理
|
||||
|
||||
2. **权限验证流程**:
|
||||
- 从请求中获取用户信息
|
||||
- 检查用户是否拥有对应权限
|
||||
- 无权限时返回403错误
|
||||
|
||||
## 5. 安全机制
|
||||
|
||||
### 5.1 Token安全
|
||||
|
||||
1. **JWT Token**:
|
||||
- 使用HS512算法签名
|
||||
- 包含用户ID、账号和token类型
|
||||
- 设置合理的过期时间
|
||||
|
||||
2. **双Token机制**:
|
||||
- accessToken用于API访问(2小时过期)
|
||||
- refreshToken用于刷新accessToken(7天过期)
|
||||
- 提高安全性的同时保证用户体验
|
||||
|
||||
### 5.2 密码安全
|
||||
|
||||
- 密码加密存储
|
||||
- 登录失败次数限制
|
||||
- 密码复杂度要求
|
||||
|
||||
### 5.3 接口安全
|
||||
|
||||
- 所有非白名单接口都需要token验证
|
||||
- 权限控制确保用户只能访问有权限的接口
|
||||
- 输入参数验证防止恶意输入
|
||||
|
||||
## 6. 消息推送系统
|
||||
|
||||
### 6.1 架构设计
|
||||
|
||||
- 基于RabbitMQ的消息队列
|
||||
- 支持邮件、短信等多种推送方式
|
||||
- 可配置的推送模板
|
||||
|
||||
### 6.2 核心功能
|
||||
|
||||
- 消息发送和接收
|
||||
- 推送日志记录
|
||||
- 多渠道推送支持
|
||||
|
||||
## 7. 数据库设计
|
||||
|
||||
### 7.1 数据库配置
|
||||
|
||||
- **地址**:wcy111.top:3306
|
||||
- **用户**:root
|
||||
- **密码**:125503wcy
|
||||
- **数据库**:nailart
|
||||
|
||||
### 7.2 表结构设计
|
||||
|
||||
#### 7.2.1 用户相关表
|
||||
|
||||
1. **t_user** - 系统用户信息表
|
||||
- id:用户唯一主键ID(雪花ID)
|
||||
- shop_id:所属店铺ID
|
||||
- nickname:用户昵称
|
||||
- account:用户账号(登录用)
|
||||
- phone:手机号
|
||||
- email:邮箱
|
||||
- phone_verified:手机号是否已验证
|
||||
- email_verified:邮箱是否已验证
|
||||
- password:用户密码(加密存储)
|
||||
- signature:用户签名
|
||||
- level:用户等级
|
||||
- type:用户类型(0-用户,2-店长,3-美甲师,4-管理员)
|
||||
- vip_id:关联VIP信息表主键
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
- status:用户状态
|
||||
- avatar:头像链接
|
||||
|
||||
2. **t_user_permission** - 用户权限关联表
|
||||
- id:关联ID
|
||||
- user_id:用户ID
|
||||
- permission_id:权限ID
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- create_by:创建人ID
|
||||
- update_by:更新人ID
|
||||
- is_delete:逻辑删除
|
||||
|
||||
3. **t_login_identity** - 用户登录标识信息表
|
||||
- id:登录标识唯一主键ID
|
||||
- user_id:关联用户表主键
|
||||
- login_method:登录方式(0-手机号、1-账号、2-邮箱)
|
||||
- input_value:前端输入的具体值
|
||||
- input_time:输入时间
|
||||
- update_time:更新时间
|
||||
- status:状态
|
||||
|
||||
#### 7.2.2 店铺相关表
|
||||
|
||||
1. **t_shop** - 店铺信息表
|
||||
- id:店铺唯一主键ID
|
||||
- shop_name:店铺名称
|
||||
- description:店铺描述
|
||||
- address:店铺地址
|
||||
- business_hours:店铺营业时间
|
||||
- cover_image_file_id:店铺封面图文件ID
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
- image_file_ids:图片文件ID集合
|
||||
|
||||
#### 7.2.3 商品相关表
|
||||
|
||||
1. **t_product** - 商品信息表
|
||||
- id:商品唯一主键ID(雪花id)
|
||||
- shop_id:所属店铺ID
|
||||
- title:商品标题
|
||||
- description:商品描述
|
||||
- image_file_ids:图片文件ID集合
|
||||
- price:商品价格
|
||||
- tags:标签集合
|
||||
- like_count:商品点赞数
|
||||
- collect_count:商品收藏数
|
||||
- approximate_duration:商品对应的服务大约耗时
|
||||
- bookable_artists:可预约的美甲师ID集合
|
||||
- available_coupons:可用的优惠券ID集合
|
||||
- create_time:商品创建时间
|
||||
- update_time:商品信息最后更新时间
|
||||
- is_delete:逻辑删除标识
|
||||
|
||||
2. **t_effect_diagram** - 商品效果图信息表
|
||||
- id:效果图唯一主键ID(雪花id)
|
||||
- product_id:所属商品ID
|
||||
- category:效果图类别
|
||||
- image_file_ids:图片文件ID集合
|
||||
- description:效果图描述
|
||||
- price:效果图对应服务价格
|
||||
- duration:效果图对应服务耗时
|
||||
- tag:效果图标签
|
||||
- like_count:效果图点赞数
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
|
||||
#### 7.2.4 订单相关表
|
||||
|
||||
1. **t_order** - 订单表
|
||||
- id:订单唯一主键ID
|
||||
- order_no:订单编号
|
||||
- user_id:关联用户表主键
|
||||
- total_amount:订单总金额
|
||||
- actual_amount:实际支付金额
|
||||
- coupon_id:使用的优惠券ID
|
||||
- status:订单状态(1-待使用,2-已完成,3-已取消)
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
|
||||
2. **t_order_item** - 订单商品表
|
||||
- id:订单商品唯一主键ID
|
||||
- order_id:关联订单表主键
|
||||
- product_id:关联商品表主键
|
||||
- quantity:商品数量
|
||||
- price:商品单价
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
|
||||
3. **t_cart** - 购物车表
|
||||
- id:购物车唯一主键ID
|
||||
- user_id:关联用户表主键
|
||||
- product_id:关联商品表主键
|
||||
- quantity:商品数量
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
|
||||
#### 7.2.5 优惠券相关表
|
||||
|
||||
1. **t_coupon** - 优惠券信息表
|
||||
- id:优惠券唯一主键ID
|
||||
- coupon_code:优惠券编码
|
||||
- coupon_name:优惠券名称
|
||||
- coupon_type:优惠券类型(1-折扣券,2-满减券)
|
||||
- discount_value:折扣值
|
||||
- min_amount:满减券最低消费金额
|
||||
- reduce_amount:满减券减免金额
|
||||
- total_count:优惠券总数量
|
||||
- used_count:已使用数量
|
||||
- start_time:开始时间
|
||||
- end_time:结束时间
|
||||
- status:状态
|
||||
- shop_id:所属店铺ID
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
|
||||
2. **t_user_coupon** - 用户优惠券关联表
|
||||
- id:用户优惠券关联唯一主键ID
|
||||
- user_id:关联用户表主键
|
||||
- coupon_id:关联优惠券表主键
|
||||
- status:状态(1-未使用,2-已使用,3-已过期)
|
||||
- obtain_time:获取时间
|
||||
- use_time:使用时间
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
|
||||
3. **t_coupon_tag** - 优惠券标签关联表
|
||||
- id:优惠券标签关联唯一主键ID
|
||||
- coupon_id:关联优惠券表主键
|
||||
- tag_id:关联标签表主键
|
||||
- is_available:是否可用
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
|
||||
#### 7.2.6 财务相关表
|
||||
|
||||
1. **t_balance** - 用户余额信息表
|
||||
- id:余额记录唯一主键ID(雪花ID)
|
||||
- user_id:关联用户表主键
|
||||
- amount:当前余额
|
||||
- create_time:余额账户创建时间
|
||||
- last_update_time:最近一次更新时间
|
||||
|
||||
2. **t_balance_change_detail** - 用户余额变动明细表
|
||||
- id:变动记录唯一主键ID(雪花ID)
|
||||
- user_id:关联用户表主键
|
||||
- amount:本次变动金额
|
||||
- type:变动类型
|
||||
- current_balance:变动后的当前余额
|
||||
- change_time:变动时间
|
||||
|
||||
#### 7.2.7 其他表
|
||||
|
||||
1. **t_permission** - 系统权限表
|
||||
- id:权限唯一主键ID
|
||||
- permission_code:权限编码
|
||||
- permission_name:权限名称
|
||||
- permission_group:权限分组
|
||||
- description:权限描述
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
|
||||
2. **t_tag** - 系统标签信息表
|
||||
- id:标签唯一主键ID
|
||||
- tag_name:标签名称
|
||||
- text_color:标签文字颜色
|
||||
- bg_color:标签背景颜色
|
||||
- border_color:标签边框颜色
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
- is_delete:逻辑删除
|
||||
- shop_id:店铺ID
|
||||
|
||||
3. **t_comment** - 用户评论信息表
|
||||
- id:评论唯一主键ID(雪花ID)
|
||||
- user_id:评论用户ID
|
||||
- shop_id:关联店铺表主键
|
||||
- product_id:关联商品表主键
|
||||
- comment_content:评论内容
|
||||
- parent_comment_id:父级评论ID
|
||||
- like_count:评论点赞数
|
||||
- create_time:评论创建时间
|
||||
- update_time:评论更新时间
|
||||
- is_delete:逻辑删除标识
|
||||
|
||||
4. **t_object_storage_file** - 对象存储文件信息表
|
||||
- id:文件记录唯一主键ID(雪花ID)
|
||||
- file_name:文件名称
|
||||
- file_url:文件访问链接
|
||||
- create_time:文件上传时间
|
||||
- update_time:文件更新时间
|
||||
- status:文件状态
|
||||
- delete_time:文件删除时间
|
||||
- recycle_time:文件移入回收站时间
|
||||
|
||||
5. **t_vip_info** - 用户VIP信息表
|
||||
- id:VIP信息唯一主键ID(雪花ID)
|
||||
- vip_level:VIP等级
|
||||
- start_time:VIP开通时间
|
||||
- expire_time:VIP到期时间
|
||||
- activation_method:VIP开通方式
|
||||
- benefit_id:关联VIP权益信息表主键
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
|
||||
6. **t_vip_benefit** - VIP权益信息表
|
||||
- id:VIP权益唯一主键ID(雪花ID)
|
||||
- benefit_info:权益详情
|
||||
- required_vip_level:所需VIP等级
|
||||
- create_time:创建时间
|
||||
- update_time:更新时间
|
||||
|
||||
### 7.3 数据库关系
|
||||
|
||||
1. **用户与权限**:t_user ↔ t_user_permission ↔ t_permission
|
||||
2. **用户与店铺**:t_user → t_shop
|
||||
3. **店铺与商品**:t_shop → t_product
|
||||
4. **商品与效果图**:t_product → t_effect_diagram
|
||||
5. **用户与订单**:t_user → t_order → t_order_item → t_product
|
||||
6. **用户与购物车**:t_user → t_cart → t_product
|
||||
7. **用户与优惠券**:t_user → t_user_coupon → t_coupon
|
||||
8. **用户与余额**:t_user → t_balance → t_balance_change_detail
|
||||
9. **用户与评论**:t_user → t_comment → t_product/t_shop
|
||||
10. **商品与标签**:t_product → t_tag
|
||||
11. **优惠券与标签**:t_coupon → t_coupon_tag → t_tag
|
||||
12. **用户与VIP**:t_user → t_vip_info → t_vip_benefit
|
||||
|
||||
### 7.4 索引设计
|
||||
|
||||
1. **用户表**:uk_account(账号唯一索引)、idx_phone、idx_email、idx_shop_id、idx_type
|
||||
2. **商品表**:idx_shop_id、idx_price、idx_title、idx_tags
|
||||
3. **订单表**:uk_order_no(订单编号唯一索引)、idx_user_id、idx_status
|
||||
4. **优惠券表**:uk_coupon_code(优惠券编码唯一索引)、idx_shop_id、idx_status
|
||||
5. **评论表**:idx_user_id、idx_shop_id、idx_product_id、idx_parent_comment_id
|
||||
6. **余额变动表**:idx_user_id、idx_change_time
|
||||
7. **用户权限表**:uk_user_permission(用户-权限唯一索引)、idx_user_id、idx_permission_id
|
||||
|
||||
### 7.5 初始化数据
|
||||
|
||||
1. **系统权限**:初始化了完整的系统权限,包括首页、仪表盘、用户管理、商品管理、店铺管理、权限管理、标签管理、优惠券管理、订单管理等模块的权限
|
||||
|
||||
2. **管理员用户**:初始化了admin用户,密码为123456(使用BCrypt加密)
|
||||
|
||||
3. **管理员权限**:为管理员分配了基本的权限,包括查看首页、仪表盘、用户管理、商品查看、店铺管理、权限管理、标签查看、优惠券查看、订单查看等权限
|
||||
|
||||
## 8. 总结
|
||||
|
||||
### 8.1 优势
|
||||
|
||||
1. **清晰的架构设计**:
|
||||
- 前后端分离架构
|
||||
- 微服务拆分合理
|
||||
- 代码组织规范
|
||||
|
||||
2. **完善的安全机制**:
|
||||
- 双Token认证
|
||||
- 细粒度权限控制
|
||||
- 多层白名单保护
|
||||
|
||||
3. **良好的用户体验**:
|
||||
- 自动token刷新
|
||||
- 权限控制平滑
|
||||
- 错误处理友好
|
||||
|
||||
4. **完整的数据库设计**:
|
||||
- 合理的表结构设计
|
||||
- 完善的索引设计
|
||||
- 清晰的数据库关系
|
||||
|
||||
### 8.2 改进空间
|
||||
|
||||
1. **白名单管理**:
|
||||
- 白名单分散在多个地方,建议集中管理
|
||||
- 可以考虑使用配置文件或数据库存储白名单
|
||||
|
||||
2. **权限管理**:
|
||||
- 权限粒度可以更细
|
||||
- 可以增加角色管理功能
|
||||
|
||||
3. **安全性增强**:
|
||||
- 考虑使用HTTPS
|
||||
- 增加API请求频率限制
|
||||
- 加强输入验证
|
||||
|
||||
4. **监控和日志**:
|
||||
- 增加API调用监控
|
||||
- 完善日志记录
|
||||
- 添加异常预警机制
|
||||
|
||||
5. **数据库优化**:
|
||||
- 考虑添加更多索引以提高查询性能
|
||||
- 可以使用数据库连接池优化
|
||||
- 定期进行数据库备份
|
||||
|
||||
### 8.3 技术栈
|
||||
|
||||
- **前端**:Vue 3 + TypeScript + Ant Design Vue
|
||||
- **后端**:Spring Boot + Spring Cloud Gateway + MyBatis Plus
|
||||
- **数据库**:MySQL
|
||||
- **消息队列**:RabbitMQ
|
||||
- **认证**:JWT
|
||||
- **存储**:Minio(对象存储)
|
||||
|
||||
## 9. 核心API说明
|
||||
|
||||
### 9.1 认证相关
|
||||
|
||||
- `POST /api/user/login` - 用户登录
|
||||
- `POST /api/user/register` - 用户注册
|
||||
- `POST /api/user/refresh-token` - 刷新token
|
||||
- `POST /api/admin/auth/login` - 管理员登录
|
||||
|
||||
### 9.2 业务相关
|
||||
|
||||
- `GET /api/shop/list/simple` - 获取店铺列表(无需登录)
|
||||
- `GET /api/product/list` - 获取产品列表
|
||||
- `POST /api/cart/add` - 添加购物车
|
||||
- `POST /api/order/create` - 创建订单
|
||||
- `GET /api/user/profile` - 获取用户信息
|
||||
|
||||
### 9.3 管理相关
|
||||
|
||||
- `GET /api/admin/dashboard` - 管理员仪表盘
|
||||
- `GET /api/admin/users` - 获取用户列表
|
||||
- `GET /api/admin/products` - 获取产品列表
|
||||
- `GET /api/admin/shops` - 获取店铺列表
|
||||
- `GET /api/admin/permissions` - 获取权限列表
|
||||
|
||||
### 9.4 权限分配
|
||||
- 管理员:
|
||||
首页的全部权限
|
||||
仪表盘的全部权限
|
||||
所有店铺的用户管理的全部权限
|
||||
所有店铺的商品管理的查看权限,无新增编辑删除管理商品分类权限
|
||||
所有店铺的店铺管理的全部权限
|
||||
所有店铺的订单管理的查看权限
|
||||
所有店铺的权限管理的全部权限
|
||||
所有店铺的标签管理的查看权限无新增编辑删除权限
|
||||
所有店铺的优惠券管理的查看权限
|
||||
|
||||
- 店长:
|
||||
首页的全部权限
|
||||
仪表盘的全部权限
|
||||
当前店铺的用户管理的全部权限
|
||||
当前店铺的商品管理的全部权限
|
||||
当前店铺的店铺管理的全部权限
|
||||
当前店铺的订单管理的全部权限
|
||||
当前店铺的权限管理的全部权限
|
||||
当前店铺的标签管理的全部权限
|
||||
当前店铺的优惠券管理的全部权限
|
||||
|
||||
- 美甲师:
|
||||
首页的全部权限
|
||||
仪表盘的全部权限
|
||||
当前店铺的用户管理的查看权限,新增权限,密码重置权限,其他无
|
||||
当前店铺的商品管理的查看权限,新增权限,编辑权限,管理管理分类权限
|
||||
当前店铺的店铺管理的查看权限,无其他权限
|
||||
当前店铺的订单管理的查看权限,无其他权限
|
||||
无当前店铺的权限管理的全部权限
|
||||
当前店铺的标签管理的查看,新增,编辑,分配权限,无删除权限
|
||||
当前店铺的优惠券管理的查看和分配权限,无其他权限
|
||||
|
||||
- 用户:
|
||||
无后台登录权限和对应的所有权限
|
||||
|
||||
|
||||
|
||||
## 10. 部署架构
|
||||
|
||||
- **前端**:部署在静态文件服务器
|
||||
- **网关**:独立部署,作为API入口
|
||||
- **核心服务**:独立部署,处理业务逻辑
|
||||
- **消息服务**:独立部署,处理消息推送
|
||||
- **数据库**:MySQL数据库
|
||||
- **对象存储**:Minio服务
|
||||
- **消息队列**:RabbitMQ服务
|
||||
|
||||
## 11. 结论
|
||||
|
||||
该项目采用了现代化的前后端分离架构,具有完善的认证和授权机制,以及良好的安全设计。通过多层白名单保护和双Token认证,确保了系统的安全性。同时,清晰的代码组织和合理的服务拆分,为系统的可维护性和扩展性奠定了基础。
|
||||
|
||||
在未来的发展中,可以通过集中管理白名单、增强权限管理、加强安全性和完善监控日志等方面进一步提升系统的可靠性和安全性。
|
||||
Reference in New Issue
Block a user