shaogen1995 1 year ago
parent
commit
33aab54afc

+ 1 - 1
src/components/ZupVideos/index.module.scss

@@ -19,7 +19,7 @@
         display: flex;
         justify-content: center;
         align-items: center;
-        margin-right: 20px;
+        margin-right: 100px;
       }
 
       .zVRow {

+ 3 - 2
src/pages/A2dynamic/A2edit/index.tsx

@@ -71,9 +71,10 @@ function A2edit({
       setDirCode(Date.now() + "");
       FormBoxRef.current?.setFieldsValue({
         myTime: dayjs(Date.now()),
+        dictId:dynamicList.find(v=>v.name==='其他')?.id
       });
     }
-  }, [editId, getInfoFu]);
+  }, [dynamicList, editId, getInfoFu]);
 
   // 附件 是否 已经点击过确定
   const [fileCheck, setFileCheck] = useState(false);
@@ -90,7 +91,7 @@ function A2edit({
 
       const coverUrl1 = ZupThumbRef.current?.fileComFileResFu();
       // 没有传 封面图
-      if (!coverUrl1.filePath) return;
+      if (!coverUrl1.filePath) return MessageFu.warning('请上传封面图!');
       // 发布日期
       const publishDate = dayjs(values.myTime).format("YYYY-MM-DD");
 

+ 1 - 1
src/pages/A3culture/A3edit/index.tsx

@@ -63,7 +63,7 @@ function A3edit({ editId, addTableFu, editTableFu, closeFu }: Props) {
 
       const coverUrl1 = ZupThumbRef.current?.fileComFileResFu();
       // 没有传 封面图
-      if (!coverUrl1.filePath) return;
+      if (!coverUrl1.filePath) return MessageFu.warning('请上传封面图!');
       // 发布日期
       const publishDate = dayjs(values.myTime).format("YYYY-MM-DD");
 

+ 4 - 3
src/pages/A4goods/A4edit/index.tsx

@@ -72,9 +72,10 @@ function A4edit({
 
       FormBoxRef.current?.setFieldsValue({
         myTime: dayjs(Date.now()),
+        dictId:goodsList.find(v=>v.name==='其他')?.id
       });
     }
-  }, [editId, getInfoFu]);
+  }, [editId, getInfoFu, goodsList]);
 
   // 附件 是否 已经点击过确定
   const [fileCheck, setFileCheck] = useState(false);
@@ -91,13 +92,13 @@ function A4edit({
 
       const coverUrl1 = ZupThumbRef.current?.fileComFileResFu();
       // 没有传 封面图
-      if (!coverUrl1.filePath) return;
+      if (!coverUrl1.filePath) return MessageFu.warning('请上传封面图!');;
 
       // 附件组件的 type 数组 和 附件id数组
       const { sonType, sonFileIds, sonIsOk } =
         ZupFilesRef.current?.fileComFileResFu();
 
-      if (sonIsOk) return;
+      if (sonIsOk) return MessageFu.warning('请最少勾选一个文件类型,并且上传对应的附件!');;
 
       // 发布日期
       const publishDate = dayjs(values.myTime).format("YYYY-MM-DD");

+ 53 - 0
src/pages/A6activity/A6edit/index.module.scss

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

+ 255 - 0
src/pages/A6activity/A6edit/index.tsx

@@ -0,0 +1,255 @@
+import React, { useCallback, useEffect, useRef, useState } from "react";
+import styles from "./index.module.scss";
+import { Z0tableType } from "@/types";
+import { Button, DatePicker, Form, FormInstance, Input, Select } from "antd";
+import ZupOne from "@/components/ZupOne";
+import dayjs from "dayjs";
+import { MessageFu } from "@/utils/message";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import { A6_APIgetInfo, A6_APIsave } from "@/store/action/A6activity";
+import ZRichText from "@/components/ZRichText";
+import ZupVideos from "@/components/ZupVideos";
+
+type Props = {
+  editId: number;
+  activityList: Z0tableType[];
+  addTableFu: () => void;
+  editTableFu: () => void;
+  closeFu: () => void;
+};
+
+function A6edit({
+  editId,
+  activityList,
+  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 A6_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 || []);
+
+      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() + "");
+
+      FormBoxRef.current?.setFieldsValue({
+        myTime: dayjs(Date.now()),
+        isNeed: 0,
+        dictId: activityList.find((v) => v.name === "其他")?.id,
+      });
+    }
+  }, [activityList, 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 flieList = ZupVideosRef.current?.fileComFileResFu() || [];
+
+      // 富文本
+      const rtfObj = ZRichTextRef.current?.fatherBtnOkFu();
+
+      const obj = {
+        ...values,
+        id: editId > 0 ? editId : null,
+        publishDate,
+        thumb: coverUrl1.filePath,
+        rtf: rtfObj.val || "",
+        fileIds: flieList.map((v: any) => v.id).join(","),
+      };
+
+      const res = await A6_APIsave(obj);
+
+      if (res.code === 0) {
+        MessageFu.success(editId > 0 ? "编辑成功!" : "新增成功!");
+        editId > 0 ? editTableFu() : addTableFu();
+        closeFu();
+      }
+    },
+    [addTableFu, closeFu, editId, editTableFu]
+  );
+
+  return (
+    <div className={styles.A6edit}>
+      <div className="A6eMain">
+        <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="dictId"
+            rules={[{ required: true, message: "请选择所属栏目!" }]}
+          >
+            <Select
+              placeholder="请选择"
+              style={{ width: 200 }}
+              options={activityList.map((v) => ({
+                value: v.id,
+                label: v.name,
+              }))}
+            />
+          </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">
+              <ZupOne
+                ref={ZupThumbRef}
+                isLook={false}
+                fileCheck={fileCheck}
+                size={5}
+                dirCode={dirCode}
+                myUrl="cms/goods/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/activity/upload"
+                upTxt=";数量不超过5个。"
+                ref={ZupVideosRef}
+              />
+            </div>
+          </div>
+
+          <Form.Item
+            label="需要预约"
+            name="isNeed"
+            rules={[{ required: true, message: "请选择需要预约!" }]}
+          >
+            <Select
+              placeholder="请选择"
+              style={{ width: 200 }}
+              options={[
+                { value: 0, label: "否" },
+                { value: 1, label: "是" },
+              ]}
+            />
+          </Form.Item>
+
+          {/* 富文本 */}
+          <div className="formRow">
+            <div className="formLeft">正文:</div>
+            <div className="formRight" style={{ height: 450 }}>
+              <ZRichText
+                check={false}
+                dirCode={dirCode}
+                isLook={false}
+                ref={ZRichTextRef}
+                myUrl="cms/activity/upload"
+              />
+            </div>
+          </div>
+          <br />
+
+          {/* 确定和取消按钮 */}
+          <Form.Item className="A6Ebtn">
+            <Button type="primary" htmlType="submit">
+              提交
+            </Button>
+            <br />
+            <br />
+            <MyPopconfirm txtK="取消" onConfirm={closeFu} />
+          </Form.Item>
+        </Form>
+      </div>
+    </div>
+  );
+}
+
+const MemoA6edit = React.memo(A6edit);
+
+export default MemoA6edit;

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

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

+ 170 - 2
src/pages/A6activity/index.tsx

@@ -1,9 +1,177 @@
-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 { Z0_APIgetList } from "@/store/action/Z0column";
+import { RootState } from "@/store";
+import { A6_APIdel, A6_APIgetList } from "@/store/action/A6activity";
+import { MessageFu } from "@/utils/message";
+import { A6tableType } from "@/types";
+import { Button, Input, Select } from "antd";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import MyTable from "@/components/MyTable";
+import { A6tableC } from "@/utils/tableData";
+import A6edit from "./A6edit";
 function A6activity() {
+  const dispatch = useDispatch();
+  // 获取所属栏目列表,用于下拉框
+  useEffect(() => {
+    dispatch(Z0_APIgetList());
+  }, [dispatch]);
+
+  const { activity } = useSelector(
+    (state: RootState) => state.Z0column.tableInfo
+  );
+
+  const [fromData, setFromData] = useState({
+    pageNum: 1,
+    pageSize: 10,
+    searchKey: "",
+    dictId: "",
+  });
+
+  const getListFu = useCallback(() => {
+    dispatch(A6_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: "",
+      dictId: "",
+    });
+  }, []);
+
+  const tableInfo = useSelector(
+    (state: RootState) => state.A6activity.tableInfo
+  );
+
+  const delTableFu = useCallback(
+    async (id: number) => {
+      const res = await A6_APIdel(id);
+      if (res.code === 0) {
+        MessageFu.success("删除成功!");
+        getListFu();
+      }
+    },
+    [getListFu]
+  );
+
+  // 新增和编辑
+  const [editId, setEditId] = useState(0);
+
+  const tableLastBtn = useMemo(() => {
+    return [
+      {
+        title: "操作",
+        render: (item: A6tableType) => (
+          <>
+            <Button size="small" type="text" onClick={() => setEditId(item.id)}>
+              编辑
+            </Button>
+            <MyPopconfirm txtK="删除" onConfirm={() => delTableFu(item.id)} />
+          </>
+        ),
+      },
+    ];
+  }, [delTableFu]);
+
   return (
     <div className={styles.A6activity}>
-      <div className="pageTitle">宁博活动</div>
+      <div className="pageTitle">
+        宁博活动{editId > 0 ? " - 编辑" : editId < 0 ? " - 新增" : ""}
+      </div>
+      {/* 顶部筛选 */}
+      <div className="A6top">
+        <div className="A6topLeft">
+          <div className="A6topRow">
+            <span>标题:</span>
+            <Input
+              key={inputKey}
+              maxLength={10}
+              showCount
+              style={{ width: 300 }}
+              placeholder="请输入"
+              allowClear
+              onChange={(e) => fromKeyChangeFu(e, "searchKey")}
+            />
+          </div>
+          <div className="A6topRow">
+            <span>所属栏目:</span>
+            <Select
+              placeholder="请选择"
+              style={{ width: 200 }}
+              value={fromData.dictId}
+              onChange={(e) =>
+                setFromData({ ...fromData, pageNum: 1, dictId: e })
+              }
+              options={[
+                { value: "", label: "全部" },
+                ...activity.map((v) => ({ value: v.id, label: v.name })),
+              ]}
+            />
+          </div>
+        </div>
+        <div>
+          <Button onClick={resetSelectFu}>重置</Button>&emsp;
+          <Button type="primary" onClick={() => setEditId(-1)}>
+            新增
+          </Button>
+        </div>
+      </div>
+
+      {/* 表格主体 */}
+      <div className="A6tableBox">
+        <MyTable
+          yHeight={625}
+          list={tableInfo.list}
+          columnsTemp={A6tableC}
+          lastBtn={tableLastBtn}
+          pageNum={fromData.pageNum}
+          pageSize={fromData.pageSize}
+          total={tableInfo.total}
+          onChange={(pageNum, pageSize) =>
+            setFromData({ ...fromData, pageNum, pageSize })
+          }
+        />
+      </div>
+
+      {/* 新增和编辑 */}
+      {editId ? (
+        <A6edit
+          editId={editId}
+          activityList={activity}
+          closeFu={() => setEditId(0)}
+          addTableFu={resetSelectFu}
+          editTableFu={getListFu}
+        />
+      ) : null}
     </div>
   );
 }

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

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

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

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

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

@@ -7,6 +7,7 @@ import A2dynamic from "./A2dynamic";
 import A3culture from "./A3culture";
 import A4goods from "./A4goods";
 import A5show from "./A5show";
+import A6activity from "./A6activity";
 import Z0column from "./Z0column";
 import Z1user from "./Z1user";
 import Z2log from "./Z2log";
@@ -18,6 +19,7 @@ const rootReducer = combineReducers({
   A3culture,
   A4goods,
   A5show,
+  A6activity,
   Z0column,
   Z1user,
   Z2log,

+ 14 - 0
src/types/api/A6activity.ts

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

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

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

+ 8 - 0
src/utils/tableData.ts

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