com-angel-authorization 1.0.8 → 1.0.10

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.
@@ -21,6 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var vue_exports = {};
22
22
  __export(vue_exports, {
23
23
  Can: () => Can,
24
+ MENU_LEAF_NO: () => MENU_LEAF_NO,
25
+ MENU_LEAF_YES: () => MENU_LEAF_YES,
24
26
  MENU_LIST_TYPE_PARAM: () => MENU_LIST_TYPE_PARAM,
25
27
  MENU_TYPE_BUTTON: () => MENU_TYPE_BUTTON,
26
28
  MENU_TYPE_LABEL: () => MENU_TYPE_LABEL,
@@ -36,6 +38,7 @@ __export(vue_exports, {
36
38
  RESOURCE_STATUS_ENABLED: () => RESOURCE_STATUS_ENABLED,
37
39
  RESOURCE_STATUS_OPTIONS: () => RESOURCE_STATUS_OPTIONS,
38
40
  RESOURCE_TYPE_API: () => RESOURCE_TYPE_API,
41
+ ROOT_MENU_DEPTH: () => ROOT_MENU_DEPTH,
39
42
  ROOT_PARENT_ID: () => ROOT_PARENT_ID,
40
43
  ResourceManager: () => ResourceManager,
41
44
  SYSTEM_ADMIN_DEFAULT_KEY: () => SYSTEM_ADMIN_DEFAULT_KEY,
@@ -56,8 +59,10 @@ __export(vue_exports, {
56
59
  extractRecords: () => extractRecords,
57
60
  getAppClientId: () => getAppClientId,
58
61
  getDeviceWorkerId: () => getDeviceWorkerId,
62
+ isMenuLeaf: () => isMenuLeaf,
59
63
  mapAuthorizationResource: () => mapAuthorizationResource,
60
64
  mapMenuResource: () => mapMenuResource,
65
+ resolveMenuDepth: () => resolveMenuDepth,
61
66
  snowyflake: () => snowyflake,
62
67
  useHasPermission: () => useHasPermission,
63
68
  useHasRole: () => useHasRole,
@@ -364,12 +369,15 @@ var Can = (0, import_vue2.defineComponent)({
364
369
  var import_vue3 = require("vue");
365
370
 
366
371
  // src/resources/types.ts
372
+ var MENU_LEAF_YES = 1;
373
+ var MENU_LEAF_NO = 0;
367
374
  var RESOURCE_TYPE_API = "api";
368
375
  var MENU_TYPE_PAGE = "page";
369
376
  var MENU_TYPE_MENU = "menu";
370
377
  var MENU_TYPE_BUTTON = "button";
371
378
  var MENU_LIST_TYPE_PARAM = "page,menu,button";
372
379
  var ROOT_PARENT_ID = "";
380
+ var ROOT_MENU_DEPTH = 1;
373
381
  var RESOURCE_STATUS_ENABLED = 1;
374
382
  var RESOURCE_STATUS_DISABLED = 0;
375
383
  var RESOURCE_STATUS_OPTIONS = [
@@ -588,9 +596,16 @@ function mapMenuResource(item) {
588
596
  const permissionPointNames = Array.isArray(permissionNamesRaw) ? permissionNamesRaw.map((n) => String(n ?? "")).filter(Boolean) : void 0;
589
597
  const rawParentId = row.parentId ?? row.parent_id;
590
598
  const parentId = rawParentId === void 0 || rawParentId === null || rawParentId === "" || String(rawParentId) === "0" ? null : String(rawParentId);
599
+ const rawDepth = row.depth;
600
+ const parsedDepth = Number(rawDepth);
601
+ const depth = Number.isFinite(parsedDepth) && parsedDepth > 0 ? Math.floor(parsedDepth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH;
602
+ const rawLeaf = row.leaf;
603
+ const leaf = rawLeaf === true || rawLeaf === 1 || rawLeaf === "1" || String(rawLeaf).toLowerCase() === "true" ? MENU_LEAF_YES : Number(rawLeaf) === MENU_LEAF_YES ? MENU_LEAF_YES : 0;
591
604
  return {
592
605
  resourceId: String(resourceId),
593
606
  parentId,
607
+ depth,
608
+ leaf,
594
609
  type: toMenuType(row.type),
595
610
  name: String(row.name ?? ""),
596
611
  identification: String(row.identification ?? row.identity ?? row.path ?? ""),
@@ -599,9 +614,21 @@ function mapMenuResource(item) {
599
614
  status: toResourceStatus(row.status)
600
615
  };
601
616
  }
617
+ function isMenuLeaf(row) {
618
+ return Number(row.leaf) === MENU_LEAF_YES;
619
+ }
620
+ function resolveMenuDepth(parentId, menus) {
621
+ if (!parentId) return ROOT_MENU_DEPTH;
622
+ const parent = menus.find((item) => item.resourceId === parentId);
623
+ const parentDepth = parent && Number.isFinite(parent.depth) && parent.depth > 0 ? Math.floor(parent.depth) : ROOT_MENU_DEPTH;
624
+ return parentDepth + 1;
625
+ }
602
626
  function buildListUrl(type, params) {
603
627
  const parts = [];
604
628
  appendQueryParam(parts, "type", type);
629
+ if (params?.depth !== void 0 && params?.depth !== null && String(params.depth) !== "") {
630
+ appendQueryParam(parts, "depth", String(params.depth));
631
+ }
605
632
  appendQueryParam(parts, "page-token", params?.pagination?.pageToken ?? "");
606
633
  appendQueryParam(parts, "page-size", params?.pagination?.pageSize ?? "20");
607
634
  appendQueryParam(parts, "page-direction", params?.pagination?.pageDirection ?? "current");
@@ -629,9 +656,11 @@ function buildUpdateBody(values) {
629
656
  };
630
657
  }
631
658
  function buildCreateMenuBody(values, resourceId = getAppClientId()) {
659
+ const parentId = values.parentId ? values.parentId : null;
632
660
  return {
633
661
  resourceId,
634
- parentId: values.parentId ? values.parentId : null,
662
+ parentId,
663
+ depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
635
664
  type: values.type,
636
665
  name: values.name.trim(),
637
666
  identification: values.identification.trim(),
@@ -640,8 +669,10 @@ function buildCreateMenuBody(values, resourceId = getAppClientId()) {
640
669
  };
641
670
  }
642
671
  function buildUpdateMenuBody(values) {
672
+ const parentId = values.parentId ? values.parentId : null;
643
673
  return {
644
- parentId: values.parentId ? values.parentId : null,
674
+ parentId,
675
+ depth: values.depth > 0 ? Math.floor(values.depth) : parentId ? ROOT_MENU_DEPTH + 1 : ROOT_MENU_DEPTH,
645
676
  type: values.type,
646
677
  name: values.name.trim(),
647
678
  identification: values.identification.trim(),
@@ -695,7 +726,10 @@ function createMenuResourceApi(request) {
695
726
  async list(params, signal) {
696
727
  const json = await request({
697
728
  method: "GET",
698
- url: buildListUrl(MENU_LIST_TYPE_PARAM, params),
729
+ url: buildListUrl(MENU_LIST_TYPE_PARAM, {
730
+ pagination: params?.pagination,
731
+ depth: params?.depth ?? ROOT_MENU_DEPTH
732
+ }),
699
733
  signal
700
734
  });
701
735
  const records = extractRecords(json).map(mapMenuResource).filter((item) => item !== null);
@@ -705,6 +739,14 @@ function createMenuResourceApi(request) {
705
739
  ...pagination
706
740
  };
707
741
  },
742
+ async listSubResources(resourceId, signal) {
743
+ const json = await request({
744
+ method: "GET",
745
+ url: `/authorization-resources/${encodeURIComponent(resourceId)}/sub-resources`,
746
+ signal
747
+ });
748
+ return extractRecords(json).map(mapMenuResource).filter((item) => item !== null);
749
+ },
708
750
  listPermissionPoints(params, signal) {
709
751
  return permissionApi.list(params, signal);
710
752
  },
@@ -1440,6 +1482,7 @@ var PAGE_SIZE_OPTIONS2 = ["10", "20", "50", "100"];
1440
1482
  function emptyForm2() {
1441
1483
  return {
1442
1484
  parentId: null,
1485
+ depth: ROOT_MENU_DEPTH,
1443
1486
  type: MENU_TYPE_MENU,
1444
1487
  name: "",
1445
1488
  identification: "",
@@ -1493,6 +1536,30 @@ var s2 = {
1493
1536
  borderBottom: "1px solid #f2f4f7",
1494
1537
  verticalAlign: "middle"
1495
1538
  },
1539
+ treeCell: {
1540
+ display: "flex",
1541
+ alignItems: "center",
1542
+ gap: "6px"
1543
+ },
1544
+ treeToggle: {
1545
+ width: "22px",
1546
+ height: "22px",
1547
+ border: "1px solid #d0d5dd",
1548
+ borderRadius: "4px",
1549
+ background: "#fff",
1550
+ color: "#475467",
1551
+ cursor: "pointer",
1552
+ fontSize: "10px",
1553
+ lineHeight: "20px",
1554
+ padding: "0",
1555
+ flexShrink: "0"
1556
+ },
1557
+ treeSpacer: {
1558
+ width: "22px",
1559
+ height: "22px",
1560
+ flexShrink: "0",
1561
+ display: "inline-block"
1562
+ },
1496
1563
  empty: {
1497
1564
  padding: "28px",
1498
1565
  textAlign: "center",
@@ -1695,6 +1762,9 @@ var MenuManager = (0, import_vue4.defineComponent)({
1695
1762
  },
1696
1763
  setup(props, { slots }) {
1697
1764
  const records = (0, import_vue4.ref)([]);
1765
+ const childrenMap = (0, import_vue4.ref)({});
1766
+ const expandedIds = (0, import_vue4.ref)({});
1767
+ const expandingIds = (0, import_vue4.ref)({});
1698
1768
  const permissionPoints = (0, import_vue4.ref)([]);
1699
1769
  const loading = (0, import_vue4.ref)(false);
1700
1770
  const error = (0, import_vue4.ref)("");
@@ -1715,17 +1785,39 @@ var MenuManager = (0, import_vue4.defineComponent)({
1715
1785
  );
1716
1786
  return map;
1717
1787
  });
1788
+ const allKnownMenus = (0, import_vue4.computed)(() => {
1789
+ const map = /* @__PURE__ */ new Map();
1790
+ records.value.forEach((row) => map.set(row.resourceId, row));
1791
+ Object.values(childrenMap.value).forEach((list) => {
1792
+ list.forEach((row) => map.set(row.resourceId, row));
1793
+ });
1794
+ return Array.from(map.values());
1795
+ });
1718
1796
  const parentOptions = (0, import_vue4.computed)(
1719
- () => records.value.filter((row) => !editing.value || row.resourceId !== editing.value.resourceId).map((row) => ({
1797
+ () => allKnownMenus.value.filter((row) => !editing.value || row.resourceId !== editing.value.resourceId).map((row) => ({
1720
1798
  value: row.resourceId,
1721
1799
  label: `${row.name}\uFF08${MENU_TYPE_LABEL[row.type]}\uFF09`
1722
1800
  }))
1723
1801
  );
1802
+ const flatRows = (0, import_vue4.computed)(() => {
1803
+ const rows = [];
1804
+ const walk = (list) => {
1805
+ list.forEach((row) => {
1806
+ rows.push(row);
1807
+ if (expandedIds.value[row.resourceId] && childrenMap.value[row.resourceId]?.length) {
1808
+ walk(childrenMap.value[row.resourceId]);
1809
+ }
1810
+ });
1811
+ };
1812
+ walk(records.value);
1813
+ return rows;
1814
+ });
1724
1815
  async function loadList(direction = "current", token = pageToken.value) {
1725
1816
  loading.value = true;
1726
1817
  error.value = "";
1727
1818
  try {
1728
1819
  const result = await props.api.list({
1820
+ depth: ROOT_MENU_DEPTH,
1729
1821
  pagination: {
1730
1822
  pageToken: token,
1731
1823
  pageSize: pageSize.value,
@@ -1733,6 +1825,9 @@ var MenuManager = (0, import_vue4.defineComponent)({
1733
1825
  }
1734
1826
  });
1735
1827
  records.value = result.records;
1828
+ childrenMap.value = {};
1829
+ expandedIds.value = {};
1830
+ expandingIds.value = {};
1736
1831
  pageToken.value = result.pageToken;
1737
1832
  hasPreviousPage.value = result.hasPreviousPage;
1738
1833
  hasNextPage.value = result.hasNextPage;
@@ -1751,6 +1846,29 @@ var MenuManager = (0, import_vue4.defineComponent)({
1751
1846
  } catch {
1752
1847
  }
1753
1848
  }
1849
+ async function toggleExpand(row) {
1850
+ if (isMenuLeaf(row)) return;
1851
+ const id = row.resourceId;
1852
+ if (expandedIds.value[id]) {
1853
+ expandedIds.value = { ...expandedIds.value, [id]: false };
1854
+ return;
1855
+ }
1856
+ if (!childrenMap.value[id]) {
1857
+ expandingIds.value = { ...expandingIds.value, [id]: true };
1858
+ error.value = "";
1859
+ try {
1860
+ const children = await props.api.listSubResources(id);
1861
+ childrenMap.value = { ...childrenMap.value, [id]: children };
1862
+ expandedIds.value = { ...expandedIds.value, [id]: true };
1863
+ } catch (err) {
1864
+ error.value = err instanceof Error ? err.message : "\u52A0\u8F7D\u4E0B\u7EA7\u83DC\u5355\u5931\u8D25";
1865
+ } finally {
1866
+ expandingIds.value = { ...expandingIds.value, [id]: false };
1867
+ }
1868
+ return;
1869
+ }
1870
+ expandedIds.value = { ...expandedIds.value, [id]: true };
1871
+ }
1754
1872
  function openCreate() {
1755
1873
  editing.value = null;
1756
1874
  Object.assign(form, emptyForm2());
@@ -1761,6 +1879,7 @@ var MenuManager = (0, import_vue4.defineComponent)({
1761
1879
  editing.value = row;
1762
1880
  Object.assign(form, {
1763
1881
  parentId: row.parentId ?? null,
1882
+ depth: resolveMenuDepth(row.parentId ?? null, allKnownMenus.value),
1764
1883
  type: row.type,
1765
1884
  name: row.name,
1766
1885
  identification: row.identification,
@@ -1868,13 +1987,41 @@ var MenuManager = (0, import_vue4.defineComponent)({
1868
1987
  (0, import_vue4.h)("tr", [
1869
1988
  (0, import_vue4.h)("td", { colspan: 6, style: s2.empty }, "\u52A0\u8F7D\u4E2D\u2026")
1870
1989
  ])
1871
- ] : records.value.length === 0 ? [
1990
+ ] : flatRows.value.length === 0 ? [
1872
1991
  (0, import_vue4.h)("tr", [
1873
1992
  (0, import_vue4.h)("td", { colspan: 6, style: s2.empty }, "\u6682\u65E0\u6570\u636E")
1874
1993
  ])
1875
- ] : records.value.map(
1876
- (row) => (0, import_vue4.h)("tr", { key: row.resourceId }, [
1877
- (0, import_vue4.h)("td", { style: s2.td }, row.name),
1994
+ ] : flatRows.value.map((row) => {
1995
+ const leaf = isMenuLeaf(row);
1996
+ const expanded = Boolean(expandedIds.value[row.resourceId]);
1997
+ const expanding = Boolean(expandingIds.value[row.resourceId]);
1998
+ const indent = Math.max(0, (row.depth || 1) - 1) * 18;
1999
+ return (0, import_vue4.h)("tr", { key: row.resourceId }, [
2000
+ (0, import_vue4.h)("td", { style: s2.td }, [
2001
+ (0, import_vue4.h)(
2002
+ "div",
2003
+ {
2004
+ style: {
2005
+ ...s2.treeCell,
2006
+ paddingLeft: `${indent}px`
2007
+ }
2008
+ },
2009
+ [
2010
+ leaf ? (0, import_vue4.h)("span", { style: s2.treeSpacer }) : (0, import_vue4.h)(
2011
+ "button",
2012
+ {
2013
+ type: "button",
2014
+ style: s2.treeToggle,
2015
+ disabled: expanding,
2016
+ "aria-label": expanded ? "\u6536\u8D77" : "\u5C55\u5F00",
2017
+ onClick: () => void toggleExpand(row)
2018
+ },
2019
+ expanding ? "\u2026" : expanded ? "\u25BC" : "\u25B6"
2020
+ ),
2021
+ (0, import_vue4.h)("span", row.name)
2022
+ ]
2023
+ )
2024
+ ]),
1878
2025
  (0, import_vue4.h)("td", { style: s2.td }, [
1879
2026
  (0, import_vue4.h)(
1880
2027
  "code",
@@ -1917,8 +2064,8 @@ var MenuManager = (0, import_vue4.defineComponent)({
1917
2064
  "\u5220\u9664"
1918
2065
  )
1919
2066
  ])
1920
- ])
1921
- )
2067
+ ]);
2068
+ })
1922
2069
  )
1923
2070
  ])
1924
2071
  ]),
@@ -2008,7 +2155,9 @@ var MenuManager = (0, import_vue4.defineComponent)({
2008
2155
  value: form.parentId ?? ROOT_PARENT_ID,
2009
2156
  onChange: (e) => {
2010
2157
  const value = e.target.value;
2011
- form.parentId = value ? value : null;
2158
+ const parentId = value ? value : null;
2159
+ form.parentId = parentId;
2160
+ form.depth = resolveMenuDepth(parentId, allKnownMenus.value);
2012
2161
  }
2013
2162
  },
2014
2163
  [
@@ -2023,6 +2172,14 @@ var MenuManager = (0, import_vue4.defineComponent)({
2023
2172
  ]
2024
2173
  )
2025
2174
  ]),
2175
+ (0, import_vue4.h)("div", { style: s2.field }, [
2176
+ (0, import_vue4.h)("span", { style: s2.label }, "\u83DC\u5355\u5C42\u7EA7\uFF08depth\uFF09"),
2177
+ (0, import_vue4.h)("input", {
2178
+ style: s2.input,
2179
+ value: form.depth,
2180
+ readOnly: true
2181
+ })
2182
+ ]),
2026
2183
  (0, import_vue4.h)("fieldset", { style: s2.fieldset }, [
2027
2184
  (0, import_vue4.h)("legend", { style: s2.label }, "\u83DC\u5355\u7C7B\u578B"),
2028
2185
  (0, import_vue4.h)(
@@ -2406,6 +2563,8 @@ var SystemAdmin = (0, import_vue5.defineComponent)({
2406
2563
  // Annotate the CommonJS export names for ESM import in node:
2407
2564
  0 && (module.exports = {
2408
2565
  Can,
2566
+ MENU_LEAF_NO,
2567
+ MENU_LEAF_YES,
2409
2568
  MENU_LIST_TYPE_PARAM,
2410
2569
  MENU_TYPE_BUTTON,
2411
2570
  MENU_TYPE_LABEL,
@@ -2421,6 +2580,7 @@ var SystemAdmin = (0, import_vue5.defineComponent)({
2421
2580
  RESOURCE_STATUS_ENABLED,
2422
2581
  RESOURCE_STATUS_OPTIONS,
2423
2582
  RESOURCE_TYPE_API,
2583
+ ROOT_MENU_DEPTH,
2424
2584
  ROOT_PARENT_ID,
2425
2585
  ResourceManager,
2426
2586
  SYSTEM_ADMIN_DEFAULT_KEY,
@@ -2441,8 +2601,10 @@ var SystemAdmin = (0, import_vue5.defineComponent)({
2441
2601
  extractRecords,
2442
2602
  getAppClientId,
2443
2603
  getDeviceWorkerId,
2604
+ isMenuLeaf,
2444
2605
  mapAuthorizationResource,
2445
2606
  mapMenuResource,
2607
+ resolveMenuDepth,
2446
2608
  snowyflake,
2447
2609
  useHasPermission,
2448
2610
  useHasRole,