@gt6/sdk 1.0.28 → 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 +57 -1
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +57 -1
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/articles.d.ts +1 -1
- package/dist/modules/products.d.ts +15 -0
- package/dist/modules/products.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gt6-sdk.esm.js
CHANGED
@@ -104,7 +104,7 @@ class ArticlesAPI {
|
|
104
104
|
return this.client.request(`/articles/${articleId}.json`);
|
105
105
|
}
|
106
106
|
/**
|
107
|
-
* 1.1 根据文章ID
|
107
|
+
* 1.1 根据文章ID获取文章详情(平台使用)
|
108
108
|
*/
|
109
109
|
async getArticle_p(articleId) {
|
110
110
|
return this.client.request(`/parentarticles/${articleId}.json`);
|
@@ -905,6 +905,56 @@ class ProductsAPI {
|
|
905
905
|
limit
|
906
906
|
};
|
907
907
|
}
|
908
|
+
/**
|
909
|
+
* 4.3. 根据大分类ID获取平台产品列表
|
910
|
+
* 适配big-product-categories/${categoryId}.json新结构,支持排序和分页,直接返回数据
|
911
|
+
* @param categoryId 分类ID
|
912
|
+
* @param options { page, limit, sortBy }
|
913
|
+
* sortBy: 'createdAt-desc' | 'createdAt-asc' | 'price-desc' | 'price-asc'
|
914
|
+
*/
|
915
|
+
async getProductsByCategory_b(categoryId, options) {
|
916
|
+
// 从大型分类静态文件获取该分类的产品信息列表
|
917
|
+
const categoryData = await this.client.request(`/big-product-categories/${categoryId}.json`);
|
918
|
+
if (!categoryData || !categoryData.productInfos || categoryData.productInfos.length === 0) {
|
919
|
+
return {
|
920
|
+
products: [],
|
921
|
+
total: 0,
|
922
|
+
page: options?.page || 1,
|
923
|
+
limit: options?.limit || 10
|
924
|
+
};
|
925
|
+
}
|
926
|
+
// 排序
|
927
|
+
let sortedProducts = [...categoryData.productInfos];
|
928
|
+
const sortBy = options?.sortBy || 'createdAt-desc';
|
929
|
+
if (sortBy === 'createdAt-desc') {
|
930
|
+
sortedProducts.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
931
|
+
}
|
932
|
+
else if (sortBy === 'createdAt-asc') {
|
933
|
+
sortedProducts.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
934
|
+
}
|
935
|
+
else if (sortBy === 'price-desc') {
|
936
|
+
sortedProducts.sort((a, b) => parseFloat(b.price) - parseFloat(a.price));
|
937
|
+
}
|
938
|
+
else if (sortBy === 'price-asc') {
|
939
|
+
sortedProducts.sort((a, b) => parseFloat(a.price) - parseFloat(b.price));
|
940
|
+
}
|
941
|
+
// 应用分页
|
942
|
+
const page = options?.page || 1;
|
943
|
+
const limit = options?.limit || 10;
|
944
|
+
const offset = (page - 1) * limit;
|
945
|
+
const paginatedProducts = sortedProducts.slice(offset, offset + limit);
|
946
|
+
// 应用状态过滤(如果有status字段)
|
947
|
+
let filteredProducts = paginatedProducts;
|
948
|
+
if (options?.status !== undefined) {
|
949
|
+
filteredProducts = paginatedProducts.filter(product => product.status === options.status);
|
950
|
+
}
|
951
|
+
return {
|
952
|
+
products: filteredProducts,
|
953
|
+
total: categoryData.productInfos.length,
|
954
|
+
page,
|
955
|
+
limit
|
956
|
+
};
|
957
|
+
}
|
908
958
|
/**
|
909
959
|
* 5. 根据标签ID获取产品列表
|
910
960
|
* 支持单个标签ID或标签ID数组
|
@@ -2739,6 +2789,12 @@ class GT6SDK {
|
|
2739
2789
|
async getProductsByCategory_t(categoryId, options) {
|
2740
2790
|
return this.products.getProductsByCategory_t(categoryId, options);
|
2741
2791
|
}
|
2792
|
+
/**
|
2793
|
+
* 11.3. 便捷方法:根据大分类ID获取平台产品列表(从big-product-categories静态JSON获取)
|
2794
|
+
*/
|
2795
|
+
async getProductsByCategory_b(categoryId, options) {
|
2796
|
+
return this.products.getProductsByCategory_b(categoryId, options);
|
2797
|
+
}
|
2742
2798
|
/**
|
2743
2799
|
* 12. 便捷方法:根据标签ID获取产品列表
|
2744
2800
|
*/
|