react-toolkits 2.13.2 → 2.13.3

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/lib/index.js CHANGED
@@ -117,7 +117,7 @@ var init_en_GB = __esm({
117
117
  UserWidget: {
118
118
  signOutText: "Sign Out"
119
119
  },
120
- UserList: {
120
+ User: {
121
121
  createTitle: "Create User",
122
122
  createSuccessfully: "User created successfully",
123
123
  updateTitle: "Update User",
@@ -126,7 +126,7 @@ var init_en_GB = __esm({
126
126
  deleteContent: "Are you sure you want to delete user <%= user %>?",
127
127
  deleteSuccessfully: "User deleted successfully"
128
128
  },
129
- RoleList: {
129
+ Role: {
130
130
  createTitle: "Create Role",
131
131
  createSuccessfully: "Role created successfully",
132
132
  updateTitle: "Update Role",
@@ -1079,7 +1079,7 @@ var init_modal = __esm({
1079
1079
  }
1080
1080
  });
1081
1081
  function useFormModal(props) {
1082
- const { content, form, formProps, onConfirm, ...modalProps } = props;
1082
+ const { content, form, formProps, onConfirm, onSuccess, ...modalProps } = props;
1083
1083
  const [internalExtraValues, setInternalExtraValues] = useState({});
1084
1084
  let [internalForm] = Form.useForm();
1085
1085
  internalForm = form || internalForm;
@@ -1087,6 +1087,7 @@ function useFormModal(props) {
1087
1087
  const hanldeConfirm = async () => {
1088
1088
  const values = await internalForm.validateFields();
1089
1089
  await onConfirm?.(values, internalExtraValues);
1090
+ onSuccess?.();
1090
1091
  hide();
1091
1092
  };
1092
1093
  const afterClose = () => {
@@ -1098,10 +1099,8 @@ function useFormModal(props) {
1098
1099
  onConfirm: hanldeConfirm,
1099
1100
  afterClose
1100
1101
  });
1101
- const onShow = ({
1102
- initialValues,
1103
- extraValues
1104
- } = {}) => {
1102
+ const onShow = (options) => {
1103
+ const { initialValues, extraValues } = options || {};
1105
1104
  if (extraValues) {
1106
1105
  setInternalExtraValues(extraValues);
1107
1106
  }
@@ -1869,63 +1868,279 @@ function useRemoveUser() {
1869
1868
  }) => axios2.post(url4, arg)
1870
1869
  );
1871
1870
  }
1872
- var useRoleModal;
1871
+ var Text2, useCreateRoleModal, useUpdateRoleModal, useCreateUserModal, useUpdateUserModal, GameSelect2, UserModalContentV2, useCreateUserModalV2, useUpdateUserModalV2;
1873
1872
  var init_hooks5 = __esm({
1874
1873
  "src/features/permission/hooks/index.tsx"() {
1875
1874
  init_locale();
1876
1875
  init_modal2();
1877
- init_queryList();
1878
1876
  init_toolkitsProvider();
1877
+ init_constants();
1879
1878
  init_hooks2();
1880
1879
  init_components();
1881
- useRoleModal = (isCreate) => {
1882
- const { message } = App.useApp();
1880
+ ({ Text: Text2 } = Typography);
1881
+ useCreateRoleModal = ({ onSuccess } = {}) => {
1883
1882
  const { t } = useTranslation();
1884
- const { refetch, mutate: mutate2 } = useQueryListStore();
1885
- const create5 = useCreateRole();
1886
- const update = useUpdateRole();
1887
- const title = isCreate ? t("RoleList.createTitle") : t("RoleList.updateTitle");
1888
- const formProps = {
1889
- layout: "vertical"
1890
- };
1891
- const content = /* @__PURE__ */ jsxs(Fragment, { children: [
1892
- /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, { disabled: !isCreate, addonBefore: "role_" }) }),
1893
- /* @__PURE__ */ jsx(Form.Item, { name: "permissions", children: /* @__PURE__ */ jsx(permissionList_default, {}) })
1894
- ] });
1895
- const url4 = "/api/usystem/role/list";
1896
- const onConfirm = async (values, extraValues) => {
1897
- if (isCreate) {
1898
- await create5.trigger({
1883
+ const { trigger } = useCreateRole();
1884
+ return useFormModal({
1885
+ title: t("Role.createTitle"),
1886
+ width: "50vw",
1887
+ formProps: {
1888
+ layout: "vertical"
1889
+ },
1890
+ content: /* @__PURE__ */ jsxs(Fragment, { children: [
1891
+ /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, { addonBefore: "role_" }) }),
1892
+ /* @__PURE__ */ jsx(Form.Item, { name: "permissions", children: /* @__PURE__ */ jsx(permissionList_default, {}) })
1893
+ ] }),
1894
+ onConfirm: async (values) => {
1895
+ await trigger({
1899
1896
  name: `role_${values.name}`,
1900
1897
  permissions: values.permissions
1901
1898
  });
1902
- refetch(url4, { page: 1 });
1903
- message.success(t("RoleList.createSuccessfully"));
1904
- } else {
1905
- await update.trigger({
1899
+ onSuccess?.();
1900
+ }
1901
+ });
1902
+ };
1903
+ useUpdateRoleModal = ({ onSuccess } = {}) => {
1904
+ const { t } = useTranslation();
1905
+ const { trigger } = useUpdateRole();
1906
+ return useFormModal({
1907
+ title: t("Role.updateTitle"),
1908
+ width: "50vw",
1909
+ formProps: {
1910
+ layout: "vertical"
1911
+ },
1912
+ content: /* @__PURE__ */ jsxs(Fragment, { children: [
1913
+ /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, { disabled: true, addonBefore: "role_" }) }),
1914
+ /* @__PURE__ */ jsx(Form.Item, { name: "permissions", children: /* @__PURE__ */ jsx(permissionList_default, {}) })
1915
+ ] }),
1916
+ onConfirm: async (values, extraValues) => {
1917
+ await trigger({
1906
1918
  id: extraValues?.id,
1907
1919
  name: `role_${values.name}`,
1908
1920
  permissions: values.permissions
1909
1921
  });
1910
- mutate2(
1911
- url4,
1912
- (prev) => produce(prev, (draft) => {
1913
- const match = draft?.List?.find((item) => item.id === extraValues?.id);
1914
- if (match) {
1915
- match.permissions = values.permissions;
1916
- }
1917
- }),
1918
- { revalidate: false }
1919
- );
1920
- message.success(t("RoleList.updateSuccessfully"));
1922
+ onSuccess?.();
1923
+ }
1924
+ });
1925
+ };
1926
+ useCreateUserModal = ({ onSuccess } = {}) => {
1927
+ const { t } = useTranslation();
1928
+ const { data: roles, isLoading } = useAllRoles();
1929
+ const { trigger } = useCreateUser();
1930
+ return useFormModal({
1931
+ title: t("User.createTitle"),
1932
+ width: 600,
1933
+ formProps: {
1934
+ autoComplete: "off",
1935
+ labelCol: { flex: "80px" }
1936
+ },
1937
+ content: /* @__PURE__ */ jsxs(Fragment, { children: [
1938
+ /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, {}) }),
1939
+ /* @__PURE__ */ jsx(Form.Item, { label: t("global.role"), name: "roles", children: /* @__PURE__ */ jsx(
1940
+ Select,
1941
+ {
1942
+ allowClear: true,
1943
+ showSearch: true,
1944
+ mode: "multiple",
1945
+ loading: isLoading,
1946
+ optionFilterProp: "label",
1947
+ options: roles?.map((role) => ({ label: role.name, value: role.name }))
1948
+ }
1949
+ ) })
1950
+ ] }),
1951
+ onConfirm: async (values) => {
1952
+ await trigger(values);
1953
+ onSuccess?.();
1954
+ }
1955
+ });
1956
+ };
1957
+ useUpdateUserModal = ({ onSuccess } = {}) => {
1958
+ const { t } = useTranslation();
1959
+ const { data: roles, isLoading } = useAllRoles();
1960
+ const { trigger } = useUpdateUser();
1961
+ return useFormModal({
1962
+ title: t("User.updateTitle"),
1963
+ width: 600,
1964
+ formProps: {
1965
+ autoComplete: "off",
1966
+ labelCol: { flex: "80px" }
1967
+ },
1968
+ content: /* @__PURE__ */ jsxs(Fragment, { children: [
1969
+ /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, { disabled: true }) }),
1970
+ /* @__PURE__ */ jsx(Form.Item, { label: t("global.role"), name: "roles", children: /* @__PURE__ */ jsx(
1971
+ Select,
1972
+ {
1973
+ allowClear: true,
1974
+ showSearch: true,
1975
+ mode: "multiple",
1976
+ loading: isLoading,
1977
+ optionFilterProp: "label",
1978
+ options: roles?.map((role) => ({ label: role.name, value: role.name }))
1979
+ }
1980
+ ) })
1981
+ ] }),
1982
+ onConfirm: async (values, extraValues) => {
1983
+ await trigger({ ...values, id: extraValues?.id });
1984
+ onSuccess?.();
1985
+ }
1986
+ });
1987
+ };
1988
+ GameSelect2 = (props) => {
1989
+ const { groups, onChange, ...rest } = props;
1990
+ const { axios: axios2 } = useToolkitsStore((s) => s);
1991
+ const { data, isLoading } = useSWR5(
1992
+ groups?.length ? `/api/enum/game_group/get_game_ids?game_groups=${groups.join(",")}` : null,
1993
+ (path) => axios2.get(path).then((response) => response.data.data.list)
1994
+ );
1995
+ const options = data?.map((group) => ({ label: group.name, value: group.id }));
1996
+ const onValueChange = (value) => {
1997
+ if (last(value) === WILDCARD) {
1998
+ onChange?.([WILDCARD]);
1999
+ } else if (first(value) === WILDCARD) {
2000
+ onChange?.(value.slice(1));
2001
+ } else {
2002
+ onChange?.(value);
1921
2003
  }
1922
2004
  };
2005
+ return /* @__PURE__ */ jsx(
2006
+ Select,
2007
+ {
2008
+ ...rest,
2009
+ allowClear: true,
2010
+ showSearch: true,
2011
+ optionFilterProp: "label",
2012
+ mode: "tags",
2013
+ loading: isLoading,
2014
+ options,
2015
+ onChange: onValueChange
2016
+ }
2017
+ );
2018
+ };
2019
+ UserModalContentV2 = ({ isCreate }) => {
2020
+ const { t } = useTranslation();
2021
+ const { axios: axios2 } = useToolkitsStore((s) => s);
2022
+ const { data: roles, isLoading: isRolesLoading } = useAllRoles();
2023
+ const { data: groups, isLoading: isGroupsLoading } = useSWR5(
2024
+ "/api/enum/get?enum=game_group",
2025
+ (path) => axios2.get(path).then((response) => response.data.data)
2026
+ );
2027
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2028
+ /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, { disabled: !isCreate }) }),
2029
+ /* @__PURE__ */ jsx(Form.List, { name: "permissions", children: (fields, { add, remove }) => /* @__PURE__ */ jsxs(Row, { gutter: 8, children: [
2030
+ /* @__PURE__ */ jsx(Col, { span: 8, className: "text-center mb-4", children: /* @__PURE__ */ jsx(Text2, { strong: true, children: t("global.projectGroup") }) }),
2031
+ /* @__PURE__ */ jsx(Col, { span: 10, className: "text-center mb-4", children: /* @__PURE__ */ jsx(Text2, { strong: true, children: t("global.game") }) }),
2032
+ /* @__PURE__ */ jsx(Col, { span: 6, className: "text-center mb-4", children: /* @__PURE__ */ jsx(Text2, { strong: true, children: t("global.role") }) }),
2033
+ fields.map((field) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
2034
+ /* @__PURE__ */ jsx(Col, { span: 8, children: /* @__PURE__ */ jsx(Form.Item, { noStyle: true, shouldUpdate: true, children: ({ setFieldValue }) => /* @__PURE__ */ jsx(Form.Item, { name: [field.name, "game_group"], children: /* @__PURE__ */ jsx(
2035
+ Select,
2036
+ {
2037
+ allowClear: true,
2038
+ showSearch: true,
2039
+ mode: "tags",
2040
+ optionFilterProp: "label",
2041
+ loading: isGroupsLoading,
2042
+ options: groups?.map((group) => ({ label: group, value: group })),
2043
+ onChange: () => {
2044
+ setFieldValue(["permissions", field.name, "game_ids"], []);
2045
+ }
2046
+ }
2047
+ ) }) }) }),
2048
+ /* @__PURE__ */ jsx(Col, { span: 10, children: /* @__PURE__ */ jsx(
2049
+ Form.Item,
2050
+ {
2051
+ noStyle: true,
2052
+ shouldUpdate: (prevValues, nextValues) => prevValues.permissions[field.name]?.game_group !== nextValues.permissions[field.name]?.game_group,
2053
+ children: ({ getFieldValue }) => {
2054
+ const _groups = getFieldValue(["permissions", field.name, "game_group"]);
2055
+ return /* @__PURE__ */ jsx(
2056
+ Form.Item,
2057
+ {
2058
+ name: [field.name, "game_ids"],
2059
+ dependencies: [["permissions", field.name, "game_group"]],
2060
+ rules: [{ required: _groups?.length, message: "\u8BF7\u9009\u62E9\u6E38\u620F" }],
2061
+ children: /* @__PURE__ */ jsx(GameSelect2, { groups: _groups })
2062
+ }
2063
+ );
2064
+ }
2065
+ }
2066
+ ) }),
2067
+ /* @__PURE__ */ jsx(Col, { span: 6, children: /* @__PURE__ */ jsxs("div", { className: "flex", children: [
2068
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
2069
+ Form.Item,
2070
+ {
2071
+ name: [field.name, "role"],
2072
+ rules: [
2073
+ { required: true, message: "\u8BF7\u9009\u62E9\u89D2\u8272" },
2074
+ ({ getFieldValue }) => ({
2075
+ validator(_rule, value) {
2076
+ const items = getFieldValue("permissions");
2077
+ const otherItems = items.filter((item, index) => !!item && index !== field.name);
2078
+ if (otherItems.some((item) => item.role === value)) {
2079
+ return Promise.reject(new Error("\u8BF7\u52FF\u91CD\u590D\u9009\u62E9\u89D2\u8272"));
2080
+ }
2081
+ return Promise.resolve();
2082
+ }
2083
+ })
2084
+ ],
2085
+ children: /* @__PURE__ */ jsx(
2086
+ Select,
2087
+ {
2088
+ allowClear: true,
2089
+ showSearch: true,
2090
+ optionFilterProp: "label",
2091
+ loading: isRolesLoading,
2092
+ options: roles?.map((role) => ({ label: role.name, value: role.name }))
2093
+ }
2094
+ )
2095
+ }
2096
+ ) }),
2097
+ /* @__PURE__ */ jsx("div", { className: "w-8 text-center", children: /* @__PURE__ */ jsx(Form.Item, { children: /* @__PURE__ */ jsx(
2098
+ MinusCircleOutlined,
2099
+ {
2100
+ onClick: () => {
2101
+ remove(field.name);
2102
+ }
2103
+ }
2104
+ ) }) })
2105
+ ] }) })
2106
+ ] }, field.key)),
2107
+ fields.length === 0 && /* @__PURE__ */ jsx(Col, { span: 24, children: /* @__PURE__ */ jsx(Empty, { className: "mb-6" }) }),
2108
+ /* @__PURE__ */ jsx(Col, { span: 24, children: /* @__PURE__ */ jsx(Button, { block: true, type: "dashed", onClick: () => add(), children: t("global.add") }) })
2109
+ ] }) })
2110
+ ] });
2111
+ };
2112
+ useCreateUserModalV2 = ({ onSuccess } = {}) => {
2113
+ const { t } = useTranslation();
2114
+ const { trigger } = useCreateUser();
2115
+ return useFormModal({
2116
+ title: t("User.createTitle"),
2117
+ width: "50vw",
2118
+ formProps: {
2119
+ autoComplete: "off",
2120
+ labelCol: { flex: "80px" }
2121
+ },
2122
+ content: /* @__PURE__ */ jsx(UserModalContentV2, { isCreate: true }),
2123
+ onConfirm: async (values) => {
2124
+ await trigger(values);
2125
+ onSuccess?.();
2126
+ }
2127
+ });
2128
+ };
2129
+ useUpdateUserModalV2 = ({ onSuccess } = {}) => {
2130
+ const { t } = useTranslation();
2131
+ const { trigger } = useUpdateUser();
1923
2132
  return useFormModal({
1924
- title,
2133
+ title: t("User.updateTitle"),
1925
2134
  width: "50vw",
1926
- formProps,
1927
- content,
1928
- onConfirm
2135
+ formProps: {
2136
+ autoComplete: "off",
2137
+ labelCol: { flex: "80px" }
2138
+ },
2139
+ content: /* @__PURE__ */ jsx(UserModalContentV2, {}),
2140
+ onConfirm: async (values, extraValues) => {
2141
+ await trigger({ ...values, id: extraValues?.id });
2142
+ onSuccess?.();
2143
+ }
1929
2144
  });
1930
2145
  };
1931
2146
  }
@@ -2021,13 +2236,13 @@ var init_permissionCollapse = __esm({
2021
2236
  permissionCollapse_default = PermissionCollapse;
2022
2237
  }
2023
2238
  });
2024
- var Text2, Option2, PermissionWithGame, PermissionWithGame_default;
2239
+ var Text3, Option2, PermissionWithGame, PermissionWithGame_default;
2025
2240
  var init_PermissionWithGame = __esm({
2026
2241
  "src/features/permission/components/permissionList/PermissionWithGame.tsx"() {
2027
2242
  init_locale();
2028
2243
  init_hooks5();
2029
2244
  init_permissionCollapse();
2030
- ({ Text: Text2 } = Typography);
2245
+ ({ Text: Text3 } = Typography);
2031
2246
  ({ Option: Option2 } = Select);
2032
2247
  PermissionWithGame = (props) => {
2033
2248
  const { expand = true, value, readonly, onChange } = props;
@@ -2046,7 +2261,7 @@ var init_PermissionWithGame = __esm({
2046
2261
  setGameList(list);
2047
2262
  }, [value]);
2048
2263
  if (error) {
2049
- return /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(Text2, { type: "danger", children: t("PermissionList.failedDescription") }) });
2264
+ return /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(Text3, { type: "danger", children: t("PermissionList.failedDescription") }) });
2050
2265
  }
2051
2266
  const addGame = () => {
2052
2267
  setGameList((prev) => [...prev, { gameId: "", permissions: [] }]);
@@ -2076,8 +2291,8 @@ var init_PermissionWithGame = __esm({
2076
2291
  Card,
2077
2292
  {
2078
2293
  title: /* @__PURE__ */ jsxs(Space, { children: [
2079
- /* @__PURE__ */ jsx(Text2, { children: t("global.game") }),
2080
- readonly ? /* @__PURE__ */ jsx(Text2, { children: games?.find((game) => String(game.id) === item.gameId)?.name }) : /* @__PURE__ */ jsx(
2294
+ /* @__PURE__ */ jsx(Text3, { children: t("global.game") }),
2295
+ readonly ? /* @__PURE__ */ jsx(Text3, { children: games?.find((game) => String(game.id) === item.gameId)?.name }) : /* @__PURE__ */ jsx(
2081
2296
  Select,
2082
2297
  {
2083
2298
  disabled: readonly,
@@ -2138,19 +2353,19 @@ var init_PermissionWithGame = __esm({
2138
2353
  PermissionWithGame_default = PermissionWithGame;
2139
2354
  }
2140
2355
  });
2141
- var Text3, PermissionWithoutGame, PermissionWithoutGame_default;
2356
+ var Text4, PermissionWithoutGame, PermissionWithoutGame_default;
2142
2357
  var init_PermissionWithoutGame = __esm({
2143
2358
  "src/features/permission/components/permissionList/PermissionWithoutGame.tsx"() {
2144
2359
  init_locale();
2145
2360
  init_hooks5();
2146
2361
  init_permissionCollapse();
2147
- ({ Text: Text3 } = Typography);
2362
+ ({ Text: Text4 } = Typography);
2148
2363
  PermissionWithoutGame = (props) => {
2149
2364
  const { expand = true, value, readonly, onChange } = props;
2150
2365
  const { data: permissions, isLoading, error } = useAllPermissions();
2151
2366
  const { t } = useTranslation();
2152
2367
  if (error) {
2153
- return /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(Text3, { type: "danger", children: t("PermissionList.failedDescription") }) });
2368
+ return /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(Text4, { type: "danger", children: t("PermissionList.failedDescription") }) });
2154
2369
  }
2155
2370
  return /* @__PURE__ */ jsx(Skeleton, { active: true, loading: isLoading, children: /* @__PURE__ */ jsx(
2156
2371
  permissionCollapse_default,
@@ -2208,242 +2423,57 @@ var userList_exports = {};
2208
2423
  __export(userList_exports, {
2209
2424
  default: () => userList_default
2210
2425
  });
2211
- var Text4, url2, useModal2, GameSelect2, useModalWithGroup, UserList, userList_default;
2426
+ var url2, UserList, userList_default;
2212
2427
  var init_userList = __esm({
2213
2428
  "src/pages/permission/userList/index.tsx"() {
2214
2429
  init_highlight();
2215
2430
  init_locale();
2216
- init_modal2();
2217
2431
  init_permissionButton();
2218
2432
  init_queryList();
2219
2433
  init_toolkitsProvider();
2220
- init_constants();
2221
2434
  init_permission();
2222
- ({ Text: Text4 } = Typography);
2223
2435
  url2 = "/api/usystem/user/list";
2224
- useModal2 = (isCreate) => {
2225
- const { message } = App.useApp();
2436
+ UserList = () => {
2437
+ const { modal, message } = App.useApp();
2226
2438
  const { t } = useTranslation();
2227
- const { refetch, mutate: mutate2 } = useQueryListStore();
2228
- const { data: roles, isLoading } = useAllRoles();
2229
- const create5 = useCreateUser();
2230
- const update = useUpdateUser();
2231
- const title = isCreate ? t("UserList.createTitle") : t("UserList.updateTitle");
2232
- const content = /* @__PURE__ */ jsxs(Fragment, { children: [
2233
- /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, { disabled: !isCreate }) }),
2234
- /* @__PURE__ */ jsx(Form.Item, { label: t("global.role"), name: "roles", children: /* @__PURE__ */ jsx(
2235
- Select,
2236
- {
2237
- allowClear: true,
2238
- showSearch: true,
2239
- mode: "multiple",
2240
- loading: isLoading,
2241
- optionFilterProp: "label",
2242
- options: roles?.map((role) => ({ label: role.name, value: role.name }))
2243
- }
2244
- ) })
2245
- ] });
2246
- const onConfirm = async (values, extraValues) => {
2247
- if (isCreate) {
2248
- await create5.trigger(values);
2439
+ const remove = useRemoveUser();
2440
+ const { mutate: mutate2, refetch } = useQueryListStore();
2441
+ const { permissionVersion } = useToolkitsStore((s) => s);
2442
+ const { show: showCreateModal, modal: createModal } = useCreateUserModal({
2443
+ onSuccess() {
2249
2444
  refetch(url2, { page: 1 });
2250
- message.success(t("UserList.createSuccessfully"));
2251
- } else {
2252
- await update.trigger({ ...values, id: extraValues?.id });
2253
- mutate2(
2254
- url2,
2255
- (prev) => {
2256
- return produce(prev, (draft) => {
2257
- if (draft?.List) {
2258
- const index = draft.List?.findIndex((item) => item.id === extraValues?.id);
2259
- if (index !== -1) {
2260
- draft.List[index].roles = values.roles;
2261
- }
2262
- }
2263
- });
2264
- },
2265
- { revalidate: false }
2266
- );
2267
- message.success(t("UserList.updateSuccessfully"));
2445
+ message.success(t("User.createSuccessfully"));
2268
2446
  }
2269
- };
2270
- return useFormModal({
2271
- title,
2272
- width: 600,
2273
- formProps: {
2274
- autoComplete: "off",
2275
- labelCol: { flex: "80px" }
2276
- },
2277
- content,
2278
- onConfirm
2279
2447
  });
2280
- };
2281
- GameSelect2 = (props) => {
2282
- const { groups, onChange, ...rest } = props;
2283
- const { axios: axios2 } = useToolkitsStore((s) => s);
2284
- const { data, isLoading } = useSWR5(
2285
- groups?.length ? `/api/enum/game_group/get_game_ids?game_groups=${groups.join(",")}` : null,
2286
- (path) => axios2.get(path).then((response) => response.data.data.list)
2287
- );
2288
- const options = data?.map((group) => ({ label: group.name, value: group.id }));
2289
- const onValueChange = (value) => {
2290
- if (last(value) === WILDCARD) {
2291
- onChange?.([WILDCARD]);
2292
- } else if (first(value) === WILDCARD) {
2293
- onChange?.(value.slice(1));
2294
- } else {
2295
- onChange?.(value);
2448
+ const { show: showUpdateModal, modal: updateModal } = useUpdateUserModal({
2449
+ onSuccess() {
2450
+ refetch(url2);
2451
+ message.success(t("User.updateSuccessfully"));
2296
2452
  }
2297
- };
2298
- return /* @__PURE__ */ jsx(
2299
- Select,
2300
- {
2301
- ...rest,
2302
- allowClear: true,
2303
- showSearch: true,
2304
- optionFilterProp: "label",
2305
- mode: "tags",
2306
- loading: isLoading,
2307
- options,
2308
- onChange: onValueChange
2309
- }
2310
- );
2311
- };
2312
- useModalWithGroup = (isCreate) => {
2313
- const { message } = App.useApp();
2314
- const { t } = useTranslation();
2315
- const { axios: axios2 } = useToolkitsStore((s) => s);
2316
- const { refetch, mutate: mutate2 } = useQueryListStore();
2317
- const { data: roles, isLoading: isRolesLoading } = useAllRoles();
2318
- const create5 = useCreateUser();
2319
- const update = useUpdateUser();
2320
- const title = isCreate ? t("UserList.createTitle") : t("UserList.updateTitle");
2321
- const { data: groups, isLoading: isGroupsLoading } = useSWR5(
2322
- "/api/enum/get?enum=game_group",
2323
- (path) => axios2.get(path).then((response) => response.data.data)
2324
- );
2325
- const content = /* @__PURE__ */ jsxs(Fragment, { children: [
2326
- /* @__PURE__ */ jsx(Form.Item, { label: t("global.name"), name: "name", rules: [{ required: true }], children: /* @__PURE__ */ jsx(Input, { disabled: !isCreate }) }),
2327
- /* @__PURE__ */ jsx(Form.List, { name: "permissions", children: (fields, { add, remove }) => /* @__PURE__ */ jsxs(Row, { gutter: 8, children: [
2328
- /* @__PURE__ */ jsx(Col, { span: 8, className: "text-center mb-4", children: /* @__PURE__ */ jsx(Text4, { strong: true, children: t("global.projectGroup") }) }),
2329
- /* @__PURE__ */ jsx(Col, { span: 10, className: "text-center mb-4", children: /* @__PURE__ */ jsx(Text4, { strong: true, children: t("global.game") }) }),
2330
- /* @__PURE__ */ jsx(Col, { span: 6, className: "text-center mb-4", children: /* @__PURE__ */ jsx(Text4, { strong: true, children: t("global.role") }) }),
2331
- fields.map((field) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
2332
- /* @__PURE__ */ jsx(Col, { span: 8, children: /* @__PURE__ */ jsx(Form.Item, { noStyle: true, shouldUpdate: true, children: ({ setFieldValue }) => /* @__PURE__ */ jsx(Form.Item, { name: [field.name, "game_group"], children: /* @__PURE__ */ jsx(
2333
- Select,
2334
- {
2335
- allowClear: true,
2336
- showSearch: true,
2337
- mode: "tags",
2338
- optionFilterProp: "label",
2339
- loading: isGroupsLoading,
2340
- options: groups?.map((group) => ({ label: group, value: group })),
2341
- onChange: () => {
2342
- setFieldValue(["permissions", field.name, "game_ids"], []);
2343
- }
2344
- }
2345
- ) }) }) }),
2346
- /* @__PURE__ */ jsx(Col, { span: 10, children: /* @__PURE__ */ jsx(
2347
- Form.Item,
2348
- {
2349
- noStyle: true,
2350
- shouldUpdate: (prevValues, nextValues) => prevValues.permissions[field.name]?.game_group !== nextValues.permissions[field.name]?.game_group,
2351
- children: ({ getFieldValue }) => {
2352
- const _groups = getFieldValue(["permissions", field.name, "game_group"]);
2353
- return /* @__PURE__ */ jsx(
2354
- Form.Item,
2355
- {
2356
- name: [field.name, "game_ids"],
2357
- dependencies: [["permissions", field.name, "game_group"]],
2358
- rules: [{ required: _groups?.length, message: "\u8BF7\u9009\u62E9\u6E38\u620F" }],
2359
- children: /* @__PURE__ */ jsx(GameSelect2, { groups: _groups })
2360
- }
2361
- );
2362
- }
2363
- }
2364
- ) }),
2365
- /* @__PURE__ */ jsx(Col, { span: 6, children: /* @__PURE__ */ jsxs("div", { className: "flex", children: [
2366
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
2367
- Form.Item,
2368
- {
2369
- name: [field.name, "role"],
2370
- rules: [
2371
- { required: true, message: "\u8BF7\u9009\u62E9\u89D2\u8272" },
2372
- ({ getFieldValue }) => ({
2373
- validator(_rule, value) {
2374
- const items = getFieldValue("permissions");
2375
- const otherItems = items.filter((item, index) => !!item && index !== field.name);
2376
- if (otherItems.some((item) => item.role === value)) {
2377
- return Promise.reject(new Error("\u8BF7\u52FF\u91CD\u590D\u9009\u62E9\u89D2\u8272"));
2378
- }
2379
- return Promise.resolve();
2380
- }
2381
- })
2382
- ],
2383
- children: /* @__PURE__ */ jsx(
2384
- Select,
2385
- {
2386
- allowClear: true,
2387
- showSearch: true,
2388
- optionFilterProp: "label",
2389
- loading: isRolesLoading,
2390
- options: roles?.map((role) => ({ label: role.name, value: role.name }))
2391
- }
2392
- )
2393
- }
2394
- ) }),
2395
- /* @__PURE__ */ jsx("div", { className: "w-8 text-center", children: /* @__PURE__ */ jsx(Form.Item, { children: /* @__PURE__ */ jsx(
2396
- MinusCircleOutlined,
2397
- {
2398
- onClick: () => {
2399
- remove(field.name);
2400
- }
2401
- }
2402
- ) }) })
2403
- ] }) })
2404
- ] }, field.key)),
2405
- fields.length === 0 && /* @__PURE__ */ jsx(Col, { span: 24, children: /* @__PURE__ */ jsx(Empty, { className: "mb-6" }) }),
2406
- /* @__PURE__ */ jsx(Col, { span: 24, children: /* @__PURE__ */ jsx(Button, { block: true, type: "dashed", onClick: () => add(), children: t("global.add") }) })
2407
- ] }) })
2408
- ] });
2409
- const onConfirm = async (values, extraValues) => {
2410
- if (isCreate) {
2411
- await create5.trigger(values);
2453
+ });
2454
+ const { show: showCreateModalV2, modal: createModalV2 } = useCreateUserModalV2({
2455
+ onSuccess() {
2412
2456
  refetch(url2, { page: 1 });
2413
- message.success(t("UserList.createSuccessfully"));
2414
- } else {
2415
- await update.trigger({ ...values, id: extraValues?.id });
2416
- mutate2(url2);
2417
- message.success(t("UserList.updateSuccessfully"));
2457
+ message.success(t("User.createSuccessfully"));
2458
+ }
2459
+ });
2460
+ const { show: showUpdateModalV2, modal: updateModalV2 } = useUpdateUserModalV2({
2461
+ onSuccess() {
2462
+ refetch(url2);
2463
+ message.success(t("User.updateSuccessfully"));
2418
2464
  }
2419
- };
2420
- return useFormModal({
2421
- title,
2422
- width: "50vw",
2423
- formProps: {
2424
- autoComplete: "off",
2425
- labelCol: { flex: "80px" }
2426
- },
2427
- content,
2428
- onConfirm
2429
2465
  });
2430
- };
2431
- UserList = () => {
2432
- const { modal, message } = App.useApp();
2433
- const remove = useRemoveUser();
2434
- const { mutate: mutate2 } = useQueryListStore();
2435
- const { permissionVersion } = useToolkitsStore((s) => s);
2436
- const { show: showCreateModal, modal: createModal } = useModal2(true);
2437
- const { show: showUpdateModal, modal: updateModal } = useModal2();
2438
- const { show: showCreateModalWithGroup, modal: createModalWithGroup } = useModalWithGroup(true);
2439
- const { show: showUpdateModalWithGroup, modal: updateModalWithGroup } = useModalWithGroup();
2440
- const { t } = useTranslation();
2441
- const navigate = useNavigate();
2442
2466
  const columns = [
2443
2467
  {
2444
2468
  title: t("global.name"),
2445
2469
  dataIndex: "name",
2446
- key: "name"
2470
+ key: "name",
2471
+ render(value, record) {
2472
+ if (permissionVersion === "v3" /* V3 */) {
2473
+ return /* @__PURE__ */ jsx(Link, { to: `./${record.id}`, children: value });
2474
+ }
2475
+ return value;
2476
+ }
2447
2477
  },
2448
2478
  {
2449
2479
  title: "ID",
@@ -2471,16 +2501,6 @@ var init_userList = __esm({
2471
2501
  render: (_, record) => {
2472
2502
  const { name, permissions, roles, id: id2 } = record;
2473
2503
  return /* @__PURE__ */ jsxs(Space, { children: [
2474
- permissionVersion === "v3" /* V3 */ && /* @__PURE__ */ jsx(
2475
- Button,
2476
- {
2477
- type: "link",
2478
- onClick: () => {
2479
- navigate(`./${id2}}`);
2480
- },
2481
- children: t("global.view")
2482
- }
2483
- ),
2484
2504
  /* @__PURE__ */ jsx(
2485
2505
  PermissionButton_default,
2486
2506
  {
@@ -2489,7 +2509,7 @@ var init_userList = __esm({
2489
2509
  code: "100003",
2490
2510
  onClick: () => {
2491
2511
  if (permissionVersion === "v3" /* V3 */) {
2492
- showUpdateModalWithGroup({
2512
+ showUpdateModalV2({
2493
2513
  initialValues: {
2494
2514
  name,
2495
2515
  permissions
@@ -2522,8 +2542,8 @@ var init_userList = __esm({
2522
2542
  type: "link",
2523
2543
  onClick: () => {
2524
2544
  modal.confirm({
2525
- title: t("UserList.deleteTitle"),
2526
- content: /* @__PURE__ */ jsx(Highlight_default, { texts: [name], children: t("UserList.deleteContent", { user: name }) }),
2545
+ title: t("User.deleteTitle"),
2546
+ content: /* @__PURE__ */ jsx(Highlight_default, { texts: [name], children: t("User.deleteContent", { user: name }) }),
2527
2547
  async onOk() {
2528
2548
  await remove.trigger({
2529
2549
  id: id2,
@@ -2537,7 +2557,7 @@ var init_userList = __esm({
2537
2557
  }
2538
2558
  });
2539
2559
  });
2540
- message.success(t("UserList.deleteSuccessfully"));
2560
+ message.success(t("User.deleteSuccessfully"));
2541
2561
  }
2542
2562
  });
2543
2563
  },
@@ -2561,12 +2581,12 @@ var init_userList = __esm({
2561
2581
  code: "100002",
2562
2582
  onClick: () => {
2563
2583
  if (permissionVersion === "v3" /* V3 */) {
2564
- showCreateModalWithGroup();
2584
+ showCreateModalV2();
2565
2585
  } else {
2566
2586
  showCreateModal();
2567
2587
  }
2568
2588
  },
2569
- children: t("UserList.createTitle")
2589
+ children: t("User.createTitle")
2570
2590
  }
2571
2591
  ),
2572
2592
  children: /* @__PURE__ */ jsx(
@@ -2585,8 +2605,8 @@ var init_userList = __esm({
2585
2605
  ),
2586
2606
  createModal,
2587
2607
  updateModal,
2588
- createModalWithGroup,
2589
- updateModalWithGroup
2608
+ createModalV2,
2609
+ updateModalV2
2590
2610
  ] });
2591
2611
  };
2592
2612
  userList_default = withContext(UserList, { isGlobal: true });
@@ -2605,15 +2625,23 @@ var init_userDetail = __esm({
2605
2625
  init_locale();
2606
2626
  init_toolkitsProvider();
2607
2627
  init_constants();
2628
+ init_permission();
2608
2629
  UserDetail = () => {
2630
+ const { message } = App.useApp();
2609
2631
  const params = useParams();
2610
2632
  const { t } = useTranslation();
2611
2633
  const { axios: axios2, gameApiV2 } = useToolkitsStore((s) => s);
2612
- const { data, isLoading } = useSWR5(
2634
+ const { data, isLoading, mutate: mutate2 } = useSWR5(
2613
2635
  params.id ? `/api/usystem/user/info?id=${params.id}` : null,
2614
2636
  (url4) => axios2.get(url4).then((res) => res.data.data)
2615
2637
  );
2616
2638
  const { data: games } = useGames();
2639
+ const { show, modal } = useUpdateUserModalV2({
2640
+ onSuccess() {
2641
+ mutate2();
2642
+ message.success(t("User.updateSuccessfully"));
2643
+ }
2644
+ });
2617
2645
  const columns = [
2618
2646
  {
2619
2647
  key: "group",
@@ -2660,11 +2688,36 @@ var init_userDetail = __esm({
2660
2688
  ]
2661
2689
  }
2662
2690
  ),
2663
- /* @__PURE__ */ jsx(Card, { title: "\u7528\u6237\u8BE6\u60C5", loading: isLoading, children: /* @__PURE__ */ jsxs(Descriptions, { bordered: true, column: 1, children: [
2664
- /* @__PURE__ */ jsx(Descriptions.Item, { label: t("global.name"), children: data?.name }),
2665
- /* @__PURE__ */ jsx(Descriptions.Item, { label: "ID", children: data?.id }),
2666
- /* @__PURE__ */ jsx(Descriptions.Item, { label: t("global.role"), children: /* @__PURE__ */ jsx(Table, { rowKey: "role", columns, dataSource: data?.permissions, pagination: false }) })
2667
- ] }) })
2691
+ /* @__PURE__ */ jsx(
2692
+ Card,
2693
+ {
2694
+ title: "\u7528\u6237\u8BE6\u60C5",
2695
+ loading: isLoading,
2696
+ extra: /* @__PURE__ */ jsx(
2697
+ Button,
2698
+ {
2699
+ onClick: () => {
2700
+ show({
2701
+ initialValues: {
2702
+ name: data?.name,
2703
+ permissions: data?.permissions
2704
+ },
2705
+ extraValues: {
2706
+ id: data.id
2707
+ }
2708
+ });
2709
+ },
2710
+ children: t("global.update")
2711
+ }
2712
+ ),
2713
+ children: /* @__PURE__ */ jsxs(Descriptions, { bordered: true, column: 1, children: [
2714
+ /* @__PURE__ */ jsx(Descriptions.Item, { label: t("global.name"), children: data?.name }),
2715
+ /* @__PURE__ */ jsx(Descriptions.Item, { label: "ID", children: data?.id }),
2716
+ /* @__PURE__ */ jsx(Descriptions.Item, { label: t("global.role"), children: /* @__PURE__ */ jsx(Table, { rowKey: "role", columns, dataSource: data?.permissions, pagination: false }) })
2717
+ ] })
2718
+ }
2719
+ ),
2720
+ modal
2668
2721
  ] });
2669
2722
  };
2670
2723
  userDetail_default = UserDetail;
@@ -2689,13 +2742,23 @@ var init_roleList = __esm({
2689
2742
  init_hooks2();
2690
2743
  url3 = "/api/usystem/role/list";
2691
2744
  RoleList = () => {
2692
- const { accessible: viewable } = usePermission("200005");
2693
2745
  const { modal, message } = App.useApp();
2746
+ const { accessible: viewable } = usePermission("200005");
2694
2747
  const { t } = useTranslation();
2695
2748
  const { axios: axios2, permissionVersion } = useToolkitsStore((s) => s);
2696
- const { mutate: mutate2 } = useQueryListStore();
2697
- const { show: showCreateModal, modal: createModal } = useRoleModal(true);
2698
- const { show: showUpdateModal, modal: updateModal } = useRoleModal();
2749
+ const { mutate: mutate2, refetch } = useQueryListStore();
2750
+ const { show: showCreateModal, modal: createModal } = useCreateRoleModal({
2751
+ onSuccess() {
2752
+ refetch(url3, { page: 1 });
2753
+ message.success(t("Role.createSuccessfully"));
2754
+ }
2755
+ });
2756
+ const { show: showUpdateModal, modal: updateModal } = useUpdateRoleModal({
2757
+ onSuccess() {
2758
+ mutate2(url3);
2759
+ message.success(t("Role.updateSuccessfully"));
2760
+ }
2761
+ });
2699
2762
  const remove = useRemoveRole();
2700
2763
  const handleUpdateBtnClick = async (record) => {
2701
2764
  const response = await axios2.get(
@@ -2749,7 +2812,7 @@ var init_roleList = __esm({
2749
2812
  onClick: async () => {
2750
2813
  handleUpdateBtnClick(record);
2751
2814
  },
2752
- children: t("global.edit")
2815
+ children: t("global.update")
2753
2816
  }
2754
2817
  ),
2755
2818
  /* @__PURE__ */ jsx(
@@ -2761,8 +2824,8 @@ var init_roleList = __esm({
2761
2824
  type: "link",
2762
2825
  onClick: () => {
2763
2826
  modal.confirm({
2764
- title: t("RoleList.deleteTitle"),
2765
- content: /* @__PURE__ */ jsx(Highlight_default, { texts: [record.name], children: t("RoleList.deleteContent", { role: record.name }) }),
2827
+ title: t("Role.deleteTitle"),
2828
+ content: /* @__PURE__ */ jsx(Highlight_default, { texts: [record.name], children: t("Role.deleteContent", { role: record.name }) }),
2766
2829
  async onOk() {
2767
2830
  await remove.trigger({
2768
2831
  id: record.id,
@@ -2776,7 +2839,7 @@ var init_roleList = __esm({
2776
2839
  }
2777
2840
  });
2778
2841
  });
2779
- message.success(t("RoleList.deleteSuccessfully"));
2842
+ message.success(t("Role.deleteSuccessfully"));
2780
2843
  }
2781
2844
  });
2782
2845
  },
@@ -2801,7 +2864,7 @@ var init_roleList = __esm({
2801
2864
  onClick: () => {
2802
2865
  showCreateModal();
2803
2866
  },
2804
- children: t("RoleList.createTitle")
2867
+ children: t("Role.createTitle")
2805
2868
  }
2806
2869
  ),
2807
2870
  children: /* @__PURE__ */ jsx(
@@ -2839,24 +2902,24 @@ var init_roleDetail = __esm({
2839
2902
  init_toolkitsProvider();
2840
2903
  init_permission();
2841
2904
  RoleDetail = () => {
2905
+ const { message } = App.useApp();
2842
2906
  const params = useParams();
2843
2907
  const { t } = useTranslation();
2844
- const { axios: axios2, permissionVersion } = useToolkitsStore((s) => s);
2845
- const { data: role, isLoading } = useRole(params.name);
2846
- const { show, modal } = useRoleModal(false);
2908
+ const { data, isLoading, mutate: mutate2 } = useRole(params.name);
2909
+ const { show, modal } = useUpdateRoleModal({
2910
+ onSuccess() {
2911
+ mutate2();
2912
+ message.success(t("Role.updateSuccessfully"));
2913
+ }
2914
+ });
2847
2915
  const handleUpdateBtnClick = async () => {
2848
- const {
2849
- data: { data }
2850
- } = await axios2.get(
2851
- `/api/usystem/role/info${permissionVersion === "v2" /* V2 */ ? "V2" : ""}?name=${role.name}`
2852
- );
2853
2916
  show({
2854
2917
  initialValues: {
2855
2918
  permissions: data?.permissions,
2856
2919
  name: data?.name.replace(/^role_/, "")
2857
2920
  },
2858
2921
  extraValues: {
2859
- id: data?.id
2922
+ id: data.id
2860
2923
  }
2861
2924
  });
2862
2925
  };
@@ -2877,13 +2940,13 @@ var init_roleDetail = __esm({
2877
2940
  ]
2878
2941
  }
2879
2942
  ),
2880
- /* @__PURE__ */ jsx(Card, { title: t("RoleDetail.title"), extra: /* @__PURE__ */ jsx(Button, { onClick: handleUpdateBtnClick, children: t("global.edit") }), children: /* @__PURE__ */ jsxs(Skeleton, { loading: isLoading, children: [
2943
+ /* @__PURE__ */ jsx(Card, { title: t("RoleDetail.title"), extra: /* @__PURE__ */ jsx(Button, { onClick: handleUpdateBtnClick, children: t("global.update") }), children: /* @__PURE__ */ jsxs(Skeleton, { loading: isLoading, children: [
2881
2944
  /* @__PURE__ */ jsxs(Descriptions, { column: 2, layout: "vertical", className: "mb-6", children: [
2882
- /* @__PURE__ */ jsx(Descriptions.Item, { label: t("global.name"), children: role?.name }),
2883
- /* @__PURE__ */ jsx(Descriptions.Item, { label: "ID", children: role?.id }),
2884
- /* @__PURE__ */ jsx(Descriptions.Item, { label: t("global.creationTime"), children: role?.ctime })
2945
+ /* @__PURE__ */ jsx(Descriptions.Item, { label: t("global.name"), children: data?.name }),
2946
+ /* @__PURE__ */ jsx(Descriptions.Item, { label: "ID", children: data?.id }),
2947
+ /* @__PURE__ */ jsx(Descriptions.Item, { label: t("global.creationTime"), children: data?.ctime })
2885
2948
  ] }),
2886
- /* @__PURE__ */ jsx(permissionList_default, { readonly: true, value: role?.permissions })
2949
+ /* @__PURE__ */ jsx(permissionList_default, { readonly: true, value: data?.permissions })
2887
2950
  ] }) }),
2888
2951
  modal
2889
2952
  ] });