|
|
@@ -11,7 +11,7 @@ import { ArrowLeft, ArrowRight, ChevronDown, ChevronRight, Info, MapPinned, Penc
|
|
|
import { Link, useNavigate, useParams, useSearchParams } from "react-router";
|
|
|
import { Button as FilterResetButton } from "../components/ui/button";
|
|
|
import { TreeSelect } from "../components/ui/tree-select";
|
|
|
-import { regionLevelText, regionTreeNodes } from "../lib/region-tree";
|
|
|
+import { regionLevelText, regionParentInTree, regionTreeNodes } from "../lib/region-tree";
|
|
|
import { OrganizationAccountDialog, type AccountTarget } from "../components/OrganizationAccountDialog";
|
|
|
import { OrganizationAccountInline } from "../components/OrganizationAccountInline";
|
|
|
import { OrganizationAccountStatus } from "../components/OrganizationAccountStatus";
|
|
|
@@ -400,7 +400,12 @@ function DeleteDialog({ data, kind, id, name, onClose, onDeleted }: { data: Orga
|
|
|
|
|
|
|
|
|
|
|
|
-const regionParentOf = (region: Region) => (!region.parent || region.parent === V_ROOT || region.parent === region.id) ? null : region.parent;
|
|
|
+/**
|
|
|
+ * 树内父级。`/region/tree@v1` 对非总运营只回**授权子树**(上级「全网」不在 nodes 内),
|
|
|
+ * 上级不可见时必须按根渲染:否则根集合过滤成空,标题写着「N 个节点」而正文一行不渲染
|
|
|
+ * (2026-11-17 运营主账号只看到「2 个节点」实证)。
|
|
|
+ */
|
|
|
+const regionParentOf = (region: Region, visibleIds: Set<string>) => regionParentInTree(region.parent === V_ROOT ? null : region.parent, region.id, visibleIds);
|
|
|
/** 业务可见根节点的真实 parent(建省份时挂到平台树根)。 */
|
|
|
function platformRootId(regions: Region[]): string {
|
|
|
for (const r of regions) {
|
|
|
@@ -563,8 +568,10 @@ function RegionTree({ data, parent, selected, expanded, menu, canAdmin, select,
|
|
|
select: (id: string) => void; toggle: (id: string) => void; setMenu: (next: RegionTreeMenuState) => void;
|
|
|
onCreateChild: (id: string) => void; onRename: (id: string) => void; onDelete: (id: string) => void; depth?: number;
|
|
|
}) {
|
|
|
- return <>{data.regions.filter((r) => r.id !== V_ROOT && regionParentOf(r) === parent).map((region) => {
|
|
|
- const hasChildren = data.regions.some((child) => child.id !== V_ROOT && regionParentOf(child) === region.id);
|
|
|
+ // 授权子树里上级可能在 collect 之外,可见 ID 集合既做根判定也做下级判定。
|
|
|
+ const visibleIds = useMemo(() => new Set(data.regions.map((region) => region.id)), [data.regions]);
|
|
|
+ return <>{data.regions.filter((r) => r.id !== V_ROOT && regionParentOf(r, visibleIds) === parent).map((region) => {
|
|
|
+ const hasChildren = data.regions.some((child) => child.id !== V_ROOT && regionParentOf(child, visibleIds) === region.id);
|
|
|
const isExpanded = expanded.has(region.id);
|
|
|
const total = <Count v={region.customersInSubtree} />;
|
|
|
const canAddChild = region.level !== 2;
|
|
|
@@ -622,7 +629,8 @@ function RegionOverview({ data, node, canAdmin, onOpenInfo, onSelect, onDelete }
|
|
|
const navigate = useNavigate();
|
|
|
const loaded = useOrganizationLoaded();
|
|
|
const status = useOrganizationStatus();
|
|
|
- const children = data.regions.filter((r) => r.id !== V_ROOT && regionParentOf(r) === node.id);
|
|
|
+ const visibleIds = useMemo(() => new Set(data.regions.map((item) => item.id)), [data.regions]);
|
|
|
+ const children = data.regions.filter((r) => r.id !== V_ROOT && regionParentOf(r, visibleIds) === node.id);
|
|
|
const referenced = [node.operators, node.partners, node.opsTeams].some((v) => (v ?? 0) > 0);
|
|
|
// 运营团队无 tree counters:按名录「建档区域」=负责范围首节点,与台账区域筛选同口径;总部内置不计。
|
|
|
const entTeamCount = !loaded.has("operationsTeams") || status.partial.operationsTeams
|
|
|
@@ -652,6 +660,7 @@ export function RegionManagementPage() {
|
|
|
const identity = useDemoIdentity();
|
|
|
const regionScoped = identity?.role === "regAdmin";
|
|
|
const visible = data.regions.filter((r) => r.id !== V_ROOT);
|
|
|
+ const visibleIds = useMemo(() => new Set(data.regions.map((r) => r.id)), [data.regions]);
|
|
|
const [selected, setSelected] = useState("");
|
|
|
const [expanded, setExpanded] = useState<Set<string>>(() => new Set());
|
|
|
const [tab, setTab] = useState<"overview" | "info">("overview");
|
|
|
@@ -665,9 +674,10 @@ export function RegionManagementPage() {
|
|
|
useEffect(() => {
|
|
|
const nodes = data.regions.filter((r) => r.id !== V_ROOT);
|
|
|
if (!nodes.length) return;
|
|
|
+ const ids = new Set(data.regions.map((r) => r.id));
|
|
|
setExpanded((current) => {
|
|
|
if (current.size) return current;
|
|
|
- return new Set(nodes.filter((region) => nodes.some((child) => regionParentOf(child) === region.id)).map((region) => region.id));
|
|
|
+ return new Set(nodes.filter((region) => nodes.some((child) => regionParentOf(child, ids) === region.id)).map((region) => region.id));
|
|
|
});
|
|
|
setSelected((current) => (current && nodes.some((r) => r.id === current) ? current : nodes[0]?.id ?? ""));
|
|
|
}, [data.regions]);
|
|
|
@@ -680,7 +690,7 @@ export function RegionManagementPage() {
|
|
|
</div>;
|
|
|
}
|
|
|
|
|
|
- const children = visible.filter((r) => regionParentOf(r) === node.id);
|
|
|
+ const children = visible.filter((r) => regionParentOf(r, visibleIds) === node.id);
|
|
|
const referenced = [node.operators, node.partners, node.opsTeams].some((v) => (v ?? 0) > 0);
|
|
|
const rootId = platformRootId(data.regions);
|
|
|
|