Skip to content

Commit

Permalink
fix: lost rolelist by search
Browse files Browse the repository at this point in the history
  • Loading branch information
dolphin0618 committed Jun 14, 2024
1 parent e1ff6bb commit 81d5445
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 39 deletions.
4 changes: 0 additions & 4 deletions src/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<title>BISHENG</title>
</head>

<script>
window.WX_LOGIN_URL = 'http://192.168.106.115:8098/api/oauth2/wx'
</script>

<body id='body' style="width: 100%; height:100%">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div style="width: 100vw; height:100vh" id='root'></div>
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/public/locales/zh/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"limit": "有限制",
"unlimited": "无限制",
"iconHover": "同时受用户组整体流量控制策略约束",
"maximum": "每秒最多",
"perMinute": "个会话",
"maximum": "每分钟最多",
"perMinute": "个并发会话",
"changeTime": "修改时间",
"deleteGroup": "删除后 【{{name}}】 将不再存在,是否删除?"
},
Expand Down
9 changes: 7 additions & 2 deletions src/frontend/src/components/Pro/security/AssistantSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ export default function AssistantSetting({ id, type }) {
// load
useEffect(() => {
id !== 3 && getSensitiveApi(id, type).then(res => {
console.log(res, 'xxx');

const { is_check, auto_reply, words, words_types } = res
setForm({
isCheck: !!is_check,
autoReply: auto_reply,
words,
wordsType: Array.isArray(words_types) ? words_types : [words_types],
})
})
}, [id])

Expand Down
9 changes: 7 additions & 2 deletions src/frontend/src/components/Pro/security/FlowSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ export default function FlowSetting({ id, type }) {
// load
useEffect(() => {
id !== 3 && getSensitiveApi(id, type).then(res => {
console.log(res, 'xxx');

const { is_check, auto_reply, words, words_types } = res
setForm({
isCheck: !!is_check,
autoReply: auto_reply,
words,
wordsType: Array.isArray(words_types) ? words_types : [words_types],
})
})
}, [id])

Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/contexts/locationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export function LocationProvider({ children }: { children: ReactNode }) {
dialogTips: res.dialog_tips,
dialogQuickSearch: res.dialog_quick_search,
websocketHost: res.websocket_url || window.location.host,
isPro: true
isPro: !!res.pro,
hasSSO: !!res.sso
})
})
}, [])
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/src/controllers/API/pro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ export const saveGroupApi = async (data: any): Promise<any> => {
// 用户组列表
export function getUserGroupsProApi() {
return axios.get(`/api/group/list`);
}

// GET sso URL
export function getSSOurlApi() {
const url = 'http://192.168.106.115:8098/api/oauth2/wx'
return Promise.resolve(url)
// return axios.get(`/api/group/list`);
}
4 changes: 2 additions & 2 deletions src/frontend/src/controllers/API/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export async function disableUserApi(userid, status) {
});
}
// 角色列表
export async function getRolesApi(searchkey = "", group_id): Promise<{ data: ROLE[] }> {
return await axios.get(`/api/v1/role/list?role_name=${searchkey}&group_id=${group_id}`)
export async function getRolesApi(searchkey = ""): Promise<{ data: ROLE[] }> {
return await axios.get(`/api/v1/role/list?role_name=${searchkey}`)
.then(res => res.data);
}
// 用户组下角色列表
Expand Down
6 changes: 4 additions & 2 deletions src/frontend/src/pages/LoginPage/login.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BookOpenIcon } from '@/components/bs-icons/bookOpen';
import { GithubIcon } from '@/components/bs-icons/github';
import { useEffect, useRef, useState } from "react";
import { useContext, useEffect, useRef, useState } from "react";
import { useTranslation } from 'react-i18next';
import json from "../../../package.json";
import { Button } from "../../components/bs-ui/button";
Expand All @@ -12,11 +12,13 @@ import { getCaptchaApi, loginApi, registerApi } from "../../controllers/API/user
import { captureAndAlertRequestErrorHoc } from "../../controllers/request";
import LoginBridge from './loginBridge';
import { PWD_RULE, handleEncrypt } from './utils';
import { locationContext } from '@/contexts/locationContext';
export const LoginPage = () => {
// const { setErrorData, setSuccessData } = useContext(alertContext);
const { t, i18n } = useTranslation();
const { message, toast } = useToast()
const navigate = useNavigate()
const { appConfig } = useContext(locationContext)

const isLoading = false

Expand Down Expand Up @@ -193,7 +195,7 @@ export const LoginPage = () => {
disabled={isLoading} onClick={handleRegister} >{t('login.registerButton')}</Button>
</>
}
<LoginBridge />
{appConfig.hasSSO && <LoginBridge />}
</div>
<div className=" absolute right-[16px] bottom-[16px] flex">
<span className="mr-4 text-sm text-gray-400 relative top-2">v{json.version}</span>
Expand Down
13 changes: 11 additions & 2 deletions src/frontend/src/pages/LoginPage/loginBridge.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import Separator from "@/components/bs-comp/chatComponent/Separator";
import { Button } from "@/components/bs-ui/button";
import { getSSOurlApi } from "@/controllers/API/pro";
import { useEffect, useRef } from "react";
import { ReactComponent as Wxpro } from "./icons/wxpro.svg";
import Separator from "@/components/bs-comp/chatComponent/Separator";

export default function LoginBridge() {



const urlRef = useRef<string>('')
useEffect(() => {
getSSOurlApi().then(url => urlRef.current = url)
}, [])

const clickQwLogin = () => {
location.href = window.WX_LOGIN_URL
location.href = urlRef.current
}

return <div>
Expand Down
18 changes: 10 additions & 8 deletions src/frontend/src/pages/SystemPage/components/EditUserGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import { Input, SearchInput } from "../../../components/bs-ui/input";
* @returns
*/

function FlowRadio({ limit, onChange }) {
function FlowRadio({ limit = 0, onChange }) {
const { t } = useTranslation()

const handleChange = (e) => {
const value = e.target.value
if(value < 0) return
if (value < 0 || value > 9999) return
onChange(parseInt(value))
}

Expand All @@ -55,7 +55,7 @@ function FlowRadio({ limit, onChange }) {
</div>
{limit !== 0 && <div className="mt-[-3px]">
<Label>{t('system.maximum')}</Label>
<Input type="number" value={limit} className="inline h-5 w-[70px] font-medium"onChange={handleChange}/>
<Input type="number" value={limit} className="inline h-5 w-[70px] font-medium" onChange={handleChange} />
<Label>{t('system.perMinute')}</Label>
</div>}
</RadioGroup>
Expand Down Expand Up @@ -88,11 +88,13 @@ function FlowControl({ groupId, type, onChange }) {
onChange(itemsRef.current)
}

const searchEndRef = useRef(false)
const handleSearch = (e) => {
searchEndRef.current = true
search(e.target.value)
}

if (!data.length) return null
if (!searchEndRef.current && !data.length) return null

return <>
<div className="flex items-center mb-4 justify-between">
Expand All @@ -117,7 +119,7 @@ function FlowControl({ groupId, type, onChange }) {
<TableRow>
<TableHead className="w-[150px]">{name}</TableHead>
<TableHead className="w-[100px]">{t('system.createdBy')}</TableHead>
<TableHead>{t('system.flowCtrlStrategy')}</TableHead>
<TableHead className="w-[380px]">{t('system.flowCtrlStrategy')}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
Expand Down Expand Up @@ -159,11 +161,11 @@ export default function EditUserGroup({ data, onBeforeChange, onChange }) {
const handleSave = async () => {
if (!form.groupName) {
setForm({ ...form, groupName: data.group_name || '' })
return toast({title: t('prompt'),description: t('system.groupNameRequired'),variant: 'error'});
return toast({ title: t('prompt'), description: t('system.groupNameRequired'), variant: 'error' });
}
if(form.groupName.length > 30) {
if (form.groupName.length > 30) {
setForm({ ...form, groupName: data.group_name || '' })
return toast({title: t('prompt'),description: t('system.groupNamePrompt'),variant: 'error'});
return toast({ title: t('prompt'), description: t('system.groupNamePrompt'), variant: 'error' });
}
const flag = onBeforeChange(form.groupName)
if (flag) {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/pages/SystemPage/components/UserGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function UserGroups() {
<TableCell>{ug.update_time.replace('T', ' ')}</TableCell>
<TableCell className="text-right">
<Button variant="link" onClick={() => setUserGroup(ug)} className="px-0 pl-6">{t('edit')}</Button>
<Button variant="link" onClick={() => handleDelete(ug)} className="text-red-500 px-0 pl-6">{t('delete')}</Button>
<Button variant="link" disabled={ug.id === 2} onClick={() => handleDelete(ug)} className="text-red-500 px-0 pl-6">{t('delete')}</Button>
</TableCell>
</TableRow>
))}
Expand Down
25 changes: 12 additions & 13 deletions src/frontend/src/pages/SystemPage/components/UserRoleModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/bs-ui/dialog"
import MultiSelect from "@/components/bs-ui/select/multi"
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"
Expand All @@ -15,20 +16,18 @@ export default function UserRoleModal({ user, onClose, onChange }) {

const [userGroups, setUserGroups] = useState([])
const [userGroupSelected, setUserGroupSelected] = useState([])
const [error, setError] = useState(false)

useEffect(() => {
if (!user) return
// get用户组list
getUserGroupsApi().then(res => {
setUserGroups([{ id: 0, group_name: '默认用户组' }, ...res.records])
setUserGroups(res.records)
setUserGroupSelected(user.groups.map(el => el.id.toString()))
})
// get角色list
getRolesApi().then(data => {
//@ts-ignore
const roleOptions = data.filter(role => role.id !== 1)
.map(role => ({ ...role, role_id: role.id }))
const roleOptions = data.map(role => ({ ...role, role_id: role.id }))
setRoles(roleOptions);
setSelected(user.roles.map(el => el.id.toString()))
// getUserRoles(id).then(userRoles => {
Expand All @@ -40,14 +39,14 @@ export default function UserRoleModal({ user, onClose, onChange }) {
// setSelected(userRoles)
// })
})
setError(false)
}, [user])

const { message } = useToast()
const handleSave = async () => {
// if (!selected.length) return setError(true)
// if (userGroupSelected.length === 0) return setError(true)
captureAndAlertRequestErrorHoc(updateUserRoles(user.user_id, selected.filter(id => id !== '2')))
captureAndAlertRequestErrorHoc(updateUserGroups(user.user_id, userGroupSelected.filter(id => id !== '0')))
if (!selected.length) return message({ title: t('prompt'), variant: 'warning', description: '请选择角色' })
if (userGroupSelected.length === 0) return message({ title: t('prompt'), variant: 'warning', description: '请选择用户组' })
captureAndAlertRequestErrorHoc(updateUserRoles(user.user_id, selected))
captureAndAlertRequestErrorHoc(updateUserGroups(user.user_id, userGroupSelected))
onChange()
}

Expand All @@ -73,9 +72,9 @@ export default function UserRoleModal({ user, onClose, onChange }) {
<MultiSelect
multiple
className="max-w-[600px]"
value={['0', ...userGroupSelected]}
value={userGroupSelected}
options={groups}
lockedValues={["0"]}
placeholder={t('system.userGroupsSel')}
onChange={setUserGroupSelected}
>
</MultiSelect>
Expand All @@ -87,9 +86,9 @@ export default function UserRoleModal({ user, onClose, onChange }) {
<MultiSelect
multiple
className="max-w-[600px]"
value={['2', ...selected]}
value={selected}
options={_roles}
lockedValues={["2"]}
placeholder={t('system.roleSelect')}
onChange={setSelected}
>
</MultiSelect>
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/types/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export type AppConfig = {
dialog_tips: string;
dialog_quick_search: string;
websocket_url: string;
pro: boolean;
sso: boolean;
};

0 comments on commit 81d5445

Please sign in to comment.