index.tsx 11 KB

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