com-angel-authorization 1.0.8 → 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.
@@ -170,6 +170,10 @@ type MenuResource = {
170
170
  resourceId: string;
171
171
  /** 上级菜单 ID;无上级时为 null */
172
172
  parentId: string | null;
173
+ /**
174
+ * 菜单层级:无上级(根)为 1,其余为上级 depth + 1
175
+ */
176
+ depth: number;
173
177
  type: MenuResourceType;
174
178
  name: string;
175
179
  identification: string;
@@ -181,6 +185,8 @@ type MenuResource = {
181
185
  type MenuResourceFormValues = {
182
186
  /** 上级菜单 ID;选择「无」时为 null */
183
187
  parentId: string | null;
188
+ /** 由 parentId 自动计算:无为 1,否则上级 depth + 1 */
189
+ depth: number;
184
190
  type: MenuResourceType;
185
191
  name: string;
186
192
  identification: string;
@@ -211,6 +217,8 @@ declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
211
217
  * 提交接口时会转换为 parentId: null。
212
218
  */
213
219
  declare const ROOT_PARENT_ID = "";
220
+ /** 无上级时的菜单层级 */
221
+ declare const ROOT_MENU_DEPTH = 1;
214
222
  declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
215
223
  declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
216
224
  declare const RESOURCE_STATUS_OPTIONS: {
@@ -259,6 +267,10 @@ type MenuResourceApi = {
259
267
  };
260
268
  declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
261
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;
262
274
  declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
263
275
  declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
264
276
  declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
@@ -359,4 +371,4 @@ declare const snowyflake: ConfigurableSnowflake;
359
371
  declare function getAppClientId(): string;
360
372
  declare function getDeviceWorkerId(): string;
361
373
 
362
- 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 };
@@ -170,6 +170,10 @@ type MenuResource = {
170
170
  resourceId: string;
171
171
  /** 上级菜单 ID;无上级时为 null */
172
172
  parentId: string | null;
173
+ /**
174
+ * 菜单层级:无上级(根)为 1,其余为上级 depth + 1
175
+ */
176
+ depth: number;
173
177
  type: MenuResourceType;
174
178
  name: string;
175
179
  identification: string;
@@ -181,6 +185,8 @@ type MenuResource = {
181
185
  type MenuResourceFormValues = {
182
186
  /** 上级菜单 ID;选择「无」时为 null */
183
187
  parentId: string | null;
188
+ /** 由 parentId 自动计算:无为 1,否则上级 depth + 1 */
189
+ depth: number;
184
190
  type: MenuResourceType;
185
191
  name: string;
186
192
  identification: string;
@@ -211,6 +217,8 @@ declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
211
217
  * 提交接口时会转换为 parentId: null。
212
218
  */
213
219
  declare const ROOT_PARENT_ID = "";
220
+ /** 无上级时的菜单层级 */
221
+ declare const ROOT_MENU_DEPTH = 1;
214
222
  declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
215
223
  declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
216
224
  declare const RESOURCE_STATUS_OPTIONS: {
@@ -259,6 +267,10 @@ type MenuResourceApi = {
259
267
  };
260
268
  declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
261
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;
262
274
  declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
263
275
  declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
264
276
  declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
@@ -359,4 +371,4 @@ declare const snowyflake: ConfigurableSnowflake;
359
371
  declare function getAppClientId(): string;
360
372
  declare function getDeviceWorkerId(): string;
361
373
 
362
- 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 };
@@ -238,6 +238,7 @@ var MENU_TYPE_MENU = "menu";
238
238
  var MENU_TYPE_BUTTON = "button";
239
239
  var MENU_LIST_TYPE_PARAM = "page,menu,button";
240
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 = [
@@ -456,9 +457,13 @@ function mapMenuResource(item) {
456
457
  const permissionPointNames = Array.isArray(permissionNamesRaw) ? permissionNamesRaw.map((n) => String(n ?? "")).filter(Boolean) : void 0;
457
458
  const rawParentId = row.parentId ?? row.parent_id;
458
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;
459
463
  return {
460
464
  resourceId: String(resourceId),
461
465
  parentId,
466
+ depth,
462
467
  type: toMenuType(row.type),
463
468
  name: String(row.name ?? ""),
464
469
  identification: String(row.identification ?? row.identity ?? row.path ?? ""),
@@ -467,6 +472,12 @@ function mapMenuResource(item) {
467
472
  status: toResourceStatus(row.status)
468
473
  };
469
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
+ }
470
481
  function buildListUrl(type, params) {
471
482
  const parts = [];
472
483
  appendQueryParam(parts, "type", type);
@@ -497,9 +508,11 @@ function buildUpdateBody(values) {
497
508
  };
498
509
  }
499
510
  function buildCreateMenuBody(values, resourceId = getAppClientId()) {
511
+ const parentId = values.parentId ? values.parentId : null;
500
512
  return {
501
513
  resourceId,
502
- parentId: values.parentId ? values.parentId : null,
514
+ parentId,
515
+ depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
503
516
  type: values.type,
504
517
  name: values.name.trim(),
505
518
  identification: values.identification.trim(),
@@ -508,8 +521,10 @@ function buildCreateMenuBody(values, resourceId = getAppClientId()) {
508
521
  };
509
522
  }
510
523
  function buildUpdateMenuBody(values) {
524
+ const parentId = values.parentId ? values.parentId : null;
511
525
  return {
512
- parentId: values.parentId ? values.parentId : null,
526
+ parentId,
527
+ depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
513
528
  type: values.type,
514
529
  name: values.name.trim(),
515
530
  identification: values.identification.trim(),
@@ -1179,6 +1194,7 @@ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1179
1194
  var PAGE_SIZE_OPTIONS2 = ["10", "20", "50", "100"];
1180
1195
  var emptyForm2 = () => ({
1181
1196
  parentId: null,
1197
+ depth: ROOT_MENU_DEPTH,
1182
1198
  type: MENU_TYPE_MENU,
1183
1199
  name: "",
1184
1200
  identification: "",
@@ -1263,6 +1279,7 @@ function MenuManager({
1263
1279
  setEditing(row);
1264
1280
  setForm({
1265
1281
  parentId: row.parentId ?? null,
1282
+ depth: resolveMenuDepth(row.parentId ?? null, records),
1266
1283
  type: row.type,
1267
1284
  name: row.name,
1268
1285
  identification: row.identification,
@@ -1439,10 +1456,14 @@ function MenuManager({
1439
1456
  {
1440
1457
  style: styles2.input,
1441
1458
  value: form.parentId ?? ROOT_PARENT_ID,
1442
- onChange: (e) => setForm((prev) => ({
1443
- ...prev,
1444
- parentId: e.target.value ? e.target.value : null
1445
- })),
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
+ },
1446
1467
  children: [
1447
1468
  /* @__PURE__ */ jsx3("option", { value: ROOT_PARENT_ID, children: "\u65E0" }),
1448
1469
  parentOptions.map((opt) => /* @__PURE__ */ jsx3("option", { value: opt.value, children: opt.label }, opt.value))
@@ -1450,6 +1471,10 @@ function MenuManager({
1450
1471
  }
1451
1472
  )
1452
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
+ ] }),
1453
1478
  /* @__PURE__ */ jsxs2("fieldset", { style: styles2.fieldset, children: [
1454
1479
  /* @__PURE__ */ jsx3("legend", { style: styles2.label, children: "\u83DC\u5355\u7C7B\u578B" }),
1455
1480
  /* @__PURE__ */ jsx3("div", { style: styles2.radioGroup, children: MENU_TYPE_OPTIONS.map((opt) => /* @__PURE__ */ jsxs2("label", { style: styles2.radioItem, children: [
@@ -1957,6 +1982,7 @@ export {
1957
1982
  RESOURCE_STATUS_ENABLED,
1958
1983
  RESOURCE_STATUS_OPTIONS,
1959
1984
  RESOURCE_TYPE_API,
1985
+ ROOT_MENU_DEPTH,
1960
1986
  ROOT_PARENT_ID,
1961
1987
  ResourceManager,
1962
1988
  SYSTEM_ADMIN_DEFAULT_KEY,
@@ -1977,6 +2003,7 @@ export {
1977
2003
  getDeviceWorkerId,
1978
2004
  mapAuthorizationResource,
1979
2005
  mapMenuResource,
2006
+ resolveMenuDepth,
1980
2007
  snowyflake,
1981
2008
  useHasPermission,
1982
2009
  useHasRole,