|
import { request_handler, type ResultPackage } from '@/api/base' |
|
import type { StreamerInfo } from '@/api/streamerInfo' |
|
import { header_authorization } from '@/api/user' |
|
|
|
|
|
type ProductListType = { |
|
currentPage?: number |
|
pageSize?: number |
|
productName?: string |
|
product_class?: string |
|
} |
|
|
|
interface ProductItem { |
|
user_id: number |
|
request_id: string |
|
|
|
product_id: number |
|
product_name: string |
|
product_class: string |
|
heighlights: string |
|
image_path: string |
|
instruction: string |
|
departure_place: string |
|
delivery_company: string |
|
selling_price: number |
|
amount: number |
|
upload_date: string |
|
delete: boolean |
|
} |
|
|
|
interface ProductData { |
|
product_list: ProductItem[] |
|
currentPage: number |
|
pageSize: number |
|
totalSize: number |
|
} |
|
|
|
|
|
const productListRequest = (params_: ProductListType) => { |
|
return request_handler<ResultPackage<ProductData>>({ |
|
method: 'GET', |
|
url: '/products/list', |
|
params: params_, |
|
headers: { |
|
Authorization: header_authorization.value |
|
} |
|
}) |
|
} |
|
|
|
|
|
const getProductByIdRequest = async (productId: string) => { |
|
return request_handler<ResultPackage<ProductItem>>({ |
|
method: 'GET', |
|
url: `/products/info/${productId}`, |
|
headers: { |
|
Authorization: header_authorization.value |
|
} |
|
}) |
|
} |
|
|
|
|
|
const productCreadeOrEditRequest = (params: ProductItem) => { |
|
if (params.product_id === 0) { |
|
|
|
return request_handler<ResultPackage<ProductData>>({ |
|
method: 'POST', |
|
url: '/products/create', |
|
data: params, |
|
headers: { |
|
Authorization: header_authorization.value |
|
} |
|
}) |
|
} else { |
|
|
|
return request_handler<ResultPackage<ProductData>>({ |
|
method: 'PUT', |
|
url: `/products/edit/${params.product_id}`, |
|
data: params, |
|
headers: { |
|
Authorization: header_authorization.value |
|
} |
|
}) |
|
} |
|
} |
|
|
|
|
|
const deleteProductByIdRequest = async (productId: number) => { |
|
return request_handler<ResultPackage<string>>({ |
|
method: 'DELETE', |
|
url: `/products/delete/${productId}`, |
|
headers: { |
|
Authorization: header_authorization.value |
|
} |
|
}) |
|
} |
|
|
|
|
|
const genProductInstructionContentRequest = (instructionPath_: string) => { |
|
|
|
return request_handler({ |
|
method: 'POST', |
|
url: '/products/instruction', |
|
data: { instructionPath: instructionPath_ }, |
|
headers: { |
|
Authorization: header_authorization.value |
|
} |
|
}) |
|
} |
|
|
|
export { |
|
type ProductItem, |
|
type StreamerInfo, |
|
type ProductListType, |
|
type ProductData, |
|
productListRequest, |
|
productCreadeOrEditRequest, |
|
getProductByIdRequest, |
|
deleteProductByIdRequest, |
|
genProductInstructionContentRequest |
|
} |
|
|