index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import { Button, Radio, Tooltip, DatePicker, Popconfirm } from "antd";
  2. import React, { useCallback, useEffect, useRef, useState } from "react";
  3. import { ExclamationCircleFilled } from "@ant-design/icons";
  4. import styles from "./index.module.scss";
  5. import dayjs from "dayjs";
  6. import {
  7. editWallAutoApi,
  8. editWallTypeApi,
  9. getWallAutoApi,
  10. getWallCategoryoApi,
  11. getWallCategoryoListApi,
  12. } from "@/store/action/B3Wall";
  13. import { MessageFu } from "@/utils/message";
  14. import WallTable from "./WallTable";
  15. import WallAdd from "./WallAdd";
  16. const { RangePicker } = DatePicker;
  17. function Wall() {
  18. // 获取自动播放信息
  19. const getWallAutoApiFu = useCallback(async () => {
  20. const res = await getWallAutoApi();
  21. if (res.code === 0) {
  22. const data = JSON.parse(res.data.content);
  23. setValue0(data.isAuto);
  24. setTime0(data.startTime + "," + data.endTime);
  25. }
  26. }, []);
  27. // 获取文物类别展示信息
  28. const getWallCategoryApiFu = useCallback(async () => {
  29. const res = await getWallCategoryoApi();
  30. if (res.code === 0) {
  31. const data = JSON.parse(res.data.content);
  32. console.log(data);
  33. setValueType(data.isAuto);
  34. setTimeType0(data.startTime + "," + data.endTime);
  35. setTypeDisplay(data.type)
  36. setTypeEdit(data.type)
  37. }
  38. }, []);
  39. // 获取文物类别列表
  40. const getWallCategoryListApiFu = useCallback(async () => {
  41. const res = await getWallCategoryoListApi();
  42. if (res.code === 0) {
  43. console.log(res);
  44. setTypes(res.data);
  45. }
  46. }, []);
  47. useEffect(() => {
  48. getWallAutoApiFu();
  49. getWallCategoryApiFu();
  50. getWallCategoryListApiFu();
  51. }, [getWallAutoApiFu, getWallCategoryApiFu, getWallCategoryListApiFu]);
  52. // 场景管理的编辑
  53. const [edit, setEdit] = useState(false);
  54. // 自动轮播开启关闭的展示
  55. const [value0, setValue0] = useState(-1);
  56. // 自动轮播开启关闭的修改
  57. const [value1, setValue1] = useState(0);
  58. // 自动轮播时间的展示
  59. const [time0, setTime0] = useState(" , ");
  60. // 自动轮播时间的修改
  61. const [time1, setTime1] = useState<string[]>([]);
  62. // 场景管理的编辑
  63. const [editType, setEditType] = useState(false);
  64. // 文物类型开启关闭的展示
  65. const [valueType, setValueType] = useState(-1);
  66. // 文物类型开启关闭的修改
  67. const [value2, setValue2] = useState(0);
  68. // 文物类型时间的展示
  69. const [timeType0, setTimeType0] = useState(" , ");
  70. // 文物类型时间的修改
  71. const [timeType1, setTimeType1] = useState<string[]>([]);
  72. // 文物类型列表
  73. const [types, setTypes] = useState([]);
  74. // 文物类型展示
  75. const [typeDisplay, setTypeDisplay] = useState([]);
  76. // 文物类型修改
  77. const [typeEdit, setTypeEdit] = useState([]);
  78. // 点击修改(海报/场景)
  79. const editAutoPlay = useCallback(() => {
  80. setValue1(value0);
  81. setTime1(time0.split(","));
  82. setEdit(true);
  83. }, [time0, value0]);
  84. // 点击修改(文物类别)
  85. const editTypeFu = useCallback(() => {
  86. setValue2(valueType);
  87. setTimeType1(timeType0.split(","));
  88. setEditType(true);
  89. }, [timeType0, valueType]);
  90. // 时间选择器改变
  91. const timeChange = (date: any, dateString: any) => {
  92. setTime1(dateString);
  93. };
  94. // 时间选择器改变
  95. const timeTypeChange = (date: any, dateString: any) => {
  96. setTimeType1(dateString);
  97. console.log(dateString);
  98. };
  99. // 点击确定 (海报/场景)
  100. const btnOk = useCallback(async () => {
  101. const obj = {
  102. endTime: time1[1],
  103. startTime: time1[0],
  104. isAuto: value1,
  105. };
  106. const res: any = await editWallAutoApi({ content: JSON.stringify(obj) });
  107. if (res.code === 0) {
  108. MessageFu.success("修改成功!");
  109. getWallAutoApiFu();
  110. }
  111. setEdit(false);
  112. }, [getWallAutoApiFu, time1, value1]);
  113. // 点击确定 (类别)
  114. const btnOkType = useCallback(async () => {
  115. const obj = {
  116. endTime: timeType1[1],
  117. startTime: timeType1[0],
  118. isAuto: value2,
  119. type: typeEdit
  120. };
  121. const res: any = await editWallTypeApi({ content: JSON.stringify(obj) });
  122. if (res.code === 0) {
  123. MessageFu.success("修改成功!");
  124. getWallCategoryApiFu();
  125. }
  126. setEditType(false);
  127. }, [getWallCategoryApiFu, timeType1, typeEdit, value2]);
  128. // 点击新增或者编辑
  129. const [editId, setEditId] = useState(0);
  130. const scrollRef = useRef({
  131. txt: "",
  132. num: 0,
  133. });
  134. const tablePageIdFu = useCallback((id: number, scrollNum: number) => {
  135. scrollRef.current = { ...scrollRef.current, num: scrollNum };
  136. setEditId(id);
  137. }, []);
  138. // 新增海报
  139. const editTableFu = useCallback(() => {
  140. // 获取当前表格的滚动位置
  141. const dom: any = document.querySelector("#wallTable .ant-table-body");
  142. tablePageIdFu(-1, dom.scrollTop);
  143. }, [tablePageIdFu]);
  144. // 从新增/编辑页面点击取消或者提交
  145. const closeWallAddFu = useCallback((txt: string) => {
  146. scrollRef.current = { ...scrollRef.current, txt };
  147. setEditId(0);
  148. }, []);
  149. return (
  150. <div className={styles.Wall}>
  151. <div className="pageTitlt">
  152. {editId === 0 ? "万物墙管理" : editId > 0 ? "编辑海报" : "新增海报"}
  153. </div>
  154. {editId === 0 ? (
  155. // 初始页面盒子
  156. <>
  157. <div className="wallTopBox">
  158. <div className="titleTxt">
  159. 海报展示管理
  160. {/* <Tooltip title="当超过15秒未操作时,将在场景&emsp;&emsp;讲述/游览/赏析/临时展&emsp;&emsp;间循环播放,每个场景播放30秒">
  161. <div className="inco">
  162. <ExclamationCircleFilled />
  163. </div>
  164. </Tooltip> */}
  165. </div>
  166. {edit ? (
  167. // 修改信息
  168. <div className="edit">
  169. <div>自动轮播:</div>
  170. <Radio.Group
  171. onChange={(e) => setValue1(e.target.value)}
  172. value={value1}
  173. >
  174. <Radio value={0}>关闭</Radio>
  175. <Radio value={1}>开启</Radio>
  176. </Radio.Group>
  177. &emsp;
  178. <RangePicker
  179. allowClear={false}
  180. defaultValue={[
  181. dayjs(time1[0], "YYYY/MM/DD"),
  182. dayjs(time1[1], "YYYY/MM/DD"),
  183. ]}
  184. onChange={timeChange}
  185. />
  186. &emsp;
  187. <Button type="primary" onClick={btnOk}>
  188. 确定
  189. </Button>
  190. &emsp;
  191. <Popconfirm
  192. title="放弃编辑后,信息将不会保存!"
  193. okText="放弃"
  194. cancelText="取消"
  195. onConfirm={() => setEdit(false)}
  196. >
  197. <Button>取消</Button>
  198. </Popconfirm>
  199. </div>
  200. ) : (
  201. // 展示信息
  202. <div className="txt">
  203. <div>自动轮播:</div>
  204. <div>{value0 ? "开启" : "关闭"}&emsp;|&emsp;</div>
  205. <div>
  206. {time0.split(",")[0]} 至 {time0.split(",")[1]}
  207. </div>
  208. &emsp;&emsp;
  209. <Button type="primary" onClick={editAutoPlay}>
  210. 修改
  211. </Button>
  212. <Button
  213. type="primary"
  214. onClick={editTableFu}
  215. style={{ marginLeft: "10px" }}
  216. >
  217. 新增海报
  218. </Button>
  219. </div>
  220. )}
  221. {/* 表格相关 */}
  222. <WallTable
  223. tablePageIdFu={tablePageIdFu}
  224. scrollNumInfo={scrollRef.current}
  225. />
  226. </div>
  227. <div className="wallTopBox">
  228. <div className="titleTxt">
  229. 文物按类别展示
  230. <Tooltip title="当关闭时,万物墙将展示所有文物。">
  231. <div className="inco">
  232. <ExclamationCircleFilled />
  233. </div>
  234. </Tooltip>
  235. </div>
  236. {editType ? (
  237. // 修改信息
  238. <div>
  239. <div className="edit">
  240. <div>展示日期:</div>
  241. <Radio.Group
  242. onChange={(e) => setValue2(e.target.value)}
  243. value={value2}
  244. >
  245. <Radio value={0}>关闭</Radio>
  246. <Radio value={1}>开启</Radio>
  247. </Radio.Group>
  248. &emsp;
  249. <RangePicker
  250. allowClear={false}
  251. defaultValue={[
  252. dayjs(timeType1[0], "YYYY/MM/DD"),
  253. dayjs(timeType1[1], "YYYY/MM/DD"),
  254. ]}
  255. onChange={timeTypeChange}
  256. />
  257. &emsp;
  258. <Button type="primary" onClick={btnOkType}>
  259. 确定
  260. </Button>
  261. &emsp;
  262. <Popconfirm
  263. title="放弃编辑后,信息将不会保存!"
  264. okText="放弃"
  265. cancelText="取消"
  266. onConfirm={() => setEditType(false)}
  267. >
  268. <Button>取消</Button>
  269. </Popconfirm>
  270. </div>
  271. <div className="txt">
  272. <div style={{ marginRight: "5px" }}>展示类别:</div>
  273. <Radio.Group
  274. onChange={(e) => setTypeEdit(e.target.value)}
  275. value={typeEdit}
  276. >
  277. {types.map((item) => {
  278. return (
  279. <Radio key={item} value={item}>
  280. {item}
  281. </Radio>
  282. );
  283. })}
  284. </Radio.Group>
  285. </div>
  286. </div>
  287. ) : (
  288. // 展示信息
  289. <div>
  290. <div className="txt">
  291. <div style={{ marginRight: "5px" }}>展示日期:</div>
  292. <div>{valueType ? "开启" : "关闭"}&emsp;|&emsp;</div>
  293. <div>
  294. {timeType0.split(",")[0]} 至 {timeType0.split(",")[1]}
  295. </div>
  296. &emsp;&emsp;
  297. <Button type="primary" onClick={editTypeFu}>
  298. 修改
  299. </Button>
  300. </div>
  301. <div className="txt">
  302. <div style={{ marginRight: "5px" }}>展示类别:</div>
  303. <div>{typeDisplay}</div>
  304. </div>
  305. </div>
  306. )}
  307. </div>
  308. </>
  309. ) : (
  310. <WallAdd id={editId} closeMoalFu={closeWallAddFu} />
  311. )}
  312. </div>
  313. );
  314. }
  315. const MemoWall = React.memo(Wall);
  316. export default MemoWall;