com-angel-authorization 1.0.7 → 1.0.9

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.
@@ -168,7 +168,12 @@ type AuthorizationResourceListResult = {
168
168
  };
169
169
  type MenuResource = {
170
170
  resourceId: string;
171
- parentId: string;
171
+ /** 上级菜单 ID;无上级时为 null */
172
+ parentId: string | null;
173
+ /**
174
+ * 菜单层级:无上级(根)为 1,其余为上级 depth + 1
175
+ */
176
+ depth: number;
172
177
  type: MenuResourceType;
173
178
  name: string;
174
179
  identification: string;
@@ -178,7 +183,10 @@ type MenuResource = {
178
183
  status: ResourceStatus;
179
184
  };
180
185
  type MenuResourceFormValues = {
181
- parentId: string;
186
+ /** 上级菜单 ID;选择「无」时为 null */
187
+ parentId: string | null;
188
+ /** 由 parentId 自动计算:无为 1,否则上级 depth + 1 */
189
+ depth: number;
182
190
  type: MenuResourceType;
183
191
  name: string;
184
192
  identification: string;
@@ -204,7 +212,13 @@ declare const MENU_TYPE_MENU: MenuResourceType;
204
212
  declare const MENU_TYPE_BUTTON: MenuResourceType;
205
213
  /** 菜单列表查询 type 参数 */
206
214
  declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
207
- declare const ROOT_PARENT_ID = "0";
215
+ /**
216
+ * 上级菜单选择「无」时,表单 select 使用的空值。
217
+ * 提交接口时会转换为 parentId: null。
218
+ */
219
+ declare const ROOT_PARENT_ID = "";
220
+ /** 无上级时的菜单层级 */
221
+ declare const ROOT_MENU_DEPTH = 1;
208
222
  declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
209
223
  declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
210
224
  declare const RESOURCE_STATUS_OPTIONS: {
@@ -253,6 +267,10 @@ type MenuResourceApi = {
253
267
  };
254
268
  declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
255
269
  declare function mapMenuResource(item: unknown): MenuResource | null;
270
+ /**
271
+ * 根据上级菜单计算 depth:无上级为 1,否则为上级 depth + 1。
272
+ */
273
+ declare function resolveMenuDepth(parentId: string | null | undefined, menus: Array<Pick<MenuResource, 'resourceId' | 'depth'>>): number;
256
274
  declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
257
275
  declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
258
276
  declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
@@ -353,4 +371,4 @@ declare const snowyflake: ConfigurableSnowflake;
353
371
  declare function getAppClientId(): string;
354
372
  declare function getDeviceWorkerId(): string;
355
373
 
356
- export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CanProps, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuManagerProps, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionListener, PermissionProvider, type PermissionProviderProps, type PermissionState, PermissionStore, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceManagerProps, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminProps, type SystemAdminSubMenu, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionStore, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, snowyflake, useHasPermission, useHasRole, usePermission };
374
+ export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CanProps, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuManagerProps, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionListener, PermissionProvider, type PermissionProviderProps, type PermissionState, PermissionStore, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_MENU_DEPTH, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceManagerProps, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminProps, type SystemAdminSubMenu, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionStore, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, resolveMenuDepth, snowyflake, useHasPermission, useHasRole, usePermission };
@@ -168,7 +168,12 @@ type AuthorizationResourceListResult = {
168
168
  };
169
169
  type MenuResource = {
170
170
  resourceId: string;
171
- parentId: string;
171
+ /** 上级菜单 ID;无上级时为 null */
172
+ parentId: string | null;
173
+ /**
174
+ * 菜单层级:无上级(根)为 1,其余为上级 depth + 1
175
+ */
176
+ depth: number;
172
177
  type: MenuResourceType;
173
178
  name: string;
174
179
  identification: string;
@@ -178,7 +183,10 @@ type MenuResource = {
178
183
  status: ResourceStatus;
179
184
  };
180
185
  type MenuResourceFormValues = {
181
- parentId: string;
186
+ /** 上级菜单 ID;选择「无」时为 null */
187
+ parentId: string | null;
188
+ /** 由 parentId 自动计算:无为 1,否则上级 depth + 1 */
189
+ depth: number;
182
190
  type: MenuResourceType;
183
191
  name: string;
184
192
  identification: string;
@@ -204,7 +212,13 @@ declare const MENU_TYPE_MENU: MenuResourceType;
204
212
  declare const MENU_TYPE_BUTTON: MenuResourceType;
205
213
  /** 菜单列表查询 type 参数 */
206
214
  declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
207
- declare const ROOT_PARENT_ID = "0";
215
+ /**
216
+ * 上级菜单选择「无」时,表单 select 使用的空值。
217
+ * 提交接口时会转换为 parentId: null。
218
+ */
219
+ declare const ROOT_PARENT_ID = "";
220
+ /** 无上级时的菜单层级 */
221
+ declare const ROOT_MENU_DEPTH = 1;
208
222
  declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
209
223
  declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
210
224
  declare const RESOURCE_STATUS_OPTIONS: {
@@ -253,6 +267,10 @@ type MenuResourceApi = {
253
267
  };
254
268
  declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
255
269
  declare function mapMenuResource(item: unknown): MenuResource | null;
270
+ /**
271
+ * 根据上级菜单计算 depth:无上级为 1,否则为上级 depth + 1。
272
+ */
273
+ declare function resolveMenuDepth(parentId: string | null | undefined, menus: Array<Pick<MenuResource, 'resourceId' | 'depth'>>): number;
256
274
  declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
257
275
  declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
258
276
  declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
@@ -353,4 +371,4 @@ declare const snowyflake: ConfigurableSnowflake;
353
371
  declare function getAppClientId(): string;
354
372
  declare function getDeviceWorkerId(): string;
355
373
 
356
- export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CanProps, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuManagerProps, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionListener, PermissionProvider, type PermissionProviderProps, type PermissionState, PermissionStore, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceManagerProps, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminProps, type SystemAdminSubMenu, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionStore, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, snowyflake, useHasPermission, useHasRole, usePermission };
374
+ export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CanProps, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuManagerProps, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionListener, PermissionProvider, type PermissionProviderProps, type PermissionState, PermissionStore, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_MENU_DEPTH, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceManagerProps, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminProps, type SystemAdminSubMenu, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionStore, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, resolveMenuDepth, snowyflake, useHasPermission, useHasRole, usePermission };
@@ -237,7 +237,8 @@ var MENU_TYPE_PAGE = "page";
237
237
  var MENU_TYPE_MENU = "menu";
238
238
  var MENU_TYPE_BUTTON = "button";
239
239
  var MENU_LIST_TYPE_PARAM = "page,menu,button";
240
- var ROOT_PARENT_ID = "0";
240
+ var ROOT_PARENT_ID = "";
241
+ var ROOT_MENU_DEPTH = 1;
241
242
  var RESOURCE_STATUS_ENABLED = 1;
242
243
  var RESOURCE_STATUS_DISABLED = 0;
243
244
  var RESOURCE_STATUS_OPTIONS = [
@@ -454,10 +455,15 @@ function mapMenuResource(item) {
454
455
  );
455
456
  const permissionNamesRaw = row.permissionPointNames ?? row.permission_point_names ?? row.permissionNames;
456
457
  const permissionPointNames = Array.isArray(permissionNamesRaw) ? permissionNamesRaw.map((n) => String(n ?? "")).filter(Boolean) : void 0;
457
- const parentId = row.parentId ?? row.parent_id ?? ROOT_PARENT_ID;
458
+ const rawParentId = row.parentId ?? row.parent_id;
459
+ const parentId = rawParentId === void 0 || rawParentId === null || rawParentId === "" || String(rawParentId) === "0" ? null : String(rawParentId);
460
+ const rawDepth = row.depth;
461
+ const parsedDepth = Number(rawDepth);
462
+ const depth = Number.isFinite(parsedDepth) && parsedDepth > 0 ? Math.floor(parsedDepth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH;
458
463
  return {
459
464
  resourceId: String(resourceId),
460
- parentId: parentId === void 0 || parentId === null ? ROOT_PARENT_ID : String(parentId),
465
+ parentId,
466
+ depth,
461
467
  type: toMenuType(row.type),
462
468
  name: String(row.name ?? ""),
463
469
  identification: String(row.identification ?? row.identity ?? row.path ?? ""),
@@ -466,6 +472,12 @@ function mapMenuResource(item) {
466
472
  status: toResourceStatus(row.status)
467
473
  };
468
474
  }
475
+ function resolveMenuDepth(parentId, menus) {
476
+ if (!parentId) return ROOT_MENU_DEPTH;
477
+ const parent = menus.find((item) => item.resourceId === parentId);
478
+ const parentDepth = parent && Number.isFinite(parent.depth) && parent.depth > 0 ? Math.floor(parent.depth) : ROOT_MENU_DEPTH;
479
+ return parentDepth + 1;
480
+ }
469
481
  function buildListUrl(type, params) {
470
482
  const parts = [];
471
483
  appendQueryParam(parts, "type", type);
@@ -496,9 +508,11 @@ function buildUpdateBody(values) {
496
508
  };
497
509
  }
498
510
  function buildCreateMenuBody(values, resourceId = getAppClientId()) {
511
+ const parentId = values.parentId ? values.parentId : null;
499
512
  return {
500
513
  resourceId,
501
- parentId: values.parentId || ROOT_PARENT_ID,
514
+ parentId,
515
+ depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
502
516
  type: values.type,
503
517
  name: values.name.trim(),
504
518
  identification: values.identification.trim(),
@@ -507,8 +521,10 @@ function buildCreateMenuBody(values, resourceId = getAppClientId()) {
507
521
  };
508
522
  }
509
523
  function buildUpdateMenuBody(values) {
524
+ const parentId = values.parentId ? values.parentId : null;
510
525
  return {
511
- parentId: values.parentId || ROOT_PARENT_ID,
526
+ parentId,
527
+ depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
512
528
  type: values.type,
513
529
  name: values.name.trim(),
514
530
  identification: values.identification.trim(),
@@ -1177,7 +1193,8 @@ import {
1177
1193
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1178
1194
  var PAGE_SIZE_OPTIONS2 = ["10", "20", "50", "100"];
1179
1195
  var emptyForm2 = () => ({
1180
- parentId: ROOT_PARENT_ID,
1196
+ parentId: null,
1197
+ depth: ROOT_MENU_DEPTH,
1181
1198
  type: MENU_TYPE_MENU,
1182
1199
  name: "",
1183
1200
  identification: "",
@@ -1261,7 +1278,8 @@ function MenuManager({
1261
1278
  const openEdit = (row) => {
1262
1279
  setEditing(row);
1263
1280
  setForm({
1264
- parentId: row.parentId || ROOT_PARENT_ID,
1281
+ parentId: row.parentId ?? null,
1282
+ depth: resolveMenuDepth(row.parentId ?? null, records),
1265
1283
  type: row.type,
1266
1284
  name: row.name,
1267
1285
  identification: row.identification,
@@ -1437,15 +1455,26 @@ function MenuManager({
1437
1455
  "select",
1438
1456
  {
1439
1457
  style: styles2.input,
1440
- value: form.parentId,
1441
- onChange: (e) => setForm((prev) => ({ ...prev, parentId: e.target.value })),
1458
+ value: form.parentId ?? ROOT_PARENT_ID,
1459
+ onChange: (e) => {
1460
+ const parentId = e.target.value ? e.target.value : null;
1461
+ setForm((prev) => ({
1462
+ ...prev,
1463
+ parentId,
1464
+ depth: resolveMenuDepth(parentId, records)
1465
+ }));
1466
+ },
1442
1467
  children: [
1443
- /* @__PURE__ */ jsx3("option", { value: ROOT_PARENT_ID, children: "\u6839\u76EE\u5F55" }),
1468
+ /* @__PURE__ */ jsx3("option", { value: ROOT_PARENT_ID, children: "\u65E0" }),
1444
1469
  parentOptions.map((opt) => /* @__PURE__ */ jsx3("option", { value: opt.value, children: opt.label }, opt.value))
1445
1470
  ]
1446
1471
  }
1447
1472
  )
1448
1473
  ] }),
1474
+ /* @__PURE__ */ jsxs2("div", { style: styles2.field, children: [
1475
+ /* @__PURE__ */ jsx3("span", { style: styles2.label, children: "\u83DC\u5355\u5C42\u7EA7\uFF08depth\uFF09" }),
1476
+ /* @__PURE__ */ jsx3("input", { style: styles2.input, value: form.depth, readOnly: true })
1477
+ ] }),
1449
1478
  /* @__PURE__ */ jsxs2("fieldset", { style: styles2.fieldset, children: [
1450
1479
  /* @__PURE__ */ jsx3("legend", { style: styles2.label, children: "\u83DC\u5355\u7C7B\u578B" }),
1451
1480
  /* @__PURE__ */ jsx3("div", { style: styles2.radioGroup, children: MENU_TYPE_OPTIONS.map((opt) => /* @__PURE__ */ jsxs2("label", { style: styles2.radioItem, children: [
@@ -1953,6 +1982,7 @@ export {
1953
1982
  RESOURCE_STATUS_ENABLED,
1954
1983
  RESOURCE_STATUS_OPTIONS,
1955
1984
  RESOURCE_TYPE_API,
1985
+ ROOT_MENU_DEPTH,
1956
1986
  ROOT_PARENT_ID,
1957
1987
  ResourceManager,
1958
1988
  SYSTEM_ADMIN_DEFAULT_KEY,
@@ -1973,6 +2003,7 @@ export {
1973
2003
  getDeviceWorkerId,
1974
2004
  mapAuthorizationResource,
1975
2005
  mapMenuResource,
2006
+ resolveMenuDepth,
1976
2007
  snowyflake,
1977
2008
  useHasPermission,
1978
2009
  useHasRole,