com-angel-authorization 1.0.18 → 1.0.22

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.
@@ -3049,7 +3049,10 @@ function UserManager({
3049
3049
  const [deleting, setDeleting] = useState5(false);
3050
3050
  const [groups, setGroups] = useState5([]);
3051
3051
  const [roles, setRoles] = useState5([]);
3052
- const [optionsLoading, setOptionsLoading] = useState5(false);
3052
+ const [rolesLoading, setRolesLoading] = useState5(false);
3053
+ const [groupsOpen, setGroupsOpen] = useState5(false);
3054
+ const [groupsLoading, setGroupsLoading] = useState5(false);
3055
+ const [groupsLoaded, setGroupsLoaded] = useState5(false);
3053
3056
  const enabledParam = enabledFilter === "all" ? void 0 : enabledFilter === "true";
3054
3057
  const loadList = useCallback5(
3055
3058
  async (direction = "current", token = pageToken) => {
@@ -3080,31 +3083,44 @@ function UserManager({
3080
3083
  useEffect5(() => {
3081
3084
  void loadList("current", "");
3082
3085
  }, [api, pageSize, keyword, enabledFilter]);
3083
- const loadOptions = useCallback5(async () => {
3084
- setOptionsLoading(true);
3086
+ const loadRoles = useCallback5(async () => {
3087
+ setRolesLoading(true);
3085
3088
  try {
3086
- const [groupList, roleList] = await Promise.all([
3087
- api.listGroups(),
3088
- api.listRoleOptions()
3089
- ]);
3090
- setGroups(groupList);
3091
- setRoles(roleList);
3089
+ setRoles(await api.listRoleOptions());
3092
3090
  } catch (err) {
3093
- setFormError(err instanceof Error ? err.message : "\u52A0\u8F7D\u90E8\u95E8/\u89D2\u8272\u5931\u8D25");
3091
+ setFormError(err instanceof Error ? err.message : "\u52A0\u8F7D\u89D2\u8272\u5931\u8D25");
3094
3092
  } finally {
3095
- setOptionsLoading(false);
3093
+ setRolesLoading(false);
3096
3094
  }
3097
3095
  }, [api]);
3096
+ const loadGroups = useCallback5(async () => {
3097
+ if (groupsLoaded || groupsLoading) return;
3098
+ setGroupsLoading(true);
3099
+ try {
3100
+ setGroups(await api.listGroups());
3101
+ setGroupsLoaded(true);
3102
+ } catch (err) {
3103
+ setFormError(err instanceof Error ? err.message : "\u52A0\u8F7D\u90E8\u95E8\u5931\u8D25");
3104
+ } finally {
3105
+ setGroupsLoading(false);
3106
+ }
3107
+ }, [api, groupsLoaded, groupsLoading]);
3098
3108
  const handleSearch = () => {
3099
3109
  setPageToken("");
3100
3110
  setKeyword(keywordInput.trim());
3101
3111
  };
3112
+ const resetGroupPanel = () => {
3113
+ setGroupsOpen(false);
3114
+ setGroups([]);
3115
+ setGroupsLoaded(false);
3116
+ };
3102
3117
  const openCreate = () => {
3103
3118
  setEditing(null);
3104
3119
  setForm(emptyForm4());
3105
3120
  setFormError("");
3121
+ resetGroupPanel();
3106
3122
  setDialogOpen(true);
3107
- void loadOptions();
3123
+ void loadRoles();
3108
3124
  };
3109
3125
  const openEdit = (row) => {
3110
3126
  setEditing(row);
@@ -3117,12 +3133,20 @@ function UserManager({
3117
3133
  enabled: row.enabled
3118
3134
  });
3119
3135
  setFormError("");
3136
+ resetGroupPanel();
3120
3137
  setDialogOpen(true);
3121
- void loadOptions();
3138
+ void loadRoles();
3122
3139
  };
3123
3140
  const closeDialog = () => {
3124
3141
  if (!saving) setDialogOpen(false);
3125
3142
  };
3143
+ const toggleGroupsPanel = () => {
3144
+ setGroupsOpen((prev) => {
3145
+ const next = !prev;
3146
+ if (next) void loadGroups();
3147
+ return next;
3148
+ });
3149
+ };
3126
3150
  const toggleId = (field, id) => {
3127
3151
  setForm((prev) => {
3128
3152
  const exists = prev[field].includes(id);
@@ -3147,6 +3171,10 @@ function UserManager({
3147
3171
  setFormError("\u8BF7\u586B\u5199\u521D\u59CB\u5BC6\u7801");
3148
3172
  return;
3149
3173
  }
3174
+ if (!form.groupIds.length) {
3175
+ setFormError("\u8BF7\u9009\u62E9\u5F52\u5C5E\u90E8\u95E8");
3176
+ return;
3177
+ }
3150
3178
  setSaving(true);
3151
3179
  setFormError("");
3152
3180
  setError("");
@@ -3185,8 +3213,7 @@ function UserManager({
3185
3213
  const groupLabel = (row) => {
3186
3214
  if (row.groupNames?.length) return row.groupNames.join("\u3001");
3187
3215
  if (!row.groupIds.length) return "\u2014";
3188
- const map = new Map(groups.map((g) => [g.groupId, g.name]));
3189
- return row.groupIds.map((id) => map.get(id) || id).join("\u3001");
3216
+ return row.groupIds.join("\u3001");
3190
3217
  };
3191
3218
  const roleLabel = (row) => {
3192
3219
  if (row.roleNames?.length) return row.roleNames.join("\u3001");
@@ -3194,15 +3221,22 @@ function UserManager({
3194
3221
  const map = new Map(roles.map((r) => [r.roleId, r.name]));
3195
3222
  return row.roleIds.map((id) => map.get(id) || id).join("\u3001");
3196
3223
  };
3224
+ const selectedGroupSummary = () => {
3225
+ if (!form.groupIds.length) return "\u8BF7\u9009\u62E9\u5F52\u5C5E\u90E8\u95E8";
3226
+ if (groupsLoaded) {
3227
+ const map = new Map(groups.map((g) => [g.groupId, g.name]));
3228
+ return form.groupIds.map((id) => map.get(id) || id).join("\u3001");
3229
+ }
3230
+ if (editing?.groupNames?.length && editing.groupIds.every((id) => form.groupIds.includes(id))) {
3231
+ const map = new Map(editing.groupIds.map((id, i) => [id, editing.groupNames?.[i] || id]));
3232
+ return form.groupIds.map((id) => map.get(id) || id).join("\u3001");
3233
+ }
3234
+ return `\u5DF2\u9009 ${form.groupIds.length} \u4E2A\u90E8\u95E8`;
3235
+ };
3197
3236
  useEffect5(() => {
3198
3237
  void (async () => {
3199
3238
  try {
3200
- const [groupList, roleList] = await Promise.all([
3201
- api.listGroups(),
3202
- api.listRoleOptions()
3203
- ]);
3204
- setGroups(groupList);
3205
- setRoles(roleList);
3239
+ setRoles(await api.listRoleOptions());
3206
3240
  } catch {
3207
3241
  }
3208
3242
  })();
@@ -3394,8 +3428,33 @@ function UserManager({
3394
3428
  )
3395
3429
  ] }),
3396
3430
  /* @__PURE__ */ jsxs4("fieldset", { style: styles4.fieldset, children: [
3397
- /* @__PURE__ */ jsx5("legend", { style: styles4.label, children: "\u5F52\u5C5E\u90E8\u95E8" }),
3398
- /* @__PURE__ */ jsx5("div", { style: styles4.multiSelect, children: optionsLoading ? /* @__PURE__ */ jsx5("div", { style: styles4.hint, children: "\u52A0\u8F7D\u4E2D\u2026" }) : groups.length === 0 ? /* @__PURE__ */ jsx5("div", { style: styles4.hint, children: "\u6682\u65E0\u90E8\u95E8\u6570\u636E" }) : groups.map((g) => /* @__PURE__ */ jsxs4("label", { style: styles4.checkItem, children: [
3431
+ /* @__PURE__ */ jsxs4("legend", { style: styles4.label, children: [
3432
+ "\u5F52\u5C5E\u90E8\u95E8 ",
3433
+ /* @__PURE__ */ jsx5("span", { style: styles4.required, children: "*" })
3434
+ ] }),
3435
+ /* @__PURE__ */ jsxs4(
3436
+ "button",
3437
+ {
3438
+ type: "button",
3439
+ style: styles4.selectTrigger,
3440
+ onClick: toggleGroupsPanel,
3441
+ "aria-expanded": groupsOpen,
3442
+ children: [
3443
+ /* @__PURE__ */ jsx5(
3444
+ "span",
3445
+ {
3446
+ style: {
3447
+ ...styles4.selectTriggerText,
3448
+ ...form.groupIds.length ? null : styles4.selectPlaceholder
3449
+ },
3450
+ children: selectedGroupSummary()
3451
+ }
3452
+ ),
3453
+ /* @__PURE__ */ jsx5("span", { style: styles4.selectChevron, children: groupsOpen ? "\u25B2" : "\u25BC" })
3454
+ ]
3455
+ }
3456
+ ),
3457
+ groupsOpen ? /* @__PURE__ */ jsx5("div", { style: styles4.multiSelect, children: groupsLoading ? /* @__PURE__ */ jsx5("div", { style: styles4.hint, children: "\u52A0\u8F7D\u4E2D\u2026" }) : groups.length === 0 ? /* @__PURE__ */ jsx5("div", { style: styles4.hint, children: "\u6682\u65E0\u90E8\u95E8\u6570\u636E" }) : groups.map((g) => /* @__PURE__ */ jsxs4("label", { style: styles4.checkItem, children: [
3399
3458
  /* @__PURE__ */ jsx5(
3400
3459
  "input",
3401
3460
  {
@@ -3406,11 +3465,11 @@ function UserManager({
3406
3465
  }
3407
3466
  ),
3408
3467
  /* @__PURE__ */ jsx5("span", { children: g.name || g.groupId })
3409
- ] }, g.groupId)) })
3468
+ ] }, g.groupId)) }) : null
3410
3469
  ] }),
3411
3470
  /* @__PURE__ */ jsxs4("fieldset", { style: styles4.fieldset, children: [
3412
3471
  /* @__PURE__ */ jsx5("legend", { style: styles4.label, children: "\u7528\u6237\u89D2\u8272" }),
3413
- /* @__PURE__ */ jsx5("div", { style: styles4.multiSelect, children: optionsLoading ? /* @__PURE__ */ jsx5("div", { style: styles4.hint, children: "\u52A0\u8F7D\u4E2D\u2026" }) : roles.length === 0 ? /* @__PURE__ */ jsx5("div", { style: styles4.hint, children: "\u6682\u65E0\u89D2\u8272\u6570\u636E" }) : roles.map((r) => /* @__PURE__ */ jsxs4("label", { style: styles4.checkItem, children: [
3472
+ /* @__PURE__ */ jsx5("div", { style: styles4.multiSelect, children: rolesLoading ? /* @__PURE__ */ jsx5("div", { style: styles4.hint, children: "\u52A0\u8F7D\u4E2D\u2026" }) : roles.length === 0 ? /* @__PURE__ */ jsx5("div", { style: styles4.hint, children: "\u6682\u65E0\u89D2\u8272\u6570\u636E" }) : roles.map((r) => /* @__PURE__ */ jsxs4("label", { style: styles4.checkItem, children: [
3414
3473
  /* @__PURE__ */ jsx5(
3415
3474
  "input",
3416
3475
  {
@@ -3687,8 +3746,34 @@ var styles4 = {
3687
3746
  flexDirection: "column",
3688
3747
  gap: 6,
3689
3748
  maxHeight: 160,
3690
- overflow: "auto"
3749
+ overflow: "auto",
3750
+ marginTop: 8
3691
3751
  },
3752
+ selectTrigger: {
3753
+ display: "flex",
3754
+ alignItems: "center",
3755
+ justifyContent: "space-between",
3756
+ gap: 8,
3757
+ width: "100%",
3758
+ border: "1px solid #d0d5dd",
3759
+ borderRadius: 8,
3760
+ padding: "8px 10px",
3761
+ background: "#fff",
3762
+ cursor: "pointer",
3763
+ fontSize: 14,
3764
+ color: "#101828",
3765
+ boxSizing: "border-box",
3766
+ textAlign: "left"
3767
+ },
3768
+ selectTriggerText: {
3769
+ flex: 1,
3770
+ overflow: "hidden",
3771
+ textOverflow: "ellipsis",
3772
+ whiteSpace: "nowrap"
3773
+ },
3774
+ selectPlaceholder: { color: "#98a2b3" },
3775
+ selectChevron: { color: "#667085", fontSize: 10, flexShrink: 0 },
3776
+ required: { color: "#d92d20", marginLeft: 2 },
3692
3777
  checkItem: {
3693
3778
  display: "flex",
3694
3779
  alignItems: "center",
@@ -3709,7 +3794,7 @@ var styles4 = {
3709
3794
  switchRow: {
3710
3795
  display: "flex",
3711
3796
  alignItems: "center",
3712
- justifyContent: "space-between",
3797
+ justifyContent: "flex-start",
3713
3798
  gap: 12
3714
3799
  },
3715
3800
  switchTrack: {
@@ -3751,10 +3836,10 @@ var SYSTEM_ADMIN_MENU = {
3751
3836
  key: "system",
3752
3837
  label: "\u7CFB\u7EDF\u7BA1\u7406",
3753
3838
  children: [
3754
- { key: "menu", label: "\u83DC\u5355\u7BA1\u7406" },
3755
- { key: "resource", label: "\u6743\u9650\u70B9\u7BA1\u7406" },
3839
+ { key: "user", label: "\u7528\u6237\u7BA1\u7406" },
3756
3840
  { key: "role", label: "\u89D2\u8272\u7BA1\u7406" },
3757
- { key: "user", label: "\u7528\u6237\u7BA1\u7406" }
3841
+ { key: "menu", label: "\u83DC\u5355\u7BA1\u7406" },
3842
+ { key: "resource", label: "\u6743\u9650\u70B9\u7BA1\u7406" }
3758
3843
  ]
3759
3844
  };
3760
3845
  var SYSTEM_ADMIN_DEFAULT_KEY = "menu";