ProjectList.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import React, {
  2. useState,
  3. useEffect,
  4. useRef,
  5. useMemo,
  6. ChangeEvent,
  7. } from 'react';
  8. import { Input, Tooltip } from 'antd';
  9. import style from './ProjectList.less';
  10. import ReactZmage from 'react-zmage';
  11. import PinyinMatch from 'pinyin-match';
  12. import { ChartBoxTitle } from './ChartBox';
  13. import { useRequest } from '@umijs/max';
  14. import { getProjectList } from '@/Project/services/DataMeter';
  15. let LoopTime: NodeJS.Timer;
  16. let searchTimer: NodeJS.Timer;
  17. const nodata = require('@/Project/assets/dataMeter/ProjectList/nodata.png');
  18. const clickTimer = 20000;
  19. const normalTimer = 15000;
  20. function ProjectList(props: DataMeter.IProjectListProps) {
  21. const { edit, subModule, layout } = props;
  22. const [currentProject, setCurrentProject] = useState<Api.IProject>();
  23. const [currentIndex, setCurrentIndex] = useState(0);
  24. // const [queryList, setQueryList] = useState<Api.IProject[]>([]);
  25. const [isClick, setIsClick] = useState(false);
  26. const [isPlay, setIsPlay] = useState(false);
  27. const [value, setValue] = useState<string>('');
  28. const ulRef = useRef<HTMLUListElement>(null);
  29. const ProjectListRequest = useRequest(getProjectList, {
  30. cacheKey: 'projectList',
  31. staleTime: -1,
  32. });
  33. const projectList = ProjectListRequest.data?.list || [];
  34. const list = useMemo<Api.IProject[]>(() => {
  35. const arr = projectList.filter((item: Api.IProject) => {
  36. let flag = subModule == 0 || item?.Stage == subModule || item?.Stage == 3;
  37. if (!flag) return;
  38. if (value) {
  39. return PinyinMatch.match(item.Name, value);
  40. }
  41. return flag;
  42. });
  43. return arr;
  44. }, [projectList]);
  45. // const getProjectList = (params, callback) => {
  46. // dispatch({
  47. // type: 'dataMeterNew/getProjectList',
  48. // payload: params,
  49. // callback: (res) => {
  50. // res = res.filter((item) => {
  51. // if (isPlatform != undefined) return true;
  52. // if (subModule == 0) return true;
  53. // else {
  54. // if (item?.Stage == subModule || item?.Stage == 3) return true;
  55. // }
  56. // });
  57. // // console.log(subModule, res);
  58. // setQueryList(res);
  59. // setCurrentIndex(0);
  60. // setCurrentProject(res[0] || {});
  61. // callback && callback(res);
  62. // },
  63. // });
  64. // };
  65. // useEffect(() => {
  66. // getProjectList();
  67. // return () => {
  68. // clearInterval(LoopTime);
  69. // };
  70. // }, []);
  71. // useEffect(() => {
  72. // if (isPlay) {
  73. // getProjectList({ carousel: 1 }, (res) => {
  74. // res = res.filter((item) => {
  75. // if (isPlatform != undefined) return true;
  76. // if (subModule == 0) return true;
  77. // else {
  78. // if (item?.Stage == subModule || item?.Stage == 3) return true;
  79. // }
  80. // });
  81. // setQueryList(res);
  82. // inputRef.current.value = '';
  83. // setCurrentProject(res[0] || {});
  84. // setProjectId(res[0].ID || 0);
  85. // ChangedProject(res[0] || {});
  86. // onPlayCallback && onPlayCallback();
  87. // ulRef.current.scrollTop = 0;
  88. // });
  89. // } else {
  90. // getProjectList({}, (res) => {
  91. // clearInterval(LoopTime);
  92. // inputRef.current.value = '';
  93. // setProjectId(0);
  94. // });
  95. // }
  96. // // // console.log(isPlay);
  97. // return () => {};
  98. // }, [isPlay]);
  99. // useEffect(() => {
  100. // UnityAction.on('projectCarousel', (isPlay) => {
  101. // setIsPlay(() => isPlay);
  102. // if (!isPlay) {
  103. // // else
  104. // OnPauseCallback && OnPauseCallback();
  105. // }
  106. // });
  107. // return () => {
  108. // UnityAction.off('projectCarousel');
  109. // clearInterval(LoopTime);
  110. // };
  111. // }, []);
  112. // const StartTimeout = (time:number) => {
  113. // LoopTime = setInterval(() => {
  114. // if (queryList.length > 0) {
  115. // var count = queryList.length;
  116. // var index;
  117. // if (currentIndex < count - 1) {
  118. // index = currentIndex + 1;
  119. // } else {
  120. // index = 0;
  121. // }
  122. // // console.log(currentIndex, queryList[index].Name);
  123. // cleanProjectData && cleanProjectData();
  124. // setCurrentIndex(index);
  125. // setCurrentProject(queryList[index]);
  126. // setProjectId(queryList[index].ID);
  127. // ChangedProject(queryList[index]);
  128. // // console.log(33333);
  129. // ulRef.current.scrollTop =
  130. // ulRef.current?.children &&
  131. // ulRef.current.children[index].clientHeight * index -
  132. // ulRef.current.clientHeight / 2 +
  133. // ulRef.current.children[index].clientHeight * 0.5 +
  134. // 6 * index +
  135. // 28;
  136. // }
  137. // }, time);
  138. // };
  139. // const sendProjectToUnity = () => {
  140. // UnityAction.sendMsg('project', JSON.stringify(currentProject));
  141. // };
  142. // const sendNoModelToUnity = () => {
  143. // UnityAction.sendMsg('noModel', JSON.stringify(currentProject));
  144. // };
  145. const onChangeInput = (e: ChangeEvent<HTMLInputElement>) => {
  146. setValue(e.target.value);
  147. };
  148. // useEffect(() => {
  149. // const timer = isClick ? clickTimer : normalTimer;
  150. // if (isClick) setIsClick(false);
  151. // if (isPlay) StartTimeout(timer);
  152. // return () => {
  153. // clearInterval(LoopTime);
  154. // };
  155. // }, [currentIndex, queryList]);
  156. return (
  157. <div className={style.main}>
  158. <ChartBoxTitle title="数字实景" width={layout.w} />
  159. <div className={style.container}>
  160. <div className={style.left}>
  161. <div className={style.search}>
  162. <input
  163. onChange={onChangeInput}
  164. type="text"
  165. placeholder="请输入项目"
  166. placeholder-style={{ color: '#366CDA', fondSize: '18px' }}
  167. ></input>
  168. <img
  169. src={require('@/Project/assets/dataMeter/ProjectList/search_Icon.png')}
  170. ></img>
  171. </div>
  172. <ul ref={ulRef} className={style.list}>
  173. {list.map((item, index) => {
  174. return (
  175. <li
  176. className={currentIndex == index ? style.active : ''}
  177. key={item.ID}
  178. onClick={() => {
  179. // clearInterval(LoopTime);
  180. // setIsClick(true);
  181. setCurrentProject(item);
  182. setCurrentIndex(index);
  183. // if (isPlay) {
  184. // setProjectId(item.ID);
  185. // ChangedProject(item);
  186. // }
  187. // if (currentIndex == index) {
  188. // if (isClick) setIsClick(false);
  189. // if (isPlay) StartTimeout(clickTimer);
  190. // }
  191. }}
  192. >
  193. {item.Name}
  194. </li>
  195. );
  196. })}
  197. </ul>
  198. </div>
  199. <div className={style.line}></div>
  200. <div className={style.right}>
  201. <div
  202. className={style.image}
  203. onClick={() => {
  204. if (edit) return;
  205. // document.getElementsByClassName('reactZmage')[0]?.click();
  206. }}
  207. style={{
  208. backgroundImage: `url('${currentProject?.ScreenShot || nodata}')`,
  209. cursor: 'pointer',
  210. }}
  211. ></div>
  212. <ReactZmage
  213. controller={{
  214. close: true,
  215. rotate: true,
  216. zoom: false,
  217. download: false,
  218. flip: false,
  219. pagination: false,
  220. }}
  221. backdrop="rgba(255,255,255,0.5)"
  222. src={currentProject?.ScreenShot || nodata}
  223. onBrowsing={(state) => {
  224. // if (state) {
  225. // clearInterval(LoopTime);
  226. // } else {
  227. // if (isPlay) StartTimeout(normalTimer);
  228. // }
  229. }}
  230. />
  231. <div className={style.bottom}>
  232. <div className={style.context}>{currentProject?.Remark}</div>
  233. <div className={style.right_bottom}>
  234. <div className={style.province}>
  235. {currentProject?.Province}
  236. <Tooltip title={currentProject?.Name}>
  237. <div className={style.name}>{currentProject?.Name}</div>
  238. </Tooltip>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. );
  246. }
  247. export default ProjectList;