shaogen1995 vor 1 Jahr
Ursprung
Commit
460964bbfe

+ 57 - 0
src/pages/A7volunteer/A7edit/index.module.scss

@@ -0,0 +1,57 @@
+.A7edit {
+  position: absolute;
+  top: 0;
+  left: 0;
+  z-index: 12;
+  width: 100%;
+  height: 100%;
+  background-color: #fff;
+  border-radius: 10px;
+  padding: 24px;
+
+  :global {
+    .A7eMain {
+      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);
+          }
+          .formRightTxt{
+            position: relative;
+            top: 3px;
+          }
+        }
+
+        .A7Ebtn {
+          position: absolute;
+          z-index: 10;
+          left: 1200px;
+          top: 50%;
+          transform: translateY(-50%);
+        }
+      }
+    }
+  }
+}

+ 222 - 0
src/pages/A7volunteer/A7edit/index.tsx

@@ -0,0 +1,222 @@
+import React, { useCallback, useEffect, useRef, useState } from "react";
+import styles from "./index.module.scss";
+import { Button, DatePicker, Form, FormInstance, Input } from "antd";
+import dayjs from "dayjs";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import ZRichText from "@/components/ZRichText";
+import ZupOne from "@/components/ZupOne";
+import ZupVideos from "@/components/ZupVideos";
+import { MessageFu } from "@/utils/message";
+import { A7_APIgetInfo, A7_APIsave } from "@/store/action/A7volunteer";
+
+type Props = {
+  editId: number;
+  type: string;
+  addTableFu: () => void;
+  editTableFu: () => void;
+  closeFu: () => void;
+};
+
+function A7edit({ editId, type, addTableFu, editTableFu, closeFu }: Props) {
+  const [dirCode, setDirCode] = 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 A7_APIgetInfo(id);
+    if (res.code === 0) {
+      const entity = res.data.entity;
+      const file = res.data.file;
+
+      setDirCode(entity.dirCode);
+
+      ZRichTextRef.current?.ritxtShowFu(entity.rtf);
+
+      FormBoxRef.current?.setFieldsValue({
+        ...entity,
+        myTime: dayjs(entity.publishDate),
+      });
+
+      // 设置封面图
+      ZupThumbRef.current?.setFileComFileFu({
+        fileName: "",
+        filePath: entity.thumb,
+      });
+
+      // 设置附件视频
+      ZupVideosRef.current?.setFileComFileFu(file || []);
+    }
+  }, []);
+
+  useEffect(() => {
+    if (editId > 0) {
+      getInfoFu(editId);
+    } else {
+      setDirCode(Date.now() + "");
+      FormBoxRef.current?.setFieldsValue({
+        myTime: dayjs(Date.now()),
+      });
+    }
+  }, [editId, getInfoFu]);
+
+  // 附件 是否 已经点击过确定
+  const [fileCheck, setFileCheck] = useState(false);
+
+  // 没有通过校验
+  const onFinishFailed = useCallback(() => {
+    setFileCheck(true);
+  }, []);
+
+  //  通过校验点击确定
+  const onFinish = useCallback(
+    async (values: any) => {
+      setFileCheck(true);
+
+      const coverUrl1 = ZupThumbRef.current?.fileComFileResFu();
+      // 没有传 封面图
+      if (!coverUrl1.filePath) return MessageFu.warning("请上传封面图!");
+      // 发布日期
+      const publishDate = dayjs(values.myTime).format("YYYY-MM-DD");
+
+      const rtf = ZRichTextRef.current?.fatherBtnOkFu();
+
+      const flieList = ZupVideosRef.current?.fileComFileResFu() || [];
+
+      const obj = {
+        ...values,
+        id: editId > 0 ? editId : null,
+        publishDate,
+        thumb: coverUrl1.filePath,
+        rtf: rtf.val || "",
+        fileIds: flieList.map((v: any) => v.id).join(","),
+        type,
+      };
+
+      const res = await A7_APIsave(obj);
+
+      if (res.code === 0) {
+        MessageFu.success(editId > 0 ? "编辑成功!" : "新增成功!");
+        editId > 0 ? editTableFu() : addTableFu();
+        closeFu();
+      }
+    },
+    [addTableFu, closeFu, editId, editTableFu, type]
+  );
+  return (
+    <div className={styles.A7edit}>
+      <div className="A7eMain">
+        <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>
+
+          <Form.Item
+            label="发布日期"
+            name="myTime"
+            rules={[{ required: true, message: "请选择发布日期!" }]}
+          >
+            <DatePicker />
+          </Form.Item>
+
+          {/* 所属栏目 */}
+          <div className="formRow">
+            <div className="formLeft">
+              <span>* </span>
+              所属栏目:
+            </div>
+            <div className="formRight formRightTxt">{type}</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/volunteer/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/overview/upload"
+                upTxt=";数量不超过5个。"
+                ref={ZupVideosRef}
+              />
+            </div>
+          </div>
+
+          {/* 富文本 */}
+          <div className="formRow">
+            <div className="formLeft">正文:</div>
+            <div className="formRight" style={{ height: 450 }}>
+              <ZRichText
+                check={false}
+                dirCode={dirCode}
+                isLook={false}
+                ref={ZRichTextRef}
+                myUrl="cms/volunteer/upload"
+              />
+            </div>
+          </div>
+
+          {/* 确定和取消按钮 */}
+          <Form.Item className="A7Ebtn">
+            <Button type="primary" htmlType="submit">
+              提交
+            </Button>
+            <br />
+            <br />
+            <MyPopconfirm txtK="取消" onConfirm={closeFu} />
+          </Form.Item>
+        </Form>
+      </div>
+    </div>
+  );
+}
+
+const MemoA7edit = React.memo(A7edit);
+
+export default MemoA7edit;

+ 16 - 1
src/pages/A7volunteer/index.module.scss

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

+ 158 - 2
src/pages/A7volunteer/index.tsx

@@ -1,9 +1,165 @@
-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 { A7_APIdel, A7_APIgetList } from "@/store/action/A7volunteer";
+import { RootState } from "@/store";
+import { MessageFu } from "@/utils/message";
+import { A7tableType } from "@/types";
+import { Button, Input } from "antd";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import MyTable from "@/components/MyTable";
+import { A7tableC } from "@/utils/tableData";
+import A7edit from "./A7edit";
+
+const topButArr = ["志愿者资讯", "志愿者风采"];
+
 function A7volunteer() {
+  const dispatch = useDispatch();
+
+  const [fromData, setFromData] = useState({
+    pageNum: 1,
+    pageSize: 10,
+    searchKey: "",
+    type: "志愿者资讯",
+  });
+
+  const getListFu = useCallback(() => {
+    dispatch(A7_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: fromData.type,
+    });
+  }, [fromData.type]);
+
+  const tableInfo = useSelector(
+    (state: RootState) => state.A7volunteer.tableInfo
+  );
+
+  const delTableFu = useCallback(
+    async (id: number) => {
+      const res = await A7_APIdel(id);
+      if (res.code === 0) {
+        MessageFu.success("删除成功!");
+        getListFu();
+      }
+    },
+    [getListFu]
+  );
+
+  // 新增和编辑
+  const [editId, setEditId] = useState(0);
+
+  const tableLastBtn = useMemo(() => {
+    return [
+      {
+        title: "操作",
+        render: (item: A7tableType) => (
+          <>
+            <Button size="small" type="text" onClick={() => setEditId(item.id)}>
+              编辑
+            </Button>
+            <MyPopconfirm txtK="删除" onConfirm={() => delTableFu(item.id)} />
+          </>
+        ),
+      },
+    ];
+  }, [delTableFu]);
+
   return (
     <div className={styles.A7volunteer}>
-      <div className="pageTitle">志愿者之家</div>
+      <div className="pageTitle">
+        志愿者之家{editId > 0 ? " - 编辑" : editId < 0 ? " - 新增" : ""}
+      </div>
+
+      {/* 顶部筛选 */}
+      <div className="A7top">
+        <div>
+          {topButArr.map((v) => (
+            <Button
+              onClick={() => setFromData({ ...fromData, type: v, pageNum: 1 })}
+              key={v}
+              type={fromData.type === v ? "primary" : "default"}
+            >
+              {v}
+            </Button>
+          ))}
+          &emsp;&emsp;
+          <span>标题:</span>
+          <Input
+            key={inputKey}
+            maxLength={10}
+            showCount
+            style={{ width: 300 }}
+            placeholder="请输入"
+            allowClear
+            onChange={(e) => fromKeyChangeFu(e, "searchKey")}
+          />
+        </div>
+        <div>
+          <Button onClick={resetSelectFu}>重置</Button>&emsp;
+          <Button type="primary" onClick={() => setEditId(-1)}>
+            新增
+          </Button>
+        </div>
+      </div>
+
+      {/* 表格主体 */}
+      <div className="A7tableBox">
+        <MyTable
+          yHeight={625}
+          list={tableInfo.list}
+          columnsTemp={A7tableC}
+          lastBtn={tableLastBtn}
+          pageNum={fromData.pageNum}
+          pageSize={fromData.pageSize}
+          total={tableInfo.total}
+          onChange={(pageNum, pageSize) =>
+            setFromData({ ...fromData, pageNum, pageSize })
+          }
+        />
+      </div>
+
+      {/* 新增和编辑 */}
+      {editId ? (
+        <A7edit
+          editId={editId}
+          type={fromData.type}
+          closeFu={() => setEditId(0)}
+          addTableFu={resetSelectFu}
+          editTableFu={getListFu}
+        />
+      ) : null}
     </div>
   );
 }

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

@@ -0,0 +1,41 @@
+import http from "@/utils/http";
+import { AppDispatch } from "..";
+
+/**
+ *志愿者之家-列表
+ */
+
+export const A7_APIgetList = (data: any): any => {
+  return async (dispatch: AppDispatch) => {
+    const res = await http.post("cms/volunteer/pageList", data);
+    if (res.code === 0) {
+      const obj = {
+        list: res.data.records,
+        total: res.data.total,
+      };
+
+      dispatch({ type: "A7/getList", payload: obj });
+    }
+  };
+};
+
+/**
+ * 志愿者之家-删除
+ */
+export const A7_APIdel = (id: number) => {
+  return http.get(`cms/volunteer/removes/${id}`);
+};
+
+/**
+ * 志愿者之家-获取详情
+ */
+export const A7_APIgetInfo = (id: number) => {
+  return http.get(`cms/volunteer/detail/${id}`);
+};
+
+/**
+ * 志愿者之家-新增、编辑
+ */
+export const A7_APIsave = (data: any) => {
+  return http.post("cms/volunteer/save", data);
+};

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

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

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

@@ -8,6 +8,7 @@ import A3culture from "./A3culture";
 import A4goods from "./A4goods";
 import A5show from "./A5show";
 import A6activity from "./A6activity";
+import A7volunteer from "./A7volunteer";
 import Z0column from "./Z0column";
 import Z1user from "./Z1user";
 import Z2log from "./Z2log";
@@ -20,6 +21,7 @@ const rootReducer = combineReducers({
   A4goods,
   A5show,
   A6activity,
+  A7volunteer,
   Z0column,
   Z1user,
   Z2log,

+ 13 - 0
src/types/api/A7volunteer.ts

@@ -0,0 +1,13 @@
+export type A7tableType = {
+	createTime: string;
+	creatorName: string;
+	dirCode: string;
+	fileIds: string;
+	id: number;
+	name: string;
+	publishDate: string;
+	rtf: string;
+	thumb: string;
+	type: string;
+	updateTime: string;
+}

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

@@ -5,5 +5,6 @@ export * from './api/A3culture'
 export * from './api/A4goods'
 export * from './api/A5show'
 export * from './api/A6activity'
+export * from './api/A7volunteer'
 export * from './api/Z1user'
 export * from './api/Z2log'

+ 6 - 0
src/utils/tableData.ts

@@ -56,6 +56,12 @@ export const A6tableC = [
   ["txtChange", "需要预约", "isNeed", { 1: "是", 0: "否" }],
 ];
 
+export const A7tableC = [
+  ["txt", "标题", "name"],
+  ["img", "封面", "thumb"],
+  ["txt", "发布日期", "publishDate"],
+];
+
 export const Z0tableC = [
   ["txt", "栏目名称", "name"],
   ["text", "说明", "rtf", 50],