shaogen1995 1 year ago
parent
commit
e1345e7c48

+ 3 - 0
src/assets/styles/base.css

@@ -50,6 +50,9 @@ textarea {
   border: 1px solid #d9d9d9;
   transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
 }
+.ant-popconfirm {
+  width: 240px;
+}
 #root {
   width: 100vw;
   height: 100vh;

+ 4 - 0
src/assets/styles/base.less

@@ -69,6 +69,10 @@ textarea {
   transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
 }
 
+// 气泡框闪烁问题
+.ant-popconfirm{
+  width: 240px;
+}
 
 // 重置antd样式
 #root {

+ 6 - 2
src/components/MyTable/index.module.scss

@@ -1,5 +1,5 @@
-.MyTable{
-  :global{
+.MyTable {
+  :global {
     .ant-table-body {
       overflow-y: auto !important;
       overflow-y: overlay !important;
@@ -7,6 +7,10 @@
       .ant-table-row {
         .ant-table-cell {
           padding: 10px;
+
+          a {
+            color: var(--themeColor) !important;
+          }
         }
       }
     }

+ 30 - 12
src/components/MyTable/index.tsx

@@ -20,6 +20,18 @@ type Props = {
   myTitle?: { name: string; Com: React.ReactNode };
 };
 
+// 表格内容定制化
+const tableComObj = (key: string, val: string[]) => {
+  const obj = {
+    A: (
+      <a href={val[1]} target="_blank" title={val[1]} rel="noreferrer">
+        {val[0]}
+      </a>
+    ),
+  };
+  return Reflect.get(obj, key);
+};
+
 function MyTable({
   yHeight,
   list,
@@ -79,18 +91,24 @@ function MyTable({
         ),
         txtChange: (item: any) =>
           Reflect.get(v[3], item[v[2]]) || v[4] || nullTxt,
-        text: (item: any) =>
-          item[v[2]] ? (
-            item[v[2]].length >= v[3] ? (
-              <span style={{ cursor: "pointer" }} title={item[v[2]]}>
-                {item[v[2]].substring(0, v[3]) + "..."}
-              </span>
-            ) : (
-              item[v[2]]
-            )
-          ) : (
-            nullTxt
-          ),
+        text: (item: any) => {
+          let tempCom: any = item[v[2]] || nullTxt;
+
+          if (tempCom.length >= v[3]) {
+            tempCom = tempCom.substring(0, v[3]) + "...";
+            if (v[4]) {
+              tempCom = tableComObj(v[4], [tempCom, item[v[2]]]);
+            } else {
+              tempCom = (
+                <span style={{ cursor: "pointer" }} title={item[v[2]]}>
+                  {tempCom}
+                </span>
+              );
+            }
+          }
+
+          return tempCom;
+        },
       };
 
       return Reflect.get(obj, v[0]);

+ 4 - 0
src/components/ZRichText/index.module.scss

@@ -8,6 +8,10 @@
       height: 100%;
       border: 1px solid #ccc;
 
+      a{
+        color: #fff !important;
+      }
+
       // 隐藏媒体功能
       .control-item.media {
         display: none;

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

@@ -51,7 +51,7 @@
         justify-content: space-around;
 
         &>a {
-          color: #fff;
+          color: #fff !important;
         }
 
         font-size: 16px;

+ 1 - 1
src/pages/A2dynamic/index.tsx

@@ -100,7 +100,7 @@ function A2dynamic() {
       {/* 顶部筛选 */}
       <div className="A2top">
         <div>
-          <span>昵称:</span>
+          <span>标题:</span>
           <Input
             key={inputKey}
             maxLength={10}

+ 50 - 0
src/pages/A3culture/A3edit/index.module.scss

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

+ 165 - 0
src/pages/A3culture/A3edit/index.tsx

@@ -0,0 +1,165 @@
+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 { A3_APIgetInfo, A3_APIsave } from "@/store/action/A3culture";
+import { MessageFu } from "@/utils/message";
+import ZupOne from "@/components/ZupOne";
+import TextArea from "antd/es/input/TextArea";
+import MyPopconfirm from "@/components/MyPopconfirm";
+
+type Props = {
+  editId: number;
+  addTableFu: () => void;
+  editTableFu: () => void;
+  closeFu: () => void;
+};
+
+function A3edit({ editId, addTableFu, editTableFu, closeFu }: Props) {
+  // 表单的ref
+  const FormBoxRef = useRef<FormInstance>(null);
+
+  // 封面图的ref
+  const ZupThumbRef = useRef<any>(null);
+
+  const getInfoFu = useCallback(async (id: number) => {
+    const res = await A3_APIgetInfo(id);
+    if (res.code === 0) {
+      const data = res.data;
+      FormBoxRef.current?.setFieldsValue({
+        ...data,
+        myTime: dayjs(data.publishDate),
+      });
+
+      // 设置封面图
+      ZupThumbRef.current?.setFileComFileFu({
+        fileName: "",
+        filePath: data.thumb,
+      });
+    }
+  }, []);
+
+  useEffect(() => {
+    if (editId > 0) {
+      getInfoFu(editId);
+    } else {
+      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;
+      // 发布日期
+      const publishDate = dayjs(values.myTime).format("YYYY-MM-DD");
+
+      const obj = {
+        ...values,
+        id: editId > 0 ? editId : null,
+        publishDate,
+        thumb: coverUrl1.filePath,
+      };
+
+      const res = await A3_APIsave(obj);
+
+      if (res.code === 0) {
+        MessageFu.success(editId > 0 ? "编辑成功!" : "新增成功!");
+        editId > 0 ? editTableFu() : addTableFu();
+        closeFu();
+      }
+    },
+    [addTableFu, closeFu, editId, editTableFu]
+  );
+
+  return (
+    <div className={styles.A3edit}>
+      <div className="A3eMain">
+        <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">
+              <ZupOne
+                ref={ZupThumbRef}
+                isLook={false}
+                fileCheck={fileCheck}
+                size={5}
+                dirCode={"A3culture"}
+                myUrl="cms/cultural/upload"
+                format={["image/jpeg", "image/png"]}
+                formatTxt="png、jpg和jpeg"
+                checkTxt="请上传封面图!"
+                upTxt="最多1张"
+                myType="thumb"
+              />
+            </div>
+          </div>
+
+          <Form.Item
+            label="跳转链接"
+            name="link"
+            rules={[{ required: true, message: "请输入跳转链接!" }]}
+          >
+            <TextArea maxLength={200} showCount placeholder="请输入内容" />
+          </Form.Item>
+
+          {/* 确定和取消按钮 */}
+          <Form.Item className="A3Ebtn">
+            <Button type="primary" htmlType="submit">
+              提交
+            </Button>
+            <br />
+            <br />
+            <MyPopconfirm txtK="取消" onConfirm={closeFu} />
+          </Form.Item>
+        </Form>
+      </div>
+    </div>
+  );
+}
+
+const MemoA3edit = React.memo(A3edit);
+
+export default MemoA3edit;

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

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

+ 143 - 2
src/pages/A3culture/index.tsx

@@ -1,9 +1,150 @@
-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 { MessageFu } from "@/utils/message";
+import { Button, Input } from "antd";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import { A3_APIdel, A3_APIgetList } from "@/store/action/A3culture";
+import { A3tableType } from "@/types";
+import { RootState } from "@/store";
+import MyTable from "@/components/MyTable";
+import { A3tableC } from "@/utils/tableData";
+import A3edit from "./A3edit";
 function A3culture() {
+  const dispatch = useDispatch();
+
+  const [fromData, setFromData] = useState({
+    pageNum: 1,
+    pageSize: 10,
+    searchKey: "",
+  });
+
+  const getListFu = useCallback(() => {
+    dispatch(A3_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: "",
+    });
+  }, []);
+
+  const tableInfo = useSelector(
+    (state: RootState) => state.A3culture.tableInfo
+  );
+
+  const delTableFu = useCallback(
+    async (id: number) => {
+      const res = await A3_APIdel(id);
+      if (res.code === 0) {
+        MessageFu.success("删除成功!");
+        getListFu();
+      }
+    },
+    [getListFu]
+  );
+
+  // 新增和编辑
+  const [editId, setEditId] = useState(0);
+
+  const tableLastBtn = useMemo(() => {
+    return [
+      {
+        title: "操作",
+        render: (item: A3tableType) => (
+          <>
+            <Button size="small" type="text" onClick={() => setEditId(item.id)}>
+              编辑
+            </Button>
+            <MyPopconfirm txtK="删除" onConfirm={() => delTableFu(item.id)} />
+          </>
+        ),
+      },
+    ];
+  }, [delTableFu]);
+
   return (
     <div className={styles.A3culture}>
-      <div className="pageTitle">宁博文化</div>
+      <div className="pageTitle"></div>
+      <div className="pageTitle">
+        宁博文化{editId > 0 ? " - 编辑" : editId < 0 ? " - 新增" : ""}
+      </div>
+
+      {/* 顶部筛选 */}
+      <div className="A3top">
+        <div>
+          <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="A3tableBox">
+        <MyTable
+          yHeight={625}
+          list={tableInfo.list}
+          columnsTemp={A3tableC}
+          lastBtn={tableLastBtn}
+          pageNum={fromData.pageNum}
+          pageSize={fromData.pageSize}
+          total={tableInfo.total}
+          onChange={(pageNum, pageSize) =>
+            setFromData({ ...fromData, pageNum, pageSize })
+          }
+        />
+      </div>
+
+      {/* 新增和编辑 */}
+      {editId ? (
+        <A3edit
+          editId={editId}
+          closeFu={() => setEditId(0)}
+          addTableFu={resetSelectFu}
+          editTableFu={getListFu}
+        />
+      ) : null}
     </div>
   );
 }

+ 54 - 0
src/store/action/A3culture.ts

@@ -0,0 +1,54 @@
+import http from "@/utils/http";
+import { AppDispatch } from "..";
+
+/**
+ *宁博文创-列表
+ */
+
+export const A3_APIgetList = (data: any): any => {
+  return async (dispatch: AppDispatch) => {
+    const res = await http.post("cms/cultural/pageList", data);
+    if (res.code === 0) {
+      const obj = {
+        list: res.data.records,
+        total: res.data.total,
+      };
+      dispatch({ type: "A3/getList", payload: obj });
+    }
+  };
+};
+
+/**
+ * 宁博文创-删除
+ */
+export const A3_APIdel = (id: number) => {
+  return http.get(`cms/cultural/removes/${id}`);
+};
+
+/**
+ * 宁博文创-获取详情
+ */
+export const A3_APIgetInfo = (id: number) => {
+  return http.get(`cms/cultural/detail/${id}`);
+};
+
+/**
+ * 宁博文创-新增、编辑
+ */
+export const A3_APIsave = (data: any) => {
+  return http.post("cms/cultural/save", data);
+};
+
+/**
+ * 宁博文创-编辑-商城状态
+ */
+export const A3_APIsetCon = (display: 0 | 1) => {
+  return http.get(`cms/cultural/editConfig/${display}`);
+};
+
+/**
+ * 宁博文创-获取-商城状态
+ */
+export const A3_APIgetCon = () => {
+  return http.get("cms/cultural/getConfig");
+};

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

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

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

@@ -4,6 +4,7 @@ import { combineReducers } from "redux";
 // 导入 登录 模块的 reducer
 import A0Layout from "./layout";
 import A2dynamic from "./A2dynamic";
+import A3culture from "./A3culture";
 import Z0column from "./Z0column";
 import Z1user from "./Z1user";
 import Z2log from "./Z2log";
@@ -12,6 +13,7 @@ import Z2log from "./Z2log";
 const rootReducer = combineReducers({
   A0Layout,
   A2dynamic,
+  A3culture,
   Z0column,
   Z1user,
   Z2log,

+ 9 - 0
src/types/api/A3culture.d.ts

@@ -0,0 +1,9 @@
+export type A3tableType = {
+  createTime: string;
+  creatorName: string;
+  id: number;
+  link: string;
+  name: string;
+  thumb: string;
+  updateTime: string;
+};

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

@@ -1,5 +1,6 @@
 export * from './api/layot'
 export * from './api/Z0column'
 export * from './api/A2dynamic'
+export * from './api/A3culture'
 export * from './api/Z1user'
 export * from './api/Z2log'

+ 8 - 1
src/utils/tableData.ts

@@ -3,7 +3,7 @@
  * txt:正常数据
  * img:图片
  * txtChange:判断显示不同字段
- * text:文字比较多的情况
+ * text:文字比较多的情况、获取使用其他标签(没有的需要自己配置)
  */
 // export const A1tableCFu = (type: "video" | "poster") => {
 //   return [
@@ -23,6 +23,13 @@ export const A2tableC = [
   ["text", "摘要", "description", 50],
 ];
 
+export const A3tableC = [
+  ["txt", "标题", "name"],
+  ["img", "封面", "thumb"],
+  ["txt", "发布日期", "publishDate"],
+  ["text", "链接", "link", 50, "A"],
+];
+
 export const Z0tableC = [
   ["txt", "栏目名称", "name"],
   ["text", "说明", "rtf", 50],