@gt6/sdk 1.0.29 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gt6-sdk.cjs.js +26 -10
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +26 -10
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/modules/products.d.ts +8 -3
- package/dist/modules/products.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gt6-sdk.cjs.js
CHANGED
@@ -911,12 +911,15 @@ class ProductsAPI {
|
|
911
911
|
}
|
912
912
|
/**
|
913
913
|
* 4.3. 根据大分类ID获取平台产品列表
|
914
|
-
*
|
914
|
+
* 适配big-product-categories/${categoryId}.json新结构,支持排序和分页,直接返回数据
|
915
|
+
* @param categoryId 分类ID
|
916
|
+
* @param options { page, limit, sortBy }
|
917
|
+
* sortBy: 'createdAt-desc' | 'createdAt-asc' | 'price-desc' | 'price-asc'
|
915
918
|
*/
|
916
919
|
async getProductsByCategory_b(categoryId, options) {
|
917
|
-
//
|
920
|
+
// 从大型分类静态文件获取该分类的产品信息列表
|
918
921
|
const categoryData = await this.client.request(`/big-product-categories/${categoryId}.json`);
|
919
|
-
if (!categoryData || !categoryData.
|
922
|
+
if (!categoryData || !categoryData.productInfos || categoryData.productInfos.length === 0) {
|
920
923
|
return {
|
921
924
|
products: [],
|
922
925
|
total: 0,
|
@@ -924,21 +927,34 @@ class ProductsAPI {
|
|
924
927
|
limit: options?.limit || 10
|
925
928
|
};
|
926
929
|
}
|
930
|
+
// 排序
|
931
|
+
let sortedProducts = [...categoryData.productInfos];
|
932
|
+
const sortBy = options?.sortBy || 'createdAt-desc';
|
933
|
+
if (sortBy === 'createdAt-desc') {
|
934
|
+
sortedProducts.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
935
|
+
}
|
936
|
+
else if (sortBy === 'createdAt-asc') {
|
937
|
+
sortedProducts.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
938
|
+
}
|
939
|
+
else if (sortBy === 'price-desc') {
|
940
|
+
sortedProducts.sort((a, b) => parseFloat(b.price) - parseFloat(a.price));
|
941
|
+
}
|
942
|
+
else if (sortBy === 'price-asc') {
|
943
|
+
sortedProducts.sort((a, b) => parseFloat(a.price) - parseFloat(b.price));
|
944
|
+
}
|
927
945
|
// 应用分页
|
928
946
|
const page = options?.page || 1;
|
929
947
|
const limit = options?.limit || 10;
|
930
948
|
const offset = (page - 1) * limit;
|
931
|
-
const
|
932
|
-
//
|
933
|
-
|
934
|
-
// 应用状态过滤
|
935
|
-
let filteredProducts = products;
|
949
|
+
const paginatedProducts = sortedProducts.slice(offset, offset + limit);
|
950
|
+
// 应用状态过滤(如果有status字段)
|
951
|
+
let filteredProducts = paginatedProducts;
|
936
952
|
if (options?.status !== undefined) {
|
937
|
-
filteredProducts =
|
953
|
+
filteredProducts = paginatedProducts.filter(product => product.status === options.status);
|
938
954
|
}
|
939
955
|
return {
|
940
956
|
products: filteredProducts,
|
941
|
-
total: categoryData.
|
957
|
+
total: categoryData.productInfos.length,
|
942
958
|
page,
|
943
959
|
limit
|
944
960
|
};
|