com-angel-authorization 1.0.18 → 1.0.20

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.
@@ -3113,7 +3113,10 @@ function UserManager({
3113
3113
  const [deleting, setDeleting] = (0, import_react5.useState)(false);
3114
3114
  const [groups, setGroups] = (0, import_react5.useState)([]);
3115
3115
  const [roles, setRoles] = (0, import_react5.useState)([]);
3116
- const [optionsLoading, setOptionsLoading] = (0, import_react5.useState)(false);
3116
+ const [rolesLoading, setRolesLoading] = (0, import_react5.useState)(false);
3117
+ const [groupsOpen, setGroupsOpen] = (0, import_react5.useState)(false);
3118
+ const [groupsLoading, setGroupsLoading] = (0, import_react5.useState)(false);
3119
+ const [groupsLoaded, setGroupsLoaded] = (0, import_react5.useState)(false);
3117
3120
  const enabledParam = enabledFilter === "all" ? void 0 : enabledFilter === "true";
3118
3121
  const loadList = (0, import_react5.useCallback)(
3119
3122
  async (direction = "current", token = pageToken) => {
@@ -3144,31 +3147,44 @@ function UserManager({
3144
3147
  (0, import_react5.useEffect)(() => {
3145
3148
  void loadList("current", "");
3146
3149
  }, [api, pageSize, keyword, enabledFilter]);
3147
- const loadOptions = (0, import_react5.useCallback)(async () => {
3148
- setOptionsLoading(true);
3150
+ const loadRoles = (0, import_react5.useCallback)(async () => {
3151
+ setRolesLoading(true);
3149
3152
  try {
3150
- const [groupList, roleList] = await Promise.all([
3151
- api.listGroups(),
3152
- api.listRoleOptions()
3153
- ]);
3154
- setGroups(groupList);
3155
- setRoles(roleList);
3153
+ setRoles(await api.listRoleOptions());
3156
3154
  } catch (err) {
3157
- setFormError(err instanceof Error ? err.message : "\u52A0\u8F7D\u90E8\u95E8/\u89D2\u8272\u5931\u8D25");
3155
+ setFormError(err instanceof Error ? err.message : "\u52A0\u8F7D\u89D2\u8272\u5931\u8D25");
3158
3156
  } finally {
3159
- setOptionsLoading(false);
3157
+ setRolesLoading(false);
3160
3158
  }
3161
3159
  }, [api]);
3160
+ const loadGroups = (0, import_react5.useCallback)(async () => {
3161
+ if (groupsLoaded || groupsLoading) return;
3162
+ setGroupsLoading(true);
3163
+ try {
3164
+ setGroups(await api.listGroups());
3165
+ setGroupsLoaded(true);
3166
+ } catch (err) {
3167
+ setFormError(err instanceof Error ? err.message : "\u52A0\u8F7D\u90E8\u95E8\u5931\u8D25");
3168
+ } finally {
3169
+ setGroupsLoading(false);
3170
+ }
3171
+ }, [api, groupsLoaded, groupsLoading]);
3162
3172
  const handleSearch = () => {
3163
3173
  setPageToken("");
3164
3174
  setKeyword(keywordInput.trim());
3165
3175
  };
3176
+ const resetGroupPanel = () => {
3177
+ setGroupsOpen(false);
3178
+ setGroups([]);
3179
+ setGroupsLoaded(false);
3180
+ };
3166
3181
  const openCreate = () => {
3167
3182
  setEditing(null);
3168
3183
  setForm(emptyForm4());
3169
3184
  setFormError("");
3185
+ resetGroupPanel();
3170
3186
  setDialogOpen(true);
3171
- void loadOptions();
3187
+ void loadRoles();
3172
3188
  };
3173
3189
  const openEdit = (row) => {
3174
3190
  setEditing(row);
@@ -3181,12 +3197,20 @@ function UserManager({
3181
3197
  enabled: row.enabled
3182
3198
  });
3183
3199
  setFormError("");
3200
+ resetGroupPanel();
3184
3201
  setDialogOpen(true);
3185
- void loadOptions();
3202
+ void loadRoles();
3186
3203
  };
3187
3204
  const closeDialog = () => {
3188
3205
  if (!saving) setDialogOpen(false);
3189
3206
  };
3207
+ const toggleGroupsPanel = () => {
3208
+ setGroupsOpen((prev) => {
3209
+ const next = !prev;
3210
+ if (next) void loadGroups();
3211
+ return next;
3212
+ });
3213
+ };
3190
3214
  const toggleId = (field, id) => {
3191
3215
  setForm((prev) => {
3192
3216
  const exists = prev[field].includes(id);
@@ -3211,6 +3235,10 @@ function UserManager({
3211
3235
  setFormError("\u8BF7\u586B\u5199\u521D\u59CB\u5BC6\u7801");
3212
3236
  return;
3213
3237
  }
3238
+ if (!form.groupIds.length) {
3239
+ setFormError("\u8BF7\u9009\u62E9\u5F52\u5C5E\u90E8\u95E8");
3240
+ return;
3241
+ }
3214
3242
  setSaving(true);
3215
3243
  setFormError("");
3216
3244
  setError("");
@@ -3249,8 +3277,7 @@ function UserManager({
3249
3277
  const groupLabel = (row) => {
3250
3278
  if (row.groupNames?.length) return row.groupNames.join("\u3001");
3251
3279
  if (!row.groupIds.length) return "\u2014";
3252
- const map = new Map(groups.map((g) => [g.groupId, g.name]));
3253
- return row.groupIds.map((id) => map.get(id) || id).join("\u3001");
3280
+ return row.groupIds.join("\u3001");
3254
3281
  };
3255
3282
  const roleLabel = (row) => {
3256
3283
  if (row.roleNames?.length) return row.roleNames.join("\u3001");
@@ -3258,15 +3285,22 @@ function UserManager({
3258
3285
  const map = new Map(roles.map((r) => [r.roleId, r.name]));
3259
3286
  return row.roleIds.map((id) => map.get(id) || id).join("\u3001");
3260
3287
  };
3288
+ const selectedGroupSummary = () => {
3289
+ if (!form.groupIds.length) return "\u8BF7\u9009\u62E9\u5F52\u5C5E\u90E8\u95E8";
3290
+ if (groupsLoaded) {
3291
+ const map = new Map(groups.map((g) => [g.groupId, g.name]));
3292
+ return form.groupIds.map((id) => map.get(id) || id).join("\u3001");
3293
+ }
3294
+ if (editing?.groupNames?.length && editing.groupIds.every((id) => form.groupIds.includes(id))) {
3295
+ const map = new Map(editing.groupIds.map((id, i) => [id, editing.groupNames?.[i] || id]));
3296
+ return form.groupIds.map((id) => map.get(id) || id).join("\u3001");
3297
+ }
3298
+ return `\u5DF2\u9009 ${form.groupIds.length} \u4E2A\u90E8\u95E8`;
3299
+ };
3261
3300
  (0, import_react5.useEffect)(() => {
3262
3301
  void (async () => {
3263
3302
  try {
3264
- const [groupList, roleList] = await Promise.all([
3265
- api.listGroups(),
3266
- api.listRoleOptions()
3267
- ]);
3268
- setGroups(groupList);
3269
- setRoles(roleList);
3303
+ setRoles(await api.listRoleOptions());
3270
3304
  } catch {
3271
3305
  }
3272
3306
  })();
@@ -3458,8 +3492,33 @@ function UserManager({
3458
3492
  )
3459
3493
  ] }),
3460
3494
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("fieldset", { style: styles4.fieldset, children: [
3461
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("legend", { style: styles4.label, children: "\u5F52\u5C5E\u90E8\u95E8" }),
3462
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.multiSelect, children: optionsLoading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.hint, children: "\u52A0\u8F7D\u4E2D\u2026" }) : groups.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.hint, children: "\u6682\u65E0\u90E8\u95E8\u6570\u636E" }) : groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { style: styles4.checkItem, children: [
3495
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("legend", { style: styles4.label, children: [
3496
+ "\u5F52\u5C5E\u90E8\u95E8 ",
3497
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles4.required, children: "*" })
3498
+ ] }),
3499
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3500
+ "button",
3501
+ {
3502
+ type: "button",
3503
+ style: styles4.selectTrigger,
3504
+ onClick: toggleGroupsPanel,
3505
+ "aria-expanded": groupsOpen,
3506
+ children: [
3507
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3508
+ "span",
3509
+ {
3510
+ style: {
3511
+ ...styles4.selectTriggerText,
3512
+ ...form.groupIds.length ? null : styles4.selectPlaceholder
3513
+ },
3514
+ children: selectedGroupSummary()
3515
+ }
3516
+ ),
3517
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles4.selectChevron, children: groupsOpen ? "\u25B2" : "\u25BC" })
3518
+ ]
3519
+ }
3520
+ ),
3521
+ groupsOpen ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.multiSelect, children: groupsLoading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.hint, children: "\u52A0\u8F7D\u4E2D\u2026" }) : groups.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.hint, children: "\u6682\u65E0\u90E8\u95E8\u6570\u636E" }) : groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { style: styles4.checkItem, children: [
3463
3522
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3464
3523
  "input",
3465
3524
  {
@@ -3470,11 +3529,11 @@ function UserManager({
3470
3529
  }
3471
3530
  ),
3472
3531
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: g.name || g.groupId })
3473
- ] }, g.groupId)) })
3532
+ ] }, g.groupId)) }) : null
3474
3533
  ] }),
3475
3534
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("fieldset", { style: styles4.fieldset, children: [
3476
3535
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("legend", { style: styles4.label, children: "\u7528\u6237\u89D2\u8272" }),
3477
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.multiSelect, children: optionsLoading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.hint, children: "\u52A0\u8F7D\u4E2D\u2026" }) : roles.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.hint, children: "\u6682\u65E0\u89D2\u8272\u6570\u636E" }) : roles.map((r) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { style: styles4.checkItem, children: [
3536
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.multiSelect, children: rolesLoading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.hint, children: "\u52A0\u8F7D\u4E2D\u2026" }) : roles.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles4.hint, children: "\u6682\u65E0\u89D2\u8272\u6570\u636E" }) : roles.map((r) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { style: styles4.checkItem, children: [
3478
3537
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3479
3538
  "input",
3480
3539
  {
@@ -3751,8 +3810,34 @@ var styles4 = {
3751
3810
  flexDirection: "column",
3752
3811
  gap: 6,
3753
3812
  maxHeight: 160,
3754
- overflow: "auto"
3813
+ overflow: "auto",
3814
+ marginTop: 8
3755
3815
  },
3816
+ selectTrigger: {
3817
+ display: "flex",
3818
+ alignItems: "center",
3819
+ justifyContent: "space-between",
3820
+ gap: 8,
3821
+ width: "100%",
3822
+ border: "1px solid #d0d5dd",
3823
+ borderRadius: 8,
3824
+ padding: "8px 10px",
3825
+ background: "#fff",
3826
+ cursor: "pointer",
3827
+ fontSize: 14,
3828
+ color: "#101828",
3829
+ boxSizing: "border-box",
3830
+ textAlign: "left"
3831
+ },
3832
+ selectTriggerText: {
3833
+ flex: 1,
3834
+ overflow: "hidden",
3835
+ textOverflow: "ellipsis",
3836
+ whiteSpace: "nowrap"
3837
+ },
3838
+ selectPlaceholder: { color: "#98a2b3" },
3839
+ selectChevron: { color: "#667085", fontSize: 10, flexShrink: 0 },
3840
+ required: { color: "#d92d20", marginLeft: 2 },
3756
3841
  checkItem: {
3757
3842
  display: "flex",
3758
3843
  alignItems: "center",
@@ -3773,7 +3858,7 @@ var styles4 = {
3773
3858
  switchRow: {
3774
3859
  display: "flex",
3775
3860
  alignItems: "center",
3776
- justifyContent: "space-between",
3861
+ justifyContent: "flex-start",
3777
3862
  gap: 12
3778
3863
  },
3779
3864
  switchTrack: {
@@ -3815,10 +3900,10 @@ var SYSTEM_ADMIN_MENU = {
3815
3900
  key: "system",
3816
3901
  label: "\u7CFB\u7EDF\u7BA1\u7406",
3817
3902
  children: [
3818
- { key: "menu", label: "\u83DC\u5355\u7BA1\u7406" },
3819
- { key: "resource", label: "\u6743\u9650\u70B9\u7BA1\u7406" },
3903
+ { key: "user", label: "\u7528\u6237\u7BA1\u7406" },
3820
3904
  { key: "role", label: "\u89D2\u8272\u7BA1\u7406" },
3821
- { key: "user", label: "\u7528\u6237\u7BA1\u7406" }
3905
+ { key: "menu", label: "\u83DC\u5355\u7BA1\u7406" },
3906
+ { key: "resource", label: "\u6743\u9650\u70B9\u7BA1\u7406" }
3822
3907
  ]
3823
3908
  };
3824
3909
  var SYSTEM_ADMIN_DEFAULT_KEY = "menu";