购物车和订单中心以及优惠券相关功能初版
This commit is contained in:
@@ -385,6 +385,9 @@ export const adminCouponApi = {
|
|||||||
},
|
},
|
||||||
deleteCoupon: (id: number) => {
|
deleteCoupon: (id: number) => {
|
||||||
return adminApi.delete(`/coupon/delete/${id}`)
|
return adminApi.delete(`/coupon/delete/${id}`)
|
||||||
|
},
|
||||||
|
distributeCoupon: (data: { couponId: number; userIds: number[]; quantity: number }) => {
|
||||||
|
return adminApi.post('/coupon/distribute', data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,5 +54,8 @@ export const userApi = {
|
|||||||
},
|
},
|
||||||
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
||||||
return api.put('/user/info', data)
|
return api.put('/user/info', data)
|
||||||
|
},
|
||||||
|
getUserByAccount: (account: string) => {
|
||||||
|
return api.get<UserVO>(`/user/get/account/${account}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,12 @@ const router = createRouter({
|
|||||||
component: () => import('../views/WishlistView.vue'),
|
component: () => import('../views/WishlistView.vue'),
|
||||||
meta: { requiresAuth: true, isAdmin: false }
|
meta: { requiresAuth: true, isAdmin: false }
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/orders',
|
||||||
|
name: 'orders',
|
||||||
|
component: () => import('../views/OrderView.vue'),
|
||||||
|
meta: { requiresAuth: true, hideNav: true, isAdmin: false }
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/settings',
|
path: '/settings',
|
||||||
name: 'settings',
|
name: 'settings',
|
||||||
@@ -109,6 +115,12 @@ const router = createRouter({
|
|||||||
name: 'admin-permissions',
|
name: 'admin-permissions',
|
||||||
component: () => import('../views/admin/PermissionsView.vue'),
|
component: () => import('../views/admin/PermissionsView.vue'),
|
||||||
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'permission:view' }
|
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'permission:view' }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'orders',
|
||||||
|
name: 'admin-orders',
|
||||||
|
component: () => import('../views/admin/OrdersView.vue'),
|
||||||
|
meta: { requiresAuth: true, isAdmin: true, hideNav: true, permissionCode: 'order:view' }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,10 @@
|
|||||||
layout="vertical"
|
layout="vertical"
|
||||||
class="auth-form"
|
class="auth-form"
|
||||||
>
|
>
|
||||||
<a-form-item name="account" label="账号">
|
<a-form-item v-if="activeTab === 'register'" name="nickname" label="昵称">
|
||||||
<a-input
|
<a-input
|
||||||
v-model:value="formData.account"
|
v-model:value="formData.nickname"
|
||||||
placeholder="请输入账号"
|
placeholder="请输入昵称"
|
||||||
size="large"
|
size="large"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
@@ -42,6 +42,27 @@
|
|||||||
</a-input>
|
</a-input>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
|
<a-form-item name="account" label="账号">
|
||||||
|
<a-input
|
||||||
|
v-model:value="formData.account"
|
||||||
|
placeholder="请输入账号"
|
||||||
|
size="large"
|
||||||
|
@blur="handleAccountBlur"
|
||||||
|
>
|
||||||
|
<template #prefix>
|
||||||
|
<UserOutlined style="color: #999" />
|
||||||
|
</template>
|
||||||
|
</a-input>
|
||||||
|
<div v-if="accountStatus" class="account-status">
|
||||||
|
<span v-if="accountStatus.exists" class="status-success">
|
||||||
|
账号存在,昵称:{{ accountStatus.nickname }}
|
||||||
|
</span>
|
||||||
|
<span v-else class="status-error">
|
||||||
|
账号不存在
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item name="password" label="密码">
|
<a-form-item name="password" label="密码">
|
||||||
<a-input-password
|
<a-input-password
|
||||||
v-model:value="formData.password"
|
v-model:value="formData.password"
|
||||||
@@ -90,18 +111,6 @@
|
|||||||
</a-select>
|
</a-select>
|
||||||
</a-form-item>
|
</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">
|
<a-form-item v-if="activeTab === 'login'" style="margin-bottom: 8px">
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<a-checkbox v-model:checked="formData.rememberMe">记住我</a-checkbox>
|
<a-checkbox v-model:checked="formData.rememberMe">记住我</a-checkbox>
|
||||||
@@ -150,6 +159,7 @@ import { UserOutlined, LockOutlined, WechatOutlined, QqOutlined } from '@ant-des
|
|||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
import { authApi } from '@/api/auth'
|
import { authApi } from '@/api/auth'
|
||||||
import { shopApi } from '@/api/shop'
|
import { shopApi } from '@/api/shop'
|
||||||
|
import { userApi } from '@/api/user'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -157,6 +167,7 @@ const activeTab = ref<'login' | 'register'>('login')
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const loadingShops = ref(false)
|
const loadingShops = ref(false)
|
||||||
const shops = ref<any[]>([])
|
const shops = ref<any[]>([])
|
||||||
|
const accountStatus = ref<any>(null)
|
||||||
|
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
account: '',
|
account: '',
|
||||||
@@ -187,7 +198,8 @@ const validateConfirmPassword = async (_rule: any, value: string) => {
|
|||||||
const rules = {
|
const rules = {
|
||||||
account: [
|
account: [
|
||||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||||
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' }
|
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' },
|
||||||
|
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
password: [
|
password: [
|
||||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||||
@@ -267,6 +279,28 @@ const handleQQLogin = () => {
|
|||||||
message.info('QQ登录功能开发中')
|
message.info('QQ登录功能开发中')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleAccountBlur = async () => {
|
||||||
|
if (activeTab.value === 'login' && formData.account) {
|
||||||
|
try {
|
||||||
|
const res = await userApi.getUserByAccount(formData.account)
|
||||||
|
if (res) {
|
||||||
|
accountStatus.value = {
|
||||||
|
exists: true,
|
||||||
|
nickname: res.nickname
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
accountStatus.value = {
|
||||||
|
exists: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
accountStatus.value = {
|
||||||
|
exists: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleAdminLogin = () => {
|
const handleAdminLogin = () => {
|
||||||
console.log('跳转到管理后台登录')
|
console.log('跳转到管理后台登录')
|
||||||
localStorage.removeItem('accessToken')
|
localStorage.removeItem('accessToken')
|
||||||
@@ -432,4 +466,17 @@ onMounted(() => {
|
|||||||
color: #764ba2;
|
color: #764ba2;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.account-status {
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-success {
|
||||||
|
color: #52c41a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-error {
|
||||||
|
color: #f5222d;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
+130
-96
@@ -29,15 +29,17 @@
|
|||||||
<a-checkbox v-model:checked="item.selected" @change="handleSelectChange" />
|
<a-checkbox v-model:checked="item.selected" @change="handleSelectChange" />
|
||||||
|
|
||||||
<!-- 商品图片 -->
|
<!-- 商品图片 -->
|
||||||
<div class="item-image" :style="{ backgroundColor: item.bgColor }">
|
<div class="item-image" v-if="item.productImage">
|
||||||
<span>{{ item.title[0] }}</span>
|
<img :src="item.productImage" :alt="item.productTitle" />
|
||||||
|
</div>
|
||||||
|
<div class="item-image" v-else :style="{ backgroundColor: getRandomColor() }">
|
||||||
|
<span>{{ item.productTitle[0] }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 商品详情 -->
|
<!-- 商品详情 -->
|
||||||
<div class="item-details">
|
<div class="item-details">
|
||||||
<h3 class="item-name">{{ item.title }}</h3>
|
<h3 class="item-name">{{ item.productTitle }}</h3>
|
||||||
<p class="item-price">¥{{ item.price.toFixed(2) }}</p>
|
<p class="item-price">¥{{ item.price.toFixed(2) }}</p>
|
||||||
<p class="item-duration">预计耗时: {{ item.approximateDuration }}</p>
|
|
||||||
|
|
||||||
<!-- 数量控制和删除按钮 -->
|
<!-- 数量控制和删除按钮 -->
|
||||||
<div class="item-actions">
|
<div class="item-actions">
|
||||||
@@ -84,10 +86,6 @@
|
|||||||
<span>小计</span>
|
<span>小计</span>
|
||||||
<span>¥{{ subtotal.toFixed(2) }}</span>
|
<span>¥{{ subtotal.toFixed(2) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="summary-row">
|
|
||||||
<span>预计消耗时间</span>
|
|
||||||
<span class="duration">{{ totalDuration }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="summary-row total">
|
<div class="summary-row total">
|
||||||
<span>总计</span>
|
<span>总计</span>
|
||||||
<span class="total-price">¥{{ subtotal.toFixed(2) }}</span>
|
<span class="total-price">¥{{ subtotal.toFixed(2) }}</span>
|
||||||
@@ -109,60 +107,84 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import {
|
import {
|
||||||
LeftOutlined,
|
LeftOutlined,
|
||||||
DeleteOutlined
|
DeleteOutlined
|
||||||
} from '@ant-design/icons-vue'
|
} from '@ant-design/icons-vue'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
import type { ProductVO } from '@/api/product'
|
import { cartApi } from '../api/cart'
|
||||||
|
import { orderApi } from '../api/order'
|
||||||
|
import { fileApi } from '../api/index'
|
||||||
|
|
||||||
|
interface CartItem {
|
||||||
|
id: number
|
||||||
|
productId: number
|
||||||
|
productTitle: string
|
||||||
|
productImage: string
|
||||||
|
price: number
|
||||||
|
quantity: number
|
||||||
|
totalPrice: number
|
||||||
|
selected: boolean
|
||||||
|
}
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
// 购物车商品数据(模拟真实产品数据结构)
|
// 购物车商品数据
|
||||||
const cartItems = ref<Array<{
|
const cartItems = ref<CartItem[]>([])
|
||||||
id: number
|
|
||||||
productId: number
|
// 图片缓存
|
||||||
title: string
|
const imageIdCache = ref<Record<string, string>>({})
|
||||||
price: number
|
|
||||||
imageUrl?: string
|
// 加载购物车数据
|
||||||
bgColor: string
|
const loadCartItems = async () => {
|
||||||
quantity: number
|
try {
|
||||||
selected: boolean
|
const data = await cartApi.getCartList()
|
||||||
approximateDuration: string
|
cartItems.value = data.map((item: any) => ({
|
||||||
}>>([
|
...item,
|
||||||
{
|
selected: true
|
||||||
id: 1,
|
}))
|
||||||
productId: 1,
|
|
||||||
title: '经典美甲',
|
// 加载商品图片的临时加签链接
|
||||||
price: 99,
|
await loadProductImages(cartItems.value)
|
||||||
bgColor: '#ffe4d6',
|
} catch (error) {
|
||||||
quantity: 1,
|
message.error('获取购物车数据失败')
|
||||||
selected: true,
|
|
||||||
approximateDuration: '30分钟'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
productId: 2,
|
|
||||||
title: '法式美甲',
|
|
||||||
price: 168,
|
|
||||||
bgColor: '#d6eaff',
|
|
||||||
quantity: 2,
|
|
||||||
selected: true,
|
|
||||||
approximateDuration: '45分钟'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
productId: 3,
|
|
||||||
title: '光疗美甲',
|
|
||||||
price: 238,
|
|
||||||
bgColor: '#e2ffd6',
|
|
||||||
quantity: 1,
|
|
||||||
selected: false,
|
|
||||||
approximateDuration: '60分钟'
|
|
||||||
}
|
}
|
||||||
])
|
}
|
||||||
|
|
||||||
|
// 加载商品图片
|
||||||
|
const loadProductImages = async (items: CartItem[]) => {
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.productImage) {
|
||||||
|
// 过滤掉HTML标签
|
||||||
|
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||||
|
|
||||||
|
// 从cleanImageUrl中提取图片ID
|
||||||
|
// 假设图片URL的格式为 '/api/file/get/123'
|
||||||
|
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||||
|
if (match && match[1]) {
|
||||||
|
const imageId = match[1]
|
||||||
|
try {
|
||||||
|
// 检查缓存
|
||||||
|
if (!imageIdCache.value[imageId]) {
|
||||||
|
const signedUrl = await fileApi.getSignedUrl(Number(imageId))
|
||||||
|
imageIdCache.value[imageId] = signedUrl
|
||||||
|
}
|
||||||
|
// 更新商品图片为临时加签链接
|
||||||
|
item.productImage = imageIdCache.value[imageId]
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取图片签名链接失败:', error)
|
||||||
|
// 如果获取签名链接失败,清除无效的图片URL
|
||||||
|
item.productImage = ''
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果不是有效的图片URL格式,清除无效的图片URL
|
||||||
|
item.productImage = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 计算选中的商品数量
|
// 计算选中的商品数量
|
||||||
const selectedCount = computed(() => {
|
const selectedCount = computed(() => {
|
||||||
@@ -178,39 +200,17 @@ const totalQuantity = computed(() => {
|
|||||||
const subtotal = computed(() => {
|
const subtotal = computed(() => {
|
||||||
return cartItems.value
|
return cartItems.value
|
||||||
.filter(item => item.selected)
|
.filter(item => item.selected)
|
||||||
.reduce((sum, item) => sum + (item.price * item.quantity), 0)
|
.reduce((sum, item) => sum + item.totalPrice, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 计算预计总消耗时间
|
// 生成随机颜色
|
||||||
const totalDuration = computed(() => {
|
const getRandomColor = () => {
|
||||||
const selectedItems = cartItems.value.filter(item => item.selected)
|
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||||
if (selectedItems.length === 0) return '0分钟'
|
return colors[Math.floor(Math.random() * colors.length)]
|
||||||
|
}
|
||||||
let totalMinutes = 0
|
|
||||||
selectedItems.forEach(item => {
|
|
||||||
const durationStr = item.approximateDuration
|
|
||||||
const match = durationStr.match(/(\d+)/)
|
|
||||||
if (match) {
|
|
||||||
totalMinutes += parseInt(match[1]) * item.quantity
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (totalMinutes < 60) {
|
|
||||||
return `${totalMinutes}分钟`
|
|
||||||
} else {
|
|
||||||
const hours = Math.floor(totalMinutes / 60)
|
|
||||||
const minutes = totalMinutes % 60
|
|
||||||
if (minutes === 0) {
|
|
||||||
return `${hours}小时`
|
|
||||||
} else {
|
|
||||||
return `${hours}小时${minutes}分钟`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 处理返回按钮点击
|
// 处理返回按钮点击
|
||||||
const handleBackClick = () => {
|
const handleBackClick = () => {
|
||||||
console.log('返回按钮被点击')
|
|
||||||
router.back()
|
router.back()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,26 +225,42 @@ const handleSelectChange = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理减少数量
|
// 处理减少数量
|
||||||
const handleDecreaseQuantity = (item: any) => {
|
const handleDecreaseQuantity = async (item: CartItem) => {
|
||||||
if (item.quantity > 1) {
|
if (item.quantity > 1) {
|
||||||
item.quantity--
|
item.quantity--
|
||||||
|
try {
|
||||||
|
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
||||||
|
} catch (error) {
|
||||||
|
message.error('更新数量失败')
|
||||||
|
item.quantity++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理增加数量
|
// 处理增加数量
|
||||||
const handleIncreaseQuantity = (item: any) => {
|
const handleIncreaseQuantity = async (item: CartItem) => {
|
||||||
if (item.quantity < 99) {
|
if (item.quantity < 99) {
|
||||||
item.quantity++
|
item.quantity++
|
||||||
|
try {
|
||||||
|
await cartApi.updateCartQuantity({ productId: item.productId, quantity: item.quantity })
|
||||||
|
} catch (error) {
|
||||||
|
message.error('更新数量失败')
|
||||||
|
item.quantity--
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理删除商品
|
// 处理删除商品
|
||||||
const handleDeleteItem = (item: any) => {
|
const handleDeleteItem = async (item: CartItem) => {
|
||||||
console.log('删除商品:', item.name)
|
try {
|
||||||
const index = cartItems.value.findIndex(i => i.id === item.id)
|
await cartApi.removeFromCart(item.productId)
|
||||||
if (index > -1) {
|
const index = cartItems.value.findIndex(i => i.id === item.id)
|
||||||
cartItems.value.splice(index, 1)
|
if (index > -1) {
|
||||||
message.success('商品已删除')
|
cartItems.value.splice(index, 1)
|
||||||
|
message.success('商品已删除')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
message.error('删除商品失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,19 +270,26 @@ const handleBrowseProducts = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理结算
|
// 处理结算
|
||||||
const handleCheckout = () => {
|
const handleCheckout = async () => {
|
||||||
const selectedItems = cartItems.value.filter(item => item.selected)
|
const selectedItems = cartItems.value.filter(item => item.selected)
|
||||||
if (selectedItems.length === 0) {
|
if (selectedItems.length === 0) {
|
||||||
message.warning('请先选择要结算的商品')
|
message.warning('请先选择要结算的商品')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('结算购物车:', {
|
|
||||||
items: selectedItems,
|
try {
|
||||||
subtotal: subtotal.value,
|
const order = await orderApi.createOrder({})
|
||||||
totalDuration: totalDuration.value
|
message.success('订单创建成功')
|
||||||
})
|
router.push('/profile')
|
||||||
message.success('正在跳转到结算页面...')
|
} catch (error) {
|
||||||
|
message.error('创建订单失败')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 页面加载时获取购物车数据
|
||||||
|
onMounted(() => {
|
||||||
|
loadCartItems()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -338,13 +361,19 @@ const handleCheckout = () => {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: rgba(0,0,0,0.1);
|
color: rgba(0,0,0,0.1);
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-image img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-details {
|
.item-details {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: space-between;
|
|
||||||
min-height: 80px;
|
min-height: 80px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,6 +382,11 @@ const handleCheckout = () => {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin: 0 0 4px 0;
|
margin: 0 0 4px 0;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-price {
|
.item-price {
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ import { useRouter, useRoute } from 'vue-router'
|
|||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { productApi, type ProductVO } from '@/api/product'
|
import { productApi, type ProductVO } from '@/api/product'
|
||||||
import { fileApi } from '@/api/index'
|
import { fileApi } from '@/api/index'
|
||||||
|
import { cartApi } from '@/api/cart'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@@ -192,15 +193,36 @@ const handleFavoriteClick = () => {
|
|||||||
ElMessage.success(isFavorite.value ? '已收藏' : '已取消收藏')
|
ElMessage.success(isFavorite.value ? '已收藏' : '已取消收藏')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAddToCart = () => {
|
const handleAddToCart = async () => {
|
||||||
console.log('添加到购物车:', product.value.title)
|
console.log('添加到购物车按钮被点击')
|
||||||
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
console.log('商品ID:', product.value.id)
|
||||||
|
console.log('商品标题:', product.value.title)
|
||||||
|
try {
|
||||||
|
console.log('开始调用cartApi.addToCart')
|
||||||
|
await cartApi.addToCart({ productId: product.value.id, quantity: 1 })
|
||||||
|
console.log('调用cartApi.addToCart成功')
|
||||||
|
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('添加到购物车失败:', error)
|
||||||
|
ElMessage.error('添加到购物车失败,请重试')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleBuyNow = () => {
|
const handleBuyNow = async () => {
|
||||||
console.log('立即购买:', product.value.title)
|
console.log('立即购买按钮被点击')
|
||||||
// 这里可以跳转到订单确认页面
|
console.log('商品ID:', product.value.id)
|
||||||
ElMessage.success('跳转到订单确认页面')
|
console.log('商品标题:', product.value.title)
|
||||||
|
try {
|
||||||
|
console.log('开始调用cartApi.addToCart')
|
||||||
|
await cartApi.addToCart({ productId: product.value.id, quantity: 1 })
|
||||||
|
console.log('调用cartApi.addToCart成功')
|
||||||
|
// 跳转到购物车页面
|
||||||
|
console.log('开始跳转到购物车页面')
|
||||||
|
router.push('/cart')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('立即购买失败:', error)
|
||||||
|
ElMessage.error('操作失败,请重试')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 页面挂载时获取商品详情
|
// 页面挂载时获取商品详情
|
||||||
|
|||||||
@@ -94,6 +94,78 @@
|
|||||||
</a-list>
|
</a-list>
|
||||||
</a-card>
|
</a-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 订单列表 -->
|
||||||
|
<a-card v-if="activeTab === 'orders'" :bordered="false" class="content-card">
|
||||||
|
<h3>我的订单</h3>
|
||||||
|
<a-empty v-if="orders.length === 0" description="暂无订单">
|
||||||
|
<a-button type="primary" @click="router.push('/products')">去购物</a-button>
|
||||||
|
</a-empty>
|
||||||
|
<div v-else class="order-list">
|
||||||
|
<a-card v-for="order in orders" :key="order.id" class="order-card">
|
||||||
|
<div class="order-header">
|
||||||
|
<span class="order-no">订单号: {{ order.orderNo }}</span>
|
||||||
|
<span :class="['order-status', order.status === 1 ? 'pending' : order.status === 2 ? 'completed' : 'cancelled']">
|
||||||
|
{{ order.statusText }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="order-items">
|
||||||
|
<div v-for="item in order.items" :key="item.id" class="order-item">
|
||||||
|
<div class="item-image" v-if="item.productImage">
|
||||||
|
<img :src="item.productImage" :alt="item.productTitle" />
|
||||||
|
</div>
|
||||||
|
<div class="item-image" v-else :style="{ backgroundColor: getRandomColor() }">
|
||||||
|
<span>{{ item.productTitle[0] }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="item-info">
|
||||||
|
<div class="item-title">{{ item.productTitle }}</div>
|
||||||
|
<div class="item-price">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="order-footer">
|
||||||
|
<div class="order-total">
|
||||||
|
总计: <span class="total-price">¥{{ order.actualAmount.toFixed(2) }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="order-actions">
|
||||||
|
<a-button v-if="order.status === 1" size="small" danger @click="handleCancelOrder(order.id)">
|
||||||
|
取消订单
|
||||||
|
</a-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a-card>
|
||||||
|
</div>
|
||||||
|
</a-card>
|
||||||
|
|
||||||
|
<!-- 优惠券列表 -->
|
||||||
|
<a-card v-if="activeTab === 'coupons'" :bordered="false" class="content-card">
|
||||||
|
<h3>我的优惠券</h3>
|
||||||
|
<a-empty v-if="coupons.length === 0" description="暂无优惠券">
|
||||||
|
<a-button type="primary">去领取</a-button>
|
||||||
|
</a-empty>
|
||||||
|
<div v-else class="coupon-list">
|
||||||
|
<a-card v-for="coupon in coupons" :key="coupon.id" class="coupon-card">
|
||||||
|
<div class="coupon-content">
|
||||||
|
<div class="coupon-value">
|
||||||
|
{{ coupon.couponType === 1 ? `${coupon.discountValue}折` : `¥${coupon.reduceAmount}` }}
|
||||||
|
</div>
|
||||||
|
<div class="coupon-info">
|
||||||
|
<div class="coupon-name">{{ coupon.couponName }}</div>
|
||||||
|
<div class="coupon-condition" v-if="coupon.couponType === 2">
|
||||||
|
满{{ coupon.minAmount }}元可用
|
||||||
|
</div>
|
||||||
|
<div class="coupon-time">
|
||||||
|
{{ coupon.startTime }} 至 {{ coupon.endTime }}
|
||||||
|
</div>
|
||||||
|
<div :class="['coupon-status', coupon.status === 1 ? 'available' : 'used']">
|
||||||
|
{{ coupon.statusName }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a-card>
|
||||||
|
</div>
|
||||||
|
</a-card>
|
||||||
|
|
||||||
<div class="logout-section">
|
<div class="logout-section">
|
||||||
<a-button danger block @click="handleLogout">
|
<a-button danger block @click="handleLogout">
|
||||||
退出登录
|
退出登录
|
||||||
@@ -154,6 +226,8 @@ import type { UploadProps } from 'ant-design-vue'
|
|||||||
import { authApi } from '@/api/auth'
|
import { authApi } from '@/api/auth'
|
||||||
import { userApi, type UserVO } from '@/api/user'
|
import { userApi, type UserVO } from '@/api/user'
|
||||||
import { fileApi } from '@/api/file'
|
import { fileApi } from '@/api/file'
|
||||||
|
import { orderApi } from '@/api/order'
|
||||||
|
import { couponApi } from '@/api/coupon'
|
||||||
import { DEFAULT_AVATAR } from '@/constants'
|
import { DEFAULT_AVATAR } from '@/constants'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -172,6 +246,12 @@ const editModalVisible = ref(false)
|
|||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
const uploading = ref(false)
|
const uploading = ref(false)
|
||||||
|
|
||||||
|
// 订单和优惠券相关状态
|
||||||
|
const activeTab = ref('')
|
||||||
|
const orders = ref<any[]>([])
|
||||||
|
const coupons = ref<any[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
const editForm = ref({
|
const editForm = ref({
|
||||||
nickname: '',
|
nickname: '',
|
||||||
avatar: '',
|
avatar: '',
|
||||||
@@ -310,12 +390,58 @@ const handleCancelEdit = () => {
|
|||||||
editModalVisible.value = false
|
editModalVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加载订单列表
|
||||||
|
const loadOrders = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const data = await orderApi.getOrderList()
|
||||||
|
orders.value = data
|
||||||
|
} catch (error) {
|
||||||
|
message.error('获取订单列表失败')
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载优惠券列表
|
||||||
|
const loadCoupons = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const data = await couponApi.listUserCoupons()
|
||||||
|
coupons.value = data
|
||||||
|
} catch (error) {
|
||||||
|
message.error('获取优惠券列表失败')
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理取消订单
|
||||||
|
const handleCancelOrder = async (orderId: number) => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认取消订单',
|
||||||
|
content: '确定要取消这个订单吗?',
|
||||||
|
onOk: async () => {
|
||||||
|
try {
|
||||||
|
await orderApi.cancelOrder(orderId)
|
||||||
|
message.success('订单已取消')
|
||||||
|
loadOrders()
|
||||||
|
} catch (error) {
|
||||||
|
message.error('取消订单失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const handleMenuClick = (key: string) => {
|
const handleMenuClick = (key: string) => {
|
||||||
console.log('菜单项被点击:', key)
|
console.log('菜单项被点击:', key)
|
||||||
if (key === 'wishlist') {
|
if (key === 'wishlist') {
|
||||||
router.push('/wishlist')
|
router.push('/wishlist')
|
||||||
} else if (key === 'orders') {
|
} else if (key === 'orders') {
|
||||||
message.info('订单功能开发中...')
|
router.push('/orders')
|
||||||
|
} else if (key === 'coupons') {
|
||||||
|
activeTab.value = 'coupons'
|
||||||
|
loadCoupons()
|
||||||
} else if (key === 'address') {
|
} else if (key === 'address') {
|
||||||
message.info('地址管理功能开发中...')
|
message.info('地址管理功能开发中...')
|
||||||
} else if (key === 'payment') {
|
} else if (key === 'payment') {
|
||||||
@@ -363,6 +489,12 @@ const handleShopClick = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 生成随机颜色
|
||||||
|
const getRandomColor = () => {
|
||||||
|
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||||
|
return colors[Math.floor(Math.random() * colors.length)]
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchUserInfo()
|
fetchUserInfo()
|
||||||
})
|
})
|
||||||
@@ -672,4 +804,213 @@ onMounted(() => {
|
|||||||
color: white !important;
|
color: white !important;
|
||||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content-card {
|
||||||
|
margin: 0 15px 15px;
|
||||||
|
border-radius: 20px;
|
||||||
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-card :deep(.ant-card-body) {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-card h3 {
|
||||||
|
margin: 0 0 20px 0;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1a1a2e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-card {
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
border-bottom: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-no {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-status {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
padding: 4px 12px;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-status.pending {
|
||||||
|
background: #fff7e6;
|
||||||
|
color: #fa8c16;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-status.completed {
|
||||||
|
background: #f6ffed;
|
||||||
|
color: #52c41a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-status.cancelled {
|
||||||
|
background: #fff1f0;
|
||||||
|
color: #ff4d4f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-items {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-item {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-image {
|
||||||
|
width: 60px;
|
||||||
|
height: 60px;
|
||||||
|
border-radius: 8px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: rgba(0,0,0,0.1);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-image img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-info {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-title {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1a1a2e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-price {
|
||||||
|
font-size: 13px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding-top: 10px;
|
||||||
|
border-top: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-total {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.total-price {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #ff4d4f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-card {
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: linear-gradient(135deg, #f5f7ff 0%, #e8ecff 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-value {
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #667eea;
|
||||||
|
padding: 20px;
|
||||||
|
background: rgba(102, 126, 234, 0.1);
|
||||||
|
border-radius: 8px;
|
||||||
|
min-width: 100px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-info {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-name {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1a1a2e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-condition {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #667eea;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-time {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #8b8b9a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-status {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 8px;
|
||||||
|
align-self: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-status.available {
|
||||||
|
background: #f6ffed;
|
||||||
|
color: #52c41a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.coupon-status.used {
|
||||||
|
background: #f5f5f5;
|
||||||
|
color: #8b8b9a;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -72,7 +72,10 @@ const formState = reactive({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const formRules = {
|
const formRules = {
|
||||||
account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
account: [
|
||||||
|
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||||
|
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||||
|
],
|
||||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,9 @@
|
|||||||
<a-button v-if="hasPermission('coupon:edit')" type="link" size="small" @click="showEditModal(record)">
|
<a-button v-if="hasPermission('coupon:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||||
编辑
|
编辑
|
||||||
</a-button>
|
</a-button>
|
||||||
|
<a-button v-if="hasPermission('coupon:assign') && record.status === 1" type="link" size="small" @click="showDistributeModal(record)">
|
||||||
|
发放
|
||||||
|
</a-button>
|
||||||
<a-button v-if="hasPermission('coupon:delete') && record.status !== 2" type="link" size="small" danger @click="handleDelete(record)">
|
<a-button v-if="hasPermission('coupon:delete') && record.status !== 2" type="link" size="small" danger @click="handleDelete(record)">
|
||||||
删除
|
删除
|
||||||
</a-button>
|
</a-button>
|
||||||
@@ -132,6 +135,43 @@
|
|||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
</a-modal>
|
</a-modal>
|
||||||
|
|
||||||
|
<!-- 发放优惠券模态框 -->
|
||||||
|
<a-modal
|
||||||
|
v-model:open="distributeModalVisible"
|
||||||
|
title="发放优惠券"
|
||||||
|
@ok="handleDistributeOk"
|
||||||
|
@cancel="handleDistributeCancel"
|
||||||
|
:confirmLoading="distributeLoading"
|
||||||
|
width="800px"
|
||||||
|
>
|
||||||
|
<a-form
|
||||||
|
ref="distributeFormRef"
|
||||||
|
:model="distributeFormState"
|
||||||
|
:rules="distributeFormRules"
|
||||||
|
:label-col="{ span: 6 }"
|
||||||
|
:wrapper-col="{ span: 16 }"
|
||||||
|
>
|
||||||
|
<a-form-item label="优惠券" name="couponId">
|
||||||
|
<a-input v-model:value="distributeFormState.couponName" disabled />
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label="选择用户" name="userIds">
|
||||||
|
<a-select
|
||||||
|
v-model:value="distributeFormState.userIds"
|
||||||
|
mode="multiple"
|
||||||
|
placeholder="请选择要发放的用户"
|
||||||
|
style="width: 100%"
|
||||||
|
>
|
||||||
|
<a-select-option v-for="user in userList" :key="user.id" :value="user.id">
|
||||||
|
{{ user.nickname }} ({{ user.account }})
|
||||||
|
</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label="发放数量" name="quantity">
|
||||||
|
<a-input-number v-model:value="distributeFormState.quantity" placeholder="请输入发放数量" :min="1" />
|
||||||
|
</a-form-item>
|
||||||
|
</a-form>
|
||||||
|
</a-modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -179,8 +219,15 @@ const searchText = ref('')
|
|||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
const currentCoupon = ref<Coupon | null>(null)
|
const currentCoupon = ref<Coupon | null>(null)
|
||||||
|
|
||||||
|
// 发放优惠券相关状态
|
||||||
|
const distributeModalVisible = ref(false)
|
||||||
|
const distributeLoading = ref(false)
|
||||||
|
const distributeFormRef = ref<FormInstance>()
|
||||||
|
const currentDistributeCoupon = ref<Coupon | null>(null)
|
||||||
|
|
||||||
const couponList = ref<Coupon[]>([])
|
const couponList = ref<Coupon[]>([])
|
||||||
const tagList = ref<TagVO[]>([])
|
const tagList = ref<TagVO[]>([])
|
||||||
|
const userList = ref<any[]>([])
|
||||||
|
|
||||||
const pagination = reactive({
|
const pagination = reactive({
|
||||||
current: 1,
|
current: 1,
|
||||||
@@ -217,6 +264,19 @@ const formRules = {
|
|||||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
|
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发放优惠券表单状态
|
||||||
|
const distributeFormState = reactive({
|
||||||
|
couponName: '',
|
||||||
|
userIds: [] as number[],
|
||||||
|
quantity: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
// 发放优惠券表单规则
|
||||||
|
const distributeFormRules = {
|
||||||
|
userIds: [{ required: true, message: '请选择要发放的用户', trigger: 'change' }],
|
||||||
|
quantity: [{ required: true, message: '请输入发放数量', trigger: 'blur' }]
|
||||||
|
}
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ title: '优惠券编码', dataIndex: 'couponCode', key: 'couponCode' },
|
{ title: '优惠券编码', dataIndex: 'couponCode', key: 'couponCode' },
|
||||||
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
||||||
@@ -371,6 +431,62 @@ const handleDelete = (record: Coupon) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加载用户列表
|
||||||
|
const fetchUsers = async () => {
|
||||||
|
try {
|
||||||
|
// 这里应该调用获取用户列表的API
|
||||||
|
// 暂时使用模拟数据
|
||||||
|
userList.value = [
|
||||||
|
{ id: 1, nickname: '用户1', account: 'user1' },
|
||||||
|
{ id: 2, nickname: '用户2', account: 'user2' },
|
||||||
|
{ id: 3, nickname: '用户3', account: 'user3' }
|
||||||
|
]
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取用户列表失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示发放优惠券模态框
|
||||||
|
const showDistributeModal = (record: Coupon) => {
|
||||||
|
currentDistributeCoupon.value = record
|
||||||
|
distributeFormState.couponName = record.couponName
|
||||||
|
distributeFormState.userIds = []
|
||||||
|
distributeFormState.quantity = 1
|
||||||
|
fetchUsers()
|
||||||
|
distributeModalVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理发放优惠券
|
||||||
|
const handleDistributeOk = async () => {
|
||||||
|
try {
|
||||||
|
await distributeFormRef.value?.validate()
|
||||||
|
distributeLoading.value = true
|
||||||
|
|
||||||
|
if (!currentDistributeCoupon.value) return
|
||||||
|
|
||||||
|
// 调用发放优惠券的API
|
||||||
|
await adminCouponApi.distributeCoupon({
|
||||||
|
couponId: currentDistributeCoupon.value.id,
|
||||||
|
userIds: distributeFormState.userIds,
|
||||||
|
quantity: distributeFormState.quantity
|
||||||
|
})
|
||||||
|
|
||||||
|
message.success('发放成功')
|
||||||
|
distributeModalVisible.value = false
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
message.error('发放失败')
|
||||||
|
} finally {
|
||||||
|
distributeLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消发放优惠券
|
||||||
|
const handleDistributeCancel = () => {
|
||||||
|
distributeModalVisible.value = false
|
||||||
|
distributeFormRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await loadUserPermissions()
|
await loadUserPermissions()
|
||||||
await fetchTags()
|
await fetchTags()
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public class AuthInterceptor implements HandlerInterceptor {
|
|||||||
return path.contains("/user/login") ||
|
return path.contains("/user/login") ||
|
||||||
path.contains("/user/register") ||
|
path.contains("/user/register") ||
|
||||||
path.contains("/user/refresh-token") ||
|
path.contains("/user/refresh-token") ||
|
||||||
|
path.contains("/user/get/account") ||
|
||||||
path.contains("/shop/list/simple") ||
|
path.contains("/shop/list/simple") ||
|
||||||
path.contains("/admin/auth/login") ||
|
path.contains("/admin/auth/login") ||
|
||||||
path.contains("/admin/object-storage-file/upload") ||
|
path.contains("/admin/object-storage-file/upload") ||
|
||||||
|
|||||||
+10
@@ -108,4 +108,14 @@ public class CouponController {
|
|||||||
List<UserCouponVO> availableCoupons = couponService.getAvailableCoupons(userId, productTags, productPrice);
|
List<UserCouponVO> availableCoupons = couponService.getAvailableCoupons(userId, productTags, productPrice);
|
||||||
return Result.success(availableCoupons);
|
return Result.success(availableCoupons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发放优惠券
|
||||||
|
*/
|
||||||
|
@PostMapping("/distribute")
|
||||||
|
@RequirePermission("coupon:assign")
|
||||||
|
public Result<Boolean> distributeCoupon(@RequestParam Long couponId, @RequestParam List<Long> userIds, @RequestParam Integer quantity, @RequestParam(required = false) Long shopId) {
|
||||||
|
boolean success = couponService.distributeCoupon(couponId, userIds, quantity, shopId);
|
||||||
|
return Result.success(success);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,4 +88,14 @@ public interface CouponService extends IService<CouponDO> {
|
|||||||
* @return 可用优惠券列表
|
* @return 可用优惠券列表
|
||||||
*/
|
*/
|
||||||
List<UserCouponVO> getAvailableCoupons(Long userId, String productTags, Double productPrice);
|
List<UserCouponVO> getAvailableCoupons(Long userId, String productTags, Double productPrice);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发放优惠券
|
||||||
|
* @param couponId 优惠券ID
|
||||||
|
* @param userIds 用户ID列表
|
||||||
|
* @param quantity 发放数量
|
||||||
|
* @param shopId 店铺ID
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean distributeCoupon(Long couponId, List<Long> userIds, Integer quantity, Long shopId);
|
||||||
}
|
}
|
||||||
|
|||||||
+43
@@ -268,6 +268,49 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
|||||||
return availableCoupons;
|
return availableCoupons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public boolean distributeCoupon(Long couponId, List<Long> userIds, Integer quantity, Long shopId) {
|
||||||
|
// 检查优惠券是否存在
|
||||||
|
CouponDO couponDO = getById(couponId);
|
||||||
|
if (couponDO == null || couponDO.getIsDelete() == 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查优惠券是否可用
|
||||||
|
if (couponDO.getStatus() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查优惠券数量是否足够
|
||||||
|
if (couponDO.getUsedCount() + userIds.size() * quantity > couponDO.getTotalCount()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发放优惠券
|
||||||
|
for (Long userId : userIds) {
|
||||||
|
for (int i = 0; i < quantity; i++) {
|
||||||
|
// 检查是否已经分配
|
||||||
|
UserCouponDO existing = userCouponMapper.selectOne(new LambdaQueryWrapper<UserCouponDO>()
|
||||||
|
.eq(UserCouponDO::getUserId, userId)
|
||||||
|
.eq(UserCouponDO::getCouponId, couponId)
|
||||||
|
.eq(UserCouponDO::getIsDelete, 0)
|
||||||
|
);
|
||||||
|
if (existing == null) {
|
||||||
|
// 分配优惠券
|
||||||
|
UserCouponDO userCouponDO = new UserCouponDO();
|
||||||
|
userCouponDO.setUserId(userId);
|
||||||
|
userCouponDO.setCouponId(couponId);
|
||||||
|
userCouponDO.setStatus(1);
|
||||||
|
userCouponDO.setObtainTime(LocalDateTime.now());
|
||||||
|
userCouponMapper.insert(userCouponDO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理优惠券标签关联
|
* 处理优惠券标签关联
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -553,3 +553,107 @@ WHERE u.type = 2
|
|||||||
'coupon:delete',
|
'coupon:delete',
|
||||||
'coupon:assign'
|
'coupon:assign'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- 购物车表
|
||||||
|
create table t_cart
|
||||||
|
(
|
||||||
|
id bigint unsigned auto_increment comment '购物车唯一主键ID'
|
||||||
|
primary key comment '购物车主键索引',
|
||||||
|
user_id bigint unsigned not null comment '关联用户表主键',
|
||||||
|
product_id bigint unsigned not null comment '关联商品表主键',
|
||||||
|
quantity int unsigned default 1 not null comment '商品数量',
|
||||||
|
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||||
|
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||||
|
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||||
|
constraint uk_user_product
|
||||||
|
unique (user_id, product_id) comment '用户-商品唯一索引'
|
||||||
|
) comment '购物车表';
|
||||||
|
|
||||||
|
create index idx_user_id
|
||||||
|
on t_cart (user_id) comment '按用户查询购物车的索引';
|
||||||
|
|
||||||
|
-- 订单表
|
||||||
|
create table t_order
|
||||||
|
(
|
||||||
|
id bigint unsigned auto_increment comment '订单唯一主键ID'
|
||||||
|
primary key comment '订单主键索引',
|
||||||
|
order_no varchar(50) not null comment '订单编号',
|
||||||
|
user_id bigint unsigned not null comment '关联用户表主键',
|
||||||
|
total_amount decimal(10, 2) not null comment '订单总金额',
|
||||||
|
actual_amount decimal(10, 2) not null comment '实际支付金额',
|
||||||
|
coupon_id bigint unsigned default 0 null comment '使用的优惠券ID',
|
||||||
|
status tinyint unsigned default 1 not null comment '订单状态:1-待使用,2-已完成,3-已取消',
|
||||||
|
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||||
|
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||||
|
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||||
|
constraint uk_order_no
|
||||||
|
unique (order_no) comment '订单编号唯一索引'
|
||||||
|
) comment '订单表';
|
||||||
|
|
||||||
|
create index idx_status
|
||||||
|
on t_order (status) comment '按状态查询订单的索引';
|
||||||
|
|
||||||
|
create index idx_user_id
|
||||||
|
on t_order (user_id) comment '按用户查询订单的索引';
|
||||||
|
|
||||||
|
-- 订单商品表
|
||||||
|
create table t_order_item
|
||||||
|
(
|
||||||
|
id bigint unsigned auto_increment comment '订单商品唯一主键ID'
|
||||||
|
primary key comment '订单商品主键索引',
|
||||||
|
order_id bigint unsigned not null comment '关联订单表主键',
|
||||||
|
product_id bigint unsigned not null comment '关联商品表主键',
|
||||||
|
quantity int unsigned not null comment '商品数量',
|
||||||
|
price decimal(10, 2) not null comment '商品单价',
|
||||||
|
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||||
|
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||||
|
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
|
||||||
|
) comment '订单商品表';
|
||||||
|
|
||||||
|
create index idx_order_id
|
||||||
|
on t_order_item (order_id) comment '按订单查询商品的索引';
|
||||||
|
|
||||||
|
-- 插入订单管理相关权限
|
||||||
|
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||||
|
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
|
||||||
|
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
|
||||||
|
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
|
||||||
|
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
|
||||||
|
|
||||||
|
-- 为管理员(type=4)分配订单管理权限
|
||||||
|
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||||
|
SELECT
|
||||||
|
u.id as user_id,
|
||||||
|
p.id as permission_id,
|
||||||
|
NOW() as create_time,
|
||||||
|
NOW() as update_time
|
||||||
|
FROM t_user u
|
||||||
|
CROSS JOIN t_permission p
|
||||||
|
WHERE u.type = 4
|
||||||
|
AND p.is_delete = 0
|
||||||
|
AND p.permission_code IN (
|
||||||
|
'order:view',
|
||||||
|
'order:edit',
|
||||||
|
'order:delete',
|
||||||
|
'order:process'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 为店长(type=2)分配订单管理权限
|
||||||
|
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||||
|
SELECT
|
||||||
|
u.id as user_id,
|
||||||
|
p.id as permission_id,
|
||||||
|
NOW() as create_time,
|
||||||
|
NOW() as update_time
|
||||||
|
FROM t_user u
|
||||||
|
CROSS JOIN t_permission p
|
||||||
|
WHERE u.type = 2
|
||||||
|
AND p.is_delete = 0
|
||||||
|
AND p.permission_code IN (
|
||||||
|
'order:view',
|
||||||
|
'order:edit',
|
||||||
|
'order:delete',
|
||||||
|
'order:process'
|
||||||
|
);
|
||||||
+8
-7
@@ -39,17 +39,17 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
ServerHttpRequest request = exchange.getRequest();
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
String path = request.getURI().getPath();
|
String path = request.getURI().getPath();
|
||||||
|
|
||||||
log.info("网关接收到请求: {}", path);
|
log.info("Gateway received request: {}", path);
|
||||||
|
|
||||||
// 1. 白名单校验(登录和注册接口不需要认证)
|
// 1. Whitelist check (login and register interfaces don't need authentication)
|
||||||
log.info("检查路径是否在白名单中: {}", path);
|
log.info("Checking if path is in whitelist: {}", path);
|
||||||
boolean isWhitelist = isWhitelist(path);
|
boolean isWhitelist = isWhitelist(path);
|
||||||
log.info("白名单校验结果: {}", isWhitelist);
|
log.info("Whitelist check result: {}", isWhitelist);
|
||||||
if (isWhitelist) {
|
if (isWhitelist) {
|
||||||
log.info("路径在白名单中,直接放行");
|
log.info("Path is in whitelist, passing through directly");
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
log.info("路径不在白名单中,需要进行Token校验");
|
log.info("Path is not in whitelist, need to check Token");
|
||||||
|
|
||||||
// 2. Token 校验
|
// 2. Token 校验
|
||||||
String token = request.getHeaders().getFirst("Authorization");
|
String token = request.getHeaders().getFirst("Authorization");
|
||||||
@@ -75,7 +75,8 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
path.equals("/api/user/register") ||
|
path.equals("/api/user/register") ||
|
||||||
path.equals("/api/user/refresh-token") ||
|
path.equals("/api/user/refresh-token") ||
|
||||||
path.equals("/api/shop/list/simple") ||
|
path.equals("/api/shop/list/simple") ||
|
||||||
path.equals("/api/admin/auth/login");
|
path.equals("/api/admin/auth/login") ||
|
||||||
|
path.contains("/api/user/get/account");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,6 +57,18 @@ spring:
|
|||||||
- Path=/api/coupon/**
|
- Path=/api/coupon/**
|
||||||
filters:
|
filters:
|
||||||
- RewritePath=/api/(?<remaining>.*), /${remaining}
|
- RewritePath=/api/(?<remaining>.*), /${remaining}
|
||||||
|
- id: cart-route
|
||||||
|
uri: lb://yumi-nail-core
|
||||||
|
predicates:
|
||||||
|
- Path=/api/cart/**
|
||||||
|
filters:
|
||||||
|
- RewritePath=/api/(?<remaining>.*), /${remaining}
|
||||||
|
- id: order-route
|
||||||
|
uri: lb://yumi-nail-core
|
||||||
|
predicates:
|
||||||
|
- Path=/api/order/**
|
||||||
|
filters:
|
||||||
|
- RewritePath=/api/(?<remaining>.*), /${remaining}
|
||||||
# 后台管理API路由
|
# 后台管理API路由
|
||||||
- id: admin-route
|
- id: admin-route
|
||||||
uri: lb://yumi-nail-core
|
uri: lb://yumi-nail-core
|
||||||
|
|||||||
Reference in New Issue
Block a user