@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.cjs.js
CHANGED
@@ -108,7 +108,7 @@ class ArticlesAPI {
|
|
108
108
|
return this.client.request(`/articles/${articleId}.json`);
|
109
109
|
}
|
110
110
|
/**
|
111
|
-
* 1.1 根据文章ID
|
111
|
+
* 1.1 根据文章ID获取文章详情(平台使用)
|
112
112
|
*/
|
113
113
|
async getArticle_p(articleId) {
|
114
114
|
return this.client.request(`/parentarticles/${articleId}.json`);
|
@@ -909,6 +909,56 @@ class ProductsAPI {
|
|
909
909
|
limit
|
910
910
|
};
|
911
911
|
}
|
912
|
+
/**
|
913
|
+
* 4.3. 根据大分类ID获取平台产品列表
|
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'
|
918
|
+
*/
|
919
|
+
async getProductsByCategory_b(categoryId, options) {
|
920
|
+
// 从大型分类静态文件获取该分类的产品信息列表
|
921
|
+
const categoryData = await this.client.request(`/big-product-categories/${categoryId}.json`);
|
922
|
+
if (!categoryData || !categoryData.productInfos || categoryData.productInfos.length === 0) {
|
923
|
+
return {
|
924
|
+
products: [],
|
925
|
+
total: 0,
|
926
|
+
page: options?.page || 1,
|
927
|
+
limit: options?.limit || 10
|
928
|
+
};
|
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
|
+
}
|
945
|
+
// 应用分页
|
946
|
+
const page = options?.page || 1;
|
947
|
+
const limit = options?.limit || 10;
|
948
|
+
const offset = (page - 1) * limit;
|
949
|
+
const paginatedProducts = sortedProducts.slice(offset, offset + limit);
|
950
|
+
// 应用状态过滤(如果有status字段)
|
951
|
+
let filteredProducts = paginatedProducts;
|
952
|
+
if (options?.status !== undefined) {
|
953
|
+
filteredProducts = paginatedProducts.filter(product => product.status === options.status);
|
954
|
+
}
|
955
|
+
return {
|
956
|
+
products: filteredProducts,
|
957
|
+
total: categoryData.productInfos.length,
|
958
|
+
page,
|
959
|
+
limit
|
960
|
+
};
|
961
|
+
}
|
912
962
|
/**
|
913
963
|
* 5. 根据标签ID获取产品列表
|
914
964
|
* 支持单个标签ID或标签ID数组
|
@@ -2743,6 +2793,12 @@ class GT6SDK {
|
|
2743
2793
|
async getProductsByCategory_t(categoryId, options) {
|
2744
2794
|
return this.products.getProductsByCategory_t(categoryId, options);
|
2745
2795
|
}
|
2796
|
+
/**
|
2797
|
+
* 11.3. 便捷方法:根据大分类ID获取平台产品列表(从big-product-categories静态JSON获取)
|
2798
|
+
*/
|
2799
|
+
async getProductsByCategory_b(categoryId, options) {
|
2800
|
+
return this.products.getProductsByCategory_b(categoryId, options);
|
2801
|
+
}
|
2746
2802
|
/**
|
2747
2803
|
* 12. 便捷方法:根据标签ID获取产品列表
|
2748
2804
|
*/
|