Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
145 lines
2.9 KiB
TypeScript
145 lines
2.9 KiB
TypeScript
import type { Recordable } from '@vben/types';
|
|
|
|
import { requestClient } from '#/api/request';
|
|
|
|
export namespace ProductApi {
|
|
export interface ProductItem {
|
|
id: number;
|
|
product_name: string;
|
|
product_en: string;
|
|
description: string;
|
|
notes: string;
|
|
cost_price: number;
|
|
sell_price: number;
|
|
create_time: string;
|
|
update_time: string;
|
|
}
|
|
|
|
export interface ProductList {
|
|
total: number;
|
|
items: ProductItem[];
|
|
}
|
|
|
|
export interface CreateProductRequest {
|
|
product_name: string;
|
|
product_en: string;
|
|
description: string;
|
|
notes?: string;
|
|
cost_price: number;
|
|
sell_price: number;
|
|
}
|
|
|
|
export interface UpdateProductRequest {
|
|
product_name?: string;
|
|
product_en?: string;
|
|
description?: string;
|
|
notes?: string;
|
|
cost_price?: number;
|
|
sell_price?: number;
|
|
}
|
|
|
|
export interface ProductFeatureListItem {
|
|
id: number;
|
|
product_id: number;
|
|
feature_id: number;
|
|
api_id: string;
|
|
name: string;
|
|
sort: number;
|
|
enable: number;
|
|
is_important: number;
|
|
create_time: string;
|
|
update_time: string;
|
|
}
|
|
|
|
export interface ProductFeatureItem {
|
|
feature_id: number;
|
|
sort: number;
|
|
enable: number;
|
|
is_important: number;
|
|
}
|
|
|
|
export interface UpdateProductFeaturesRequest {
|
|
features: ProductFeatureItem[];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取产品列表数据
|
|
*/
|
|
async function getProductList(params: Recordable<any>) {
|
|
return requestClient.get<ProductApi.ProductList>('/product/list', {
|
|
params,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 获取产品详情
|
|
* @param id 产品ID
|
|
*/
|
|
async function getProductDetail(id: number) {
|
|
return requestClient.get<ProductApi.ProductItem>(`/product/detail/${id}`);
|
|
}
|
|
|
|
/**
|
|
* 创建产品
|
|
* @param data 产品数据
|
|
*/
|
|
async function createProduct(data: ProductApi.CreateProductRequest) {
|
|
return requestClient.post<{ id: number }>('/product/create', data);
|
|
}
|
|
|
|
/**
|
|
* 更新产品
|
|
* @param id 产品ID
|
|
* @param data 产品数据
|
|
*/
|
|
async function updateProduct(
|
|
id: number,
|
|
data: ProductApi.UpdateProductRequest,
|
|
) {
|
|
return requestClient.put<{ success: boolean }>(`/product/update/${id}`, data);
|
|
}
|
|
|
|
/**
|
|
* 删除产品
|
|
* @param id 产品ID
|
|
*/
|
|
async function deleteProduct(id: number) {
|
|
return requestClient.delete<{ success: boolean }>(`/product/delete/${id}`);
|
|
}
|
|
|
|
/**
|
|
* 获取产品功能列表
|
|
* @param productId 产品ID
|
|
*/
|
|
async function getProductFeatureList(productId: number) {
|
|
return requestClient.get<ProductApi.ProductFeatureListItem[]>(
|
|
`/product/feature/list/${productId}`,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 更新产品功能关联
|
|
* @param productId 产品ID
|
|
* @param data 功能列表数据
|
|
*/
|
|
async function updateProductFeatures(
|
|
productId: number,
|
|
data: ProductApi.UpdateProductFeaturesRequest,
|
|
) {
|
|
return requestClient.put<{ success: boolean }>(
|
|
`/product/feature/update/${productId}`,
|
|
data,
|
|
);
|
|
}
|
|
|
|
export {
|
|
createProduct,
|
|
deleteProduct,
|
|
getProductDetail,
|
|
getProductFeatureList,
|
|
getProductList,
|
|
updateProduct,
|
|
updateProductFeatures,
|
|
};
|