@gt6/sdk 1.0.39 → 1.0.40

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.
@@ -644,8 +644,8 @@ class ArticlesAPI {
644
644
  const limit = options?.limit || 10;
645
645
  const offset = (page - 1) * limit;
646
646
  const paginatedArticleIds = categoryData.articleIds.slice(offset, offset + limit);
647
- // 获取文章详情
648
- const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_all(articleId)));
647
+ // 获取文章详情 - 修复:提取 articleId 字段
648
+ const articles = await Promise.all(paginatedArticleIds.map(articleObj => this.getArticle_all(articleObj.articleId)));
649
649
  // 应用状态过滤
650
650
  let filteredArticles = articles;
651
651
  if (options?.status) {
@@ -658,6 +658,111 @@ class ArticlesAPI {
658
658
  limit
659
659
  };
660
660
  }
661
+ /**
662
+ * 1.2.2 根据分类ID获取文章列表(支持搜索过滤)
663
+ */
664
+ async getArticlesByCategory_all_search(categoryId, searchOptions) {
665
+ // 从大型分类静态文件获取该分类的文章ID列表
666
+ const categoryData = await this.client.request(`/big-article-categories/${categoryId}.json`);
667
+ if (!categoryData || !categoryData.articleIds || categoryData.articleIds.length === 0) {
668
+ return {
669
+ articles: [],
670
+ total: 0,
671
+ page: searchOptions?.page || 1,
672
+ limit: searchOptions?.limit || 10,
673
+ filteredTotal: 0
674
+ };
675
+ }
676
+ // 应用搜索过滤
677
+ let filteredArticleIds = categoryData.articleIds.filter(articleObj => {
678
+ // 1. regionId 过滤
679
+ if (searchOptions?.regionIds && searchOptions.regionIds.length > 0) {
680
+ if (!articleObj.regionId || !searchOptions.regionIds.includes(articleObj.regionId)) {
681
+ return false;
682
+ }
683
+ }
684
+ // 2. price 范围过滤
685
+ if (searchOptions?.priceRange) {
686
+ const price = parseFloat(articleObj.price || '0');
687
+ if (searchOptions.priceRange.min !== undefined && price < searchOptions.priceRange.min) {
688
+ return false;
689
+ }
690
+ if (searchOptions.priceRange.max !== undefined && price > searchOptions.priceRange.max) {
691
+ return false;
692
+ }
693
+ }
694
+ // 3. propertyArea 范围过滤
695
+ if (searchOptions?.propertyAreaRange) {
696
+ const propertyArea = parseFloat(articleObj.propertyArea || '0');
697
+ if (searchOptions.propertyAreaRange.min !== undefined && propertyArea < searchOptions.propertyAreaRange.min) {
698
+ return false;
699
+ }
700
+ if (searchOptions.propertyAreaRange.max !== undefined && propertyArea > searchOptions.propertyAreaRange.max) {
701
+ return false;
702
+ }
703
+ }
704
+ // 4. plotArea 范围过滤
705
+ if (searchOptions?.plotAreaRange) {
706
+ const plotArea = parseFloat(articleObj.plotArea || '0');
707
+ if (searchOptions.plotAreaRange.min !== undefined && plotArea < searchOptions.plotAreaRange.min) {
708
+ return false;
709
+ }
710
+ if (searchOptions.plotAreaRange.max !== undefined && plotArea > searchOptions.plotAreaRange.max) {
711
+ return false;
712
+ }
713
+ }
714
+ // 5. tagIds 过滤
715
+ if (searchOptions?.tagIds && searchOptions.tagIds.length > 0) {
716
+ if (!articleObj.tagIds || articleObj.tagIds.length === 0) {
717
+ return false;
718
+ }
719
+ if (searchOptions.requireAllTags) {
720
+ // 要求包含所有指定的 tagIds
721
+ const hasAllTags = searchOptions.tagIds.every(tagId => articleObj.tagIds.includes(tagId));
722
+ if (!hasAllTags) {
723
+ return false;
724
+ }
725
+ }
726
+ else {
727
+ // 包含任意一个指定的 tagId 即可
728
+ const hasAnyTag = searchOptions.tagIds.some(tagId => articleObj.tagIds.includes(tagId));
729
+ if (!hasAnyTag) {
730
+ return false;
731
+ }
732
+ }
733
+ }
734
+ return true;
735
+ });
736
+ const filteredTotal = filteredArticleIds.length;
737
+ if (filteredTotal === 0) {
738
+ return {
739
+ articles: [],
740
+ total: categoryData.articleIds.length,
741
+ page: searchOptions?.page || 1,
742
+ limit: searchOptions?.limit || 10,
743
+ filteredTotal: 0
744
+ };
745
+ }
746
+ // 应用分页
747
+ const page = searchOptions?.page || 1;
748
+ const limit = searchOptions?.limit || 10;
749
+ const offset = (page - 1) * limit;
750
+ const paginatedArticleIds = filteredArticleIds.slice(offset, offset + limit);
751
+ // 获取文章详情
752
+ const articles = await Promise.all(paginatedArticleIds.map(articleObj => this.getArticle_all(articleObj.articleId)));
753
+ // 应用状态过滤
754
+ let finalArticles = articles;
755
+ if (searchOptions?.status) {
756
+ finalArticles = articles.filter(article => article.status === searchOptions.status);
757
+ }
758
+ return {
759
+ articles: finalArticles,
760
+ total: categoryData.articleIds.length, // 原始总数
761
+ page,
762
+ limit,
763
+ filteredTotal // 过滤后的总数
764
+ };
765
+ }
661
766
  /**
662
767
  * 1.2.1 根据平台ID获取文章列表(平台用户都可以使用)
663
768
  */