123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- import { Button, Radio, Tooltip, DatePicker, Popconfirm } from "antd";
- import React, { useCallback, useEffect, useRef, useState } from "react";
- import { ExclamationCircleFilled } from "@ant-design/icons";
- import styles from "./index.module.scss";
- import dayjs from "dayjs";
- import {
- editWallAutoApi,
- editWallTypeApi,
- getWallAutoApi,
- getWallCategoryoApi,
- getWallCategoryoListApi,
- } from "@/store/action/B3Wall";
- import { MessageFu } from "@/utils/message";
- import WallTable from "./WallTable";
- import WallAdd from "./WallAdd";
- const { RangePicker } = DatePicker;
- function Wall() {
- // 获取自动播放信息
- const getWallAutoApiFu = useCallback(async () => {
- const res = await getWallAutoApi();
- if (res.code === 0) {
- const data = JSON.parse(res.data.content);
- setValue0(data.isAuto);
- setTime0(data.startTime + "," + data.endTime);
- }
- }, []);
- // 获取文物类别展示信息
- const getWallCategoryApiFu = useCallback(async () => {
- const res = await getWallCategoryoApi();
- if (res.code === 0) {
- const data = JSON.parse(res.data.content);
- console.log(data);
- setValueType(data.isAuto);
- setTimeType0(data.startTime + "," + data.endTime);
- setTypeDisplay(data.type)
- }
- }, []);
- // 获取文物类别列表
- const getWallCategoryListApiFu = useCallback(async () => {
- const res = await getWallCategoryoListApi();
- if (res.code === 0) {
- console.log(res);
- setTypes(res.data);
- }
- }, []);
- useEffect(() => {
- getWallAutoApiFu();
- getWallCategoryApiFu();
- getWallCategoryListApiFu();
- }, [getWallAutoApiFu, getWallCategoryApiFu, getWallCategoryListApiFu]);
- // 场景管理的编辑
- const [edit, setEdit] = useState(false);
- // 自动轮播开启关闭的展示
- const [value0, setValue0] = useState(-1);
- // 自动轮播开启关闭的修改
- const [value1, setValue1] = useState(0);
- // 自动轮播时间的展示
- const [time0, setTime0] = useState(" , ");
- // 自动轮播时间的修改
- const [time1, setTime1] = useState<string[]>([]);
- // 场景管理的编辑
- const [editType, setEditType] = useState(false);
- // 文物类型开启关闭的展示
- const [valueType, setValueType] = useState(-1);
- // 文物类型开启关闭的修改
- const [value2, setValue2] = useState(0);
- // 文物类型时间的展示
- const [timeType0, setTimeType0] = useState(" , ");
- // 文物类型时间的修改
- const [timeType1, setTimeType1] = useState<string[]>([]);
- // 文物类型列表
- const [types, setTypes] = useState([]);
- // 文物类型展示
- const [typeDisplay, setTypeDisplay] = useState([]);
- // 文物类型修改
- const [typeEdit, setTypeEdit] = useState([]);
- // 点击修改(海报/场景)
- const editAutoPlay = useCallback(() => {
- setValue1(value0);
- setTime1(time0.split(","));
- setEdit(true);
- }, [time0, value0]);
- // 点击修改(文物类别)
- const editTypeFu = useCallback(() => {
- setValue2(valueType);
- setTimeType1(timeType0.split(","));
- setEditType(true);
- }, [timeType0, valueType]);
- // 时间选择器改变
- const timeChange = (date: any, dateString: any) => {
- setTime1(dateString);
- };
- // 时间选择器改变
- const timeTypeChange = (date: any, dateString: any) => {
- setTimeType1(dateString);
- console.log(dateString);
- };
- // 点击确定 (海报/场景)
- const btnOk = useCallback(async () => {
- const obj = {
- endTime: time1[1],
- startTime: time1[0],
- isAuto: value1,
- };
- const res: any = await editWallAutoApi({ content: JSON.stringify(obj) });
- if (res.code === 0) {
- MessageFu.success("修改成功!");
- getWallAutoApiFu();
- }
- setEdit(false);
- }, [getWallAutoApiFu, time1, value1]);
- // 点击确定 (类别)
- const btnOkType = useCallback(async () => {
- const obj = {
- endTime: timeType1[1],
- startTime: timeType1[0],
- isAuto: value2,
- type: typeEdit
- };
- const res: any = await editWallTypeApi({ content: JSON.stringify(obj) });
- if (res.code === 0) {
- MessageFu.success("修改成功!");
- getWallCategoryApiFu();
- }
- setEditType(false);
- }, [getWallCategoryApiFu, timeType1, typeEdit, value2]);
- // 点击新增或者编辑
- const [editId, setEditId] = useState(0);
- const scrollRef = useRef({
- txt: "",
- num: 0,
- });
- const tablePageIdFu = useCallback((id: number, scrollNum: number) => {
- scrollRef.current = { ...scrollRef.current, num: scrollNum };
- setEditId(id);
- }, []);
- // 新增海报
- const editTableFu = useCallback(() => {
- // 获取当前表格的滚动位置
- const dom: any = document.querySelector("#wallTable .ant-table-body");
- tablePageIdFu(-1, dom.scrollTop);
- }, [tablePageIdFu]);
- // 从新增/编辑页面点击取消或者提交
- const closeWallAddFu = useCallback((txt: string) => {
- scrollRef.current = { ...scrollRef.current, txt };
- setEditId(0);
- }, []);
- return (
- <div className={styles.Wall}>
- <div className="pageTitlt">
- {editId === 0 ? "万物墙管理" : editId > 0 ? "编辑海报" : "新增海报"}
- </div>
- {editId === 0 ? (
- // 初始页面盒子
- <>
- <div className="wallTopBox">
- <div className="titleTxt">
- 海报展示管理
- {/* <Tooltip title="当超过15秒未操作时,将在场景  讲述/游览/赏析/临时展  间循环播放,每个场景播放30秒">
- <div className="inco">
- <ExclamationCircleFilled />
- </div>
- </Tooltip> */}
- </div>
- {edit ? (
- // 修改信息
- <div className="edit">
- <div>自动轮播:</div>
- <Radio.Group
- onChange={(e) => setValue1(e.target.value)}
- value={value1}
- >
- <Radio value={0}>关闭</Radio>
- <Radio value={1}>开启</Radio>
- </Radio.Group>
-  
- <RangePicker
- allowClear={false}
- defaultValue={[
- dayjs(time1[0], "YYYY/MM/DD"),
- dayjs(time1[1], "YYYY/MM/DD"),
- ]}
- onChange={timeChange}
- />
-  
- <Button type="primary" onClick={btnOk}>
- 确定
- </Button>
-  
- <Popconfirm
- title="放弃编辑后,信息将不会保存!"
- okText="放弃"
- cancelText="取消"
- onConfirm={() => setEdit(false)}
- >
- <Button>取消</Button>
- </Popconfirm>
- </div>
- ) : (
- // 展示信息
- <div className="txt">
- <div>自动轮播:</div>
- <div>{value0 ? "开启" : "关闭"} | </div>
- <div>
- {time0.split(",")[0]} 至 {time0.split(",")[1]}
- </div>
-   
- <Button type="primary" onClick={editAutoPlay}>
- 修改
- </Button>
- <Button
- type="primary"
- onClick={editTableFu}
- style={{ marginLeft: "10px" }}
- >
- 新增海报
- </Button>
- </div>
- )}
- {/* 表格相关 */}
- <WallTable
- tablePageIdFu={tablePageIdFu}
- scrollNumInfo={scrollRef.current}
- />
- </div>
- <div className="wallTopBox">
- <div className="titleTxt">
- 文物按类别展示
- <Tooltip title="当关闭时,万物墙将展示所有文物。">
- <div className="inco">
- <ExclamationCircleFilled />
- </div>
- </Tooltip>
- </div>
- {editType ? (
- // 修改信息
- <div>
- <div className="edit">
- <div>展示日期:</div>
- <Radio.Group
- onChange={(e) => setValue2(e.target.value)}
- value={value2}
- >
- <Radio value={0}>关闭</Radio>
- <Radio value={1}>开启</Radio>
- </Radio.Group>
-  
- <RangePicker
- allowClear={false}
- defaultValue={[
- dayjs(timeType1[0], "YYYY/MM/DD"),
- dayjs(timeType1[1], "YYYY/MM/DD"),
- ]}
- onChange={timeTypeChange}
- />
-  
- <Button type="primary" onClick={btnOkType}>
- 确定
- </Button>
-  
- <Popconfirm
- title="放弃编辑后,信息将不会保存!"
- okText="放弃"
- cancelText="取消"
- onConfirm={() => setEditType(false)}
- >
- <Button>取消</Button>
- </Popconfirm>
- </div>
- <div className="txt">
- <div style={{ marginRight: "5px" }}>展示类别:</div>
- <Radio.Group
- onChange={(e) => setTypeEdit(e.target.value)}
- value={typeEdit}
- >
- {types.map((item) => {
- return (
- <Radio key={item} value={item}>
- {item}
- </Radio>
- );
- })}
- </Radio.Group>
- </div>
- </div>
- ) : (
- // 展示信息
- <div>
- <div className="txt">
- <div style={{ marginRight: "5px" }}>展示日期:</div>
- <div>{valueType ? "开启" : "关闭"} | </div>
- <div>
- {timeType0.split(",")[0]} 至 {timeType0.split(",")[1]}
- </div>
-   
- <Button type="primary" onClick={editTypeFu}>
- 修改
- </Button>
- </div>
- <div className="txt">
- <div style={{ marginRight: "5px" }}>展示类别:</div>
- <div>{typeDisplay}</div>
- </div>
- </div>
- )}
- </div>
- </>
- ) : (
- <WallAdd id={editId} closeMoalFu={closeWallAddFu} />
- )}
- </div>
- );
- }
- const MemoWall = React.memo(Wall);
- export default MemoWall;
|