product.ts
3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import axios from 'axios'
// 创建axios实例
const api = axios.create({
baseURL: 'http://localhost:8083/api',
timeout: 10000
})
// 请求拦截器
api.interceptors.request.use(
config => {
const token = localStorage.getItem('token')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
},
error => {
return Promise.reject(error)
}
)
// 响应拦截器
api.interceptors.response.use(
response => {
return response.data
},
error => {
if (error.response?.status === 401) {
localStorage.removeItem('token')
localStorage.removeItem('userInfo')
window.location.href = '/login'
}
return Promise.reject(error)
}
)
// 产品信息接口
export interface ProductInfo {
productId: number
productCode: string
productName: string
productModel: string
productType: string
storageCapacity: string
color: string
officialPrice: number
saleStatus: number
rebateFlag: number
saleStartDate: string
saleEndDate: string
imageUrl: string
remark: string
createTime: string
updateTime: string
}
// 产品简单信息接口(用于下拉选择)
export interface ProductSimpleRes {
productId: number
productCode: string
productName: string
}
// 产品查询请求参数
export interface ProductQueryReq {
productCode?: string
productName?: string
productModel?: string
saleStatus?: number
rebateFlag?: number
pageNum: number
pageSize: number
}
// 产品新增请求参数
export interface ProductAddReq {
productCode: string
productName: string
productModel: string
productType: string
storageCapacity: string
color: string
officialPrice: number
saleStatus: number
rebateFlag: number
saleStartDate: string
saleEndDate: string
imageUrl?: string
remark?: string
}
// 产品修改请求参数
export interface ProductUpdateReq {
productId: number
productCode: string
productName: string
productModel: string
productType: string
storageCapacity: string
color: string
officialPrice: number
saleStatus: number
rebateFlag: number
saleStartDate: string
saleEndDate: string
imageUrl?: string
remark?: string
}
// 分页数据接口
export interface PageData<T> {
records: T[]
total: number
current: number
size: number
pages: number
}
// API响应接口
export interface ApiResponse<T> {
code: number
message: string
data: T
}
// API接口
export const productApi = {
// 获取产品列表
getProductList: (params: ProductQueryReq) => {
return api.get<ApiResponse<PageData<ProductInfo>>>('/product/list', { params })
},
// 获取产品详情
getProductDetail: (productId: number) => {
return api.get<ProductInfo>(`/product/${productId}`)
},
// 新增产品
addProduct: (data: ProductAddReq) => {
return api.post('/product', data)
},
// 修改产品
updateProduct: (data: ProductUpdateReq) => {
return api.post('/product/update', data)
},
// 删除产品
deleteProduct: (productId: number) => {
return api.delete(`/product/${productId}`)
},
// 批量删除产品
batchDeleteProduct: (productIds: number[]) => {
return api.post('/product/batchDelete', productIds)
},
// 修改销售状态
updateSaleStatus: (productId: number, saleStatus: number) => {
return api.post(`/product/${productId}/status`, null, { params: { saleStatus } })
},
// 修改返利标识
updateRebateFlag: (productId: number, rebateFlag: number) => {
return api.post(`/product/${productId}/rebate`, null, { params: { rebateFlag } })
},
// 获取所有产品(用于下拉选择)
getAllProducts: () => {
return api.get<ApiResponse<ProductSimpleRes[]>>('/product/all')
}
}