修复前端打包问题
提取基础接口为配置
This commit is contained in:
@@ -286,8 +286,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { adminCouponApi, adminTagApi, adminShopApi, userApi, type Shop } from '@/api/admin'
|
||||
@@ -408,7 +408,7 @@ const formRules = {
|
||||
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
|
||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
}
|
||||
} as any
|
||||
|
||||
// 发放优惠券表单状态
|
||||
const distributeFormState = reactive({
|
||||
@@ -421,7 +421,7 @@ const distributeFormState = reactive({
|
||||
const distributeFormRules = {
|
||||
userIds: [{ required: true, message: '请选择要发放的用户', trigger: 'change' }],
|
||||
quantity: [{ required: true, message: '请输入发放数量', trigger: 'blur' }]
|
||||
}
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '优惠券编码', dataIndex: 'couponCode', key: 'couponCode' },
|
||||
@@ -456,15 +456,15 @@ const fetchCoupons = async () => {
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
const res = await adminCouponApi.listAllCoupons(shopId)
|
||||
const res = await adminCouponApi.listAllCoupons(shopId) as unknown as Coupon[]
|
||||
// 后端返回的是数组,直接使用
|
||||
if (Array.isArray(res)) {
|
||||
couponList.value = res
|
||||
pagination.total = res.length
|
||||
} else {
|
||||
// 兼容分页数据结构
|
||||
couponList.value = res?.list || []
|
||||
pagination.total = res?.total || 0
|
||||
couponList.value = (res as any)?.list || []
|
||||
pagination.total = (res as any)?.total || 0
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取优惠券列表失败')
|
||||
@@ -475,7 +475,7 @@ const fetchCoupons = async () => {
|
||||
|
||||
const fetchTags = async () => {
|
||||
try {
|
||||
const res = await adminTagApi.listAllTags()
|
||||
const res = await adminTagApi.listAllTags() as unknown as TagVO[]
|
||||
tagList.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
@@ -485,7 +485,7 @@ const fetchTags = async () => {
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const res = await adminShopApi.listAllShops()
|
||||
const res = await adminShopApi.listAllShops() as unknown as Shop[]
|
||||
shops.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
@@ -526,27 +526,28 @@ const showAddModal = () => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: Coupon) => {
|
||||
if (!record) {
|
||||
const showEditModal = (record: Record<string, any>) => {
|
||||
const coupon = record as Coupon
|
||||
if (!coupon) {
|
||||
message.error('优惠券数据不存在')
|
||||
return
|
||||
}
|
||||
try {
|
||||
isEdit.value = true
|
||||
currentCoupon.value = record
|
||||
currentCoupon.value = coupon
|
||||
Object.assign(formState, {
|
||||
couponCode: record.couponCode || '',
|
||||
couponName: record.couponName || '',
|
||||
couponType: record.couponType || 1,
|
||||
discountValue: record.discountValue || 0,
|
||||
minAmount: record.minAmount || 0,
|
||||
reduceAmount: record.reduceAmount || 0,
|
||||
totalCount: record.totalCount || 0,
|
||||
startTime: record.startTime ? dayjs(record.startTime) : undefined,
|
||||
endTime: record.endTime ? dayjs(record.endTime) : undefined,
|
||||
availableTagIds: record.availableTags ? record.availableTags.map(tag => tag.id) : [],
|
||||
unavailableTagIds: record.unavailableTags ? record.unavailableTags.map(tag => tag.id) : [],
|
||||
shopId: record.shopId
|
||||
couponCode: coupon.couponCode || '',
|
||||
couponName: coupon.couponName || '',
|
||||
couponType: coupon.couponType || 1,
|
||||
discountValue: coupon.discountValue || 0,
|
||||
minAmount: coupon.minAmount || 0,
|
||||
reduceAmount: coupon.reduceAmount || 0,
|
||||
totalCount: coupon.totalCount || 0,
|
||||
startTime: coupon.startTime ? dayjs(coupon.startTime) : undefined,
|
||||
endTime: coupon.endTime ? dayjs(coupon.endTime) : undefined,
|
||||
availableTagIds: coupon.availableTags ? coupon.availableTags.map(tag => tag.id) : [],
|
||||
unavailableTagIds: coupon.unavailableTags ? coupon.unavailableTags.map(tag => tag.id) : [],
|
||||
shopId: coupon.shopId
|
||||
})
|
||||
modalVisible.value = true
|
||||
} catch (error) {
|
||||
@@ -555,25 +556,26 @@ const showEditModal = (record: Coupon) => {
|
||||
}
|
||||
}
|
||||
|
||||
const showViewModal = (record: Coupon) => {
|
||||
if (!record) {
|
||||
const showViewModal = (record: Record<string, any>) => {
|
||||
const coupon = record as Coupon
|
||||
if (!coupon) {
|
||||
message.error('优惠券数据不存在')
|
||||
return
|
||||
}
|
||||
try {
|
||||
Object.assign(viewFormState, {
|
||||
couponCode: record.couponCode || '',
|
||||
couponName: record.couponName || '',
|
||||
couponType: record.couponType || 1,
|
||||
discountValue: record.discountValue || 0,
|
||||
minAmount: record.minAmount || 0,
|
||||
reduceAmount: record.reduceAmount || 0,
|
||||
totalCount: record.totalCount || 0,
|
||||
startTime: record.startTime ? dayjs(record.startTime) : undefined,
|
||||
endTime: record.endTime ? dayjs(record.endTime) : undefined,
|
||||
availableTagIds: record.availableTags ? record.availableTags.map(tag => tag.id) : [],
|
||||
unavailableTagIds: record.unavailableTags ? record.unavailableTags.map(tag => tag.id) : [],
|
||||
shopId: record.shopId
|
||||
couponCode: coupon.couponCode || '',
|
||||
couponName: coupon.couponName || '',
|
||||
couponType: coupon.couponType || 1,
|
||||
discountValue: coupon.discountValue || 0,
|
||||
minAmount: coupon.minAmount || 0,
|
||||
reduceAmount: coupon.reduceAmount || 0,
|
||||
totalCount: coupon.totalCount || 0,
|
||||
startTime: coupon.startTime ? dayjs(coupon.startTime) : undefined,
|
||||
endTime: coupon.endTime ? dayjs(coupon.endTime) : undefined,
|
||||
availableTagIds: coupon.availableTags ? coupon.availableTags.map(tag => tag.id) : [],
|
||||
unavailableTagIds: coupon.unavailableTags ? coupon.unavailableTags.map(tag => tag.id) : [],
|
||||
shopId: coupon.shopId
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
} catch (error) {
|
||||
@@ -640,10 +642,10 @@ const handleModalOk = async () => {
|
||||
}
|
||||
|
||||
if (isEdit.value && currentCoupon.value) {
|
||||
await adminCouponApi.updateCoupon(currentCoupon.value.id, requestData, shopId)
|
||||
await adminCouponApi.updateCoupon(currentCoupon.value.id, requestData)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminCouponApi.createCoupon(requestData, shopId)
|
||||
await adminCouponApi.createCoupon(requestData)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
@@ -658,7 +660,7 @@ const handleModalOk = async () => {
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
message.confirm({
|
||||
Modal.confirm({
|
||||
title: '确认关闭',
|
||||
content: '确定要关闭编辑模态框吗?未保存的更改将会丢失。',
|
||||
onOk: () => {
|
||||
@@ -668,15 +670,14 @@ const handleModalCancel = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const handleDelete = (record: Coupon) => {
|
||||
message.confirm({
|
||||
const handleDelete = (record: Record<string, any>) => {
|
||||
const coupon = record as Coupon
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
content: `确定要删除优惠券 ${record.couponName} 吗?`,
|
||||
content: `确定要删除优惠券 ${coupon.couponName} 吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : record.shopId
|
||||
await adminCouponApi.deleteCoupon(record.id, shopId)
|
||||
await adminCouponApi.deleteCoupon(coupon.id)
|
||||
message.success('删除成功')
|
||||
fetchCoupons()
|
||||
} catch (error) {
|
||||
@@ -695,10 +696,9 @@ const fetchUsers = async () => {
|
||||
const res = await userApi.listUsers({
|
||||
page: 1,
|
||||
size: 100,
|
||||
shopId: shopId,
|
||||
status: 1 // 只获取激活状态的用户
|
||||
shopId: shopId
|
||||
})
|
||||
userList.value = res.list || []
|
||||
userList.value = (res as any).list || []
|
||||
} catch (error) {
|
||||
console.error('获取用户列表失败:', error)
|
||||
// 如果API调用失败,使用模拟数据作为 fallback
|
||||
@@ -711,9 +711,10 @@ const fetchUsers = async () => {
|
||||
}
|
||||
|
||||
// 显示发放优惠券模态框
|
||||
const showDistributeModal = (record: Coupon) => {
|
||||
currentDistributeCoupon.value = record
|
||||
distributeFormState.couponName = record.couponName
|
||||
const showDistributeModal = (record: Record<string, any>) => {
|
||||
const coupon = record as Coupon
|
||||
currentDistributeCoupon.value = coupon
|
||||
distributeFormState.couponName = coupon.couponName
|
||||
distributeFormState.userIds = []
|
||||
distributeFormState.quantity = 1
|
||||
fetchUsers()
|
||||
@@ -728,21 +729,12 @@ const handleDistributeOk = async () => {
|
||||
|
||||
if (!currentDistributeCoupon.value) return
|
||||
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : currentDistributeCoupon.value.shopId
|
||||
|
||||
if (!shopId) {
|
||||
message.error('请选择所属店铺')
|
||||
distributeLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
// 调用发放优惠券的API
|
||||
await adminCouponApi.distributeCoupon({
|
||||
couponId: currentDistributeCoupon.value.id,
|
||||
userIds: distributeFormState.userIds,
|
||||
quantity: distributeFormState.quantity
|
||||
}, shopId)
|
||||
})
|
||||
|
||||
message.success('发放成功')
|
||||
distributeModalVisible.value = false
|
||||
|
||||
Reference in New Issue
Block a user