Skip to content

Commit

Permalink
级联
Browse files Browse the repository at this point in the history
  • Loading branch information
QwQ-wuwuwu committed Jun 18, 2024
1 parent a40116f commit f7cbcdd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/frontend/src/controllers/API/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export async function getRolesApi(searchkey = ""): Promise<{ data: ROLE[] }> {
.then(res => res.data);
}
// 用户组下角色列表
export async function getRolesByGroupApi(searchkey = "", group_id): Promise<{ data: ROLE[] }> {
return await axios.get(`/api/v1/group/roles?keyword=${searchkey}&group_id=${group_id}`)
export async function getRolesByGroupApi(searchkey = "", groupIds:any[]): Promise<{ data: ROLE[] }> {
const groupStr = groupIds?.reduce((pre, id) => `${pre}&group_id=${id}`, '') || ''
return await axios.get(`/api/v1/group/roles?keyword=${searchkey}${groupStr}`)
.then(res => res.data);
}
/**
Expand Down
14 changes: 7 additions & 7 deletions src/frontend/src/pages/SystemPage/components/Roles.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React, { useEffect, useRef, useState, useCallback, useReducer } from "react";
import { PlusIcon } from "@/components/bs-icons/plus";
import { bsConfirm } from "@/components/bs-ui/alertDialog/useConfirm";
import { Label } from "@/components/bs-ui/label";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/bs-ui/select";
import React, { useCallback, useEffect, useReducer, useRef } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "../../../components/bs-ui/button";
import { bsConfirm } from "@/components/bs-ui/alertDialog/useConfirm";
import { SearchInput } from "../../../components/bs-ui/input";
import {
Table,
TableBody,
Expand All @@ -11,14 +15,10 @@ import {
TableHeader,
TableRow
} from "../../../components/bs-ui/table";
import { delRoleApi, getRolesApi, getRolesByGroupApi, getUserGroupsApi } from "../../../controllers/API/user";
import { delRoleApi, getRolesByGroupApi, getUserGroupsApi } from "../../../controllers/API/user";
import { captureAndAlertRequestErrorHoc } from "../../../controllers/request";
import { ROLE } from "../../../types/api/user";
import EditRole from "./EditRole";
import { SearchInput } from "../../../components/bs-ui/input";
import { PlusIcon } from "@/components/bs-icons/plus";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/bs-ui/select";
import { Label } from "@/components/bs-ui/label";

interface State {
roles: ROLE[];
Expand Down
10 changes: 9 additions & 1 deletion src/frontend/src/pages/SystemPage/components/UserRoleModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useToast } from "@/components/bs-ui/toast/use-toast"
import { useEffect, useMemo, useState } from "react"
import { useTranslation } from "react-i18next"
import { Button } from "../../../components/bs-ui/button"
import { getRolesApi, getUserGroupsApi, updateUserGroups, updateUserRoles } from "../../../controllers/API/user"
import { getRolesApi, getUserGroupsApi, getRolesByGroupApi, updateUserGroups, updateUserRoles } from "../../../controllers/API/user"
import { captureAndAlertRequestErrorHoc } from "../../../controllers/request"
import { ROLE } from "../../../types/api/user"

Expand Down Expand Up @@ -42,6 +42,14 @@ export default function UserRoleModal({ user, onClose, onChange }) {
})
}, [user])

useEffect(() => {
getRolesByGroupApi('', userGroupSelected).then(data => {
//@ts-ignore
const roleOptions = data.map(role => ({ ...role, role_id: role.id }))
setRoles(roleOptions);
})
},[userGroupSelected])

const { message } = useToast()
const handleSave = async () => {
if (!selected.length) return message({ title: t('prompt'), variant: 'warning', description: '请选择角色' })
Expand Down

0 comments on commit f7cbcdd

Please sign in to comment.