完善代码
This commit is contained in:
@@ -57,8 +57,9 @@ export const orderApi = {
|
||||
}))
|
||||
},
|
||||
|
||||
getList(params?: PageParams & { status?: string }): Promise<ApiResponse<PageResponse<Order>>> {
|
||||
getList(params?: PageParams & { status?: string; userId?: number }): Promise<ApiResponse<PageResponse<Order>>> {
|
||||
return request.post<ApiResponse<Record<string, any>>>('/api/order/my-orders', {
|
||||
userId: params?.userId,
|
||||
status: orderStatusToCode(params?.status),
|
||||
page: params?.page ?? 0,
|
||||
size: params?.size ?? 10,
|
||||
@@ -122,7 +123,7 @@ export const orderApi = {
|
||||
return request.delete(`/api/order/${id}`)
|
||||
},
|
||||
|
||||
getStatistics(): Promise<ApiResponse<{
|
||||
getStatistics(userId?: number): Promise<ApiResponse<{
|
||||
total: number;
|
||||
pending: number;
|
||||
paid: number;
|
||||
@@ -130,7 +131,7 @@ export const orderApi = {
|
||||
completed: number;
|
||||
cancelled: number
|
||||
}>> {
|
||||
return request.get<ApiResponse<any>>('/api/order/statistics').then((res) => ({
|
||||
return request.get<ApiResponse<any>>('/api/order/statistics', userId ? {userId} : undefined).then((res) => ({
|
||||
...res,
|
||||
data: {
|
||||
total: Number(res.data.totalOrders || 0),
|
||||
|
||||
@@ -58,22 +58,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 热门搜索 -->
|
||||
<div v-if="!searchQuery" class="search-section">
|
||||
<div class="section-header">
|
||||
<span class="title">热门搜索</span>
|
||||
</div>
|
||||
<div class="tag-list">
|
||||
<el-tag
|
||||
v-for="item in hotSearches"
|
||||
:key="item"
|
||||
@click="selectHot(item)"
|
||||
>
|
||||
{{ item }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 搜索建议 -->
|
||||
<div v-if="searchQuery && suggestions.length > 0" class="search-suggestions">
|
||||
<div class="section-header">
|
||||
@@ -116,7 +100,7 @@
|
||||
<el-select v-model="advancedForm.category" placeholder="选择分类">
|
||||
<el-option label="全部分类" value=""/>
|
||||
<el-option v-for="item in categories" :key="item" :label="item" :value="item"/>
|
||||
<el-option label="图书音像" value="books"/>
|
||||
<!-- <el-option label="图书音像" value="books"/>-->
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="价格区间">
|
||||
@@ -157,7 +141,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {ref, reactive, watch, onMounted} from 'vue'
|
||||
import {onMounted, reactive, ref, watch} from 'vue'
|
||||
import {useRouter} from 'vue-router'
|
||||
import {debounce} from 'lodash-es'
|
||||
import {productApi} from '@/api/modules/product'
|
||||
@@ -172,16 +156,6 @@ const activeCollapse = ref<string[]>([])
|
||||
// 搜索历史
|
||||
const searchHistory = ref<string[]>([])
|
||||
|
||||
// 热门搜索
|
||||
const hotSearches = ref([
|
||||
'iPhone 15',
|
||||
'MacBook Pro',
|
||||
'限时活动',
|
||||
'AirPods',
|
||||
'限时特价',
|
||||
'新品上市'
|
||||
])
|
||||
|
||||
// 搜索建议
|
||||
const suggestions = ref<any[]>([])
|
||||
const categories = ref<string[]>([])
|
||||
|
||||
@@ -95,7 +95,8 @@
|
||||
<template #default="{ row }">
|
||||
<el-button text type="primary" @click="openDetail(row.id)">查看</el-button>
|
||||
<el-button text type="primary" @click="openEditDialog(row.id)">编辑</el-button>
|
||||
<el-button text type="danger" @click="removeProduct(row)">删除</el-button>
|
||||
<el-button v-if="row.status === 1" text type="danger" @click="removeProduct(row)">下架</el-button>
|
||||
<el-button v-else disabled text type="info">已下架</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -185,8 +186,8 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {onMounted, reactive, ref} from 'vue'
|
||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||
import type {FormInstance, FormRules} from 'element-plus'
|
||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||
import dayjs from 'dayjs'
|
||||
import ImageUpload from '@/components/common/ImageUpload.vue'
|
||||
import SafeImage from '@/components/common/SafeImage.vue'
|
||||
@@ -207,7 +208,7 @@ const categories = ref<string[]>([])
|
||||
const query = reactive({
|
||||
keyword: '',
|
||||
category: '',
|
||||
status: '' as number | '',
|
||||
status: 1 as number | '',
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
@@ -348,12 +349,19 @@ const submitForm = async () => {
|
||||
}
|
||||
|
||||
const removeProduct = async (row: AdminProductRow) => {
|
||||
await ElMessageBox.confirm(`确定删除商品“${row.name}”吗?`, '删除确认', {
|
||||
type: 'warning',
|
||||
})
|
||||
await adminApi.deleteProduct(row.id)
|
||||
ElMessage.success('商品已删除')
|
||||
await reloadData()
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定下架商品“${row.name}”吗?下架后前台将不再展示该商品,历史订单仍会保留。`, '下架确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '确认下架',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
await adminApi.deleteProduct(row.id)
|
||||
ElMessage.success('商品已下架')
|
||||
await reloadData()
|
||||
} catch (error: any) {
|
||||
if (error === 'cancel' || error === 'close') return
|
||||
ElMessage.error(error?.message || '商品下架失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
@@ -364,7 +372,7 @@ const handleSearch = () => {
|
||||
const handleReset = () => {
|
||||
query.keyword = ''
|
||||
query.category = ''
|
||||
query.status = ''
|
||||
query.status = 1
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {ref, onMounted} from 'vue'
|
||||
import {onMounted, ref} from 'vue'
|
||||
import {useRouter} from 'vue-router'
|
||||
import {ElMessage} from 'element-plus'
|
||||
import FlashSaleCard from '@/components/business/FlashSaleCard.vue'
|
||||
@@ -239,7 +239,7 @@ const categoryIconMap: Record<string, string> = {
|
||||
'电子产品': 'Monitor',
|
||||
'家电': 'House',
|
||||
'服饰鞋包': 'Goods',
|
||||
'图书音像': 'Reading',
|
||||
// '图书音像': 'Reading',
|
||||
'食品饮料': 'Coffee',
|
||||
'运动户外': 'Trophy',
|
||||
'美妆护肤': 'MagicStick',
|
||||
|
||||
@@ -156,12 +156,13 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {ref, reactive, onMounted} from 'vue'
|
||||
import {onMounted, reactive, ref} from 'vue'
|
||||
import {useRouter} from 'vue-router'
|
||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||
import {orderApi} from '@/api/modules/order'
|
||||
import {reviewApi} from '@/api/modules/review'
|
||||
import {useCartStore} from '@/stores/cart'
|
||||
import {useUserStore} from '@/stores/user'
|
||||
import type {Order} from '@/types/api'
|
||||
import dayjs from 'dayjs'
|
||||
import SafeImage from '@/components/common/SafeImage.vue'
|
||||
@@ -170,6 +171,7 @@ import ReturnDialog from '@/components/business/ReturnDialog.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const cartStore = useCartStore()
|
||||
const userStore = useUserStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const orders = ref<Order[]>([])
|
||||
@@ -213,9 +215,17 @@ const getStatusText = (status: string) => ({
|
||||
}[status] || status)
|
||||
|
||||
const loadOrders = async () => {
|
||||
const currentUserId = userStore.user?.id
|
||||
if (!currentUserId) {
|
||||
ElMessage.warning('请先登录后查看订单')
|
||||
await router.push({path: '/login', query: {redirect: '/orders'}})
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await orderApi.getList({
|
||||
userId: currentUserId,
|
||||
page: pagination.page - 1,
|
||||
size: pagination.size,
|
||||
status: filters.status || undefined
|
||||
@@ -236,7 +246,10 @@ const loadOrders = async () => {
|
||||
|
||||
const loadStatistics = async () => {
|
||||
try {
|
||||
const res = await orderApi.getStatistics()
|
||||
const currentUserId = userStore.user?.id
|
||||
if (!currentUserId) return
|
||||
|
||||
const res = await orderApi.getStatistics(currentUserId)
|
||||
if (res.success) {
|
||||
orderStats.value[0].count = res.data.total
|
||||
orderStats.value[1].count = res.data.pending
|
||||
|
||||
Reference in New Issue
Block a user