com-angel-authorization 1.0.26 → 1.0.27

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.
@@ -457,7 +457,7 @@ function mapMenuResource(item) {
457
457
  );
458
458
  const permissionNamesRaw = row.permissionPointNames ?? row.permission_point_names ?? row.permissionNames;
459
459
  const permissionPointNames = Array.isArray(permissionNamesRaw) ? permissionNamesRaw.map((n) => String(n ?? "")).filter(Boolean) : void 0;
460
- const rawParentId = row.parentId ?? row.parent_id;
460
+ const rawParentId = row.parentId ?? row.parent_id ?? (row.parent && typeof row.parent === "object" ? row.parent.resourceId ?? row.parent.resource_id ?? row.parent.id : void 0);
461
461
  const parentId = rawParentId === void 0 || rawParentId === null || rawParentId === "" || String(rawParentId) === "0" ? null : String(rawParentId);
462
462
  const rawDepth = row.depth;
463
463
  const parsedDepth = Number(rawDepth);
@@ -614,7 +614,11 @@ function createMenuResourceApi(request) {
614
614
  url: `/authorization-resources/${encodeURIComponent(resourceId)}/sub-resources`,
615
615
  signal
616
616
  });
617
- return extractRecords(json).map(mapMenuResource).filter((item) => item !== null);
617
+ return extractRecords(json).map(mapMenuResource).filter((item) => item !== null).map((item) => ({
618
+ ...item,
619
+ // 子资源接口常不回 parentId,用请求路径上的父级补齐
620
+ parentId: item.parentId ?? resourceId
621
+ }));
618
622
  },
619
623
  listPermissionPoints(params, signal) {
620
624
  return permissionApi.list(params, signal);
@@ -1266,12 +1270,32 @@ function MenuManager({
1266
1270
  });
1267
1271
  return Array.from(map.values());
1268
1272
  }, [records, childrenMap]);
1273
+ const resolveRowParentId = useCallback3(
1274
+ (row) => {
1275
+ if (row.parentId) return row.parentId;
1276
+ for (const [parentId, children] of Object.entries(childrenMap)) {
1277
+ if (children.some((child) => child.resourceId === row.resourceId)) {
1278
+ return parentId;
1279
+ }
1280
+ }
1281
+ return null;
1282
+ },
1283
+ [childrenMap]
1284
+ );
1269
1285
  const parentOptions = useMemo3(() => {
1270
- return allKnownMenus.filter((row) => !editing || row.resourceId !== editing.resourceId).map((row) => ({
1286
+ const opts = allKnownMenus.filter((row) => !editing || row.resourceId !== editing.resourceId).map((row) => ({
1271
1287
  value: row.resourceId,
1272
1288
  label: `${row.name}\uFF08${MENU_TYPE_LABEL[row.type]}\uFF09`
1273
1289
  }));
1274
- }, [allKnownMenus, editing]);
1290
+ if (form.parentId && !opts.some((opt) => opt.value === form.parentId)) {
1291
+ const parent = allKnownMenus.find((row) => row.resourceId === form.parentId);
1292
+ opts.unshift({
1293
+ value: form.parentId,
1294
+ label: parent ? `${parent.name}\uFF08${MENU_TYPE_LABEL[parent.type]}\uFF09` : form.parentId
1295
+ });
1296
+ }
1297
+ return opts;
1298
+ }, [allKnownMenus, editing, form.parentId]);
1275
1299
  const flatRows = useMemo3(() => {
1276
1300
  const rows = [];
1277
1301
  const walk = (list) => {
@@ -1364,10 +1388,11 @@ function MenuManager({
1364
1388
  void loadPermissionPoints();
1365
1389
  };
1366
1390
  const openEdit = (row) => {
1391
+ const parentId = resolveRowParentId(row);
1367
1392
  setEditing(row);
1368
1393
  setForm({
1369
- parentId: row.parentId ?? null,
1370
- depth: resolveMenuDepth(row.parentId ?? null, allKnownMenus),
1394
+ parentId,
1395
+ depth: row.depth > 0 ? row.depth : resolveMenuDepth(parentId, allKnownMenus),
1371
1396
  type: row.type,
1372
1397
  name: row.name,
1373
1398
  identification: row.identification,