|
@@ -1,9 +1,220 @@
|
|
|
-import React from "react";
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
+import {
|
|
|
+ Button,
|
|
|
+ Form,
|
|
|
+ FormInstance,
|
|
|
+ Input,
|
|
|
+ Modal,
|
|
|
+ Popconfirm,
|
|
|
+ Table,
|
|
|
+} from "antd";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
+import { B1_APIgetList } from "@/store/action/B1Plate";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import { A1ListType } from "@/types";
|
|
|
+import { A1_APIgetInfo, A1_APIsave } from "@/store/action/A1Plate";
|
|
|
+import TextArea from "antd/es/input/TextArea";
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
function B1Plate() {
|
|
|
+ const dispatch = useDispatch();
|
|
|
+
|
|
|
+ const [name, setName] = useState("");
|
|
|
+ const [inputKey, setInputKey] = useState(1);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ dispatch(B1_APIgetList(name));
|
|
|
+ }, [dispatch, name]);
|
|
|
+
|
|
|
+ // 标题的输入
|
|
|
+ const nameTime = useRef(-1);
|
|
|
+ const nameChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
+ clearTimeout(nameTime.current);
|
|
|
+ nameTime.current = window.setTimeout(() => {
|
|
|
+ setName(e.target.value);
|
|
|
+ }, 500);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 点击重置
|
|
|
+ const resetSelectFu = useCallback(() => {
|
|
|
+ setInputKey(Date.now());
|
|
|
+ setName("");
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 从仓库获取表格数据
|
|
|
+ const { list } = useSelector((state: RootState) => state.B1Plate);
|
|
|
+
|
|
|
+ // 表单的ref
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null);
|
|
|
+
|
|
|
+ // 点击编辑
|
|
|
+ const openModel = useCallback(async (id: number) => {
|
|
|
+ const res = await A1_APIgetInfo(id);
|
|
|
+ if (res.code === 0) setInfo(res.data.entity);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const [info, setInfo] = useState({} as A1ListType);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (info.content) {
|
|
|
+ FormBoxRef.current?.setFieldsValue({
|
|
|
+ content: info.content,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, [info]);
|
|
|
+
|
|
|
+ const columns = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: "标题",
|
|
|
+ dataIndex: "name",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "简介",
|
|
|
+ render: (item: A1ListType) =>
|
|
|
+ item.content.length >= 50 ? (
|
|
|
+ <span style={{ cursor: "pointer" }} title={item.content}>
|
|
|
+ {item.content.substring(0, 50) + "..."}
|
|
|
+ </span>
|
|
|
+ ) : (
|
|
|
+ item.content
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "操作",
|
|
|
+ render: (item: A1ListType) => (
|
|
|
+ <Button size="small" type="text" onClick={() => openModel(item.id)}>
|
|
|
+ 编辑
|
|
|
+ </Button>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }, [openModel]);
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {}, []);
|
|
|
+ // 通过校验点击确定
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (value: any) => {
|
|
|
+ const obj = {
|
|
|
+ ...value,
|
|
|
+ id: info.id,
|
|
|
+ type: "appreciate",
|
|
|
+ };
|
|
|
+ const res = await A1_APIsave(obj);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success("编辑成功!");
|
|
|
+ dispatch(B1_APIgetList(name));
|
|
|
+ setInfo({} as A1ListType);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [dispatch, info.id, name]
|
|
|
+ );
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.B1Plate}>
|
|
|
<div className="pageTitle">板块</div>
|
|
|
+ {/* 顶部搜索 */}
|
|
|
+ <div className="top">
|
|
|
+ <span>标题:</span>
|
|
|
+ <Input
|
|
|
+ key={inputKey}
|
|
|
+ maxLength={50}
|
|
|
+ style={{ width: 300 }}
|
|
|
+ placeholder="请输入关键字"
|
|
|
+ allowClear
|
|
|
+ onChange={(e) => nameChange(e)}
|
|
|
+ />
|
|
|
+   
|
|
|
+ <Button onClick={resetSelectFu}>重置</Button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 表格主体 */}
|
|
|
+ <div className="tableBox">
|
|
|
+ <Table
|
|
|
+ scroll={{ y: 617 }}
|
|
|
+ dataSource={list}
|
|
|
+ columns={columns}
|
|
|
+ rowKey="id"
|
|
|
+ pagination={false}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 点击编辑出来的弹窗 */}
|
|
|
+ {info.id ? (
|
|
|
+ <Modal
|
|
|
+ wrapClassName={styles.B1Modal}
|
|
|
+ destroyOnClose
|
|
|
+ open={true}
|
|
|
+ title={info.name}
|
|
|
+ footer={
|
|
|
+ [] // 设置footer为空,去掉 取消 确定默认按钮
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <div className="main">
|
|
|
+ <Form
|
|
|
+ ref={FormBoxRef}
|
|
|
+ name="basic"
|
|
|
+ labelCol={{ span: 2 }}
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete="off"
|
|
|
+ >
|
|
|
+ <Form.Item
|
|
|
+ label="简介"
|
|
|
+ name="content"
|
|
|
+ rules={[
|
|
|
+ { required: true, message: "请输入正文!" },
|
|
|
+ {
|
|
|
+ validator: (rule, value) => {
|
|
|
+ if (value) {
|
|
|
+ const txt = value
|
|
|
+ .replaceAll(" ", "")
|
|
|
+ .replaceAll("\n", "");
|
|
|
+ return txt === ""
|
|
|
+ ? Promise.reject("请输入有效字符!")
|
|
|
+ : Promise.resolve();
|
|
|
+ } else return Promise.resolve();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ <TextArea
|
|
|
+ autoSize
|
|
|
+ placeholder="请输入内容"
|
|
|
+ showCount
|
|
|
+ maxLength={500}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ {/* 确定和取消按钮 */}
|
|
|
+ <br />
|
|
|
+ <Form.Item
|
|
|
+ wrapperCol={{ offset: 10, span: 20 }}
|
|
|
+ className="closeLook"
|
|
|
+ >
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Popconfirm
|
|
|
+ title="放弃编辑后,信息将不会保存!"
|
|
|
+ okText="放弃"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => setInfo({} as A1ListType)}
|
|
|
+ >
|
|
|
+ <Button>取消</Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ </Modal>
|
|
|
+ ) : null}
|
|
|
</div>
|
|
|
);
|
|
|
}
|