|
@@ -0,0 +1,193 @@
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
|
+import styles from "./index.module.scss";
|
|
|
+import {
|
|
|
+ Button,
|
|
|
+ Form,
|
|
|
+ FormInstance,
|
|
|
+ Input,
|
|
|
+ InputNumber,
|
|
|
+ Modal,
|
|
|
+ Select,
|
|
|
+} from "antd";
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
+import TextArea from "antd/es/input/TextArea";
|
|
|
+import ZupOne from "@/components/ZupOne";
|
|
|
+import MyPopconfirm from "@/components/MyPopconfirm";
|
|
|
+import { A5_1_APIgetInfo, A5_1_APIsave } from "@/store/action/A5_1remains";
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ fId: number;
|
|
|
+ closeFu: () => void;
|
|
|
+ addTableFu: () => void;
|
|
|
+ upTableFu: () => void;
|
|
|
+};
|
|
|
+
|
|
|
+function A5_1edit({ fId, closeFu, addTableFu, upTableFu }: Props) {
|
|
|
+ // 设置表单初始数据(区分编辑和新增)
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null);
|
|
|
+
|
|
|
+ const getInfoFu = useCallback(async (id: number) => {
|
|
|
+ const res = await A5_1_APIgetInfo(id);
|
|
|
+ if (res.code === 0) {
|
|
|
+ const data = res.data;
|
|
|
+
|
|
|
+ FormBoxRef.current?.setFieldsValue(data);
|
|
|
+
|
|
|
+ // 设置封面图
|
|
|
+ ZupOneRef1.current?.setFileComFileFu({
|
|
|
+ fileName: "",
|
|
|
+ filePath: data.thumb,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (fId > 0) getInfoFu(fId);
|
|
|
+ }, [fId, getInfoFu]);
|
|
|
+
|
|
|
+ // 附件的ref
|
|
|
+ const ZupOneRef1 = useRef<any>(null);
|
|
|
+
|
|
|
+ // 附件 是否 已经点击过确定
|
|
|
+ const [fileCheck, setFileCheck] = useState(false);
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {
|
|
|
+ setFileCheck(true);
|
|
|
+ }, []);
|
|
|
+ // 通过校验点击确定
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (values: any) => {
|
|
|
+ setFileCheck(true);
|
|
|
+ // 没有传 封面图 或者视频
|
|
|
+ const coverUrl1 = ZupOneRef1.current?.fileComFileResFu();
|
|
|
+
|
|
|
+ if (!coverUrl1.filePath) return;
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ ...values,
|
|
|
+ id: fId > 0 ? fId : null,
|
|
|
+ thumb: coverUrl1.filePath,
|
|
|
+ };
|
|
|
+
|
|
|
+ const res = await A5_1_APIsave(obj);
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success(fId > 0 ? "编辑成功!" : "新增成功!");
|
|
|
+ fId > 0 ? upTableFu() : addTableFu();
|
|
|
+ closeFu();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [addTableFu, closeFu, fId, upTableFu]
|
|
|
+ );
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Modal
|
|
|
+ wrapClassName={styles.A5_1edit}
|
|
|
+ open={true}
|
|
|
+ title={fId > 0 ? "编辑" : "新增"}
|
|
|
+ footer={
|
|
|
+ [] // 设置footer为空,去掉 取消 确定默认按钮
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <div className="A5_1eMain">
|
|
|
+ <Form
|
|
|
+ scrollToFirstError={true}
|
|
|
+ ref={FormBoxRef}
|
|
|
+ name="basic"
|
|
|
+ labelCol={{ span: 3 }}
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete="off"
|
|
|
+ >
|
|
|
+ <Form.Item
|
|
|
+ label="标题"
|
|
|
+ name="name"
|
|
|
+ rules={[{ required: true, message: "请输入标题!" }]}
|
|
|
+ // getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={50} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ {/* 封面 */}
|
|
|
+ <div className="formRow">
|
|
|
+ <div className="formLeft">
|
|
|
+ <span>* </span>
|
|
|
+ 封面:
|
|
|
+ </div>
|
|
|
+ <div className="formRight">
|
|
|
+ <ZupOne
|
|
|
+ ref={ZupOneRef1}
|
|
|
+ isLook={false}
|
|
|
+ fileCheck={fileCheck}
|
|
|
+ size={2}
|
|
|
+ dirCode={"remainsThumb"}
|
|
|
+ myUrl="cms/remains/upload"
|
|
|
+ format={["image/jpeg", "image/png"]}
|
|
|
+ formatTxt="png、jpg和jpeg"
|
|
|
+ checkTxt="请上传封面!"
|
|
|
+ upTxt="最多1张"
|
|
|
+ myType="thumb"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <Form.Item
|
|
|
+ label="区域"
|
|
|
+ name="region"
|
|
|
+ rules={[{ required: true, message: "请选择区域!" }]}
|
|
|
+ >
|
|
|
+ <Select
|
|
|
+ placeholder="请选择"
|
|
|
+ style={{ width: 200 }}
|
|
|
+ options={[
|
|
|
+ { value: "江阴市", label: "江阴市" },
|
|
|
+ { value: "宜兴市", label: "宜兴市" },
|
|
|
+ { value: "梁溪区", label: "梁溪区" },
|
|
|
+ { value: "锡山区", label: "锡山区" },
|
|
|
+ { value: "惠山区", label: "惠山区" },
|
|
|
+ { value: "滨湖区", label: "滨湖区" },
|
|
|
+ { value: "新吴区", label: "新吴区" },
|
|
|
+ { value: "经开区", label: "经开区" },
|
|
|
+ ]}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item label="简介" name="description" className="A5ET1">
|
|
|
+ <TextArea maxLength={1000} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item label="场景链接" name="link" className="A5ET2">
|
|
|
+ <TextArea maxLength={200} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ label="排序值"
|
|
|
+ name="sort"
|
|
|
+ rules={[{ required: true, message: "请输入排序值!" }]}
|
|
|
+ >
|
|
|
+ <InputNumber
|
|
|
+ min={1}
|
|
|
+ max={999}
|
|
|
+ precision={0}
|
|
|
+ placeholder="请输入1~999,数字越小,排序越前"
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ {/* 确定和取消按钮 */}
|
|
|
+ <Form.Item className="A5_1eBtn">
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+ <br />
|
|
|
+ <br />
|
|
|
+ <MyPopconfirm txtK="取消" onConfirm={closeFu} />
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ </Modal>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA5_1edit = React.memo(A5_1edit);
|
|
|
+
|
|
|
+export default MemoA5_1edit;
|