OperationRecord.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import PageContent from '@/components/PageContent';
  2. import PageTitle from '@/components/PageTitle';
  3. import ScrollLoading from '@/components/ScrollLoading';
  4. import { getVarValues } from '@/services/DeviceInfo';
  5. import { useNavigate, useParams, useRequest } from '@umijs/max';
  6. import { Button, DatePicker, Select, Table } from 'antd';
  7. import dayjs from 'dayjs';
  8. import { useEffect, useState } from 'react';
  9. import styles from './index.less';
  10. const { RangePicker } = DatePicker;
  11. const { Option } = Select;
  12. const OperationRecord = (props) => {
  13. const { projectId } = useParams();
  14. const navigate = useNavigate();
  15. const convertObject2FormData = (params) => {
  16. const formData = new FormData();
  17. Object.entries(params).forEach(([key, value]) => {
  18. if (value !== null && value !== undefined && value !== NaN) {
  19. formData.append(key, value);
  20. }
  21. });
  22. return formData;
  23. };
  24. const defaultParams = {
  25. project_id: Number(projectId),
  26. s_time: '',
  27. e_time: '',
  28. cause_type: '',
  29. currentPage: 1,
  30. pageSize: 20,
  31. };
  32. const [data, setData] = useState([]);
  33. const [pagination, setPagination] = useState({});
  34. const [queryParams, setQueryParams] = useState(defaultParams);
  35. const [formData, setFormData] = useState(
  36. convertObject2FormData(defaultParams),
  37. );
  38. const { run: getList, loading } = useRequest(
  39. (params = formData) => getVarValues(params),
  40. {
  41. onSuccess: (res) => {
  42. if (res.pagination?.current == 1) {
  43. setData(res?.list);
  44. } else {
  45. setData([...data, ...res?.list]);
  46. }
  47. setPagination(res.pagination);
  48. },
  49. },
  50. );
  51. const columns = [
  52. {
  53. title: '操作时间',
  54. dataIndex: 'c_time',
  55. key: 'c_time',
  56. align: 'center',
  57. render: (value) => {
  58. return <div>{dayjs(value).format('YYYY-MM-DD HH:mm')}</div>;
  59. },
  60. },
  61. {
  62. title: '操作类型',
  63. dataIndex: 'cause_type',
  64. key: 'cause_type',
  65. render: (text) => {
  66. if (Number(text) === 0) {
  67. return '自主操作';
  68. }
  69. if (Number(text) === 1) {
  70. return '系统任务';
  71. }
  72. return '系统自控';
  73. },
  74. },
  75. {
  76. title: '来源',
  77. dataIndex: 'source',
  78. key: 'source',
  79. render: (text) => {
  80. if (text === undefined) {
  81. return '-';
  82. }
  83. const temp = Number(text);
  84. if (temp === 0) {
  85. return '客户端';
  86. }
  87. if (temp === 1) {
  88. return '移动端';
  89. }
  90. if (temp === 2) {
  91. return 'Pad端';
  92. }
  93. return '系统';
  94. },
  95. },
  96. {
  97. title: '点位名称',
  98. dataIndex: 'item_alias',
  99. key: 'item_alias',
  100. align: 'center',
  101. render: (text) => {
  102. if (!text) {
  103. return '--';
  104. }
  105. return text;
  106. },
  107. },
  108. {
  109. title: '设备名称',
  110. dataIndex: 'device_name',
  111. key: 'device_name',
  112. align: 'center',
  113. render: (text) => {
  114. if (!text) {
  115. return '--';
  116. }
  117. return text;
  118. },
  119. },
  120. {
  121. title: '操作前数值',
  122. dataIndex: 'old_value',
  123. key: 'old_value',
  124. align: 'center',
  125. render: (text) => {
  126. if (!text) {
  127. return '--';
  128. }
  129. return text;
  130. },
  131. },
  132. {
  133. title: '操作后数值',
  134. dataIndex: 'new_value',
  135. key: 'new_value',
  136. align: 'center',
  137. render: (text) => {
  138. if (!text) {
  139. return '--';
  140. }
  141. return text;
  142. },
  143. },
  144. {
  145. title: '操作人',
  146. dataIndex: 'operator_name',
  147. key: 'operator_name',
  148. align: 'center',
  149. render: (text) => {
  150. if (!text) {
  151. return '--';
  152. }
  153. return text;
  154. },
  155. },
  156. ];
  157. const handleParamsChange = (key, value) => {
  158. const tempParams = {
  159. project_id: Number(projectId),
  160. s_time: queryParams.s_time || '',
  161. e_time: queryParams.e_time || '',
  162. cause_type: queryParams.cause_type || '',
  163. source: queryParams.source || '',
  164. currentPage: 1,
  165. pageSize: queryParams.pageSize || 20,
  166. };
  167. switch (key) {
  168. case 'cause_type':
  169. case 'source':
  170. tempParams[key] = value;
  171. break;
  172. case 'date':
  173. tempParams.currentPage = 1;
  174. if (value?.length === 2) {
  175. tempParams.s_time = dayjs(value[0]).format('YYYY-MM-DD 00:00:00');
  176. tempParams.e_time = dayjs(value[1]).format('YYYY-MM-DD 23:59:59');
  177. } else {
  178. tempParams.s_time = '';
  179. tempParams.e_time = '';
  180. }
  181. break;
  182. case 'page':
  183. tempParams.currentPage = value;
  184. handleSearch(convertObject2FormData(tempParams));
  185. default:
  186. break;
  187. }
  188. setQueryParams(tempParams);
  189. };
  190. const handleSearch = (params) => {
  191. if (params !== undefined) {
  192. getList(params);
  193. return;
  194. }
  195. getList(formData);
  196. };
  197. useEffect(() => {
  198. const tempFormData = convertObject2FormData(queryParams);
  199. // page变更自动请求接口
  200. setFormData(tempFormData);
  201. }, [queryParams]);
  202. return (
  203. <PageContent closeable={false}>
  204. <PageTitle returnable>操作记录</PageTitle>
  205. <div className={styles.searchContent}>
  206. <RangePicker
  207. inputReadOnly
  208. className={[styles.timePicker, styles.marginRight].join(' ')}
  209. onChange={(value) => handleParamsChange('date', value)}
  210. />
  211. {/* <span>操作类型:</span> */}
  212. <Select
  213. placeholder="请选择操作类型"
  214. popupMatchSelectWidth
  215. style={{ width: '2.5rem' }}
  216. onChange={(value) => handleParamsChange('cause_type', value)}
  217. allowClear
  218. >
  219. <Option value="0">自主操作</Option>
  220. <Option value="1">系统任务</Option>
  221. <Option value="2">系统自控</Option>
  222. </Select>
  223. {/* <span>来源:</span> */}
  224. <Select
  225. style={{ width: '2rem' }}
  226. placeholder="请选择来源"
  227. onChange={(value) => handleParamsChange('source', value)}
  228. allowClear
  229. >
  230. <Option value="0">客户端</Option>
  231. <Option value="1">移动端</Option>
  232. <Option value="2">Pad端</Option>
  233. <Option value="3">系统</Option>
  234. </Select>
  235. <Button
  236. className={styles.marginLeft}
  237. style={{
  238. height: '0.44rem',
  239. display: 'flex',
  240. // justifyContent: 'center',
  241. alignItems: 'center',
  242. }}
  243. type="primary"
  244. onClick={() => handleSearch()}
  245. >
  246. <div>查询</div>
  247. </Button>
  248. </div>
  249. <ScrollLoading
  250. loading={loading}
  251. pagination={pagination}
  252. handleLoadData={(current) => handleParamsChange('page', current)}
  253. >
  254. <Table dataSource={data || []} columns={columns} pagination={false} />
  255. </ScrollLoading>
  256. </PageContent>
  257. );
  258. };
  259. export default OperationRecord;