shaogen1995 преди 1 година
родител
ревизия
7d9d1fbbb4

+ 1 - 1
src/components/ZRichText/index.tsx

@@ -157,7 +157,7 @@ function ZRichText({ check, dirCode, isLook, myUrl, full }: Props, ref: any) {
     setEditorValue(BraftEditor.createEditorState(val));
   }, []);
 
-  // 让父组件调用的返回 富文本信息 和 表单校验
+  // 让父组件调用的返回 富文本信息 和 表单校验 isTxtFlag为ture表示未通过校验
   const fatherBtnOkFu = useCallback(() => {
     return { val: editorValue.toHTML(), flag: isTxtFlag };
   }, [editorValue, isTxtFlag]);

+ 53 - 0
src/pages/A5show/A5edit/index.module.scss

@@ -0,0 +1,53 @@
+.A5edit {
+  position: absolute;
+  top: 0;
+  left: 0;
+  z-index: 12;
+  width: 100%;
+  height: 100%;
+  background-color: #fff;
+  border-radius: 10px;
+  padding: 24px;
+
+  :global {
+    .A5eMain {
+      width: 100%;
+      height: 100%;
+      overflow-y: auto;
+
+      .ant-form {
+        width: 800px;
+
+        // .ant-input-affix-wrapper{
+        //   width: 800px;
+        // }
+        .formRow {
+          display: flex;
+
+          .formLeft {
+            position: relative;
+            top: 3px;
+            width: 100px;
+            text-align: right;
+
+            &>span {
+              color: #ff4d4f;
+            }
+          }
+
+          .formRight {
+            width: calc(100% - 100px);
+          }
+        }
+
+        .A5Ebtn {
+          position: absolute;
+          z-index: 10;
+          left: 1200px;
+          top: 50%;
+          transform: translateY(-50%);
+        }
+      }
+    }
+  }
+}

+ 307 - 0
src/pages/A5show/A5edit/index.tsx

@@ -0,0 +1,307 @@
+import React, { useCallback, useEffect, useRef, useState } from "react";
+import styles from "./index.module.scss";
+import { Button, DatePicker, Form, FormInstance, Input, Select } from "antd";
+import { A5_APIgetInfo, A5_APIsave } from "@/store/action/A5show";
+import dayjs from "dayjs";
+import { MessageFu } from "@/utils/message";
+import ZupOne from "@/components/ZupOne";
+import TextArea from "antd/es/input/TextArea";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import ZRichText from "@/components/ZRichText";
+import ZupVideos from "@/components/ZupVideos";
+const { RangePicker } = DatePicker;
+
+type Props = {
+  editId: number;
+  addTableFu: () => void;
+  editTableFu: () => void;
+  closeFu: () => void;
+};
+
+function A5edit({ editId, addTableFu, editTableFu, closeFu }: Props) {
+  const [dirCode, setDirCode] = useState("");
+
+  // 自定义类型
+  const [type, setType] = useState<"常设展览" | "临时展览" | "">("");
+
+  // 表单的ref
+  const FormBoxRef = useRef<FormInstance>(null);
+  // 封面图的ref
+  const ZupThumbRef = useRef<any>(null);
+
+  // 富文本的ref
+  const ZRichTextRef = useRef<any>(null);
+  //  视频的ref
+  const ZupVideosRef = useRef<any>(null);
+
+  const getInfoFu = useCallback(async (id: number) => {
+    const res = await A5_APIgetInfo(id);
+    if (res.code === 0) {
+      const entity = res.data.entity;
+      const file = res.data.file;
+
+      setDirCode(entity.dirCode);
+
+      // 设置富文本
+      ZRichTextRef.current?.ritxtShowFu(entity.rtf);
+
+      // 设置附件视频
+      ZupVideosRef.current?.setFileComFileFu(file || []);
+
+      // 设置展览类型
+      setType(entity.type);
+
+      // 设置临时展览日期
+      if (entity.type === "临时展览" && entity.dateStart && entity.dateEnd) {
+        setTimeArr([entity.dateStart, entity.dateEnd]);
+      }
+
+      FormBoxRef.current?.setFieldsValue({
+        ...entity,
+        myTime: dayjs(entity.publishDate),
+      });
+
+      // 设置封面图
+      ZupThumbRef.current?.setFileComFileFu({
+        fileName: "",
+        filePath: entity.thumb,
+      });
+    }
+  }, []);
+
+  useEffect(() => {
+    if (editId > 0) {
+      getInfoFu(editId);
+    } else {
+      setDirCode(Date.now() + "");
+
+      setType("常设展览");
+
+      FormBoxRef.current?.setFieldsValue({
+        myTime: dayjs(Date.now()),
+      });
+    }
+  }, [editId, getInfoFu]);
+
+  // 附件 是否 已经点击过确定
+  const [fileCheck, setFileCheck] = useState(false);
+
+  const [timeArr, setTimeArr] = useState<any>(null);
+
+  // 时间选择器改变
+  const timeChange = useCallback((date: any, dateString: any) => {
+    setTimeArr(dateString);
+  }, []);
+
+  // 没有通过校验
+  const onFinishFailed = useCallback(() => {
+    setFileCheck(true);
+  }, []);
+
+  //  通过校验点击确定
+  const onFinish = useCallback(
+    async (values: any) => {
+      setFileCheck(true);
+
+      const coverUrl1 = ZupThumbRef.current?.fileComFileResFu();
+
+      // 富文本
+      const rtfObj = ZRichTextRef.current?.fatherBtnOkFu();
+
+      if (rtfObj.flag) return MessageFu.warning("请输入正文!");
+
+      // 没有传 封面图
+      if (!coverUrl1.filePath) return MessageFu.warning("请上传封面图!");
+
+      let timeArrRes = ["", ""];
+
+      if (type === "临时展览") {
+        if (timeArr && timeArr[0] && timeArr[1]) {
+          timeArrRes = timeArr;
+        } else return MessageFu.warning("请选择临时展览日期!");
+      }
+
+      // 发布日期
+      const publishDate = dayjs(values.myTime).format("YYYY-MM-DD");
+
+      const flieList = ZupVideosRef.current?.fileComFileResFu() || [];
+
+      const obj = {
+        ...values,
+        id: editId > 0 ? editId : null,
+        publishDate,
+        thumb: coverUrl1.filePath,
+        rtf: rtfObj.val || "",
+        fileIds: flieList.map((v: any) => v.id).join(","),
+        type,
+        dateStart: timeArrRes[0],
+        dateEnd: timeArrRes[1],
+      };
+
+      const res = await A5_APIsave(obj);
+
+      if (res.code === 0) {
+        MessageFu.success(editId > 0 ? "编辑成功!" : "新增成功!");
+        editId > 0 ? editTableFu() : addTableFu();
+        closeFu();
+      }
+    },
+    [addTableFu, closeFu, editId, editTableFu, timeArr, type]
+  );
+
+  return (
+    <div className={styles.A5edit}>
+      <div className="A5eMain">
+        <Form
+          ref={FormBoxRef}
+          name="basic"
+          labelCol={{ span: 3 }}
+          onFinish={onFinish}
+          onFinishFailed={onFinishFailed}
+          autoComplete="off"
+          scrollToFirstError
+        >
+          <Form.Item
+            label="标题"
+            name="name"
+            rules={[{ required: true, message: "请输入标题!" }]}
+            getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
+          >
+            <Input maxLength={30} showCount placeholder="请输入内容" />
+          </Form.Item>
+
+          {/* 自定义展览类型 */}
+          <div className="formRow">
+            <div className="formLeft">
+              <span>* </span>展览类型:
+            </div>
+            <div className="formRight">
+              <Select
+                placeholder="请选择"
+                style={{ width: 200 }}
+                value={type}
+                onChange={(e) => setType(e)}
+                options={[
+                  { value: "常设展览", label: "常设展览" },
+                  { value: "临时展览", label: "临时展览" },
+                ]}
+              />
+              &emsp;
+              <span hidden={type === "常设展览"}>
+                <RangePicker
+                  onChange={timeChange}
+                  value={
+                    timeArr && timeArr[0] && timeArr[1]
+                      ? [dayjs(timeArr[0]), dayjs(timeArr[1])]
+                      : null
+                  }
+                />
+              </span>
+            </div>
+          </div>
+          <br />
+
+          <Form.Item
+            label="发布日期"
+            name="myTime"
+            rules={[{ required: true, message: "请选择发布日期!" }]}
+          >
+            <DatePicker />
+          </Form.Item>
+
+          {/* 富文本 */}
+          <div className="formRow">
+            <div className="formLeft">
+              <span>* </span>正文:
+            </div>
+            <div className="formRight" style={{ height: 450 }}>
+              <ZRichText
+                check={fileCheck}
+                dirCode={dirCode}
+                isLook={false}
+                ref={ZRichTextRef}
+                myUrl="cms/exhibition/upload"
+              />
+            </div>
+          </div>
+          <br />
+
+          {/* 封面 */}
+          <div className="formRow">
+            <div className="formLeft">
+              <span>* </span>
+              封面图:
+            </div>
+            <div className="formRight">
+              <ZupOne
+                ref={ZupThumbRef}
+                isLook={false}
+                fileCheck={fileCheck}
+                size={5}
+                dirCode={dirCode}
+                myUrl="cms/exhibition/upload"
+                format={["image/jpeg", "image/png"]}
+                formatTxt="png、jpg和jpeg"
+                checkTxt="请上传封面图!"
+                upTxt="最多1张"
+                myType="thumb"
+              />
+            </div>
+          </div>
+
+          {/* 视频 */}
+          <div className="formRow">
+            <div className="formLeft">视频:</div>
+            <div className="formRight">
+              <ZupVideos
+                isLook={false}
+                size={500}
+                fileNum={5}
+                dirCode={dirCode}
+                myUrl="cms/exhibition/upload"
+                upTxt=";数量不超过5个。"
+                ref={ZupVideosRef}
+              />
+            </div>
+          </div>
+          <Form.Item
+            label="位置"
+            name="location"
+            getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
+          >
+            <Input maxLength={30} showCount placeholder="请输入内容" />
+          </Form.Item>
+          <Form.Item
+            label="摘要"
+            name="description"
+            getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
+          >
+            <TextArea placeholder="请输入内容" showCount maxLength={100} />
+          </Form.Item>
+
+          <Form.Item
+            label="虚拟展厅"
+            name="link"
+            getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
+          >
+            <TextArea placeholder="请输入链接" showCount maxLength={200} />
+          </Form.Item>
+
+          {/* 确定和取消按钮 */}
+          <Form.Item className="A5Ebtn">
+            <Button type="primary" htmlType="submit">
+              提交
+            </Button>
+            <br />
+            <br />
+            <MyPopconfirm txtK="取消" onConfirm={closeFu} />
+          </Form.Item>
+        </Form>
+      </div>
+    </div>
+  );
+}
+
+const MemoA5edit = React.memo(A5edit);
+
+export default MemoA5edit;

+ 22 - 1
src/pages/A5show/index.module.scss

@@ -1,5 +1,26 @@
 .A5show{
+  position: relative;
   :global{
-    
+    .A5top {
+      padding: 15px 24px;
+      border-radius: 10px;
+      background-color: #fff;
+      display: flex;
+      justify-content: space-between;
+      .A5topLeft{
+        display: flex;
+        .A5topRow{
+          margin-right: 20px;
+        }
+      }
+    }
+
+    .A5tableBox {
+      border-radius: 10px;
+      overflow: hidden;
+      margin-top: 15px;
+      height: calc(100% - 77px);
+      background-color: #fff;
+    }
   }
 }

+ 159 - 2
src/pages/A5show/index.tsx

@@ -1,9 +1,166 @@
-import React from "react";
+import React, {
+  useCallback,
+  useEffect,
+  useMemo,
+  useRef,
+  useState,
+} from "react";
 import styles from "./index.module.scss";
+import { useDispatch, useSelector } from "react-redux";
+import { A5_APIdel, A5_APIgetList } from "@/store/action/A5show";
+import { A5tableType } from "@/types";
+import { Button, Input, Select } from "antd";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import { MessageFu } from "@/utils/message";
+import { RootState } from "@/store";
+import MyTable from "@/components/MyTable";
+import { A5tableC } from "@/utils/tableData";
+import A5edit from "./A5edit";
 function A5show() {
+  const dispatch = useDispatch();
+
+  const [fromData, setFromData] = useState({
+    pageNum: 1,
+    pageSize: 10,
+    searchKey: "",
+    type: "",
+  });
+
+  const getListFu = useCallback(() => {
+    dispatch(A5_APIgetList(fromData));
+  }, [dispatch, fromData]);
+
+  useEffect(() => {
+    getListFu();
+  }, [getListFu]);
+
+  const [inputKey, setInputKey] = useState(1);
+
+  // 标题的输入
+  const timeRef = useRef(-1);
+  const fromKeyChangeFu = useCallback(
+    (e: React.ChangeEvent<HTMLInputElement>, key: "searchKey") => {
+      clearTimeout(timeRef.current);
+      timeRef.current = window.setTimeout(() => {
+        setFromData({ ...fromData, [key]: e.target.value, pageNum: 1 });
+      }, 500);
+    },
+    [fromData]
+  );
+
+  // 点击重置
+  const resetSelectFu = useCallback(() => {
+    setInputKey(Date.now());
+    setFromData({
+      pageNum: 1,
+      pageSize: 10,
+      searchKey: "",
+      type: "",
+    });
+  }, []);
+
+  const tableInfo = useSelector((state: RootState) => state.A5show.tableInfo);
+
+  const delTableFu = useCallback(
+    async (id: number) => {
+      const res = await A5_APIdel(id);
+      if (res.code === 0) {
+        MessageFu.success("删除成功!");
+        getListFu();
+      }
+    },
+    [getListFu]
+  );
+
+  // 新增和编辑
+  const [editId, setEditId] = useState(0);
+
+  const tableLastBtn = useMemo(() => {
+    return [
+      {
+        title: "操作",
+        render: (item: A5tableType) => (
+          <>
+            <Button size="small" type="text" onClick={() => setEditId(item.id)}>
+              编辑
+            </Button>
+            <MyPopconfirm txtK="删除" onConfirm={() => delTableFu(item.id)} />
+          </>
+        ),
+      },
+    ];
+  }, [delTableFu]);
   return (
     <div className={styles.A5show}>
-      <div className="pageTitle">宁博展览</div>
+      <div className="pageTitle">
+        宁博展览{editId > 0 ? " - 编辑" : editId < 0 ? " - 新增" : ""}
+      </div>
+
+      {/* 顶部筛选 */}
+      <div className="A5top">
+        <div className="A5topLeft">
+          <div className="A5topRow">
+            <span>标题:</span>
+            <Input
+              key={inputKey}
+              maxLength={10}
+              showCount
+              style={{ width: 300 }}
+              placeholder="请输入"
+              allowClear
+              onChange={(e) => fromKeyChangeFu(e, "searchKey")}
+            />
+          </div>
+          <div className="A5topRow">
+            <span>展览类型:</span>
+            <Select
+              placeholder="请选择"
+              style={{ width: 200 }}
+              value={fromData.type}
+              onChange={(e) =>
+                setFromData({ ...fromData, pageNum: 1, type: e })
+              }
+              options={[
+                { value: "", label: "全部" },
+                { value: "常设展览", label: "常设展览" },
+                { value: "临时展览", label: "临时展览" },
+              ]}
+            />
+          </div>
+        </div>
+        <div>
+          <Button onClick={resetSelectFu}>重置</Button>&emsp;
+          <Button type="primary" onClick={() => setEditId(-1)}>
+            新增
+          </Button>
+        </div>
+      </div>
+
+      {/* 表格主体 */}
+      <div className="A5tableBox">
+        <MyTable
+          yHeight={625}
+          list={tableInfo.list}
+          columnsTemp={A5tableC}
+          lastBtn={tableLastBtn}
+          pageNum={fromData.pageNum}
+          pageSize={fromData.pageSize}
+          total={tableInfo.total}
+          onChange={(pageNum, pageSize) =>
+            setFromData({ ...fromData, pageNum, pageSize })
+          }
+        />
+      </div>
+
+      {/* 新增和编辑 */}
+      {editId ? (
+        <A5edit
+          editId={editId}
+          closeFu={() => setEditId(0)}
+          addTableFu={resetSelectFu}
+          editTableFu={getListFu}
+        />
+      ) : null}
     </div>
   );
 }

+ 41 - 0
src/store/action/A5show.ts

@@ -0,0 +1,41 @@
+import http from "@/utils/http";
+import { AppDispatch } from "..";
+
+/**
+ *宁博展览-列表
+ */
+
+export const A5_APIgetList = (data: any): any => {
+  return async (dispatch: AppDispatch) => {
+    const res = await http.post("cms/exhibition/pageList", data);
+    if (res.code === 0) {
+      const obj = {
+        list: res.data.records,
+        total: res.data.total,
+      };
+
+      dispatch({ type: "A5/getList", payload: obj });
+    }
+  };
+};
+
+/**
+ * 宁博展览-删除
+ */
+export const A5_APIdel = (id: number) => {
+  return http.get(`cms/exhibition/removes/${id}`);
+};
+
+/**
+ * 宁博展览-获取详情
+ */
+export const A5_APIgetInfo = (id: number) => {
+  return http.get(`cms/exhibition/detail/${id}`);
+};
+
+/**
+ * 宁博展览-新增、编辑
+ */
+export const A5_APIsave = (data: any) => {
+  return http.post("cms/exhibition/save", data);
+};

+ 28 - 0
src/store/reducer/A5show.ts

@@ -0,0 +1,28 @@
+import { A5tableType } from "@/types";
+
+// 初始化状态
+const initState = {
+  // 列表数据
+  tableInfo: {
+    list: [] as A5tableType[],
+    total: 0,
+  },
+};
+
+// 定义 action 类型
+type Props = {
+  type: "A5/getList";
+  payload: { list: A5tableType[]; total: number };
+};
+
+// reducer
+export default function Reducer(state = initState, action: Props) {
+  switch (action.type) {
+    // 获取列表数据
+    case "A5/getList":
+      return { ...state, tableInfo: action.payload };
+
+    default:
+      return state;
+  }
+}

+ 2 - 0
src/store/reducer/index.ts

@@ -6,6 +6,7 @@ import A0Layout from "./layout";
 import A2dynamic from "./A2dynamic";
 import A3culture from "./A3culture";
 import A4goods from "./A4goods";
+import A5show from "./A5show";
 import Z0column from "./Z0column";
 import Z1user from "./Z1user";
 import Z2log from "./Z2log";
@@ -16,6 +17,7 @@ const rootReducer = combineReducers({
   A2dynamic,
   A3culture,
   A4goods,
+  A5show,
   Z0column,
   Z1user,
   Z2log,

+ 16 - 0
src/types/api/A5show.d.ts

@@ -0,0 +1,16 @@
+export type A5tableType ={
+	createTime: string;
+	creatorName: string;
+	description: string;
+	dirCode: string;
+	fileIds: string;
+	id: number;
+	link: string;
+	location: string;
+	name: string;
+	publishDate: string;
+	rtf: string;
+	thumb: string;
+	type: string;
+	updateTime: string;
+}

+ 1 - 0
src/types/index.d.ts

@@ -3,5 +3,6 @@ export * from './api/Z0column'
 export * from './api/A2dynamic'
 export * from './api/A3culture'
 export * from './api/A4goods'
+export * from './api/A5show'
 export * from './api/Z1user'
 export * from './api/Z2log'

+ 8 - 0
src/utils/tableData.ts

@@ -40,6 +40,14 @@ export const A4tableC = [
   ["text", "简介", "description", 50],
 ];
 
+export const A5tableC = [
+  ["txt", "标题", "name"],
+  ["img", "封面", "thumb"],
+  ["txt", "发布日期", "publishDate"],
+  ["txt", "展览类型", "type"],
+  ["text", "摘要", "description", 50],
+];
+
 export const Z0tableC = [
   ["txt", "栏目名称", "name"],
   ["text", "说明", "rtf", 50],