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.
- package/README.md +1 -0
- package/dist/index.cjs +19 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +35 -6
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +13 -1
- package/dist/react/index.d.ts +13 -1
- package/dist/react/index.js +33 -6
- package/dist/react/index.js.map +1 -1
- package/dist/vue/index.cjs +34 -3
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +13 -1
- package/dist/vue/index.d.ts +13 -1
- package/dist/vue/index.js +32 -3
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
package/dist/vue/index.d.cts
CHANGED
|
@@ -224,6 +224,10 @@ type MenuResource = {
|
|
|
224
224
|
resourceId: string;
|
|
225
225
|
/** 上级菜单 ID;无上级时为 null */
|
|
226
226
|
parentId: string | null;
|
|
227
|
+
/**
|
|
228
|
+
* 菜单层级:无上级(根)为 1,其余为上级 depth + 1
|
|
229
|
+
*/
|
|
230
|
+
depth: number;
|
|
227
231
|
type: MenuResourceType;
|
|
228
232
|
name: string;
|
|
229
233
|
identification: string;
|
|
@@ -235,6 +239,8 @@ type MenuResource = {
|
|
|
235
239
|
type MenuResourceFormValues = {
|
|
236
240
|
/** 上级菜单 ID;选择「无」时为 null */
|
|
237
241
|
parentId: string | null;
|
|
242
|
+
/** 由 parentId 自动计算:无为 1,否则上级 depth + 1 */
|
|
243
|
+
depth: number;
|
|
238
244
|
type: MenuResourceType;
|
|
239
245
|
name: string;
|
|
240
246
|
identification: string;
|
|
@@ -265,6 +271,8 @@ declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
|
|
|
265
271
|
* 提交接口时会转换为 parentId: null。
|
|
266
272
|
*/
|
|
267
273
|
declare const ROOT_PARENT_ID = "";
|
|
274
|
+
/** 无上级时的菜单层级 */
|
|
275
|
+
declare const ROOT_MENU_DEPTH = 1;
|
|
268
276
|
declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
|
|
269
277
|
declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
|
|
270
278
|
declare const RESOURCE_STATUS_OPTIONS: {
|
|
@@ -313,6 +321,10 @@ type MenuResourceApi = {
|
|
|
313
321
|
};
|
|
314
322
|
declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
|
|
315
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;
|
|
316
328
|
declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
|
|
317
329
|
declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
|
|
318
330
|
declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
|
|
@@ -511,4 +523,4 @@ declare const snowyflake: ConfigurableSnowflake;
|
|
|
511
523
|
declare function getAppClientId(): string;
|
|
512
524
|
declare function getDeviceWorkerId(): string;
|
|
513
525
|
|
|
514
|
-
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.d.ts
CHANGED
|
@@ -224,6 +224,10 @@ type MenuResource = {
|
|
|
224
224
|
resourceId: string;
|
|
225
225
|
/** 上级菜单 ID;无上级时为 null */
|
|
226
226
|
parentId: string | null;
|
|
227
|
+
/**
|
|
228
|
+
* 菜单层级:无上级(根)为 1,其余为上级 depth + 1
|
|
229
|
+
*/
|
|
230
|
+
depth: number;
|
|
227
231
|
type: MenuResourceType;
|
|
228
232
|
name: string;
|
|
229
233
|
identification: string;
|
|
@@ -235,6 +239,8 @@ type MenuResource = {
|
|
|
235
239
|
type MenuResourceFormValues = {
|
|
236
240
|
/** 上级菜单 ID;选择「无」时为 null */
|
|
237
241
|
parentId: string | null;
|
|
242
|
+
/** 由 parentId 自动计算:无为 1,否则上级 depth + 1 */
|
|
243
|
+
depth: number;
|
|
238
244
|
type: MenuResourceType;
|
|
239
245
|
name: string;
|
|
240
246
|
identification: string;
|
|
@@ -265,6 +271,8 @@ declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
|
|
|
265
271
|
* 提交接口时会转换为 parentId: null。
|
|
266
272
|
*/
|
|
267
273
|
declare const ROOT_PARENT_ID = "";
|
|
274
|
+
/** 无上级时的菜单层级 */
|
|
275
|
+
declare const ROOT_MENU_DEPTH = 1;
|
|
268
276
|
declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
|
|
269
277
|
declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
|
|
270
278
|
declare const RESOURCE_STATUS_OPTIONS: {
|
|
@@ -313,6 +321,10 @@ type MenuResourceApi = {
|
|
|
313
321
|
};
|
|
314
322
|
declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
|
|
315
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;
|
|
316
328
|
declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
|
|
317
329
|
declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
|
|
318
330
|
declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
|
|
@@ -511,4 +523,4 @@ declare const snowyflake: ConfigurableSnowflake;
|
|
|
511
523
|
declare function getAppClientId(): string;
|
|
512
524
|
declare function getDeviceWorkerId(): string;
|
|
513
525
|
|
|
514
|
-
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
|
@@ -315,6 +315,7 @@ var MENU_TYPE_MENU = "menu";
|
|
|
315
315
|
var MENU_TYPE_BUTTON = "button";
|
|
316
316
|
var MENU_LIST_TYPE_PARAM = "page,menu,button";
|
|
317
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 = [
|
|
@@ -533,9 +534,13 @@ function mapMenuResource(item) {
|
|
|
533
534
|
const permissionPointNames = Array.isArray(permissionNamesRaw) ? permissionNamesRaw.map((n) => String(n ?? "")).filter(Boolean) : void 0;
|
|
534
535
|
const rawParentId = row.parentId ?? row.parent_id;
|
|
535
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;
|
|
536
540
|
return {
|
|
537
541
|
resourceId: String(resourceId),
|
|
538
542
|
parentId,
|
|
543
|
+
depth,
|
|
539
544
|
type: toMenuType(row.type),
|
|
540
545
|
name: String(row.name ?? ""),
|
|
541
546
|
identification: String(row.identification ?? row.identity ?? row.path ?? ""),
|
|
@@ -544,6 +549,12 @@ function mapMenuResource(item) {
|
|
|
544
549
|
status: toResourceStatus(row.status)
|
|
545
550
|
};
|
|
546
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
|
+
}
|
|
547
558
|
function buildListUrl(type, params) {
|
|
548
559
|
const parts = [];
|
|
549
560
|
appendQueryParam(parts, "type", type);
|
|
@@ -574,9 +585,11 @@ function buildUpdateBody(values) {
|
|
|
574
585
|
};
|
|
575
586
|
}
|
|
576
587
|
function buildCreateMenuBody(values, resourceId = getAppClientId()) {
|
|
588
|
+
const parentId = values.parentId ? values.parentId : null;
|
|
577
589
|
return {
|
|
578
590
|
resourceId,
|
|
579
|
-
parentId
|
|
591
|
+
parentId,
|
|
592
|
+
depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
|
|
580
593
|
type: values.type,
|
|
581
594
|
name: values.name.trim(),
|
|
582
595
|
identification: values.identification.trim(),
|
|
@@ -585,8 +598,10 @@ function buildCreateMenuBody(values, resourceId = getAppClientId()) {
|
|
|
585
598
|
};
|
|
586
599
|
}
|
|
587
600
|
function buildUpdateMenuBody(values) {
|
|
601
|
+
const parentId = values.parentId ? values.parentId : null;
|
|
588
602
|
return {
|
|
589
|
-
parentId
|
|
603
|
+
parentId,
|
|
604
|
+
depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
|
|
590
605
|
type: values.type,
|
|
591
606
|
name: values.name.trim(),
|
|
592
607
|
identification: values.identification.trim(),
|
|
@@ -1393,6 +1408,7 @@ var PAGE_SIZE_OPTIONS2 = ["10", "20", "50", "100"];
|
|
|
1393
1408
|
function emptyForm2() {
|
|
1394
1409
|
return {
|
|
1395
1410
|
parentId: null,
|
|
1411
|
+
depth: ROOT_MENU_DEPTH,
|
|
1396
1412
|
type: MENU_TYPE_MENU,
|
|
1397
1413
|
name: "",
|
|
1398
1414
|
identification: "",
|
|
@@ -1714,6 +1730,7 @@ var MenuManager = defineComponent3({
|
|
|
1714
1730
|
editing.value = row;
|
|
1715
1731
|
Object.assign(form, {
|
|
1716
1732
|
parentId: row.parentId ?? null,
|
|
1733
|
+
depth: resolveMenuDepth(row.parentId ?? null, records.value),
|
|
1717
1734
|
type: row.type,
|
|
1718
1735
|
name: row.name,
|
|
1719
1736
|
identification: row.identification,
|
|
@@ -1961,7 +1978,9 @@ var MenuManager = defineComponent3({
|
|
|
1961
1978
|
value: form.parentId ?? ROOT_PARENT_ID,
|
|
1962
1979
|
onChange: (e) => {
|
|
1963
1980
|
const value = e.target.value;
|
|
1964
|
-
|
|
1981
|
+
const parentId = value ? value : null;
|
|
1982
|
+
form.parentId = parentId;
|
|
1983
|
+
form.depth = resolveMenuDepth(parentId, records.value);
|
|
1965
1984
|
}
|
|
1966
1985
|
},
|
|
1967
1986
|
[
|
|
@@ -1976,6 +1995,14 @@ var MenuManager = defineComponent3({
|
|
|
1976
1995
|
]
|
|
1977
1996
|
)
|
|
1978
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
|
+
]),
|
|
1979
2006
|
h2("fieldset", { style: s2.fieldset }, [
|
|
1980
2007
|
h2("legend", { style: s2.label }, "\u83DC\u5355\u7C7B\u578B"),
|
|
1981
2008
|
h2(
|
|
@@ -2373,6 +2400,7 @@ export {
|
|
|
2373
2400
|
RESOURCE_STATUS_ENABLED,
|
|
2374
2401
|
RESOURCE_STATUS_OPTIONS,
|
|
2375
2402
|
RESOURCE_TYPE_API,
|
|
2403
|
+
ROOT_MENU_DEPTH,
|
|
2376
2404
|
ROOT_PARENT_ID,
|
|
2377
2405
|
ResourceManager,
|
|
2378
2406
|
SYSTEM_ADMIN_DEFAULT_KEY,
|
|
@@ -2395,6 +2423,7 @@ export {
|
|
|
2395
2423
|
getDeviceWorkerId,
|
|
2396
2424
|
mapAuthorizationResource,
|
|
2397
2425
|
mapMenuResource,
|
|
2426
|
+
resolveMenuDepth,
|
|
2398
2427
|
snowyflake,
|
|
2399
2428
|
useHasPermission,
|
|
2400
2429
|
useHasRole,
|