标签功能初版实现
This commit is contained in:
@@ -20,15 +20,8 @@ import BottomNav from './components/BottomNav.vue'
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
// 计算是否需要隐藏导航栏
|
||||
const isHiddenNav = computed(() => {
|
||||
// 需要隐藏导航栏的页面路径
|
||||
const hiddenNavRoutes = ['/settings']
|
||||
|
||||
// 检查是否是商品详情页(/product/数字)
|
||||
const isProductDetail = /^\/product\/\d+$/.test(route.path)
|
||||
|
||||
return hiddenNavRoutes.some(path => route.path.startsWith(path)) || isProductDetail
|
||||
return route.meta.hideNav as boolean
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import api from './index'
|
||||
|
||||
export interface LoginRequest {
|
||||
account: string
|
||||
password: string
|
||||
rememberMe?: boolean
|
||||
}
|
||||
|
||||
export interface RegisterRequest {
|
||||
account: string
|
||||
password: string
|
||||
nickname: string
|
||||
shopId?: number
|
||||
}
|
||||
|
||||
export interface LoginResponse {
|
||||
accessToken: string
|
||||
refreshToken: string
|
||||
userInfo: UserInfo
|
||||
}
|
||||
|
||||
export interface UserInfo {
|
||||
id: number
|
||||
account: string
|
||||
nickname: string
|
||||
avatar?: string
|
||||
createTime: string
|
||||
}
|
||||
|
||||
export interface RefreshTokenRequest {
|
||||
refreshToken: string
|
||||
}
|
||||
|
||||
export interface RefreshTokenResponse {
|
||||
accessToken: string
|
||||
refreshToken: string
|
||||
}
|
||||
|
||||
export const authApi = {
|
||||
login: (data: LoginRequest) => {
|
||||
return api.post<LoginResponse>('/user/login', data)
|
||||
},
|
||||
|
||||
register: (data: RegisterRequest) => {
|
||||
return api.post('/user/register', data)
|
||||
},
|
||||
|
||||
refreshToken: (data: RefreshTokenRequest) => {
|
||||
return api.post<RefreshTokenResponse>('/user/refresh-token', data)
|
||||
},
|
||||
|
||||
logout: () => {
|
||||
return api.post('/user/logout')
|
||||
},
|
||||
|
||||
getUserInfo: () => {
|
||||
return api.get<UserInfo>('/user/info')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import axios, { AxiosError } from 'axios'
|
||||
import { authApi } from './auth'
|
||||
import router from '../router'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:8088/api',
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
let isRefreshing = false
|
||||
let failedQueue: Array<{
|
||||
resolve: (value?: any) => void
|
||||
reject: (reason?: any) => void
|
||||
}> = []
|
||||
|
||||
const processQueue = (error: any, token: string | null = null) => {
|
||||
failedQueue.forEach(prom => {
|
||||
if (error) {
|
||||
prom.reject(error)
|
||||
} else {
|
||||
prom.resolve(token)
|
||||
}
|
||||
})
|
||||
failedQueue = []
|
||||
}
|
||||
|
||||
api.interceptors.request.use(
|
||||
config => {
|
||||
let token = localStorage.getItem('accessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('accessToken')
|
||||
}
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
api.interceptors.response.use(
|
||||
response => {
|
||||
return response.data.data
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
const originalRequest = error.config as any
|
||||
|
||||
if (error.response?.status === 401 && !originalRequest._retry) {
|
||||
if (isRefreshing) {
|
||||
return new Promise((resolve, reject) => {
|
||||
failedQueue.push({ resolve, reject })
|
||||
}).then(token => {
|
||||
if (token) {
|
||||
originalRequest.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return api(originalRequest)
|
||||
}).catch(err => {
|
||||
return Promise.reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
originalRequest._retry = true
|
||||
isRefreshing = true
|
||||
|
||||
try {
|
||||
const refreshToken = localStorage.getItem('refreshToken')
|
||||
if (!refreshToken) {
|
||||
throw new Error('No refresh token available')
|
||||
}
|
||||
|
||||
const response = await authApi.refreshToken({ refreshToken })
|
||||
const newToken = response.data.accessToken
|
||||
const newRefreshToken = response.data.refreshToken
|
||||
|
||||
localStorage.setItem('accessToken', newToken)
|
||||
localStorage.setItem('refreshToken', newRefreshToken)
|
||||
sessionStorage.setItem('accessToken', newToken)
|
||||
|
||||
processQueue(null, newToken)
|
||||
|
||||
originalRequest.headers.Authorization = `Bearer ${newToken}`
|
||||
return api(originalRequest)
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null)
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
router.push('/auth')
|
||||
return Promise.reject(refreshError)
|
||||
} finally {
|
||||
isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
console.error('API Error:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default api
|
||||
@@ -0,0 +1,59 @@
|
||||
import api from './index'
|
||||
|
||||
export interface ProductVO {
|
||||
id: number
|
||||
shopId: number
|
||||
shopName: string
|
||||
title: string
|
||||
description: string
|
||||
imageFileIds: string
|
||||
imageUrls: string[]
|
||||
price: number
|
||||
tags: string
|
||||
tagList: string[]
|
||||
likeCount: number
|
||||
collectCount: number
|
||||
approximateDuration: string
|
||||
bookableArtists: string
|
||||
availableCoupons: string
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface ProductDTO {
|
||||
shopId: number
|
||||
title: string
|
||||
description: string
|
||||
imageFileIds: string
|
||||
price: number
|
||||
tags: string
|
||||
approximateDuration: string
|
||||
bookableArtists: string
|
||||
availableCoupons: string
|
||||
}
|
||||
|
||||
export const productApi = {
|
||||
getAllProducts: () => {
|
||||
return api.get<ProductVO[]>('/product/list/all')
|
||||
},
|
||||
|
||||
getProductById: (id: number) => {
|
||||
return api.get<ProductVO>(`/product/get/${id}`)
|
||||
},
|
||||
|
||||
getProductsByTag: (tag: string) => {
|
||||
return api.get<ProductVO[]>(`/product/list/tag/${tag}`)
|
||||
},
|
||||
|
||||
createProduct: (data: ProductDTO) => {
|
||||
return api.post<ProductVO>('/product/add', data)
|
||||
},
|
||||
|
||||
updateProduct: (id: number, data: ProductDTO) => {
|
||||
return api.put<ProductVO>(`/product/update/${id}`, data)
|
||||
},
|
||||
|
||||
deleteProduct: (id: number) => {
|
||||
return api.delete(`/product/delete/${id}`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import api from './index'
|
||||
|
||||
export interface ShopVO {
|
||||
id: number
|
||||
shopName: string
|
||||
address: string
|
||||
phone: string
|
||||
businessHours: string
|
||||
description: string
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface ShopSimpleVO {
|
||||
id: number
|
||||
shopName: string
|
||||
}
|
||||
|
||||
export const shopApi = {
|
||||
getAllShops: () => {
|
||||
return api.get<ShopVO[]>('/shop/list/all')
|
||||
},
|
||||
|
||||
getShopsSimple: () => {
|
||||
return api.get<ShopSimpleVO[]>('/shop/list/simple')
|
||||
},
|
||||
|
||||
getShopById: (id: number) => {
|
||||
return api.get<ShopVO>(`/shop/get/${id}`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import api from './index'
|
||||
|
||||
export interface TagVO {
|
||||
id: number
|
||||
tagName: string
|
||||
textColor: string
|
||||
bgColor: string
|
||||
borderColor: string
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface TagDTO {
|
||||
tagName: string
|
||||
textColor: string
|
||||
bgColor: string
|
||||
borderColor: string
|
||||
}
|
||||
|
||||
export const tagApi = {
|
||||
getAllTags: () => {
|
||||
return api.get<TagVO[]>('/tag/list/all')
|
||||
},
|
||||
|
||||
getTagById: (id: number) => {
|
||||
return api.get<TagVO>(`/tag/get/${id}`)
|
||||
},
|
||||
|
||||
createTag: (data: TagDTO) => {
|
||||
return api.post<TagVO>('/tag/add', data)
|
||||
},
|
||||
|
||||
updateTag: (id: number, data: TagDTO) => {
|
||||
return api.put<TagVO>(`/tag/update/${id}`, data)
|
||||
},
|
||||
|
||||
deleteTag: (id: number) => {
|
||||
return api.delete(`/tag/delete/${id}`)
|
||||
}
|
||||
}
|
||||
Vendored
+1
-4
@@ -12,13 +12,10 @@ export {}
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
BottomNav: typeof import('./components/BottomNav.vue')['default']
|
||||
ElAvatar: typeof import('element-plus/es')['ElAvatar']
|
||||
ElBadge: typeof import('element-plus/es')['ElBadge']
|
||||
ElButton: typeof import('element-plus/es')['ElButton']
|
||||
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
|
||||
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||
ElInput: typeof import('element-plus/es')['ElInput']
|
||||
ElRate: typeof import('element-plus/es')['ElRate']
|
||||
ElTag: typeof import('element-plus/es')['ElTag']
|
||||
HelloWorld: typeof import('./components/HelloWorld.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
|
||||
@@ -6,39 +6,65 @@ const router = createRouter({
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: () => import('../views/HomeView.vue')
|
||||
component: () => import('../views/HomeView.vue'),
|
||||
meta: { requiresAuth: false }
|
||||
},
|
||||
{
|
||||
path: '/auth',
|
||||
name: 'auth',
|
||||
component: () => import('../views/AuthView.vue'),
|
||||
meta: { requiresAuth: false, hideNav: true }
|
||||
},
|
||||
{
|
||||
path: '/products',
|
||||
name: 'products',
|
||||
component: () => import('../views/ProductListView.vue')
|
||||
component: () => import('../views/ProductListView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/product/:id',
|
||||
name: 'product-detail',
|
||||
component: () => import('../views/ProductDetailView.vue')
|
||||
component: () => import('../views/ProductDetailView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true }
|
||||
},
|
||||
{
|
||||
path: '/cart',
|
||||
name: 'cart',
|
||||
component: () => import('../views/CartView.vue')
|
||||
component: () => import('../views/CartView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/profile',
|
||||
name: 'profile',
|
||||
component: () => import('../views/ProfileView.vue')
|
||||
component: () => import('../views/ProfileView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/wishlist',
|
||||
name: 'wishlist',
|
||||
component: () => import('../views/WishlistView.vue')
|
||||
component: () => import('../views/WishlistView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/settings',
|
||||
name: 'settings',
|
||||
component: () => import('../views/SettingsView.vue')
|
||||
component: () => import('../views/SettingsView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const token = localStorage.getItem('accessToken')
|
||||
const requiresAuth = to.meta.requiresAuth as boolean
|
||||
|
||||
if (requiresAuth && !token) {
|
||||
next('/auth')
|
||||
} else if (to.path === '/auth' && token) {
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,396 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<div class="auth-container">
|
||||
<div class="logo-section">
|
||||
<div class="logo">Yumi</div>
|
||||
<div class="subtitle">美甲服务平台</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-container">
|
||||
<div
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'login' }"
|
||||
@click="activeTab = 'login'"
|
||||
>
|
||||
登录
|
||||
</div>
|
||||
<div
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'register' }"
|
||||
@click="activeTab = 'register'"
|
||||
>
|
||||
注册
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a-form
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
@finish="handleSubmit"
|
||||
layout="vertical"
|
||||
class="auth-form"
|
||||
>
|
||||
<a-form-item name="account" label="账号">
|
||||
<a-input
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="password" label="密码">
|
||||
<a-input-password
|
||||
v-model:value="formData.password"
|
||||
placeholder="请输入密码"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'register'" name="confirmPassword" label="确认密码">
|
||||
<a-input-password
|
||||
v-model:value="formData.confirmPassword"
|
||||
placeholder="请再次输入密码"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'register'" name="shopId" label="选择店铺">
|
||||
<a-select
|
||||
v-model:value="formData.shopId"
|
||||
placeholder="请选择店铺"
|
||||
size="large"
|
||||
:loading="loadingShops"
|
||||
>
|
||||
<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 v-if="activeTab === 'register'" name="nickname" label="昵称">
|
||||
<a-input
|
||||
v-model:value="formData.nickname"
|
||||
placeholder="请输入昵称"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'login'" style="margin-bottom: 8px">
|
||||
<div class="form-actions">
|
||||
<a-checkbox v-model:checked="formData.rememberMe">记住我</a-checkbox>
|
||||
<a class="forgot-password" @click="handleForgotPassword">忘记密码?</a>
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="loading"
|
||||
>
|
||||
{{ activeTab === 'login' ? '登录' : '注册' }}
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
|
||||
<div class="social-login">
|
||||
<div class="divider">
|
||||
<span>其他登录方式</span>
|
||||
</div>
|
||||
<div class="social-buttons">
|
||||
<a-button shape="circle" size="large" @click="handleWeChatLogin">
|
||||
<WechatOutlined />
|
||||
</a-button>
|
||||
<a-button shape="circle" size="large" @click="handleQQLogin">
|
||||
<QqOutlined />
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { UserOutlined, LockOutlined, WechatOutlined, QqOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { shopApi } from '@/api/shop'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const activeTab = ref<'login' | 'register'>('login')
|
||||
const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const shops = ref<any[]>([])
|
||||
|
||||
const formData = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
nickname: '',
|
||||
shopId: undefined as number | undefined,
|
||||
rememberMe: false
|
||||
})
|
||||
|
||||
const validatePassword = async (_rule: any, value: string) => {
|
||||
if (value.length < 6) {
|
||||
return Promise.reject('密码长度不能少于6位')
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const validateConfirmPassword = async (_rule: any, value: string) => {
|
||||
if (!value) {
|
||||
return Promise.reject('请确认密码')
|
||||
}
|
||||
if (value !== formData.password) {
|
||||
return Promise.reject('两次输入的密码不一致')
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const rules = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
{ validator: validatePassword, trigger: 'blur' }
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: '请确认密码', trigger: 'blur' },
|
||||
{ validator: validateConfirmPassword, trigger: 'blur' }
|
||||
],
|
||||
nickname: [
|
||||
{ required: true, message: '请输入昵称', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '昵称长度在2到20个字符', trigger: 'blur' }
|
||||
],
|
||||
shopId: [
|
||||
{ required: true, message: '请选择店铺', trigger: 'change' }
|
||||
]
|
||||
}
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const response = await shopApi.getShopsSimple()
|
||||
shops.value = response.data || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
message.error('获取店铺列表失败')
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
if (activeTab.value === 'login') {
|
||||
const response = await authApi.login({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
rememberMe: formData.rememberMe
|
||||
})
|
||||
|
||||
const loginData = response as any
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
|
||||
message.success('登录成功')
|
||||
router.push('/products')
|
||||
} else {
|
||||
await authApi.register({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
nickname: formData.nickname,
|
||||
shopId: formData.shopId!
|
||||
})
|
||||
|
||||
message.success('注册成功,请登录')
|
||||
activeTab.value = 'login'
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || (activeTab.value === 'login' ? '登录失败' : '注册失败'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleForgotPassword = () => {
|
||||
message.info('忘记密码功能开发中')
|
||||
}
|
||||
|
||||
const handleWeChatLogin = () => {
|
||||
message.info('微信登录功能开发中')
|
||||
}
|
||||
|
||||
const handleQQLogin = () => {
|
||||
message.info('QQ登录功能开发中')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchShops()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.auth-container {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.logo-section {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 48px;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 16px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.tab-container {
|
||||
display: flex;
|
||||
margin-bottom: 30px;
|
||||
border-bottom: 2px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.tab-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 15px;
|
||||
font-size: 16px;
|
||||
color: #999;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tab-item.active {
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.tab-item.active::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -2px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2px;
|
||||
background: #667eea;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.forgot-password {
|
||||
color: #667eea;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.social-login {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.divider::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 50%;
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
.divider span {
|
||||
background: white;
|
||||
padding: 0 15px;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.social-buttons {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.social-buttons .ant-btn {
|
||||
border-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.social-buttons .ant-btn:hover {
|
||||
border-color: #667eea;
|
||||
color: #667eea;
|
||||
}
|
||||
</style>
|
||||
@@ -45,7 +45,7 @@
|
||||
:min="1"
|
||||
:max="99"
|
||||
size="small"
|
||||
@change="(val) => handleQuantityChange(item, val)"
|
||||
@change="(val: number | null) => handleQuantityChange(item, val)"
|
||||
/>
|
||||
<a-popconfirm
|
||||
title="确定要删除这个商品吗?"
|
||||
|
||||
@@ -6,72 +6,67 @@
|
||||
<div class="back-btn" @click="handleBackClick">
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
</div>
|
||||
<h1>Product Detail</h1>
|
||||
<h1>{{ product.title || '商品详情' }}</h1>
|
||||
<div class="actions">
|
||||
<el-icon @click="handleFavoriteClick"><Star /></el-icon>
|
||||
<el-icon @click="handleFavoriteClick" :style="{ fontSize: '20px' }" :class="{ active: isFavorite }"><Star /></el-icon>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Product Image -->
|
||||
<div class="product-image" :style="{ backgroundColor: product.bgColor }">
|
||||
<span class="product-letter">{{ product.name[0] }}</span>
|
||||
<div class="product-image-container">
|
||||
<img
|
||||
v-if="product.imageUrls && product.imageUrls.length > 0"
|
||||
:src="product.imageUrls[0]"
|
||||
:alt="product.title"
|
||||
class="product-image"
|
||||
/>
|
||||
<div v-else class="product-image-placeholder">
|
||||
<span class="product-letter">{{ product.title ? product.title[0] : '商' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Product Info -->
|
||||
<div class="product-info">
|
||||
<div class="info-header">
|
||||
<h2 class="product-name">{{ product.name }}</h2>
|
||||
<div class="price-tag">${{ product.price }}</div>
|
||||
<h2 class="product-name">{{ product.title }}</h2>
|
||||
<div class="price-tag">¥{{ product.price }}</div>
|
||||
</div>
|
||||
<div class="rating">
|
||||
<el-rate v-model="product.rating" disabled show-score text-color="#ff9900" />
|
||||
<div class="shop-info">
|
||||
<span class="shop-name">{{ product.shopName }}</span>
|
||||
</div>
|
||||
<div class="product-meta">
|
||||
<div class="duration">
|
||||
<el-icon><Clock /></el-icon>
|
||||
<span>{{ product.approximateDuration }}</span>
|
||||
</div>
|
||||
<div class="stats">
|
||||
<span class="like-count">
|
||||
<el-icon><Star /></el-icon>
|
||||
{{ product.likeCount }} 赞
|
||||
</span>
|
||||
<span class="collect-count">
|
||||
<el-icon><Collection /></el-icon>
|
||||
{{ product.collectCount }} 收藏
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tags">
|
||||
<el-tag v-for="(tag, index) in product.tagList" :key="index" size="small" effect="light" style="margin-right: 8px; margin-bottom: 8px">
|
||||
{{ tag }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<p class="description">{{ product.description }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Size Selection -->
|
||||
<div class="size-section">
|
||||
<h3>Size</h3>
|
||||
<div class="size-options">
|
||||
<div v-for="size in sizes" :key="size"
|
||||
class="size-option"
|
||||
:class="{ active: selectedSize === size }"
|
||||
@click="handleSizeClick(size)">
|
||||
{{ size }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Color Selection -->
|
||||
<div class="color-section">
|
||||
<h3>Color</h3>
|
||||
<div class="color-options">
|
||||
<div v-for="color in colors" :key="color.name"
|
||||
class="color-option"
|
||||
:class="{ active: selectedColor === color.name }"
|
||||
:style="{ backgroundColor: color.value }"
|
||||
@click="handleColorClick(color.name)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quantity -->
|
||||
<div class="quantity-section">
|
||||
<h3>Quantity</h3>
|
||||
<div class="quantity-control">
|
||||
<el-button @click="decreaseQuantity" :disabled="quantity <= 1">-</el-button>
|
||||
<span class="quantity">{{ quantity }}</span>
|
||||
<el-button @click="increaseQuantity">+</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="action-buttons">
|
||||
<el-button class="add-cart-btn" @click="handleAddToCart">
|
||||
Add to Cart
|
||||
<el-icon><ShoppingCart /></el-icon>
|
||||
添加到购物车
|
||||
</el-button>
|
||||
<el-button class="buy-now-btn" type="primary" @click="handleBuyNow">
|
||||
Buy Now
|
||||
<el-icon><Right /></el-icon>
|
||||
立即购买
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -79,94 +74,103 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ArrowLeft, Star } from '@element-plus/icons-vue'
|
||||
import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right } from '@element-plus/icons-vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const product = ref({
|
||||
id: 1,
|
||||
name: 'Watch',
|
||||
price: 40,
|
||||
bgColor: '#ffe4d6',
|
||||
rating: 4.5,
|
||||
description: 'This is a premium quality watch with excellent design and durability. Perfect for any occasion.'
|
||||
const product = ref<ProductVO>({
|
||||
id: 0,
|
||||
shopId: 0,
|
||||
shopName: '',
|
||||
title: '',
|
||||
description: '',
|
||||
imageFileIds: '',
|
||||
imageUrls: [],
|
||||
price: 0,
|
||||
tags: '',
|
||||
tagList: [],
|
||||
likeCount: 0,
|
||||
collectCount: 0,
|
||||
approximateDuration: '',
|
||||
bookableArtists: '',
|
||||
availableCoupons: '',
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
const sizes = ['S', 'M', 'L', 'XL']
|
||||
const colors = [
|
||||
{ name: 'red', value: '#ff6b6b' },
|
||||
{ name: 'blue', value: '#4ecdc4' },
|
||||
{ name: 'black', value: '#2c3e50' },
|
||||
{ name: 'white', value: '#ecf0f1' }
|
||||
]
|
||||
const isFavorite = ref(false)
|
||||
|
||||
const selectedSize = ref('M')
|
||||
const selectedColor = ref('black')
|
||||
const quantity = ref(1)
|
||||
|
||||
onMounted(() => {
|
||||
// 从后端获取商品详情
|
||||
const fetchProductDetail = async () => {
|
||||
const productId = route.params.id
|
||||
console.log('产品ID:', productId)
|
||||
})
|
||||
|
||||
try {
|
||||
const response = await productApi.getProductById(Number(productId))
|
||||
|
||||
// 处理返回的数据
|
||||
const productData = response as any
|
||||
product.value = {
|
||||
...productData,
|
||||
imageUrls: productData.imageUrls || [],
|
||||
tagList: productData.tagList || []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取商品详情失败:', error)
|
||||
ElMessage.error('获取商品详情失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackClick = () => {
|
||||
console.log('返回按钮被点击')
|
||||
router.back()
|
||||
}
|
||||
|
||||
const handleFavoriteClick = () => console.log('收藏按钮被点击')
|
||||
|
||||
const handleSizeClick = (size: string) => {
|
||||
console.log('选择尺码:', size)
|
||||
selectedSize.value = size
|
||||
}
|
||||
|
||||
const handleColorClick = (color: string) => {
|
||||
console.log('选择颜色:', color)
|
||||
selectedColor.value = color
|
||||
}
|
||||
|
||||
const decreaseQuantity = () => {
|
||||
if (quantity.value > 1) {
|
||||
quantity.value--
|
||||
console.log('数量减少:', quantity.value)
|
||||
}
|
||||
}
|
||||
|
||||
const increaseQuantity = () => {
|
||||
quantity.value++
|
||||
console.log('数量增加:', quantity.value)
|
||||
const handleFavoriteClick = () => {
|
||||
isFavorite.value = !isFavorite.value
|
||||
console.log('收藏状态:', isFavorite.value)
|
||||
ElMessage.success(isFavorite.value ? '已收藏' : '已取消收藏')
|
||||
}
|
||||
|
||||
const handleAddToCart = () => {
|
||||
console.log('添加到购物车:', {
|
||||
product: product.value,
|
||||
size: selectedSize.value,
|
||||
color: selectedColor.value,
|
||||
quantity: quantity.value
|
||||
})
|
||||
console.log('添加到购物车:', product.value.title)
|
||||
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
||||
}
|
||||
|
||||
const handleBuyNow = () => {
|
||||
console.log('立即购买:', {
|
||||
product: product.value,
|
||||
size: selectedSize.value,
|
||||
color: selectedColor.value,
|
||||
quantity: quantity.value
|
||||
})
|
||||
console.log('立即购买:', product.value.title)
|
||||
// 这里可以跳转到订单确认页面
|
||||
ElMessage.success('跳转到订单确认页面')
|
||||
}
|
||||
|
||||
// 页面挂载时获取商品详情
|
||||
onMounted(() => {
|
||||
fetchProductDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px 20px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
background: white;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
@@ -174,10 +178,13 @@ const handleBuyNow = () => {
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.actions {
|
||||
width: 40px;
|
||||
display: flex;
|
||||
@@ -186,124 +193,153 @@ const handleBuyNow = () => {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
.actions .active {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.product-image-container {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
background: white;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.product-image-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 80px;
|
||||
font-weight: bold;
|
||||
color: rgba(0,0,0,0.1);
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
.product-info {
|
||||
padding: 20px;
|
||||
background: white;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.info-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
font-size: 24px;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
.price-tag {
|
||||
font-size: 24px;
|
||||
color: var(--primary-color);
|
||||
font-size: 22px;
|
||||
color: #ff4d4f;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rating {
|
||||
margin-bottom: 15px;
|
||||
|
||||
.shop-info {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.shop-name {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
background: #f8f8f8;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.product-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
padding: 12px;
|
||||
background: #f8f8f8;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.duration {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.like-count, .collect-count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.tags {
|
||||
margin-bottom: 16px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.description {
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.size-section, .color-section, .quantity-section {
|
||||
padding: 20px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
.size-section h3, .color-section h3, .quantity-section h3 {
|
||||
margin: 0 0 15px 0;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.size-options {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.size-option {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
.size-option.active {
|
||||
border-color: var(--primary-color);
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.color-options {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
}
|
||||
.color-option {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
border: 3px solid transparent;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
.color-option.active {
|
||||
border-color: var(--primary-color);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.quantity-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
}
|
||||
.quantity {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
min-width: 30px;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
padding-bottom: 20px;
|
||||
background: white;
|
||||
margin-top: 10px;
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
z-index: 90;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.add-cart-btn, .buy-now-btn {
|
||||
flex: 1;
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.add-cart-btn {
|
||||
background-color: #f5f5f5;
|
||||
border: none;
|
||||
border: 1px solid #e8e8e8;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.buy-now-btn {
|
||||
background-color: var(--primary-color);
|
||||
background-color: #ff4d4f;
|
||||
border: none;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
@@ -40,47 +40,94 @@
|
||||
@click="handleProductClick(item)"
|
||||
>
|
||||
<!-- 商品图片 -->
|
||||
<div class="product-img" :style="{ backgroundColor: item.bgColor }">
|
||||
<span>{{ item.name[0] }}</span>
|
||||
<div class="product-img">
|
||||
<img
|
||||
v-if="item.imageUrls && item.imageUrls.length > 0"
|
||||
:src="item.imageUrls[0]"
|
||||
:alt="item.title"
|
||||
class="product-image"
|
||||
/>
|
||||
<div v-else class="product-img-placeholder">
|
||||
<span>{{ item.title ? item.title[0] : '商' }}</span>
|
||||
</div>
|
||||
<a-badge
|
||||
v-if="item.tag"
|
||||
:text="item.tag"
|
||||
v-if="item.tagList && item.tagList.length > 0"
|
||||
:text="item.tagList[0]"
|
||||
color="#ff4d4f"
|
||||
class="product-tag"
|
||||
/>
|
||||
</div>
|
||||
<!-- 商品信息 -->
|
||||
<div class="product-info">
|
||||
<p class="name">{{ item.title }}</p>
|
||||
<div class="product-meta">
|
||||
<span class="duration">{{ item.approximateDuration }}</span>
|
||||
<div class="stats">
|
||||
<span class="like-count">{{ item.likeCount }} 赞</span>
|
||||
<span class="collect-count">{{ item.collectCount }} 收藏</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 标签展示 -->
|
||||
<div class="product-tags">
|
||||
<template v-if="item.tags">
|
||||
<a-tag
|
||||
v-for="(tagIdStr, index) in item.tags.split(';')"
|
||||
:key="index"
|
||||
size="small"
|
||||
:style="{
|
||||
marginRight: '4px',
|
||||
marginBottom: '4px',
|
||||
fontSize: '9px',
|
||||
padding: '1px 6px',
|
||||
color: getTagById(Number(tagIdStr))?.textColor || '#333333',
|
||||
backgroundColor: getTagById(Number(tagIdStr))?.bgColor || '#F0F0F0',
|
||||
borderColor: getTagById(Number(tagIdStr))?.borderColor || '#F0F0F0',
|
||||
borderWidth: '1px',
|
||||
borderStyle: 'solid',
|
||||
borderRadius: '8px'
|
||||
}"
|
||||
>
|
||||
{{ getTagById(Number(tagIdStr))?.tagName || `标签${tagIdStr}` }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<a-tag v-else size="small" color="gray" style="font-size: 10px; padding: 2px 6px">
|
||||
无标签
|
||||
</a-tag>
|
||||
</div>
|
||||
<div class="price-row">
|
||||
<p class="price">¥{{ item.price }}</p>
|
||||
<a-button
|
||||
type="primary"
|
||||
size="small"
|
||||
shape="circle"
|
||||
@click.stop="handleAddToCart(item)"
|
||||
>
|
||||
<ShoppingCartOutlined />
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
<!-- 商品信息 -->
|
||||
<div class="product-info">
|
||||
<p class="name">{{ item.name }}</p>
|
||||
<div class="price-row">
|
||||
<p class="price">${{ item.price }}</p>
|
||||
<a-button
|
||||
type="primary"
|
||||
size="small"
|
||||
shape="circle"
|
||||
@click.stop="handleAddToCart(item)"
|
||||
>
|
||||
<ShoppingCartOutlined />
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<div class="load-more">
|
||||
<a-button v-if="hasMore" type="link" @click="handleLoadMore">
|
||||
加载更多 <DownOutlined />
|
||||
</a-button>
|
||||
<a-typography-text v-else type="secondary">没有更多商品了</a-typography-text>
|
||||
</div>
|
||||
<!-- 空状态 -->
|
||||
<div v-if="products.length === 0 && !loading" class="empty-state">
|
||||
<a-typography-text type="secondary">商家暂未上架更多商品</a-typography-text>
|
||||
</div>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<div v-else-if="products.length > 0" class="load-more">
|
||||
<a-button v-if="hasMore" type="link" @click="handleLoadMore">
|
||||
加载更多 <DownOutlined />
|
||||
</a-button>
|
||||
<a-typography-text v-else type="secondary">没有更多商品了</a-typography-text>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
LeftOutlined,
|
||||
@@ -89,28 +136,77 @@ import {
|
||||
DownOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
import { tagApi, type TagVO } from '@/api/tag'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 标签列表
|
||||
const allTags = ref<TagVO[]>([])
|
||||
|
||||
// 当前选中的分类
|
||||
const selectedCategory = ref('全部')
|
||||
|
||||
// 分类列表
|
||||
const categories = ['全部', '电子产品', '服装', '配饰', '家居']
|
||||
const categories = ['全部', '美甲', '美睫', '手足护理', '纹绣']
|
||||
|
||||
// 商品数据
|
||||
const products = ref([
|
||||
{ id: 1, name: 'Watch', price: 40, bgColor: '#ffe4d6', tag: '热销' },
|
||||
{ id: 2, name: 'LG TV', price: 330, bgColor: '#f0d6ff', tag: '新品' },
|
||||
{ id: 3, name: 'Jacket', price: 50, bgColor: '#ffd6e2' },
|
||||
{ id: 4, name: 'Nike Shoes', price: 430, bgColor: '#d6eaff', tag: '限时' },
|
||||
{ id: 5, name: 'Airpods', price: 333, bgColor: '#e2ffd6' },
|
||||
{ id: 6, name: 'Hoodie', price: 50, bgColor: '#d6fff0' }
|
||||
])
|
||||
const products = ref<ProductVO[]>([])
|
||||
|
||||
// 是否还有更多数据
|
||||
const hasMore = ref(true)
|
||||
|
||||
// 加载状态
|
||||
const loading = ref(false)
|
||||
|
||||
// 从后端获取标签列表
|
||||
const fetchTags = async () => {
|
||||
try {
|
||||
const tags = await tagApi.getAllTags()
|
||||
allTags.value = tags as unknown as TagVO[]
|
||||
} catch (error) {
|
||||
console.error('获取标签失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 根据标签ID获取标签信息
|
||||
const getTagById = (tagId: number): TagVO | undefined => {
|
||||
return allTags.value.find((tag: TagVO) => tag.id === tagId)
|
||||
}
|
||||
|
||||
// 从后端获取商品数据
|
||||
const fetchProducts = async () => {
|
||||
if (loading.value) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
let response: any
|
||||
|
||||
if (selectedCategory.value === '全部') {
|
||||
response = await productApi.getAllProducts()
|
||||
} else {
|
||||
response = await productApi.getProductsByTag(selectedCategory.value)
|
||||
}
|
||||
|
||||
// 处理返回的数据
|
||||
console.log('Products response:', response)
|
||||
products.value = (response as ProductVO[]).map(product => ({
|
||||
...product,
|
||||
imageUrls: product.imageUrls || [],
|
||||
tagList: product.tagList || []
|
||||
}))
|
||||
|
||||
console.log('Processed products:', products.value)
|
||||
|
||||
hasMore.value = false
|
||||
} catch (error) {
|
||||
console.error('获取商品失败:', error)
|
||||
message.error('获取商品失败,请稍后重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理返回按钮点击
|
||||
const handleBackClick = () => {
|
||||
console.log('返回按钮被点击')
|
||||
@@ -122,18 +218,19 @@ const handleCategoryClick = (category: string) => {
|
||||
console.log('选择分类:', category)
|
||||
selectedCategory.value = category
|
||||
// 这里可以添加筛选逻辑
|
||||
fetchProducts()
|
||||
}
|
||||
|
||||
// 处理商品卡片点击
|
||||
const handleProductClick = (item: any) => {
|
||||
console.log('商品被点击:', item.name)
|
||||
console.log('商品被点击:', item.title)
|
||||
router.push(`/product/${item.id}`)
|
||||
}
|
||||
|
||||
// 处理添加到购物车
|
||||
const handleAddToCart = (item: any) => {
|
||||
console.log('添加到购物车:', item.name)
|
||||
message.success(`已将 ${item.name} 添加到购物车`)
|
||||
console.log('添加到购物车:', item.title)
|
||||
message.success(`已将 ${item.title} 添加到购物车`)
|
||||
}
|
||||
|
||||
// 处理加载更多
|
||||
@@ -142,6 +239,12 @@ const handleLoadMore = () => {
|
||||
// 这里可以添加加载更多逻辑
|
||||
hasMore.value = false
|
||||
}
|
||||
|
||||
// 页面挂载时获取商品数据
|
||||
onMounted(() => {
|
||||
fetchTags()
|
||||
fetchProducts()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -252,15 +355,27 @@ const handleLoadMore = () => {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 12px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
margin-bottom: 10px;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.product-img-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 40px;
|
||||
font-weight: bold;
|
||||
color: rgba(0,0,0,0.1);
|
||||
margin-bottom: 10px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.product-tag {
|
||||
@@ -285,6 +400,32 @@ const handleLoadMore = () => {
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.product-meta {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-bottom: 6px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.duration {
|
||||
background: #f0f0f0;
|
||||
padding: 2px 8px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.like-count,
|
||||
.collect-count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.price-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -298,8 +439,21 @@ const handleLoadMore = () => {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.product-tags {
|
||||
margin: 8px 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 60px 20px;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -83,7 +83,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, h } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
SettingOutlined,
|
||||
|
||||
@@ -25,7 +25,7 @@ export default defineConfig({
|
||||
configureServer(server) {
|
||||
// 暂时禁用 IP 访问控制,允许所有 IP 访问
|
||||
// 生产环境应该重新启用并配置正确的 IP 列表
|
||||
server.middlewares.use((req, res, next) => {
|
||||
server.middlewares.use((_req, _res, next) => {
|
||||
// 直接允许所有 IP 访问
|
||||
next()
|
||||
})
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
|
||||
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
||||
<druid.version>1.2.23</druid.version>
|
||||
<jwt.version>0.11.5</jwt.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -144,6 +145,25 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.xiaowang.yuminailcore.config;
|
||||
|
||||
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AuthInterceptor implements HandlerInterceptor {
|
||||
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
private static final String AUTHORIZATION_HEADER = "Authorization";
|
||||
private static final String BEARER_PREFIX = "Bearer ";
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String path = request.getRequestURI();
|
||||
|
||||
if (isWhitelistedPath(path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String authHeader = request.getHeader(AUTHORIZATION_HEADER);
|
||||
|
||||
if (authHeader == null || !authHeader.startsWith(BEARER_PREFIX)) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":401,\"message\":\"未提供认证Token\"}");
|
||||
return false;
|
||||
}
|
||||
|
||||
String token = authHeader.substring(BEARER_PREFIX.length());
|
||||
|
||||
if (!jwtUtil.validateToken(token)) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":401,\"message\":\"Token无效或已过期\"}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!jwtUtil.isAccessToken(token)) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":401,\"message\":\"Token类型错误\"}");
|
||||
return false;
|
||||
}
|
||||
|
||||
Long userId = jwtUtil.getUserIdFromToken(token);
|
||||
request.setAttribute("userId", userId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isWhitelistedPath(String path) {
|
||||
return path.contains("/user/login") ||
|
||||
path.contains("/user/register") ||
|
||||
path.contains("/user/refresh-token") ||
|
||||
path.contains("/shop/list/simple");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.xiaowang.yuminailcore.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
private final AuthInterceptor authInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(authInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(
|
||||
"/user/login",
|
||||
"/user/register",
|
||||
"/user/refresh-token",
|
||||
"/shop/list/simple",
|
||||
"/error"
|
||||
);
|
||||
}
|
||||
}
|
||||
+17
-1
@@ -2,12 +2,14 @@ package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.ShopDTO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import com.xiaowang.yuminailcore.service.ShopService;
|
||||
import com.xiaowang.yuminailcore.vo.ShopSimpleVO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 店铺信息表 Controller
|
||||
@@ -94,4 +96,18 @@ public class ShopController {
|
||||
List<ShopVO> shopVOs = shopService.listShopsByShopName(shopName);
|
||||
return Result.success(shopVOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有店铺(仅ID和名称,用于注册页面)
|
||||
*
|
||||
* @return 店铺简单信息列表
|
||||
*/
|
||||
@GetMapping("/list/simple")
|
||||
public Result<List<ShopSimpleVO>> listShopsSimple() {
|
||||
List<ShopVO> shopVOs = shopService.listAllShops();
|
||||
List<ShopSimpleVO> simpleVOs = shopVOs.stream()
|
||||
.map(shop -> new ShopSimpleVO(shop.getId(), shop.getShopName()))
|
||||
.collect(Collectors.toList());
|
||||
return Result.success(simpleVOs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.BindEmailRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RefreshTokenRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -118,4 +125,88 @@ public class UserController {
|
||||
UserVO userVO = userService.getUserByAccount(account);
|
||||
return Result.success(userVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @param loginRequestDTO 登录请求DTO
|
||||
* @return 登录响应VO
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public Result<LoginResponseVO> login(@RequestBody LoginRequestDTO loginRequestDTO) {
|
||||
LoginResponseVO loginResponseVO = userService.login(loginRequestDTO);
|
||||
return Result.success(loginResponseVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param registerRequestDTO 注册请求DTO
|
||||
* @return 是否注册成功
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
public Result<Boolean> register(@RequestBody RegisterRequestDTO registerRequestDTO) {
|
||||
boolean success = userService.register(registerRequestDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
*
|
||||
* @param refreshTokenRequestDTO 刷新Token请求DTO
|
||||
* @return 新的Token
|
||||
*/
|
||||
@PostMapping("/refresh-token")
|
||||
public Result<LoginResponseVO> refreshToken(@RequestBody RefreshTokenRequestDTO refreshTokenRequestDTO) {
|
||||
LoginResponseVO loginResponseVO = userService.refreshToken(refreshTokenRequestDTO.getRefreshToken());
|
||||
return Result.success(loginResponseVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登出
|
||||
*
|
||||
* @return 是否登出成功
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
public Result<Boolean> logout() {
|
||||
boolean success = userService.logout();
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
*
|
||||
* @return 用户VO
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public Result<UserVO> getCurrentUserInfo() {
|
||||
UserVO userVO = userService.getCurrentUserInfo();
|
||||
return Result.success(userVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定手机号
|
||||
*
|
||||
* @param bindPhoneRequestDTO 绑定手机号请求DTO
|
||||
* @return 是否绑定成功
|
||||
*/
|
||||
@PostMapping("/bind-phone")
|
||||
public Result<Boolean> bindPhone(HttpServletRequest request, @RequestBody BindPhoneRequestDTO bindPhoneRequestDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
boolean success = userService.bindPhone(userId, bindPhoneRequestDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定邮箱
|
||||
*
|
||||
* @param bindEmailRequestDTO 绑定邮箱请求DTO
|
||||
* @return 是否绑定成功
|
||||
*/
|
||||
@PostMapping("/bind-email")
|
||||
public Result<Boolean> bindEmail(HttpServletRequest request, @RequestBody BindEmailRequestDTO bindEmailRequestDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
boolean success = userService.bindEmail(userId, bindEmailRequestDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BindEmailRequestDTO {
|
||||
|
||||
private String email;
|
||||
private String code;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BindPhoneRequestDTO {
|
||||
|
||||
private String phone;
|
||||
private String code;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 登录请求 DTO
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-14
|
||||
*/
|
||||
@Data
|
||||
public class LoginRequestDTO {
|
||||
|
||||
private String account;
|
||||
|
||||
private String password;
|
||||
|
||||
private Boolean rememberMe;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 刷新Token请求 DTO
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-14
|
||||
*/
|
||||
@Data
|
||||
public class RefreshTokenRequestDTO {
|
||||
|
||||
private String refreshToken;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 注册请求 DTO
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-14
|
||||
*/
|
||||
@Data
|
||||
public class RegisterRequestDTO {
|
||||
|
||||
private String account;
|
||||
|
||||
private String password;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private Long shopId;
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -36,10 +35,4 @@ public abstract class BaseEntity {
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标识 (0:未删除, 1:已删除)
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -35,6 +36,30 @@ public class UserDO extends BaseEntity {
|
||||
@TableField("account")
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@TableField("phone")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@TableField("email")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号是否已验证:0-未验证,1-已验证
|
||||
*/
|
||||
@TableField("phone_verified")
|
||||
private Integer phoneVerified;
|
||||
|
||||
/**
|
||||
* 邮箱是否已验证:0-未验证,1-已验证
|
||||
*/
|
||||
@TableField("email_verified")
|
||||
private Integer emailVerified;
|
||||
|
||||
/**
|
||||
* 用户密码(加密存储)
|
||||
*/
|
||||
@@ -69,5 +94,6 @@ public class UserDO extends BaseEntity {
|
||||
* 逻辑删除:0-未删,1-已删
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,12 @@ package com.xiaowang.yuminailcore.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindEmailRequestDTO;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
|
||||
import java.util.List;
|
||||
@@ -79,4 +84,60 @@ public interface UserService extends IService<UserDO> {
|
||||
* @return 用户VO
|
||||
*/
|
||||
UserVO getUserByAccount(String account);
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @param loginRequestDTO 登录请求DTO
|
||||
* @return 登录响应VO
|
||||
*/
|
||||
LoginResponseVO login(LoginRequestDTO loginRequestDTO);
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*
|
||||
* @param registerRequestDTO 注册请求DTO
|
||||
* @return 是否注册成功
|
||||
*/
|
||||
boolean register(RegisterRequestDTO registerRequestDTO);
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
*
|
||||
* @param refreshToken 刷新Token
|
||||
* @return 新的Token
|
||||
*/
|
||||
LoginResponseVO refreshToken(String refreshToken);
|
||||
|
||||
/**
|
||||
* 用户登出
|
||||
*
|
||||
* @return 是否登出成功
|
||||
*/
|
||||
boolean logout();
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
*
|
||||
* @return 用户VO
|
||||
*/
|
||||
UserVO getCurrentUserInfo();
|
||||
|
||||
/**
|
||||
* 绑定手机号
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param bindPhoneRequestDTO 绑定手机号请求DTO
|
||||
* @return 是否绑定成功
|
||||
*/
|
||||
boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO);
|
||||
|
||||
/**
|
||||
* 绑定邮箱
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param bindEmailRequestDTO 绑定邮箱请求DTO
|
||||
* @return 是否绑定成功
|
||||
*/
|
||||
boolean bindEmail(Long userId, BindEmailRequestDTO bindEmailRequestDTO);
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.BalanceChangeDetailDO;
|
||||
import com.xiaowang.yuminailcore.dto.BalanceChangeDetailDTO;
|
||||
@@ -76,7 +77,7 @@ public class BalanceChangeDetailServiceImpl extends ServiceImpl<BalanceChangeDet
|
||||
@Override
|
||||
public List<BalanceChangeDetailVO> listBalanceChangeDetailsByUserId(Long userId) {
|
||||
List<BalanceChangeDetailDO> balanceChangeDetailDOs = balanceChangeDetailMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<BalanceChangeDetailDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(BalanceChangeDetailDO.class)
|
||||
.eq(BalanceChangeDetailDO::getUserId, userId)
|
||||
);
|
||||
return balanceChangeDetailDOs.stream()
|
||||
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.BalanceDO;
|
||||
import com.xiaowang.yuminailcore.dto.BalanceDTO;
|
||||
import com.xiaowang.yuminailcore.vo.BalanceVO;
|
||||
import com.xiaowang.yuminailcore.entity.BalanceDO;
|
||||
import com.xiaowang.yuminailcore.mapper.BalanceMapper;
|
||||
import com.xiaowang.yuminailcore.service.BalanceService;
|
||||
import com.xiaowang.yuminailcore.vo.BalanceVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -73,7 +74,7 @@ public class BalanceServiceImpl extends ServiceImpl<BalanceMapper, BalanceDO> im
|
||||
@Override
|
||||
public BalanceVO getBalanceByUserId(Long userId) {
|
||||
BalanceDO balanceDO = balanceMapper.selectOne(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<BalanceDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(BalanceDO.class)
|
||||
.eq(BalanceDO::getUserId, userId)
|
||||
);
|
||||
if (balanceDO == null) {
|
||||
|
||||
+7
-6
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.CommentDO;
|
||||
import com.xiaowang.yuminailcore.dto.CommentDTO;
|
||||
import com.xiaowang.yuminailcore.vo.CommentVO;
|
||||
import com.xiaowang.yuminailcore.entity.CommentDO;
|
||||
import com.xiaowang.yuminailcore.mapper.CommentMapper;
|
||||
import com.xiaowang.yuminailcore.service.CommentService;
|
||||
import com.xiaowang.yuminailcore.vo.CommentVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -82,7 +83,7 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, CommentDO> im
|
||||
@Override
|
||||
public List<CommentVO> listCommentsByUserId(Long userId) {
|
||||
List<CommentDO> commentDOs = commentMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<CommentDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(CommentDO.class)
|
||||
.eq(CommentDO::getUserId, userId)
|
||||
);
|
||||
return commentDOs.stream()
|
||||
@@ -93,7 +94,7 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, CommentDO> im
|
||||
@Override
|
||||
public List<CommentVO> listCommentsByShopId(Long shopId) {
|
||||
List<CommentDO> commentDOs = commentMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<CommentDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(CommentDO.class)
|
||||
.eq(CommentDO::getShopId, shopId)
|
||||
);
|
||||
return commentDOs.stream()
|
||||
@@ -104,7 +105,7 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, CommentDO> im
|
||||
@Override
|
||||
public List<CommentVO> listCommentsByProductId(Long productId) {
|
||||
List<CommentDO> commentDOs = commentMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<CommentDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(CommentDO.class)
|
||||
.eq(CommentDO::getProductId, productId)
|
||||
);
|
||||
return commentDOs.stream()
|
||||
@@ -115,7 +116,7 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, CommentDO> im
|
||||
@Override
|
||||
public List<CommentVO> listCommentsByParentCommentId(Long parentCommentId) {
|
||||
List<CommentDO> commentDOs = commentMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<CommentDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(CommentDO.class)
|
||||
.eq(CommentDO::getParentCommentId, parentCommentId)
|
||||
);
|
||||
return commentDOs.stream()
|
||||
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.EffectDiagramDO;
|
||||
import com.xiaowang.yuminailcore.dto.EffectDiagramDTO;
|
||||
import com.xiaowang.yuminailcore.vo.EffectDiagramVO;
|
||||
import com.xiaowang.yuminailcore.entity.EffectDiagramDO;
|
||||
import com.xiaowang.yuminailcore.mapper.EffectDiagramMapper;
|
||||
import com.xiaowang.yuminailcore.service.EffectDiagramService;
|
||||
import com.xiaowang.yuminailcore.vo.EffectDiagramVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -86,7 +87,7 @@ public class EffectDiagramServiceImpl extends ServiceImpl<EffectDiagramMapper, E
|
||||
@Override
|
||||
public List<EffectDiagramVO> listEffectDiagramsByProductId(Long productId) {
|
||||
List<EffectDiagramDO> effectDiagramDOs = effectDiagramMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<EffectDiagramDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(EffectDiagramDO.class)
|
||||
.eq(EffectDiagramDO::getProductId, productId)
|
||||
);
|
||||
return effectDiagramDOs.stream()
|
||||
@@ -97,7 +98,7 @@ public class EffectDiagramServiceImpl extends ServiceImpl<EffectDiagramMapper, E
|
||||
@Override
|
||||
public List<EffectDiagramVO> listEffectDiagramsByCategory(String category) {
|
||||
List<EffectDiagramDO> effectDiagramDOs = effectDiagramMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<EffectDiagramDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(EffectDiagramDO.class)
|
||||
.eq(EffectDiagramDO::getCategory, category)
|
||||
);
|
||||
return effectDiagramDOs.stream()
|
||||
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.LoginIdentityDO;
|
||||
import com.xiaowang.yuminailcore.dto.LoginIdentityDTO;
|
||||
import com.xiaowang.yuminailcore.vo.LoginIdentityVO;
|
||||
import com.xiaowang.yuminailcore.entity.LoginIdentityDO;
|
||||
import com.xiaowang.yuminailcore.mapper.LoginIdentityMapper;
|
||||
import com.xiaowang.yuminailcore.service.LoginIdentityService;
|
||||
import com.xiaowang.yuminailcore.vo.LoginIdentityVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class LoginIdentityServiceImpl extends ServiceImpl<LoginIdentityMapper, L
|
||||
@Override
|
||||
public List<LoginIdentityVO> listLoginIdentitiesByUserId(Long userId) {
|
||||
List<LoginIdentityDO> loginIdentityDOs = loginIdentityMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<LoginIdentityDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(LoginIdentityDO.class)
|
||||
.eq(LoginIdentityDO::getUserId, userId)
|
||||
);
|
||||
return loginIdentityDOs.stream()
|
||||
@@ -87,7 +88,7 @@ public class LoginIdentityServiceImpl extends ServiceImpl<LoginIdentityMapper, L
|
||||
@Override
|
||||
public List<LoginIdentityVO> listLoginIdentitiesByLoginMethod(String loginMethod) {
|
||||
List<LoginIdentityDO> loginIdentityDOs = loginIdentityMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<LoginIdentityDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(LoginIdentityDO.class)
|
||||
.eq(LoginIdentityDO::getLoginMethod, loginMethod)
|
||||
);
|
||||
return loginIdentityDOs.stream()
|
||||
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.ObjectStorageFileDO;
|
||||
import com.xiaowang.yuminailcore.dto.ObjectStorageFileDTO;
|
||||
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
|
||||
import com.xiaowang.yuminailcore.entity.ObjectStorageFileDO;
|
||||
import com.xiaowang.yuminailcore.mapper.ObjectStorageFileMapper;
|
||||
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
||||
import com.xiaowang.yuminailcore.vo.ObjectStorageFileVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class ObjectStorageFileServiceImpl extends ServiceImpl<ObjectStorageFileM
|
||||
@Override
|
||||
public List<ObjectStorageFileVO> listObjectStorageFilesByStatus(Integer status) {
|
||||
List<ObjectStorageFileDO> objectStorageFileDOs = objectStorageFileMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<ObjectStorageFileDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(ObjectStorageFileDO.class)
|
||||
.eq(ObjectStorageFileDO::getStatus, status)
|
||||
);
|
||||
return objectStorageFileDOs.stream()
|
||||
|
||||
+38
-4
@@ -1,11 +1,15 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.service.ProductService;
|
||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||
import com.xiaowang.yuminailcore.service.TagService;
|
||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||
import com.xiaowang.yuminailcore.vo.TagInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -24,6 +28,7 @@ import java.util.stream.Collectors;
|
||||
public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> implements ProductService {
|
||||
|
||||
private final ProductMapper productMapper;
|
||||
private final TagService tagService;
|
||||
|
||||
@Override
|
||||
public Long createProduct(ProductDTO productDTO) {
|
||||
@@ -90,7 +95,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
@Override
|
||||
public List<ProductVO> listProductsByShopId(Long shopId) {
|
||||
List<ProductDO> productDOs = productMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<ProductDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(ProductDO.class)
|
||||
.eq(ProductDO::getShopId, shopId)
|
||||
);
|
||||
return productDOs.stream()
|
||||
@@ -101,7 +106,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
@Override
|
||||
public List<ProductVO> listProductsByTag(String tag) {
|
||||
List<ProductDO> productDOs = productMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<ProductDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(ProductDO.class)
|
||||
.like(ProductDO::getTags, tag)
|
||||
);
|
||||
return productDOs.stream()
|
||||
@@ -131,6 +136,35 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
productVO.setAvailableCoupons(productDO.getAvailableCoupons());
|
||||
productVO.setCreateTime(productDO.getCreateTime());
|
||||
productVO.setUpdateTime(productDO.getUpdateTime());
|
||||
|
||||
// 转换标签ID为标签名称列表
|
||||
java.util.List<String> tagNames = new java.util.ArrayList<>();
|
||||
java.util.List<TagInfo> tagInfos = new java.util.ArrayList<>();
|
||||
if (productDO.getTags() != null && !productDO.getTags().isEmpty()) {
|
||||
String[] tagIds = productDO.getTags().split(";");
|
||||
for (String tagIdStr : tagIds) {
|
||||
try {
|
||||
Long tagId = Long.parseLong(tagIdStr.trim());
|
||||
TagVO tagVO = tagService.getTagById(tagId);
|
||||
if (tagVO != null) {
|
||||
tagNames.add(tagVO.getTagName());
|
||||
// 添加标签详情(包含样式信息)
|
||||
TagInfo tagInfo = new TagInfo();
|
||||
tagInfo.setId(tagId);
|
||||
tagInfo.setTagName(tagVO.getTagName());
|
||||
tagInfo.setTextColor(tagVO.getTextColor());
|
||||
tagInfo.setBgColor(tagVO.getBgColor());
|
||||
tagInfo.setBorderColor(tagVO.getBorderColor());
|
||||
tagInfos.add(tagInfo);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略无效的标签ID
|
||||
}
|
||||
}
|
||||
}
|
||||
productVO.setTagList(tagNames);
|
||||
productVO.setTagInfos(tagInfos);
|
||||
|
||||
return productVO;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.ShopDO;
|
||||
import com.xiaowang.yuminailcore.dto.ShopDTO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import com.xiaowang.yuminailcore.entity.ShopDO;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.service.ShopService;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -82,7 +83,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
|
||||
@Override
|
||||
public List<ShopVO> listShopsByShopName(String shopName) {
|
||||
List<ShopDO> shopDOs = shopMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<ShopDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(ShopDO.class)
|
||||
.like(ShopDO::getShopName, shopName)
|
||||
);
|
||||
return shopDOs.stream()
|
||||
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.TagDO;
|
||||
import com.xiaowang.yuminailcore.dto.TagDTO;
|
||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||
import com.xiaowang.yuminailcore.entity.TagDO;
|
||||
import com.xiaowang.yuminailcore.mapper.TagMapper;
|
||||
import com.xiaowang.yuminailcore.service.TagService;
|
||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -80,7 +81,7 @@ public class TagServiceImpl extends ServiceImpl<TagMapper, TagDO> implements Tag
|
||||
@Override
|
||||
public TagVO getTagByTagName(String tagName) {
|
||||
TagDO tagDO = tagMapper.selectOne(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<TagDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(TagDO.class)
|
||||
.eq(TagDO::getTagName, tagName)
|
||||
);
|
||||
if (tagDO == null) {
|
||||
|
||||
+147
-5
@@ -1,14 +1,22 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.dto.BindEmailRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -24,6 +32,7 @@ import java.util.stream.Collectors;
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
@Override
|
||||
public Long createUser(UserDTO userDTO) {
|
||||
@@ -88,7 +97,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
@Override
|
||||
public List<UserVO> listUsersByShopId(Long shopId) {
|
||||
List<UserDO> userDOs = userMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<UserDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getShopId, shopId)
|
||||
);
|
||||
return userDOs.stream()
|
||||
@@ -99,7 +108,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
@Override
|
||||
public List<UserVO> listUsersByType(Integer type) {
|
||||
List<UserDO> userDOs = userMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<UserDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getType, type)
|
||||
);
|
||||
return userDOs.stream()
|
||||
@@ -110,7 +119,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
@Override
|
||||
public UserVO getUserByAccount(String account) {
|
||||
UserDO userDO = userMapper.selectOne(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<UserDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, account)
|
||||
);
|
||||
if (userDO == null) {
|
||||
@@ -139,4 +148,137 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userVO.setUpdateTime(userDO.getUpdateTime());
|
||||
return userVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginResponseVO login(LoginRequestDTO loginRequestDTO) {
|
||||
UserDO userDO = userMapper.selectOne(
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
||||
);
|
||||
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
if (!userDO.getPassword().equals(loginRequestDTO.getPassword())) {
|
||||
throw new RuntimeException("密码错误");
|
||||
}
|
||||
|
||||
String accessToken = jwtUtil.generateAccessToken(userDO.getId(), userDO.getAccount());
|
||||
String refreshToken = jwtUtil.generateRefreshToken(userDO.getId(), userDO.getAccount());
|
||||
|
||||
LoginResponseVO responseVO = new LoginResponseVO();
|
||||
responseVO.setAccessToken(accessToken);
|
||||
responseVO.setRefreshToken(refreshToken);
|
||||
|
||||
LoginResponseVO.UserInfo userInfo = new LoginResponseVO.UserInfo();
|
||||
userInfo.setId(userDO.getId());
|
||||
userInfo.setAccount(userDO.getAccount());
|
||||
userInfo.setNickname(userDO.getNickname());
|
||||
userInfo.setType(userDO.getType());
|
||||
userInfo.setCreateTime(userDO.getCreateTime());
|
||||
responseVO.setUserInfo(userInfo);
|
||||
|
||||
return responseVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(RegisterRequestDTO registerRequestDTO) {
|
||||
UserDO existingUser = userMapper.selectOne(
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, registerRequestDTO.getAccount())
|
||||
);
|
||||
|
||||
if (existingUser != null) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
}
|
||||
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setShopId(registerRequestDTO.getShopId());
|
||||
userDO.setAccount(registerRequestDTO.getAccount());
|
||||
userDO.setPassword(registerRequestDTO.getPassword());
|
||||
userDO.setNickname(registerRequestDTO.getNickname());
|
||||
userDO.setType(Integer.valueOf(0));
|
||||
userDO.setLevel("普通");
|
||||
userDO.setIsDelete(Integer.valueOf(0));
|
||||
userDO.setCreateTime(LocalDateTime.now());
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
userMapper.insert(userDO);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginResponseVO refreshToken(String refreshToken) {
|
||||
if (!jwtUtil.validateToken(refreshToken)) {
|
||||
throw new RuntimeException("刷新Token无效或已过期");
|
||||
}
|
||||
|
||||
if (!jwtUtil.isRefreshToken(refreshToken)) {
|
||||
throw new RuntimeException("Token类型错误");
|
||||
}
|
||||
|
||||
Long userId = jwtUtil.getUserIdFromToken(refreshToken);
|
||||
String account = jwtUtil.getAccountFromToken(refreshToken);
|
||||
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
String newAccessToken = jwtUtil.generateAccessToken(userId, account);
|
||||
String newRefreshToken = jwtUtil.generateRefreshToken(userId, account);
|
||||
|
||||
LoginResponseVO responseVO = new LoginResponseVO();
|
||||
responseVO.setAccessToken(newAccessToken);
|
||||
responseVO.setRefreshToken(newRefreshToken);
|
||||
|
||||
LoginResponseVO.UserInfo userInfo = new LoginResponseVO.UserInfo();
|
||||
userInfo.setId(userDO.getId());
|
||||
userInfo.setAccount(userDO.getAccount());
|
||||
userInfo.setNickname(userDO.getNickname());
|
||||
userInfo.setType(userDO.getType());
|
||||
userInfo.setCreateTime(userDO.getCreateTime());
|
||||
responseVO.setUserInfo(userInfo);
|
||||
|
||||
return responseVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean logout() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO getCurrentUserInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO) {
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
userDO.setPhone(bindPhoneRequestDTO.getPhone());
|
||||
userDO.setPhoneVerified(1);
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindEmail(Long userId, BindEmailRequestDTO bindEmailRequestDTO) {
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
userDO.setEmail(bindEmailRequestDTO.getEmail());
|
||||
userDO.setEmailVerified(1);
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.VipBenefitDO;
|
||||
import com.xiaowang.yuminailcore.dto.VipBenefitDTO;
|
||||
import com.xiaowang.yuminailcore.vo.VipBenefitVO;
|
||||
import com.xiaowang.yuminailcore.entity.VipBenefitDO;
|
||||
import com.xiaowang.yuminailcore.mapper.VipBenefitMapper;
|
||||
import com.xiaowang.yuminailcore.service.VipBenefitService;
|
||||
import com.xiaowang.yuminailcore.vo.VipBenefitVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -70,7 +71,7 @@ public class VipBenefitServiceImpl extends ServiceImpl<VipBenefitMapper, VipBene
|
||||
@Override
|
||||
public List<VipBenefitVO> listVipBenefitsByRequiredVipLevel(String requiredVipLevel) {
|
||||
List<VipBenefitDO> vipBenefitDOs = vipBenefitMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<VipBenefitDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(VipBenefitDO.class)
|
||||
.eq(VipBenefitDO::getRequiredVipLevel, requiredVipLevel)
|
||||
);
|
||||
return vipBenefitDOs.stream()
|
||||
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.entity.VipInfoDO;
|
||||
import com.xiaowang.yuminailcore.dto.VipInfoDTO;
|
||||
import com.xiaowang.yuminailcore.vo.VipInfoVO;
|
||||
import com.xiaowang.yuminailcore.entity.VipInfoDO;
|
||||
import com.xiaowang.yuminailcore.mapper.VipInfoMapper;
|
||||
import com.xiaowang.yuminailcore.service.VipInfoService;
|
||||
import com.xiaowang.yuminailcore.vo.VipInfoVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class VipInfoServiceImpl extends ServiceImpl<VipInfoMapper, VipInfoDO> im
|
||||
@Override
|
||||
public List<VipInfoVO> listVipInfosByVipLevel(String vipLevel) {
|
||||
List<VipInfoDO> vipInfoDOs = vipInfoMapper.selectList(
|
||||
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.<VipInfoDO>lambdaQuery()
|
||||
Wrappers.lambdaQuery(VipInfoDO.class)
|
||||
.eq(VipInfoDO::getVipLevel, vipLevel)
|
||||
);
|
||||
return vipInfoDOs.stream()
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.xiaowang.yuminailcore.utils;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class JwtUtil {
|
||||
|
||||
private static final String SECRET = "yuminail-secret-key-for-jwt-token-generation-2026-must-be-at-least-512-bits-long-for-hs512-algorithm-security-requirements";
|
||||
private static final long ACCESS_TOKEN_EXPIRATION = 20 * 60 * 1000;
|
||||
private static final long REFRESH_TOKEN_EXPIRATION = 7 * 24 * 60 * 60 * 1000;
|
||||
|
||||
private final SecretKey key;
|
||||
|
||||
public JwtUtil() {
|
||||
this.key = Keys.hmacShaKeyFor(SECRET.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public String generateAccessToken(Long userId, String account) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put("userId", userId);
|
||||
claims.put("account", account);
|
||||
claims.put("type", "access");
|
||||
return createToken(claims, userId.toString(), ACCESS_TOKEN_EXPIRATION);
|
||||
}
|
||||
|
||||
public String generateRefreshToken(Long userId, String account) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put("userId", userId);
|
||||
claims.put("account", account);
|
||||
claims.put("type", "refresh");
|
||||
return createToken(claims, userId.toString(), REFRESH_TOKEN_EXPIRATION);
|
||||
}
|
||||
|
||||
private String createToken(Map<String, Object> claims, String subject, long expiration) {
|
||||
Date now = new Date();
|
||||
Date expiryDate = new Date(now.getTime() + expiration);
|
||||
|
||||
return Jwts.builder()
|
||||
.setClaims(claims)
|
||||
.setSubject(subject)
|
||||
.setIssuedAt(now)
|
||||
.setExpiration(expiryDate)
|
||||
.signWith(key, SignatureAlgorithm.HS512)
|
||||
.compact();
|
||||
}
|
||||
|
||||
public Claims parseToken(String token) {
|
||||
return Jwts.parserBuilder()
|
||||
.setSigningKey(key)
|
||||
.build()
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
}
|
||||
|
||||
public Long getUserIdFromToken(String token) {
|
||||
Claims claims = parseToken(token);
|
||||
return claims.get("userId", Long.class);
|
||||
}
|
||||
|
||||
public String getAccountFromToken(String token) {
|
||||
Claims claims = parseToken(token);
|
||||
return claims.get("account", String.class);
|
||||
}
|
||||
|
||||
public String getTokenType(String token) {
|
||||
Claims claims = parseToken(token);
|
||||
return claims.get("type", String.class);
|
||||
}
|
||||
|
||||
public boolean isTokenExpired(String token) {
|
||||
try {
|
||||
Claims claims = parseToken(token);
|
||||
return claims.getExpiration().before(new Date());
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateToken(String token) {
|
||||
try {
|
||||
parseToken(token);
|
||||
return !isTokenExpired(token);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAccessToken(String token) {
|
||||
return "access".equals(getTokenType(token));
|
||||
}
|
||||
|
||||
public boolean isRefreshToken(String token) {
|
||||
return "refresh".equals(getTokenType(token));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 登录响应 VO
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-14
|
||||
*/
|
||||
@Data
|
||||
public class LoginResponseVO {
|
||||
|
||||
private String accessToken;
|
||||
|
||||
private String refreshToken;
|
||||
|
||||
private UserInfo userInfo;
|
||||
|
||||
@Data
|
||||
public static class UserInfo {
|
||||
private Long id;
|
||||
private String account;
|
||||
private String nickname;
|
||||
private String avatar;
|
||||
private Integer type;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import com.xiaowang.yuminailcore.vo.TagInfo;
|
||||
|
||||
/**
|
||||
* 商品信息表 VO
|
||||
@@ -66,6 +67,11 @@ public class ProductVO {
|
||||
*/
|
||||
private List<String> tagList;
|
||||
|
||||
/**
|
||||
* 标签详情列表(包含样式信息)
|
||||
*/
|
||||
private List<TagInfo> tagInfos;
|
||||
|
||||
/**
|
||||
* 商品点赞数
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShopSimpleVO {
|
||||
|
||||
private Long id;
|
||||
private String shopName;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 标签信息 VO
|
||||
* 用于前端展示标签,包含样式信息
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-14
|
||||
*/
|
||||
@Data
|
||||
public class TagInfo {
|
||||
|
||||
/**
|
||||
* 标签ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
private String tagName;
|
||||
|
||||
/**
|
||||
* 标签文字颜色(16进制)
|
||||
*/
|
||||
private String textColor;
|
||||
|
||||
/**
|
||||
* 标签背景颜色(16进制)
|
||||
*/
|
||||
private String bgColor;
|
||||
|
||||
/**
|
||||
* 标签边框颜色(16进制)
|
||||
*/
|
||||
private String borderColor;
|
||||
|
||||
public TagInfo() {
|
||||
}
|
||||
|
||||
public TagInfo(Long id, String tagName, String textColor, String bgColor, String borderColor) {
|
||||
this.id = id;
|
||||
this.tagName = tagName;
|
||||
this.textColor = textColor;
|
||||
this.bgColor = bgColor;
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
}
|
||||
@@ -1 +1,12 @@
|
||||
spring.application.name=YumiNail-Core
|
||||
# 数据库连接编码配置
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/yumi_nail?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
|
||||
# 日志编码配置
|
||||
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
|
||||
# 服务器编码配置
|
||||
server.servlet.encoding.charset=UTF-8
|
||||
server.servlet.encoding.force=true
|
||||
server.servlet.encoding.enabled=true
|
||||
|
||||
# MyBatis编码配置
|
||||
mybatis.configuration.map-underscore-to-camel-case=true
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
-- 为用户表添加手机号和邮箱字段
|
||||
ALTER TABLE `t_user`
|
||||
ADD COLUMN `phone` VARCHAR(20) DEFAULT NULL COMMENT '手机号' AFTER `account`,
|
||||
ADD COLUMN `email` VARCHAR(100) DEFAULT NULL COMMENT '邮箱' AFTER `phone`,
|
||||
ADD COLUMN `phone_verified` TINYINT UNSIGNED DEFAULT 0 COMMENT '手机号是否已验证:0-未验证,1-已验证' AFTER `email`,
|
||||
ADD COLUMN `email_verified` TINYINT UNSIGNED DEFAULT 0 COMMENT '邮箱是否已验证:0-未验证,1-已验证' AFTER `phone_verified`;
|
||||
|
||||
-- 添加索引
|
||||
ALTER TABLE `t_user`
|
||||
ADD INDEX `idx_phone` (`phone`) COMMENT '按手机号查询的索引',
|
||||
ADD INDEX `idx_email` (`email`) COMMENT '按邮箱查询的索引';
|
||||
@@ -0,0 +1,55 @@
|
||||
-- 1. 创建标签表
|
||||
CREATE TABLE IF NOT EXISTS `t_tag` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`tag_name` varchar(50) NOT NULL COMMENT '标签名称',
|
||||
`text_color` varchar(20) NOT NULL DEFAULT '#FFFFFF' COMMENT '标签文字颜色(16进制)',
|
||||
`bg_color` varchar(20) NOT NULL DEFAULT '#1890FF' COMMENT '标签背景颜色(16进制)',
|
||||
`border_color` varchar(20) NOT NULL DEFAULT '#1890FF' COMMENT '标签边框颜色(16进制)',
|
||||
`is_delete` int NOT NULL DEFAULT '0' COMMENT '逻辑删除:0-未删,1-已删',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='系统标签信息表';
|
||||
|
||||
-- 2. 插入标签数据
|
||||
INSERT INTO `t_tag` (`id`, `tag_name`, `text_color`, `bg_color`, `border_color`) VALUES
|
||||
(0, '精选', '#FFFFFF', '#FF4D4F', '#FF4D4F'),
|
||||
(1, '热门', '#FFFFFF', '#FAAD14', '#FAAD14'),
|
||||
(2, '美甲', '#FFFFFF', '#1890FF', '#1890FF'),
|
||||
(3, '美睫', '#FFFFFF', '#52C41A', '#52C41A'),
|
||||
(4, '手足护理', '#FFFFFF', '#722ED1', '#722ED1'),
|
||||
(5, '纹绣', '#FFFFFF', '#EB2F96', '#EB2F96'),
|
||||
(6, '基础', '#333333', '#F0F0F0', '#F0F0F0'),
|
||||
(7, '法式', '#333333', '#E6F7FF', '#91D5FF'),
|
||||
(8, '光疗', '#333333', '#F6FFED', '#B7EB8F'),
|
||||
(9, '手绘', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(10, '钻饰', '#333333', '#FFF0F5', '#FFB3C6'),
|
||||
(11, '脚部', '#333333', '#F9F0FF', '#D3ADF7'),
|
||||
(12, '新娘', '#333333', '#E8F5FF', '#91D5FF'),
|
||||
(13, '儿童', '#333333', '#E6FFFB', '#67C23A'),
|
||||
(14, '定制', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(15, '持久', '#333333', '#F6FFED', '#B7EB8F');
|
||||
|
||||
-- 3. 修改产品表的标签字段(如果需要)
|
||||
-- 注意:如果已经存在 t_product 表,需要执行以下修改
|
||||
ALTER TABLE `t_product` MODIFY COLUMN `tags` varchar(255) COMMENT '标签ID集合,多个ID以分号分隔';
|
||||
|
||||
-- 4. 更新测试商品的标签为标签ID
|
||||
-- 请将下面的 shop_id 替换为实际的店铺ID
|
||||
INSERT INTO `t_product` (`shop_id`, `title`, `description`, `price`, `tags`, `like_count`, `collect_count`, `approximate_duration`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
(1, '基础美甲套餐', '包含基础修甲、抛光、上色', 88.00, '2;6', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '法式美甲', '经典法式美甲,优雅大方', 128.00, '2;7', 0, 0, '45分钟', 0, NOW(), NOW()),
|
||||
(1, '光疗甲', '持久光疗甲,不易脱落', 168.00, '2;8;15', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '手绘美甲', '创意手绘图案,个性定制', 198.00, '2;9;14', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '钻饰美甲', '镶嵌钻饰,闪亮夺目', 228.00, '2;10', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '脚部美甲', '脚部护理+美甲', 158.00, '2;11', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '新娘美甲', '婚礼专用美甲套餐', 298.00, '0;2;12;14', 0, 0, '120分钟', 0, NOW(), NOW()),
|
||||
(1, '儿童美甲', '无毒无害,专为儿童设计', 68.00, '2;13', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '美睫套餐', '自然浓密美睫', 198.00, '1;3', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '手足护理套餐', '深层护理,滋润保湿', 168.00, '4', 0, 0, '120分钟', 0, NOW(), NOW());
|
||||
|
||||
-- 5. 查看标签数据
|
||||
SELECT * FROM `t_tag` ORDER BY `id`;
|
||||
|
||||
-- 6. 查看商品数据
|
||||
SELECT `id`, `shop_id`, `title`, `price`, `tags` FROM `t_product` WHERE `is_delete` = 0;
|
||||
@@ -0,0 +1,24 @@
|
||||
# 数据库连接配置
|
||||
sspring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/yumi_nail?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: 123456
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
# 连接池配置
|
||||
druid:
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
max-wait: 60000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
filters: stat,wall
|
||||
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
@@ -0,0 +1,51 @@
|
||||
-- 插入标签数据
|
||||
INSERT INTO `t_tag` (`id`, `tag_name`, `text_color`, `bg_color`, `border_color`) VALUES
|
||||
(0, '精选', '#FFFFFF', '#FF4D4F', '#FF4D4F'),
|
||||
(1, '热门', '#FFFFFF', '#FAAD14', '#FAAD14'),
|
||||
(2, '美甲', '#333333', '#E6F7FF', '#91D5FF'),
|
||||
(3, '美睫', '#333333', '#F6FFED', '#B7EB8F'),
|
||||
(4, '手足护理', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(5, '纹绣', '#333333', '#FFF0F5', '#FFB3C6'),
|
||||
(6, '基础', '#333333', '#F0F0F0', '#F0F0F0'),
|
||||
(7, '法式', '#333333', '#F9F0FF', '#D3ADF7'),
|
||||
(8, '光疗', '#333333', '#E6FFFB', '#67C23A'),
|
||||
(9, '手绘', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(10, '钻饰', '#333333', '#FFF0F5', '#FFB3C6'),
|
||||
(11, '脚部', '#333333', '#E8F5FF', '#91D5FF'),
|
||||
(12, '新娘', '#333333', '#F0F5FF', '#91D5FF'),
|
||||
(13, '儿童', '#333333', '#F6FFED', '#B7EB8F'),
|
||||
(14, '定制', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(15, '持久', '#333333', '#F6FFED', '#B7EB8F'),
|
||||
(16, '快速', '#333333', '#FFF7E6', '#FFD591'),
|
||||
(17, '优惠', '#FFFFFF', '#52C41A', '#52C41A'),
|
||||
(18, '新品', '#FFFFFF', '#1890FF', '#1890FF');
|
||||
|
||||
-- 更新商品标签为标签ID(假设商品表已存在)
|
||||
-- 请将下面的 shop_id 替换为实际的店铺ID
|
||||
INSERT INTO `t_product` (`shop_id`, `title`, `description`, `price`, `tags`, `like_count`, `collect_count`, `approximate_duration`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
(1, '基础美甲套餐', '包含基础修甲、抛光、上色', 88.00, '2;6', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '法式美甲', '经典法式美甲,优雅大方', 128.00, '2;7', 0, 0, '45分钟', 0, NOW(), NOW()),
|
||||
(1, '光疗甲', '持久光疗甲,不易脱落', 168.00, '2;8;15', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '手绘美甲', '创意手绘图案,个性定制', 198.00, '2;9;14', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '钻饰美甲', '镶嵌钻饰,闪亮夺目', 228.00, '0;2;10', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '脚部美甲', '脚部护理+美甲', 158.00, '2;11', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '新娘美甲', '婚礼专用美甲套餐', 298.00, '0;2;12;14', 0, 0, '120分钟', 0, NOW(), NOW()),
|
||||
(1, '儿童美甲', '无毒无害,专为儿童设计', 68.00, '2;13', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '美睫套餐', '自然浓密美睫', 198.00, '1;3', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '手足护理套餐', '深层护理,滋润保湿', 168.00, '1;4', 0, 0, '120分钟', 0, NOW(), NOW());
|
||||
|
||||
-- 查看标签数据
|
||||
SELECT * FROM `t_tag` ORDER BY `id`;
|
||||
|
||||
-- 查看商品数据
|
||||
SELECT `id`, `shop_id`, `title`, `price`, `tags` FROM `t_product` WHERE `is_delete` = 0;
|
||||
|
||||
-- 查看精选商品(包含标签0)
|
||||
SELECT p.`id`, p.`title`, p.`price`, p.`tags`
|
||||
FROM `t_product` p
|
||||
WHERE p.`is_delete` = 0 AND p.`tags` LIKE '%0%';
|
||||
|
||||
-- 查看热门商品(包含标签1)
|
||||
SELECT p.`id`, p.`title`, p.`price`, p.`tags`
|
||||
FROM `t_product` p
|
||||
WHERE p.`is_delete` = 0 AND p.`tags` LIKE '%1%';
|
||||
@@ -0,0 +1,17 @@
|
||||
-- 查询店铺信息
|
||||
SELECT `id`, `shop_name`, `address` FROM `t_shop` WHERE `is_delete` = 0;
|
||||
|
||||
-- 插入测试商品数据(修正版)
|
||||
-- 请将下面的 shop_id 替换为上面查询到的 "美甲工作室 - 中心店" 的 ID
|
||||
INSERT INTO `t_product` (`shop_id`, `title`, `description`, `price`, `tags`, `like_count`, `collect_count`, `approximate_duration`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
(1, '基础美甲套餐', '包含基础修甲、抛光、上色', 88.00, '美甲,基础', 0, 0, '30分钟', 0, NOW(), NOW()),
|
||||
(1, '法式美甲', '经典法式美甲,优雅大方', 128.00, '美甲,法式', 0, 0, '45分钟', 0, NOW(), NOW()),
|
||||
(1, '光疗甲', '持久光疗甲,不易脱落', 168.00, '美甲,光疗', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '手绘美甲', '创意手绘图案,个性定制', 198.00, '美甲,手绘,定制', 0, 0, '90分钟', 0, NOW(), NOW()),
|
||||
(1, '钻饰美甲', '镶嵌钻饰,闪亮夺目', 228.00, '美甲,钻饰', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '脚部美甲', '脚部护理+美甲', 158.00, '美甲,脚部', 0, 0, '60分钟', 0, NOW(), NOW()),
|
||||
(1, '新娘美甲', '婚礼专用美甲套餐', 298.00, '美甲,新娘,定制', 0, 0, '120分钟', 0, NOW(), NOW()),
|
||||
(1, '儿童美甲', '无毒无害,专为儿童设计', 68.00, '美甲,儿童', 0, 0, '30分钟', 0, NOW(), NOW());
|
||||
|
||||
-- 查看插入结果
|
||||
SELECT `id`, `shop_id`, `title`, `price`, `tags` FROM `t_product` WHERE `is_delete` = 0 AND `shop_id` = 1;
|
||||
@@ -0,0 +1,10 @@
|
||||
-- 插入测试店铺数据
|
||||
INSERT INTO `t_shop` (`shop_name`, `address`, `phone`, `business_hours`, `description`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
('美甲工作室 - 中心店', '北京市朝阳区建国路88号', '13812345678', '10:00-21:00', '专业美甲服务,使用进口产品', 0, NOW(), NOW()),
|
||||
('Yumi Nail - 国贸店', '北京市朝阳区国贸CBD', '13987654321', '09:30-20:30', '高端美甲沙龙,提供定制服务', 0, NOW(), NOW()),
|
||||
('指尖艺术 - 三里屯店', '北京市朝阳区三里屯SOHO', '13756789012', '10:00-22:00', '创意美甲,流行款式', 0, NOW(), NOW()),
|
||||
('Pretty Nails - 望京店', '北京市朝阳区望京SOHO', '13623456789', '10:00-21:00', '温馨舒适的美甲环境', 0, NOW(), NOW()),
|
||||
('指甲花 - 西单店', '北京市西城区西单商业街', '13587654321', '10:00-21:30', '实惠价格,优质服务', 0, NOW(), NOW());
|
||||
|
||||
-- 查看插入结果
|
||||
SELECT `id`, `shop_name`, `address`, `phone` FROM `t_shop` WHERE `is_delete` = 0;
|
||||
@@ -0,0 +1,10 @@
|
||||
-- 插入测试店铺数据(修正版)
|
||||
INSERT INTO `t_shop` (`shop_name`, `address`, `business_hours`, `description`, `is_delete`, `create_time`, `update_time`) VALUES
|
||||
('美甲工作室 - 中心店', '北京市朝阳区建国路88号', '10:00-21:00', '专业美甲服务,使用进口产品', 0, NOW(), NOW()),
|
||||
('Yumi Nail - 国贸店', '北京市朝阳区国贸CBD', '09:30-20:30', '高端美甲沙龙,提供定制服务', 0, NOW(), NOW()),
|
||||
('指尖艺术 - 三里屯店', '北京市朝阳区三里屯SOHO', '10:00-22:00', '创意美甲,流行款式', 0, NOW(), NOW()),
|
||||
('Pretty Nails - 望京店', '北京市朝阳区望京SOHO', '10:00-21:00', '温馨舒适的美甲环境', 0, NOW(), NOW()),
|
||||
('指甲花 - 西单店', '北京市西城区西单商业街', '10:00-21:30', '实惠价格,优质服务', 0, NOW(), NOW());
|
||||
|
||||
-- 查看插入结果
|
||||
SELECT `id`, `shop_name`, `address`, `business_hours` FROM `t_shop` WHERE `is_delete` = 0;
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.xiaowang.yumitailgateway.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.reactive.CorsWebFilter;
|
||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Gateway CORS 配置
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsWebFilter corsWebFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
|
||||
config.addAllowedOriginPattern("*");
|
||||
config.addAllowedMethod("*");
|
||||
config.addAllowedHeader("*");
|
||||
config.setAllowCredentials(true);
|
||||
config.setMaxAge(3600L);
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
|
||||
return new CorsWebFilter(source);
|
||||
}
|
||||
}
|
||||
+10
-16
@@ -41,7 +41,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
||||
|
||||
log.info("网关接收到请求: {}", path);
|
||||
|
||||
// 1. 白名单校验
|
||||
// 1. 白名单校验(登录和注册接口不需要认证)
|
||||
if (isWhitelist(path)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
@@ -52,16 +52,11 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
||||
return unAuthorized(exchange, "未携带Token,拒绝访问");
|
||||
}
|
||||
|
||||
// TODO: 这里可以集成 Redis 进一步校验 Token 的合法性和有效期
|
||||
// String userJson = redisTemplate.opsForValue().get("TOKEN:" + token);
|
||||
// if (!StringUtils.hasText(userJson)) {
|
||||
// return unAuthorized(exchange, "Token已过期或非法");
|
||||
// }
|
||||
|
||||
// 3. 示例:简单的 Token 校验逻辑(后续可扩展)
|
||||
if (!"yuminail-test-token".equals(token)) {
|
||||
// 仅做演示,实际应解析JWT或查询Redis
|
||||
// return unAuthorized(exchange, "Token校验失败");
|
||||
// 3. 双 Token 校验模式
|
||||
// accessToken 用于 API 访问,refreshToken 用于刷新 accessToken
|
||||
// 这里只验证 accessToken 是否存在,具体验证由后端服务处理
|
||||
if (!token.startsWith("Bearer ")) {
|
||||
return unAuthorized(exchange, "Token格式错误");
|
||||
}
|
||||
|
||||
return chain.filter(exchange);
|
||||
@@ -71,11 +66,10 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
||||
* 判断是否在白名单中
|
||||
*/
|
||||
private boolean isWhitelist(String path) {
|
||||
if (gatewayConfig.getWhitelist() == null) {
|
||||
return false;
|
||||
}
|
||||
return gatewayConfig.getWhitelist().stream()
|
||||
.anyMatch(pattern -> pathMatcher.match(pattern, path));
|
||||
return path.equals("/api/user/login") ||
|
||||
path.equals("/api/user/register") ||
|
||||
path.equals("/api/user/refresh-token") ||
|
||||
path.equals("/api/shop/list/simple");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
spring:
|
||||
cloud:
|
||||
gateway:
|
||||
routes:
|
||||
- id: product-route
|
||||
uri: lb://yumi-nail-core
|
||||
predicates:
|
||||
- Path=/api/product/**
|
||||
- id: shop-route
|
||||
uri: lb://yumi-nail-core
|
||||
predicates:
|
||||
- Path=/api/shop/**
|
||||
- id: user-route
|
||||
uri: lb://yumi-nail-core
|
||||
predicates:
|
||||
- Path=/api/user/**
|
||||
- id: comment-route
|
||||
uri: lb://yumi-nail-core
|
||||
predicates:
|
||||
- Path=/api/comment/**
|
||||
- id: balance-route
|
||||
uri: lb://yumi-nail-core
|
||||
predicates:
|
||||
- Path=/api/balance/**
|
||||
- id: tag-route
|
||||
uri: lb://yumi-nail-core
|
||||
predicates:
|
||||
- Path=/api/tag/**
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Property>
|
||||
<Property name="LOG_HOME">E:/code/xiaowang/YumiNail-Gateway/logs</Property>
|
||||
</Properties>
|
||||
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</Console>
|
||||
|
||||
<RollingFile name="RollingFile" fileName="${LOG_HOME}/yuminail-gateway.log"
|
||||
filePattern="${LOG_HOME}/yuminail-gateway-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
<SizeBasedTriggeringPolicy size="100 MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30">
|
||||
<Delete basePath="${LOG_HOME}" maxDepth="1">
|
||||
<IfFileName glob="yuminail-gateway-*.log.gz"/>
|
||||
<IfLastModified age="30d"/>
|
||||
</Delete>
|
||||
</DefaultRolloverStrategy>
|
||||
</RollingFile>
|
||||
|
||||
<RollingFile name="ErrorRollingFile" fileName="${LOG_HOME}/yuminail-gateway-error.log"
|
||||
filePattern="${LOG_HOME}/yuminail-gateway-error-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
<SizeBasedTriggeringPolicy size="100 MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30">
|
||||
<Delete basePath="${LOG_HOME}" maxDepth="1">
|
||||
<IfFileName glob="yuminail-gateway-error-*.log.gz"/>
|
||||
<IfLastModified age="30d"/>
|
||||
</Delete>
|
||||
</DefaultRolloverStrategy>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="RollingFile"/>
|
||||
<AppenderRef ref="ErrorRollingFile"/>
|
||||
</Root>
|
||||
|
||||
<Logger name="com.xiaowang.yumitailgateway" level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="RollingFile"/>
|
||||
<AppenderRef ref="ErrorRollingFile"/>
|
||||
</Logger>
|
||||
|
||||
<Logger name="org.springframework" level="INFO"/>
|
||||
<Logger name="com.alibaba.nacos" level="INFO"/>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user