Skip to content

Commit

Permalink
update code optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxin666789 committed Oct 9, 2024
1 parent 9238005 commit 5b0be7e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
57 changes: 33 additions & 24 deletions web/src/pages/meeting-white-list/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,43 @@ import {
PostUpdateWhiteList,
} from "../../api/white-list";
import { IIWhiteListsDto } from "../../dtos/white-list";
import { IAddEditWhiteListDto, IWhiteListsRequest } from "./props";

const useAction = () => {
const [successText, setSuccessText] = useState<string>("");

const [success, successAction] = useBoolean(false);

const [failSend, failSendAction] = useBoolean(false);

const [loading, loadingAction] = useBoolean(false);

const [failSendText, setFailSendText] = useState<string>("");

const [isConfirmDialog, confirmDialogAction] = useBoolean(false);

const [openAddWhiteList, setOpenAddWhiteList] = useState<boolean>(false);

const [updateLoading, setUpdateLoading] = useState<boolean>(false);

const [delLoading, setDelLoading] = useState<boolean>(false);
const [dto, setDto] = useState({
pageIndex: 0,
pageSize: 10,
rowCount: 0,
ketWord: "",
});
const [addEditWhiteListDto, setAddEditWhiteListDto] = useState<{
MeetingCode: string;
NotifyUserId: string;
type: "add" | "edit";
Id: string;
}>({
MeetingCode: "",
NotifyUserId: "",
type: "add",
Id: "",
});

const [whiteListsRequest, setWhiteListsRequest] =
useState<IWhiteListsRequest>({
pageIndex: 0,
pageSize: 10,
rowCount: 0,
keyword: "",
});

const [addEditWhiteListDto, setAddEditWhiteListDto] =
useState<IAddEditWhiteListDto>({
MeetingCode: "",
NotifyUserId: "",
type: "add",
Id: "",
});

const [rows, setRows] = useState<IIWhiteListsDto[]>([]);

const handleCopyMeetingLink = (link: string) => {
Expand All @@ -48,17 +57,17 @@ const useAction = () => {

const getMeetingList = () => {
const data = {
PageIndex: dto.pageIndex + 1,
PageSize: dto.pageSize,
KeyWord: dto.ketWord,
PageIndex: whiteListsRequest.pageIndex + 1,
PageSize: whiteListsRequest.pageSize,
KeyWord: whiteListsRequest.keyword,
};
loadingAction.setTrue();

GetWhiteLists(data)
.then((res) => {
if (res && res.whitelist) {
setRows(res.whitelist);
setDto((prev) => ({ ...prev, rowCount: res.count }));
setWhiteListsRequest((prev) => ({ ...prev, rowCount: res.count }));
loadingAction.setFalse();
} else {
failSendAction.setTrue();
Expand Down Expand Up @@ -130,7 +139,7 @@ const useAction = () => {

useEffect(() => {
getMeetingList();
}, [dto.pageIndex, dto.pageSize]);
}, [whiteListsRequest.pageIndex, whiteListsRequest.pageSize]);

// 延迟关闭警告提示
useEffect(() => {
Expand All @@ -150,9 +159,9 @@ const useAction = () => {
failSend,
failSendText,
successText,
dto,
whiteListsRequest,
rows,
setDto,
setWhiteListsRequest,
handleCopyMeetingLink,
isConfirmDialog,
confirmDialogAction,
Expand Down
14 changes: 7 additions & 7 deletions web/src/pages/meeting-white-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const MeetingWhiteList = () => {
failSend,
failSendText,
successText,
dto,
setDto,
whiteListsRequest,
setWhiteListsRequest,
loading,
isConfirmDialog,
confirmDialogAction,
Expand Down Expand Up @@ -158,8 +158,8 @@ const MeetingWhiteList = () => {
<DataGrid
rows={rows}
columns={columns}
pageSize={dto.pageSize}
page={dto.pageIndex}
pageSize={whiteListsRequest.pageSize}
page={whiteListsRequest.pageIndex}
showCellRightBorder
showColumnRightBorder
rowsPerPageOptions={[5, 10, 15, 20]}
Expand All @@ -169,12 +169,12 @@ const MeetingWhiteList = () => {
paginationMode="server"
rowHeight={56}
style={{ height: 700, width: "95%" }}
rowCount={dto.rowCount}
rowCount={whiteListsRequest.rowCount}
onPageChange={(value) =>
setDto((prve) => ({ ...prve, pageIndex: value }))
setWhiteListsRequest((prve) => ({ ...prve, pageIndex: value }))
}
onPageSizeChange={(value) =>
setDto((prve) => ({ ...prve, pageSize: value }))
setWhiteListsRequest((prve) => ({ ...prve, pageSize: value }))
}
/>
</div>
Expand Down
13 changes: 13 additions & 0 deletions web/src/pages/meeting-white-list/props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface IAddEditWhiteListDto {
MeetingCode: string;
NotifyUserId: string;
type: "add" | "edit";
Id: string;
}

export interface IWhiteListsRequest {
pageIndex: number;
pageSize: number;
rowCount: number;
keyword: string;
}

0 comments on commit 5b0be7e

Please sign in to comment.