@gt6/sdk 1.0.39 → 1.0.41

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