This commit is contained in:
yj 2024-12-13 12:17:18 +08:00
parent 8176c9b5d7
commit bfd629f264
2 changed files with 20 additions and 12 deletions

View File

@ -5,13 +5,16 @@ import { Button, Input, message, Modal } from 'antd';
import { useState, useImperativeHandle, forwardRef } from "react"; import { useState, useImperativeHandle, forwardRef } from "react";
const UserName = forwardRef((props: any, ref: any) => { const UserName = forwardRef((props: any, ref: any) => {
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
changeModal: (str: string) => { changeModal: (data: any) => {
setUserName(str) setInfo(data)
setUserNameModal(true) setUserNameModal(true)
} }
})) }))
const [userNameModal, setUserNameModal] = useState(false); const [userNameModal, setUserNameModal] = useState(false);
const [userName, setUserName] = useState(''); const [info, setInfo] = useState({
userName: '',
uid: ''
});
return ( return (
<> <>
<Modal <Modal
@ -28,9 +31,12 @@ const UserName = forwardRef((props: any, ref: any) => {
<Input <Input
placeholder="请输入用户名称" placeholder="请输入用户名称"
style={{ width: '100%' }} style={{ width: '100%' }}
value={userName} value={info.userName}
onChange={(e) => { onChange={(e) => {
setUserName(e.target.value) setInfo({
...info,
userName: e.target.value
})
}} }}
/> />
</div> </div>
@ -40,12 +46,11 @@ const UserName = forwardRef((props: any, ref: any) => {
<Button type="primary" <Button type="primary"
onClick={async () => { onClick={async () => {
const stateInfo = await JSON.parse(storage.getItem('stateInfo') as string); const stateInfo = await JSON.parse(storage.getItem('stateInfo') as string);
const userInfo = await JSON.parse(storage.getItem('user') as string); if (info.userName) {
if (userName) {
PutAlterUname({ PutAlterUname({
nickName: userName, nickName: info.userName,
roomNum: stateInfo.channelId, roomNum: stateInfo.channelId,
uid: userInfo.uid, uid: info.uid,
}).then((res) => { }).then((res) => {
if (res.code === 200) { if (res.code === 200) {
message.success('修改成功') message.success('修改成功')

View File

@ -1284,7 +1284,7 @@ const Meeting: React.FC = () => {
break; break;
case 'ModifyNickName': case 'ModifyNickName':
setRoomUserList((res: any) => { setRoomUserList((res: any) => {
let userItem = res.find((row: any) => row.uid === item.uid) let userItem = res.find((row: any) => row.uid == item.uid)
if (userItem) { if (userItem) {
userItem.userName = item.nickName userItem.userName = item.nickName
} }
@ -2505,9 +2505,12 @@ const Meeting: React.FC = () => {
<Button <Button
type="primary" type="primary"
className='m-ant-btn' className='m-ant-btn'
style={{ width: '100%' }} style={{ width: '100%', marginTop: '10px' }}
onClick={() => { onClick={() => {
userNameRef.current.changeModal(item.userName) userNameRef.current.changeModal({
userName: item.userName,
uid: item.uid
})
}} }}
></Button> ></Button>
</div> </div>