Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

154 строки
4.6 KiB

  1. // material-ui
  2. import {FiDataGrid} from "components/FiDataGrid";
  3. import {useState, useEffect} from "react";
  4. import {useNavigate} from "react-router-dom";
  5. import { useTheme } from '@mui/material/styles';
  6. import Checkbox from '@mui/material/Checkbox';
  7. import * as HttpUtils from 'utils/HttpUtils';
  8. import { GLD_USER_PATH, GET_USER_LOCK, GET_USER_UNLOCK } from "utils/ApiPathConst";
  9. import { notifyLockSuccess, notifyUnlockSuccess , clickableLink} from 'utils/CommonFunction';
  10. import { isGrantedAny } from "auth/utils";
  11. import * as React from 'react';
  12. // ==============================|| EVENT TABLE ||============================== //
  13. export default function UserTable({searchCriteria, applyGridOnReady,applySearch}) {
  14. const [_searchCriteria, set_searchCriteria] = useState(searchCriteria);
  15. const [reloadTime, setReloadTime] = useState(new Date());
  16. const theme = useTheme();
  17. const navigate = useNavigate()
  18. useEffect(() => {
  19. set_searchCriteria(searchCriteria);
  20. }, [searchCriteria]);
  21. useEffect(() => {
  22. searchCriteria.reloadTime = reloadTime;
  23. set_searchCriteria(searchCriteria);
  24. }, [reloadTime]);
  25. const handleLock = (params) => () => {
  26. if(!isGrantedAny(["MAINTAIN_USER", "MAINTAIN_GLD_USER"])) return;
  27. if (params.row.locked==true){
  28. doUnlock(params.id)
  29. }else{
  30. doLock(params.id)
  31. }
  32. }
  33. const doLock = (id) => {
  34. HttpUtils.post({
  35. url: GET_USER_LOCK+"/"+id,
  36. onSuccess: function(){
  37. //setChangeLocked(true)
  38. notifyLockSuccess()
  39. setReloadTime(new Date());
  40. }
  41. });
  42. };
  43. const doUnlock = (id) => {
  44. HttpUtils.post({
  45. url: GET_USER_UNLOCK+"/"+id,
  46. onSuccess: function(){
  47. //setChangeLocked(true)
  48. notifyUnlockSuccess()
  49. setReloadTime(new Date());
  50. }
  51. });
  52. };
  53. const columns = [
  54. // {
  55. // field: 'actions',
  56. // type: 'actions',
  57. // headerName: 'Actions',
  58. // width: 100,
  59. // cellClassName: 'actions',
  60. // getActions: ({id}) => {
  61. // return [
  62. // <GridActionsCellItem
  63. // key="OutSave"
  64. // icon={<EditIcon/>}
  65. // label="Edit"
  66. // className="textPrimary"
  67. // onClick={handleEditClick(id)}
  68. // color="primary"
  69. // />]
  70. // },
  71. // },
  72. {
  73. id: 'username',
  74. field: 'username',
  75. headerName: 'Username',
  76. flex: 1,
  77. renderCell: (params) => {
  78. return clickableLink('/user/'+ params.row.id, params.row.username);
  79. },
  80. },
  81. {
  82. id: 'enName',
  83. field: 'enName',
  84. headerName: 'Full Name',
  85. flex: 1,
  86. },
  87. {
  88. id: 'post',
  89. field: 'post',
  90. headerName: 'Post',
  91. flex: 1,
  92. },
  93. {
  94. id: 'emailAddress',
  95. field: 'emailAddress',
  96. headerName: 'Email',
  97. flex: 1,
  98. },
  99. {
  100. id: 'locked',
  101. field: 'locked',
  102. type: 'bool',
  103. headerName: 'Locked',
  104. flex: 1,
  105. renderCell: (params) => {
  106. return (
  107. <Checkbox
  108. theme={theme}
  109. key="locked"
  110. checked={params.row.locked}
  111. color="primary"
  112. size="small"
  113. onClick={handleLock(params)}
  114. />
  115. );
  116. },
  117. },
  118. ];
  119. function handleRowDoubleClick(params) {
  120. navigate('/user/'+ params.id);
  121. }
  122. return (
  123. <div style={{height: "fit-content", width: '100%'}}>
  124. <FiDataGrid
  125. columns={columns}
  126. customPageSize={10}
  127. onRowDoubleClick={handleRowDoubleClick}
  128. getRowHeight={() => 'auto'}
  129. applyGridOnReady={applyGridOnReady}
  130. applySearch={applySearch}
  131. // doLoad={{
  132. // url: GLD_USER_PATH,
  133. // params: _searchCriteria,
  134. // }}
  135. doLoad={React.useMemo(() => ({
  136. url: GLD_USER_PATH,
  137. params: _searchCriteria,
  138. }), [_searchCriteria])}
  139. />
  140. </div>
  141. );
  142. }