|
@@ -6,11 +6,13 @@ import {
|
|
|
DageUpload,
|
|
|
DageUploadConsumer,
|
|
|
DageUploadProvider,
|
|
|
- DageUploadType,
|
|
|
} from "@dage/pc-components";
|
|
|
import { DatePicker, Form, FormInstance, Input, Select } from "antd";
|
|
|
-import { useCallback, useRef, useState } from "react";
|
|
|
+import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
import { useNavigate, useParams } from "react-router-dom";
|
|
|
+import { LEVEL_TYPE } from "../constants";
|
|
|
+import { collectionApi } from "@/api";
|
|
|
+import { dayjs, formatDate } from "@dage/utils";
|
|
|
|
|
|
export default function CollectionCreateOrEditPage() {
|
|
|
const dageFileCheckboxRef = useRef<DageFileCheckboxMethods>(null);
|
|
@@ -19,10 +21,47 @@ export default function CollectionCreateOrEditPage() {
|
|
|
const navigate = useNavigate();
|
|
|
const params = useParams();
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
- const richTxtRef = useRef<any>(null);
|
|
|
- const [check, setCheck] = useState(false);
|
|
|
- // 文件的code码
|
|
|
- const [dirCode, setDirCode] = useState("");
|
|
|
+
|
|
|
+ const getDetail = useCallback(async () => {
|
|
|
+ setLoading(true);
|
|
|
+ try {
|
|
|
+ const {
|
|
|
+ entity: { thumb, publishDate, ...rest },
|
|
|
+ file,
|
|
|
+ } = await collectionApi.getDetail(params.id as string);
|
|
|
+
|
|
|
+ if (thumb) {
|
|
|
+ rest.thumb = [
|
|
|
+ {
|
|
|
+ uid: thumb,
|
|
|
+ url: `${process.env.REACT_APP_API_URL}${process.env.REACT_APP_IMG_PUBLIC}${thumb}`,
|
|
|
+ name: thumb,
|
|
|
+ status: "done",
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ formRef.current?.setFieldsValue({
|
|
|
+ publishDate: dayjs(publishDate),
|
|
|
+ ...rest,
|
|
|
+ });
|
|
|
+ dageFileCheckboxRef.current?.setFileList(
|
|
|
+ file.map((i: any) => ({
|
|
|
+ uid: i.id + "",
|
|
|
+ url: `${process.env.REACT_APP_API_URL}${process.env.REACT_APP_IMG_PUBLIC}${i.filePath}`,
|
|
|
+ thumbUrl: `${process.env.REACT_APP_API_URL}${process.env.REACT_APP_IMG_PUBLIC}${i.filePath}`,
|
|
|
+ name: i.fileName,
|
|
|
+ dType: i.type,
|
|
|
+ status: "done",
|
|
|
+ }))
|
|
|
+ );
|
|
|
+ } finally {
|
|
|
+ setLoading(false);
|
|
|
+ }
|
|
|
+ }, [params.id]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ !!params.id && getDetail();
|
|
|
+ }, [getDetail, params.id]);
|
|
|
|
|
|
const handleCancel = useCallback(() => {
|
|
|
navigate(-1);
|
|
@@ -31,12 +70,25 @@ export default function CollectionCreateOrEditPage() {
|
|
|
const handleSubmit = useCallback(async () => {
|
|
|
if (!(await formRef.current?.validateFields())) return;
|
|
|
|
|
|
- const { banner = [], ...rest } = formRef.current?.getFieldsValue();
|
|
|
+ const {
|
|
|
+ thumb = [],
|
|
|
+ publishDate,
|
|
|
+ ...rest
|
|
|
+ } = formRef.current?.getFieldsValue();
|
|
|
|
|
|
if (params.id) {
|
|
|
rest.id = params.id;
|
|
|
}
|
|
|
|
|
|
+ await collectionApi.save({
|
|
|
+ ...rest,
|
|
|
+ publishDate: formatDate(publishDate),
|
|
|
+ thumb: thumb[0].response ? thumb[0].response.filePath : thumb[0].name,
|
|
|
+ fileIds: fileList.current
|
|
|
+ .map((i) => (i.response ? i.response.id : i.uid))
|
|
|
+ .join(),
|
|
|
+ });
|
|
|
+
|
|
|
handleCancel();
|
|
|
}, [handleCancel, params]);
|
|
|
|
|
@@ -51,10 +103,16 @@ export default function CollectionCreateOrEditPage() {
|
|
|
<DageUploadConsumer>
|
|
|
{(data) => (
|
|
|
<>
|
|
|
- <Form ref={formRef} labelCol={{ span: 2 }}>
|
|
|
+ <Form
|
|
|
+ ref={formRef}
|
|
|
+ labelCol={{ span: 2 }}
|
|
|
+ initialValues={{
|
|
|
+ dictLevel: LEVEL_TYPE[0].value,
|
|
|
+ }}
|
|
|
+ >
|
|
|
<Form.Item
|
|
|
label="标题"
|
|
|
- name="title"
|
|
|
+ name="name"
|
|
|
rules={[{ required: true, message: "请输入内容" }]}
|
|
|
>
|
|
|
<Input
|
|
@@ -64,7 +122,7 @@ export default function CollectionCreateOrEditPage() {
|
|
|
showCount
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="时代" name="title">
|
|
|
+ <Form.Item label="时代" name="dictAge">
|
|
|
<Input
|
|
|
className="w220"
|
|
|
placeholder="请输入内容"
|
|
@@ -72,7 +130,7 @@ export default function CollectionCreateOrEditPage() {
|
|
|
showCount
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="质地" name="title">
|
|
|
+ <Form.Item label="质地" name="dictTexture">
|
|
|
<Input
|
|
|
className="w220"
|
|
|
placeholder="请输入内容"
|
|
@@ -80,23 +138,14 @@ export default function CollectionCreateOrEditPage() {
|
|
|
showCount
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="级别" name="type">
|
|
|
- <Select
|
|
|
- defaultValue="lucy"
|
|
|
- style={{ width: 220 }}
|
|
|
- options={[
|
|
|
- { value: "jack", label: "Jack" },
|
|
|
- { value: "lucy", label: "Lucy" },
|
|
|
- { value: "Yiminghe", label: "yiminghe" },
|
|
|
- { value: "disabled", label: "Disabled", disabled: true },
|
|
|
- ]}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
<Form.Item
|
|
|
- label="来源"
|
|
|
- name="title"
|
|
|
- rules={[{ required: true, message: "请输入内容" }]}
|
|
|
+ label="级别"
|
|
|
+ name="dictLevel"
|
|
|
+ rules={[{ required: true, message: "请选择" }]}
|
|
|
>
|
|
|
+ <Select style={{ width: 220 }} options={LEVEL_TYPE} />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item label="来源" name="dictSource">
|
|
|
<Input
|
|
|
className="w220"
|
|
|
placeholder="请输入内容"
|
|
@@ -104,7 +153,7 @@ export default function CollectionCreateOrEditPage() {
|
|
|
showCount
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="简介" name="content">
|
|
|
+ <Form.Item label="简介" name="description">
|
|
|
<Input.TextArea
|
|
|
className="w450"
|
|
|
placeholder="请输入内容,最多200字"
|
|
@@ -115,13 +164,13 @@ export default function CollectionCreateOrEditPage() {
|
|
|
</Form.Item>
|
|
|
<Form.Item
|
|
|
label="封面图"
|
|
|
- name="banner"
|
|
|
+ name="thumb"
|
|
|
rules={[{ required: true, message: "请上传封面图" }]}
|
|
|
>
|
|
|
<DageUpload
|
|
|
tips="支持png、jpg和jpeg格式;最多1张,最大20M"
|
|
|
action={
|
|
|
- process.env.REACT_APP_API_URL + "/api/cms/history/upload"
|
|
|
+ process.env.REACT_APP_API_URL + "/api/cms/goods/upload"
|
|
|
}
|
|
|
maxSize={20}
|
|
|
maxCount={1}
|
|
@@ -129,8 +178,9 @@ export default function CollectionCreateOrEditPage() {
|
|
|
</Form.Item>
|
|
|
<Form.Item
|
|
|
label="文件类型"
|
|
|
- name="fileTypes"
|
|
|
+ name="fileType"
|
|
|
rules={[
|
|
|
+ { required: true, message: "" },
|
|
|
{
|
|
|
validator: (...args) => {
|
|
|
dageFileCheckboxRef.current!.validate(...args);
|
|
@@ -141,17 +191,18 @@ export default function CollectionCreateOrEditPage() {
|
|
|
>
|
|
|
<DageFileCheckbox
|
|
|
ref={dageFileCheckboxRef}
|
|
|
- hasMobileModel={true}
|
|
|
- action="https://sit-shgybwg.4dage.com/api/cms/goods/upload"
|
|
|
+ action={
|
|
|
+ process.env.REACT_APP_API_URL + "/api/cms/goods/upload"
|
|
|
+ }
|
|
|
onFileChange={handleFileChange}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
<Form.Item
|
|
|
label="发布日期"
|
|
|
- name="date"
|
|
|
+ name="publishDate"
|
|
|
rules={[{ required: true, message: "请选择发布日期" }]}
|
|
|
>
|
|
|
- <DatePicker className="w220" />
|
|
|
+ <DatePicker className="w220" format="YYYY-MM-DD" />
|
|
|
</Form.Item>
|
|
|
</Form>
|
|
|
|