@gt6/sdk 1.0.30 → 1.0.32

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.
@@ -124,7 +124,7 @@ class ArticlesAPI {
124
124
  async getCategories_p(rootCategoryId_p) {
125
125
  const config = this.client.getConfig();
126
126
  const categoryId = rootCategoryId_p || config.rootCategoryId_p || '671920';
127
- const response = await this.client.request(`/article-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
127
+ const response = await this.client.request(`/article-categories/platform/platform-${config.platformId_p}-root-${categoryId}.json`);
128
128
  return response.categories;
129
129
  }
130
130
  /**
@@ -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
  * 用于前端面包屑导航
@@ -697,7 +758,7 @@ class ProductsAPI {
697
758
  async getCategories_p(productRootCategoryId_p) {
698
759
  const config = this.client.getConfig();
699
760
  const categoryId = productRootCategoryId_p || config.productRootCategoryId_p;
700
- const response = await this.client.request(`/product-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
761
+ const response = await this.client.request(`/product-categories/platform/platform-${config.platformId_p}-root-${categoryId}.json`);
701
762
  return response.categories;
702
763
  }
703
764
  /**
@@ -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数组
@@ -1091,6 +1171,48 @@ class ProductsAPI {
1091
1171
  limit
1092
1172
  };
1093
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
+ }
1094
1216
  /**
1095
1217
  * 6. 根据分类ID获取该分类的层级路径
1096
1218
  * 用于前端面包屑导航
@@ -2675,6 +2797,18 @@ class GT6SDK {
2675
2797
  async getTags_p(tagAlias_p) {
2676
2798
  return this.articles.getTags_p(tagAlias_p);
2677
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
+ }
2678
2812
  /**
2679
2813
  * 4. 便捷方法:根据分类ID获取文章列表
2680
2814
  */
@@ -2717,6 +2851,12 @@ class GT6SDK {
2717
2851
  async getArticlesByTag_t(tagId, options) {
2718
2852
  return this.articles.getArticlesByTag_t(tagId, options);
2719
2853
  }
2854
+ /**
2855
+ * 5.3. 便捷方法:根据单个标签ID获取平台文章列表
2856
+ */
2857
+ async getArticlesByTag_single(tagId, options) {
2858
+ return this.articles.getArticlesByTag_single(tagId, options);
2859
+ }
2720
2860
  /**
2721
2861
  * 6. 便捷方法:根据分类ID获取该分类的层级路径
2722
2862
  */
@@ -2771,6 +2911,18 @@ class GT6SDK {
2771
2911
  async getProductTags_p(productTagAlias_p) {
2772
2912
  return this.products.getTags_p(productTagAlias_p);
2773
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
+ }
2774
2926
  /**
2775
2927
  * 11. 便捷方法:根据分类ID获取产品列表
2776
2928
  */
@@ -2813,6 +2965,12 @@ class GT6SDK {
2813
2965
  async getProductsByTag_t(tagId, options) {
2814
2966
  return this.products.getProductsByTag_t(tagId, options);
2815
2967
  }
2968
+ /**
2969
+ * 12.3. 便捷方法:根据单个标签ID获取平台产品列表
2970
+ */
2971
+ async getProductsByTag_single(tagId, options) {
2972
+ return this.products.getProductsByTag_single(tagId, options);
2973
+ }
2816
2974
  /**
2817
2975
  * 13. 便捷方法:根据分类ID获取该分类的层级路径
2818
2976
  */