|
|
@@ -1,7 +1,7 @@
|
|
|
"""OA 表单设计器:部门选择控件 form_data 校验"""
|
|
|
from __future__ import annotations
|
|
|
|
|
|
-from typing import Any, Dict, List, Optional
|
|
|
+from typing import Any, Dict, List, Optional, Set
|
|
|
|
|
|
|
|
|
def _walk_rules(rules: Any, out: List[dict]) -> None:
|
|
|
@@ -139,3 +139,26 @@ def validate_dept_form_values(schema: Any, form_data: Optional[Dict[str, Any]])
|
|
|
forced["props"] = props
|
|
|
errors.extend(_validate_dept_rule(forced, data))
|
|
|
return errors
|
|
|
+
|
|
|
+
|
|
|
+def extract_dept_ids(raw: Any) -> Set[str]:
|
|
|
+ ids: Set[str] = set()
|
|
|
+ items = raw if isinstance(raw, list) else ([raw] if isinstance(raw, dict) else [])
|
|
|
+ for item in items:
|
|
|
+ if not isinstance(item, dict):
|
|
|
+ continue
|
|
|
+ did = str(item.get("id") or "").strip()
|
|
|
+ if did:
|
|
|
+ ids.add(did)
|
|
|
+ return ids
|
|
|
+
|
|
|
+
|
|
|
+def dept_contains_match(form_value: Any, cond_ids: Any) -> bool:
|
|
|
+ form_ids = extract_dept_ids(form_value)
|
|
|
+ if isinstance(cond_ids, str):
|
|
|
+ want = {cond_ids.strip()} if cond_ids.strip() else set()
|
|
|
+ elif isinstance(cond_ids, list):
|
|
|
+ want = {str(x).strip() for x in cond_ids if str(x).strip()}
|
|
|
+ else:
|
|
|
+ want = set()
|
|
|
+ return bool(form_ids & want)
|