Other.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import React, { useState, useEffect } from 'react';
  2. import { Popover, Radio, Avatar, Tooltip, Empty, Table } from 'antd';
  3. import style from '../index.less';
  4. import moment from 'moment';
  5. import { ChartBoxTitle } from './ChartBox';
  6. import { useModel, useRequest } from '@umijs/max';
  7. import { queryProjectFileList } from '@/Project/services/FileAdmin';
  8. import { getDailyList } from '@/Project/services/DataMeter';
  9. function Other(props: DataMeter.IModelsProps) {
  10. const { child, setActive, layout, projectId, subModule } = props;
  11. const [active, setSelfActive] = useState(
  12. layout.active || child.find((item) => item.show)?.key,
  13. );
  14. const [showTabs, setShowTabs] = useState(false);
  15. const [title, setTitle] = useState('');
  16. const { getProject } = useModel('project');
  17. const id = projectId || -1;
  18. const fileListRequest = useRequest(queryProjectFileList, {
  19. defaultParams: [
  20. {
  21. fileType: 29,
  22. projectId: id,
  23. deviceCode: -1,
  24. },
  25. ],
  26. });
  27. const dailyListRequest = useRequest(getDailyList, {
  28. defaultParams: [
  29. {
  30. projectId: id,
  31. },
  32. ],
  33. });
  34. const fileList = fileListRequest.data || [];
  35. const dailyList = dailyListRequest.data?.list || [];
  36. useEffect(() => {
  37. const current = child.find(
  38. (item: DataMeter.ILayoutChild) => item.key == active,
  39. );
  40. if (current) setTitle(current.title);
  41. }, [active]);
  42. const getTitle = (title: string) => {
  43. return (
  44. <Popover
  45. placement="topLeft"
  46. content={<div style={{ maxWidth: '2rem' }}>{title}</div>}
  47. >
  48. {title}
  49. </Popover>
  50. );
  51. };
  52. var content;
  53. switch (active) {
  54. case 1:
  55. if (fileList.length > 0) {
  56. content = (
  57. <>
  58. <table
  59. className={style.other}
  60. style={{ width: 'calc(100% - 16px)' }}
  61. >
  62. <thead>
  63. <tr>
  64. <th
  65. style={
  66. subModule == 0
  67. ? { width: '40%', paddingRight: '10px' }
  68. : { width: '50%', paddingRight: '10px' }
  69. }
  70. >
  71. 文件名称
  72. </th>
  73. <th
  74. style={
  75. subModule == 0
  76. ? { width: '20%', paddingRight: '10px' }
  77. : { width: '50%', paddingRight: '10px' }
  78. }
  79. >
  80. 日期
  81. </th>
  82. {subModule == 0 && (
  83. <th
  84. style={
  85. subModule == 0
  86. ? { width: '40%', paddingRight: '10px' }
  87. : { width: '50%', paddingRight: '10px' }
  88. }
  89. >
  90. 项目名称
  91. </th>
  92. )}
  93. </tr>
  94. </thead>
  95. </table>
  96. <div
  97. style={{
  98. overflowY: 'scroll',
  99. height: 'calc(100% - 24px)',
  100. }}
  101. >
  102. <table className={style.other}>
  103. <tbody>
  104. {fileList.map((item: any) => (
  105. <>
  106. <tr className={style.messageContent} key={item.Id}>
  107. <td
  108. style={
  109. subModule == 0
  110. ? { width: '40%', paddingRight: '10px' }
  111. : { width: '50%', paddingRight: '10px' }
  112. }
  113. className={style.alarmTitle}
  114. >
  115. {getTitle(item.Name)}
  116. </td>
  117. <td
  118. style={
  119. subModule == 0
  120. ? { width: '20%', paddingRight: '10px' }
  121. : { width: '50%', paddingRight: '10px' }
  122. }
  123. >
  124. {moment(item.CreatedTime).format('YYYY-MM-DD')}
  125. </td>
  126. {subModule == 0 && (
  127. <td
  128. style={{ width: '40%', paddingRight: '10px' }}
  129. className={style.alarmTitle}
  130. >
  131. {getTitle(getProject(item.ProjectId)?.Name || '无')}
  132. </td>
  133. )}
  134. </tr>
  135. </>
  136. ))}
  137. </tbody>
  138. </table>
  139. </div>
  140. </>
  141. );
  142. } else {
  143. content = <Empty />;
  144. }
  145. break;
  146. case 2:
  147. if (dailyList.length > 0) {
  148. content = (
  149. <>
  150. <table
  151. className={style.other}
  152. style={{ width: 'calc(100% - 16px)' }}
  153. >
  154. <thead>
  155. <tr>
  156. <th
  157. style={
  158. subModule == 0
  159. ? { width: '25%', paddingRight: '10px' }
  160. : { width: '50%', paddingRight: '10px' }
  161. }
  162. >
  163. 创建人
  164. </th>
  165. <th
  166. style={
  167. subModule == 0
  168. ? { width: '20%', paddingRight: '10px' }
  169. : { width: '50%', paddingRight: '10px' }
  170. }
  171. >
  172. 日期
  173. </th>
  174. {subModule == 0 && (
  175. <th style={{ width: '55%', paddingRight: '10px' }}>
  176. 项目名称
  177. </th>
  178. )}
  179. </tr>
  180. </thead>
  181. </table>
  182. <div
  183. style={{
  184. overflowY: 'scroll',
  185. height: 'calc(100% - 24px)',
  186. }}
  187. >
  188. <table className={style.other}>
  189. <tbody>
  190. {dailyList.map((item: any) => (
  191. <>
  192. <tr className={style.messageContent} key={item.id}>
  193. <td
  194. style={
  195. subModule == 0
  196. ? { width: '25%', paddingRight: '10px' }
  197. : { width: '50%', paddingRight: '10px' }
  198. }
  199. className={style.alarmTitle}
  200. >
  201. {getTitle(item.CreatorUser.CName)}
  202. </td>
  203. <td
  204. style={
  205. subModule == 0
  206. ? { width: '20%', paddingRight: '10px' }
  207. : { width: '50%', paddingRight: '10px' }
  208. }
  209. >
  210. {moment(item.ReportDate).format('YYYY-MM-DD')}
  211. </td>
  212. {subModule == 0 && (
  213. <td
  214. style={{ width: '55%', paddingRight: '10px' }}
  215. className={style.alarmTitle}
  216. >
  217. {getTitle(getProject(item.ProjectId)?.Name || '无')}
  218. </td>
  219. )}
  220. </tr>
  221. </>
  222. ))}
  223. </tbody>
  224. </table>
  225. </div>
  226. </>
  227. );
  228. } else {
  229. content = <Empty />;
  230. }
  231. break;
  232. }
  233. return (
  234. <div className={style.modelBox}>
  235. <ChartBoxTitle
  236. title={title}
  237. showTabs={showTabs}
  238. setShowTabs={setShowTabs}
  239. width={layout.w}
  240. ></ChartBoxTitle>
  241. {showTabs && (
  242. <ul className={style.tabsList}>
  243. {(child || [])
  244. .filter((item: DataMeter.ILayoutChild) => item.show)
  245. .map((item: DataMeter.ILayoutChild, index: number) => (
  246. <li
  247. key={index}
  248. className={`${active == item.key ? style.active : ''}`}
  249. onClick={() => {
  250. setActive(item.key);
  251. setSelfActive(item.key);
  252. }}
  253. >
  254. {item.title}
  255. </li>
  256. ))}
  257. </ul>
  258. )}
  259. <div
  260. style={{
  261. paddingTop: '10px',
  262. paddingLeft: '14px',
  263. flex: 1,
  264. height: 0,
  265. }}
  266. >
  267. {content}
  268. </div>
  269. </div>
  270. );
  271. }
  272. export default Other;