diff --git a/business/views.py b/business/views.py index dd9a020..49ce2a6 100644 --- a/business/views.py +++ b/business/views.py @@ -1804,7 +1804,7 @@ class caseManagementDetail(APIView): Q_obj &= Q(party_name__icontains=party_name) if client_name: Q_obj &= Q(client_name__icontains=client_name) - # 按标签搜索:tags 可为字符串(名称模糊)或数组(标签ID如 [2,3]);tag_ids 为标签ID列表;满足任一标签即匹配 + # 按标签搜索:tags 可为字符串(名称模糊)、数组(标签ID)、或 form 传来的字符串 "[2]";tag_ids 为标签ID列表;满足任一标签即匹配 tag_id_list = [] if tags is not None and tags != '': if isinstance(tags, list): @@ -1813,9 +1813,19 @@ class caseManagementDetail(APIView): except (ValueError, TypeError): pass elif isinstance(tags, str): - tag_id_list.extend( - CaseTag.objects.filter(name__icontains=tags, is_deleted=False).values_list('id', flat=True) - ) + tags_stripped = tags.strip() + # 前端 form-data 可能把 [2] 或 [2,3] 当成字符串传,先尝试按 JSON 数组解析 + if tags_stripped.startswith('[') and tags_stripped.endswith(']'): + try: + parsed = json.loads(tags_stripped) + if isinstance(parsed, list): + tag_id_list.extend([int(x) for x in parsed if x is not None and str(x).strip() != '']) + except (ValueError, TypeError, json.JSONDecodeError): + pass + if not tag_id_list: + tag_id_list.extend( + CaseTag.objects.filter(name__icontains=tags, is_deleted=False).values_list('id', flat=True) + ) if tag_ids: try: if isinstance(tag_ids, str): @@ -2434,9 +2444,18 @@ class CaseDropdownList(APIView): except (ValueError, TypeError): pass elif isinstance(tags, str): - tag_id_list.extend( - CaseTag.objects.filter(name__icontains=tags, is_deleted=False).values_list('id', flat=True) - ) + tags_stripped = tags.strip() + if tags_stripped.startswith('[') and tags_stripped.endswith(']'): + try: + parsed = json.loads(tags_stripped) + if isinstance(parsed, list): + tag_id_list.extend([int(x) for x in parsed if x is not None and str(x).strip() != '']) + except (ValueError, TypeError, json.JSONDecodeError): + pass + if not tag_id_list: + tag_id_list.extend( + CaseTag.objects.filter(name__icontains=tags, is_deleted=False).values_list('id', flat=True) + ) if tag_ids: try: if isinstance(tag_ids, str):