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.
@@ -222,7 +222,12 @@ type AuthorizationResourceListResult = {
222
222
  };
223
223
  type MenuResource = {
224
224
  resourceId: string;
225
- parentId: string;
225
+ /** 上级菜单 ID;无上级时为 null */
226
+ parentId: string | null;
227
+ /**
228
+ * 菜单层级:无上级(根)为 1,其余为上级 depth + 1
229
+ */
230
+ depth: number;
226
231
  type: MenuResourceType;
227
232
  name: string;
228
233
  identification: string;
@@ -232,7 +237,10 @@ type MenuResource = {
232
237
  status: ResourceStatus;
233
238
  };
234
239
  type MenuResourceFormValues = {
235
- parentId: string;
240
+ /** 上级菜单 ID;选择「无」时为 null */
241
+ parentId: string | null;
242
+ /** 由 parentId 自动计算:无为 1,否则上级 depth + 1 */
243
+ depth: number;
236
244
  type: MenuResourceType;
237
245
  name: string;
238
246
  identification: string;
@@ -258,7 +266,13 @@ declare const MENU_TYPE_MENU: MenuResourceType;
258
266
  declare const MENU_TYPE_BUTTON: MenuResourceType;
259
267
  /** 菜单列表查询 type 参数 */
260
268
  declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
261
- declare const ROOT_PARENT_ID = "0";
269
+ /**
270
+ * 上级菜单选择「无」时,表单 select 使用的空值。
271
+ * 提交接口时会转换为 parentId: null。
272
+ */
273
+ declare const ROOT_PARENT_ID = "";
274
+ /** 无上级时的菜单层级 */
275
+ declare const ROOT_MENU_DEPTH = 1;
262
276
  declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
263
277
  declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
264
278
  declare const RESOURCE_STATUS_OPTIONS: {
@@ -307,6 +321,10 @@ type MenuResourceApi = {
307
321
  };
308
322
  declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
309
323
  declare function mapMenuResource(item: unknown): MenuResource | null;
324
+ /**
325
+ * 根据上级菜单计算 depth:无上级为 1,否则为上级 depth + 1。
326
+ */
327
+ declare function resolveMenuDepth(parentId: string | null | undefined, menus: Array<Pick<MenuResource, 'resourceId' | 'depth'>>): number;
310
328
  declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
311
329
  declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
312
330
  declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
@@ -505,4 +523,4 @@ declare const snowyflake: ConfigurableSnowflake;
505
523
  declare function getAppClientId(): string;
506
524
  declare function getDeviceWorkerId(): string;
507
525
 
508
- export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, 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 MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, PERMISSION_STORE_KEY, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionDirectiveValue, type PermissionListener, type PermissionPluginOptions, 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 ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminSubMenu, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionPlugin, createPermissionStore, createVPermission, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, snowyflake, useHasPermission, useHasRole, usePermission };
526
+ export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, 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 MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, PERMISSION_STORE_KEY, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionDirectiveValue, type PermissionListener, type PermissionPluginOptions, 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 ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminSubMenu, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionPlugin, createPermissionStore, createVPermission, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, resolveMenuDepth, snowyflake, useHasPermission, useHasRole, usePermission };
@@ -222,7 +222,12 @@ type AuthorizationResourceListResult = {
222
222
  };
223
223
  type MenuResource = {
224
224
  resourceId: string;
225
- parentId: string;
225
+ /** 上级菜单 ID;无上级时为 null */
226
+ parentId: string | null;
227
+ /**
228
+ * 菜单层级:无上级(根)为 1,其余为上级 depth + 1
229
+ */
230
+ depth: number;
226
231
  type: MenuResourceType;
227
232
  name: string;
228
233
  identification: string;
@@ -232,7 +237,10 @@ type MenuResource = {
232
237
  status: ResourceStatus;
233
238
  };
234
239
  type MenuResourceFormValues = {
235
- parentId: string;
240
+ /** 上级菜单 ID;选择「无」时为 null */
241
+ parentId: string | null;
242
+ /** 由 parentId 自动计算:无为 1,否则上级 depth + 1 */
243
+ depth: number;
236
244
  type: MenuResourceType;
237
245
  name: string;
238
246
  identification: string;
@@ -258,7 +266,13 @@ declare const MENU_TYPE_MENU: MenuResourceType;
258
266
  declare const MENU_TYPE_BUTTON: MenuResourceType;
259
267
  /** 菜单列表查询 type 参数 */
260
268
  declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
261
- declare const ROOT_PARENT_ID = "0";
269
+ /**
270
+ * 上级菜单选择「无」时,表单 select 使用的空值。
271
+ * 提交接口时会转换为 parentId: null。
272
+ */
273
+ declare const ROOT_PARENT_ID = "";
274
+ /** 无上级时的菜单层级 */
275
+ declare const ROOT_MENU_DEPTH = 1;
262
276
  declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
263
277
  declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
264
278
  declare const RESOURCE_STATUS_OPTIONS: {
@@ -307,6 +321,10 @@ type MenuResourceApi = {
307
321
  };
308
322
  declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
309
323
  declare function mapMenuResource(item: unknown): MenuResource | null;
324
+ /**
325
+ * 根据上级菜单计算 depth:无上级为 1,否则为上级 depth + 1。
326
+ */
327
+ declare function resolveMenuDepth(parentId: string | null | undefined, menus: Array<Pick<MenuResource, 'resourceId' | 'depth'>>): number;
310
328
  declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
311
329
  declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
312
330
  declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
@@ -505,4 +523,4 @@ declare const snowyflake: ConfigurableSnowflake;
505
523
  declare function getAppClientId(): string;
506
524
  declare function getDeviceWorkerId(): string;
507
525
 
508
- export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, 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 MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, PERMISSION_STORE_KEY, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionDirectiveValue, type PermissionListener, type PermissionPluginOptions, 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 ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminSubMenu, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionPlugin, createPermissionStore, createVPermission, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, snowyflake, useHasPermission, useHasRole, usePermission };
526
+ export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, 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 MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, PERMISSION_STORE_KEY, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionDirectiveValue, type PermissionListener, type PermissionPluginOptions, 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 ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, SYSTEM_ADMIN_DEFAULT_KEY, SYSTEM_ADMIN_MENU, SystemAdmin, type SystemAdminMenuGroup, type SystemAdminMenuKey, type SystemAdminSubMenu, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionPlugin, createPermissionStore, createVPermission, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, resolveMenuDepth, snowyflake, useHasPermission, useHasRole, usePermission };
package/dist/vue/index.js CHANGED
@@ -314,7 +314,8 @@ var MENU_TYPE_PAGE = "page";
314
314
  var MENU_TYPE_MENU = "menu";
315
315
  var MENU_TYPE_BUTTON = "button";
316
316
  var MENU_LIST_TYPE_PARAM = "page,menu,button";
317
- var ROOT_PARENT_ID = "0";
317
+ var ROOT_PARENT_ID = "";
318
+ var ROOT_MENU_DEPTH = 1;
318
319
  var RESOURCE_STATUS_ENABLED = 1;
319
320
  var RESOURCE_STATUS_DISABLED = 0;
320
321
  var RESOURCE_STATUS_OPTIONS = [
@@ -531,10 +532,15 @@ function mapMenuResource(item) {
531
532
  );
532
533
  const permissionNamesRaw = row.permissionPointNames ?? row.permission_point_names ?? row.permissionNames;
533
534
  const permissionPointNames = Array.isArray(permissionNamesRaw) ? permissionNamesRaw.map((n) => String(n ?? "")).filter(Boolean) : void 0;
534
- const parentId = row.parentId ?? row.parent_id ?? ROOT_PARENT_ID;
535
+ const rawParentId = row.parentId ?? row.parent_id;
536
+ const parentId = rawParentId === void 0 || rawParentId === null || rawParentId === "" || String(rawParentId) === "0" ? null : String(rawParentId);
537
+ const rawDepth = row.depth;
538
+ const parsedDepth = Number(rawDepth);
539
+ const depth = Number.isFinite(parsedDepth) && parsedDepth > 0 ? Math.floor(parsedDepth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH;
535
540
  return {
536
541
  resourceId: String(resourceId),
537
- parentId: parentId === void 0 || parentId === null ? ROOT_PARENT_ID : String(parentId),
542
+ parentId,
543
+ depth,
538
544
  type: toMenuType(row.type),
539
545
  name: String(row.name ?? ""),
540
546
  identification: String(row.identification ?? row.identity ?? row.path ?? ""),
@@ -543,6 +549,12 @@ function mapMenuResource(item) {
543
549
  status: toResourceStatus(row.status)
544
550
  };
545
551
  }
552
+ function resolveMenuDepth(parentId, menus) {
553
+ if (!parentId) return ROOT_MENU_DEPTH;
554
+ const parent = menus.find((item) => item.resourceId === parentId);
555
+ const parentDepth = parent && Number.isFinite(parent.depth) && parent.depth > 0 ? Math.floor(parent.depth) : ROOT_MENU_DEPTH;
556
+ return parentDepth + 1;
557
+ }
546
558
  function buildListUrl(type, params) {
547
559
  const parts = [];
548
560
  appendQueryParam(parts, "type", type);
@@ -573,9 +585,11 @@ function buildUpdateBody(values) {
573
585
  };
574
586
  }
575
587
  function buildCreateMenuBody(values, resourceId = getAppClientId()) {
588
+ const parentId = values.parentId ? values.parentId : null;
576
589
  return {
577
590
  resourceId,
578
- parentId: values.parentId || ROOT_PARENT_ID,
591
+ parentId,
592
+ depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
579
593
  type: values.type,
580
594
  name: values.name.trim(),
581
595
  identification: values.identification.trim(),
@@ -584,8 +598,10 @@ function buildCreateMenuBody(values, resourceId = getAppClientId()) {
584
598
  };
585
599
  }
586
600
  function buildUpdateMenuBody(values) {
601
+ const parentId = values.parentId ? values.parentId : null;
587
602
  return {
588
- parentId: values.parentId || ROOT_PARENT_ID,
603
+ parentId,
604
+ depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
589
605
  type: values.type,
590
606
  name: values.name.trim(),
591
607
  identification: values.identification.trim(),
@@ -1391,7 +1407,8 @@ import {
1391
1407
  var PAGE_SIZE_OPTIONS2 = ["10", "20", "50", "100"];
1392
1408
  function emptyForm2() {
1393
1409
  return {
1394
- parentId: ROOT_PARENT_ID,
1410
+ parentId: null,
1411
+ depth: ROOT_MENU_DEPTH,
1395
1412
  type: MENU_TYPE_MENU,
1396
1413
  name: "",
1397
1414
  identification: "",
@@ -1712,7 +1729,8 @@ var MenuManager = defineComponent3({
1712
1729
  function openEdit(row) {
1713
1730
  editing.value = row;
1714
1731
  Object.assign(form, {
1715
- parentId: row.parentId || ROOT_PARENT_ID,
1732
+ parentId: row.parentId ?? null,
1733
+ depth: resolveMenuDepth(row.parentId ?? null, records.value),
1716
1734
  type: row.type,
1717
1735
  name: row.name,
1718
1736
  identification: row.identification,
@@ -1957,13 +1975,16 @@ var MenuManager = defineComponent3({
1957
1975
  "select",
1958
1976
  {
1959
1977
  style: s2.input,
1960
- value: form.parentId,
1978
+ value: form.parentId ?? ROOT_PARENT_ID,
1961
1979
  onChange: (e) => {
1962
- form.parentId = e.target.value;
1980
+ const value = e.target.value;
1981
+ const parentId = value ? value : null;
1982
+ form.parentId = parentId;
1983
+ form.depth = resolveMenuDepth(parentId, records.value);
1963
1984
  }
1964
1985
  },
1965
1986
  [
1966
- h2("option", { value: ROOT_PARENT_ID }, "\u6839\u76EE\u5F55"),
1987
+ h2("option", { value: ROOT_PARENT_ID }, "\u65E0"),
1967
1988
  ...parentOptions.value.map(
1968
1989
  (opt) => h2(
1969
1990
  "option",
@@ -1974,6 +1995,14 @@ var MenuManager = defineComponent3({
1974
1995
  ]
1975
1996
  )
1976
1997
  ]),
1998
+ h2("div", { style: s2.field }, [
1999
+ h2("span", { style: s2.label }, "\u83DC\u5355\u5C42\u7EA7\uFF08depth\uFF09"),
2000
+ h2("input", {
2001
+ style: s2.input,
2002
+ value: form.depth,
2003
+ readOnly: true
2004
+ })
2005
+ ]),
1977
2006
  h2("fieldset", { style: s2.fieldset }, [
1978
2007
  h2("legend", { style: s2.label }, "\u83DC\u5355\u7C7B\u578B"),
1979
2008
  h2(
@@ -2371,6 +2400,7 @@ export {
2371
2400
  RESOURCE_STATUS_ENABLED,
2372
2401
  RESOURCE_STATUS_OPTIONS,
2373
2402
  RESOURCE_TYPE_API,
2403
+ ROOT_MENU_DEPTH,
2374
2404
  ROOT_PARENT_ID,
2375
2405
  ResourceManager,
2376
2406
  SYSTEM_ADMIN_DEFAULT_KEY,
@@ -2393,6 +2423,7 @@ export {
2393
2423
  getDeviceWorkerId,
2394
2424
  mapAuthorizationResource,
2395
2425
  mapMenuResource,
2426
+ resolveMenuDepth,
2396
2427
  snowyflake,
2397
2428
  useHasPermission,
2398
2429
  useHasRole,