@gt6/sdk 1.0.29 → 1.0.31

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.
@@ -154,6 +154,25 @@ class ArticlesAPI {
154
154
  const response = await this.client.request(`/article-tags/platform-${config.platformId_p}-${alias}.json`);
155
155
  return response.tags;
156
156
  }
157
+ /**
158
+ * 3.2. 获取单个平台文章标签列表
159
+ */
160
+ async getTags_p_single(tagId_p) {
161
+ const config = this.client.getConfig();
162
+ const tagId = tagId_p || config.tagId_p;
163
+ if (!tagId) {
164
+ throw new Error('Article tag ID is required');
165
+ }
166
+ const response = await this.client.request(`/article-tags/${tagId}.json`);
167
+ return response;
168
+ }
169
+ /**
170
+ * 3.3. 获取单个平台文章标签的文章ID列表
171
+ */
172
+ async getTagArticleIds_p(tagId_p) {
173
+ const tagData = await this.getTags_p_single(tagId_p);
174
+ return tagData.articleIds;
175
+ }
157
176
  /**
158
177
  * 4. 根据分类ID获取文章列表
159
178
  * 支持单个分类ID或分类ID数组
@@ -464,6 +483,48 @@ class ArticlesAPI {
464
483
  limit
465
484
  };
466
485
  }
486
+ /**
487
+ * 5.3. 根据单个标签ID获取平台文章列表
488
+ * 使用getTags_p_single获取指定标签数据,然后获取文章详情
489
+ * @param tagId 单个标签ID
490
+ * @param options 查询选项
491
+ */
492
+ async getArticlesByTag_single(tagId, options) {
493
+ // 获取指定标签的数据
494
+ const tagData = await this.getTags_p_single(tagId);
495
+ if (!tagData || !tagData.articleIds || tagData.articleIds.length === 0) {
496
+ // 剔除articleIds字段
497
+ const { articleIds, ...tagInfo } = tagData;
498
+ return {
499
+ articles: [],
500
+ total: 0,
501
+ page: options?.page || 1,
502
+ limit: options?.limit || 10,
503
+ tag: tagInfo
504
+ };
505
+ }
506
+ // 应用分页
507
+ const page = options?.page || 1;
508
+ const limit = options?.limit || 10;
509
+ const offset = (page - 1) * limit;
510
+ const paginatedArticleIds = tagData.articleIds.slice(offset, offset + limit);
511
+ // 获取文章详情
512
+ const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
513
+ // 应用状态过滤
514
+ let filteredArticles = articles;
515
+ if (options?.status) {
516
+ filteredArticles = articles.filter(article => article.status === options.status);
517
+ }
518
+ // 剔除articleIds字段
519
+ const { articleIds, ...tagInfo } = tagData;
520
+ return {
521
+ articles: filteredArticles,
522
+ total: tagData.articleIds.length,
523
+ page,
524
+ limit,
525
+ tag: tagInfo
526
+ };
527
+ }
467
528
  /**
468
529
  * 6. 根据分类ID获取该分类的层级路径
469
530
  * 用于前端面包屑导航
@@ -727,6 +788,25 @@ class ProductsAPI {
727
788
  const response = await this.client.request(`/product-tags/platform-${config.platformId_p}-${alias}.json`);
728
789
  return response.tags;
729
790
  }
791
+ /**
792
+ * 3.2. 获取单个平台产品标签列表
793
+ */
794
+ async getTags_p_single(productTagId_p) {
795
+ const config = this.client.getConfig();
796
+ const productTagId = productTagId_p || config.productTagId_p;
797
+ if (!productTagId) {
798
+ throw new Error('Product tag ID is required');
799
+ }
800
+ const response = await this.client.request(`/product-tags/${productTagId}.json`);
801
+ return response;
802
+ }
803
+ /**
804
+ * 3.3. 获取单个平台产品标签的产品ID列表
805
+ */
806
+ async getTagProductIds_p(productTagId_p) {
807
+ const tagData = await this.getTags_p_single(productTagId_p);
808
+ return tagData.productIds;
809
+ }
730
810
  /**
731
811
  * 4. 根据分类ID获取产品列表
732
812
  * 支持单个分类ID或分类ID数组
@@ -907,12 +987,15 @@ class ProductsAPI {
907
987
  }
908
988
  /**
909
989
  * 4.3. 根据大分类ID获取平台产品列表
910
- * 先从big-product-categories/${categoryId}.json获取产品ID,再分页后用getProduct_p获取详情
990
+ * 适配big-product-categories/${categoryId}.json新结构,支持排序和分页,直接返回数据
991
+ * @param categoryId 分类ID
992
+ * @param options { page, limit, sortBy }
993
+ * sortBy: 'createdAt-desc' | 'createdAt-asc' | 'price-desc' | 'price-asc'
911
994
  */
912
995
  async getProductsByCategory_b(categoryId, options) {
913
- // 从大型分类静态文件获取该分类的产品ID列表
996
+ // 从大型分类静态文件获取该分类的产品信息列表
914
997
  const categoryData = await this.client.request(`/big-product-categories/${categoryId}.json`);
915
- if (!categoryData || !categoryData.productIds || categoryData.productIds.length === 0) {
998
+ if (!categoryData || !categoryData.productInfos || categoryData.productInfos.length === 0) {
916
999
  return {
917
1000
  products: [],
918
1001
  total: 0,
@@ -920,21 +1003,34 @@ class ProductsAPI {
920
1003
  limit: options?.limit || 10
921
1004
  };
922
1005
  }
1006
+ // 排序
1007
+ let sortedProducts = [...categoryData.productInfos];
1008
+ const sortBy = options?.sortBy || 'createdAt-desc';
1009
+ if (sortBy === 'createdAt-desc') {
1010
+ sortedProducts.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
1011
+ }
1012
+ else if (sortBy === 'createdAt-asc') {
1013
+ sortedProducts.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
1014
+ }
1015
+ else if (sortBy === 'price-desc') {
1016
+ sortedProducts.sort((a, b) => parseFloat(b.price) - parseFloat(a.price));
1017
+ }
1018
+ else if (sortBy === 'price-asc') {
1019
+ sortedProducts.sort((a, b) => parseFloat(a.price) - parseFloat(b.price));
1020
+ }
923
1021
  // 应用分页
924
1022
  const page = options?.page || 1;
925
1023
  const limit = options?.limit || 10;
926
1024
  const offset = (page - 1) * limit;
927
- const paginatedProductIds = categoryData.productIds.slice(offset, offset + limit);
928
- // 获取产品详情(使用上级平台数据)
929
- const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
930
- // 应用状态过滤
931
- let filteredProducts = products;
1025
+ const paginatedProducts = sortedProducts.slice(offset, offset + limit);
1026
+ // 应用状态过滤(如果有status字段)
1027
+ let filteredProducts = paginatedProducts;
932
1028
  if (options?.status !== undefined) {
933
- filteredProducts = products.filter(product => product.status === options.status);
1029
+ filteredProducts = paginatedProducts.filter(product => product.status === options.status);
934
1030
  }
935
1031
  return {
936
1032
  products: filteredProducts,
937
- total: categoryData.productIds.length,
1033
+ total: categoryData.productInfos.length,
938
1034
  page,
939
1035
  limit
940
1036
  };
@@ -1075,6 +1171,48 @@ class ProductsAPI {
1075
1171
  limit
1076
1172
  };
1077
1173
  }
1174
+ /**
1175
+ * 5.3. 根据单个标签ID获取平台产品列表
1176
+ * 使用getTags_p_single获取指定标签数据,然后获取产品详情
1177
+ * @param tagId 单个标签ID
1178
+ * @param options 查询选项
1179
+ */
1180
+ async getProductsByTag_single(tagId, options) {
1181
+ // 获取指定标签的数据
1182
+ const tagData = await this.getTags_p_single(tagId);
1183
+ if (!tagData || !tagData.productIds || tagData.productIds.length === 0) {
1184
+ // 剔除productIds字段
1185
+ const { productIds, ...tagInfo } = tagData;
1186
+ return {
1187
+ products: [],
1188
+ total: 0,
1189
+ page: options?.page || 1,
1190
+ limit: options?.limit || 10,
1191
+ tag: tagInfo
1192
+ };
1193
+ }
1194
+ // 应用分页
1195
+ const page = options?.page || 1;
1196
+ const limit = options?.limit || 10;
1197
+ const offset = (page - 1) * limit;
1198
+ const paginatedProductIds = tagData.productIds.slice(offset, offset + limit);
1199
+ // 获取产品详情
1200
+ const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
1201
+ // 应用状态过滤
1202
+ let filteredProducts = products;
1203
+ if (options?.status !== undefined) {
1204
+ filteredProducts = products.filter(product => product.status === options.status);
1205
+ }
1206
+ // 剔除productIds字段
1207
+ const { productIds, ...tagInfo } = tagData;
1208
+ return {
1209
+ products: filteredProducts,
1210
+ total: tagData.productIds.length,
1211
+ page,
1212
+ limit,
1213
+ tag: tagInfo
1214
+ };
1215
+ }
1078
1216
  /**
1079
1217
  * 6. 根据分类ID获取该分类的层级路径
1080
1218
  * 用于前端面包屑导航
@@ -2659,6 +2797,18 @@ class GT6SDK {
2659
2797
  async getTags_p(tagAlias_p) {
2660
2798
  return this.articles.getTags_p(tagAlias_p);
2661
2799
  }
2800
+ /**
2801
+ * 3.2. 便捷方法:获取单个平台文章标签列表
2802
+ */
2803
+ async getTags_p_single(tagId_p) {
2804
+ return this.articles.getTags_p_single(tagId_p);
2805
+ }
2806
+ /**
2807
+ * 3.3. 便捷方法:获取单个平台文章标签的文章ID列表
2808
+ */
2809
+ async getTagArticleIds_p(tagId_p) {
2810
+ return this.articles.getTagArticleIds_p(tagId_p);
2811
+ }
2662
2812
  /**
2663
2813
  * 4. 便捷方法:根据分类ID获取文章列表
2664
2814
  */
@@ -2701,6 +2851,12 @@ class GT6SDK {
2701
2851
  async getArticlesByTag_t(tagId, options) {
2702
2852
  return this.articles.getArticlesByTag_t(tagId, options);
2703
2853
  }
2854
+ /**
2855
+ * 5.3. 便捷方法:根据单个标签ID获取平台文章列表
2856
+ */
2857
+ async getArticlesByTag_single(tagId, options) {
2858
+ return this.articles.getArticlesByTag_single(tagId, options);
2859
+ }
2704
2860
  /**
2705
2861
  * 6. 便捷方法:根据分类ID获取该分类的层级路径
2706
2862
  */
@@ -2755,6 +2911,18 @@ class GT6SDK {
2755
2911
  async getProductTags_p(productTagAlias_p) {
2756
2912
  return this.products.getTags_p(productTagAlias_p);
2757
2913
  }
2914
+ /**
2915
+ * 10.2. 便捷方法:获取单个平台产品标签列表
2916
+ */
2917
+ async getProductTags_p_single(productTagId_p) {
2918
+ return this.products.getTags_p_single(productTagId_p);
2919
+ }
2920
+ /**
2921
+ * 10.3. 便捷方法:获取单个平台产品标签的产品ID列表
2922
+ */
2923
+ async getProductTagProductIds_p(productTagId_p) {
2924
+ return this.products.getTagProductIds_p(productTagId_p);
2925
+ }
2758
2926
  /**
2759
2927
  * 11. 便捷方法:根据分类ID获取产品列表
2760
2928
  */
@@ -2797,6 +2965,12 @@ class GT6SDK {
2797
2965
  async getProductsByTag_t(tagId, options) {
2798
2966
  return this.products.getProductsByTag_t(tagId, options);
2799
2967
  }
2968
+ /**
2969
+ * 12.3. 便捷方法:根据单个标签ID获取平台产品列表
2970
+ */
2971
+ async getProductsByTag_single(tagId, options) {
2972
+ return this.products.getProductsByTag_single(tagId, options);
2973
+ }
2800
2974
  /**
2801
2975
  * 13. 便捷方法:根据分类ID获取该分类的层级路径
2802
2976
  */