index.tsx
6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import React from 'react';
import { Button, Card, message, Upload } from 'antd';
import CardDetailPreview from '../CardDetailPreview';
import { UploadOutlined } from '@ant-design/icons';
import { UploadProps, UploadFile, UploadChangeParam } from 'antd/lib/upload/interface';
import detailS from './index.less';
import COS from "@/utils/COS";
import { setFormData, stateTransforToStore, beforeUpload } from '@/pages/mkt/ActivityCreate/BasicInformation/entity';
import ImgCropItem from '@/components/ImgCrop';
import { getFidFile } from "@/utils";
// import { useStore } from '../../index';
import Form, { FormInstance } from 'antd/lib/form';
interface Props {
form: FormInstance,
readOnly: boolean,
bizType?: number
}
const FormItem = Form.Item;
export default function Detail({ form, readOnly, bizType }: Props) {
const uploadProps: UploadProps = {
accept: "image/*",
action: "/file/upload",
// action: "/activity/util/file/uploadStatic",
listType: "picture-card",
showUploadList: { showPreviewIcon: true, showRemoveIcon: !readOnly },
disabled: readOnly,
// beforeUpload
};
const ImageUploadProps: UploadProps = {
accept: "image/*",
// action: "/file/upload",
// action: "/activity/util/file/uploadStatic",
listType: "picture-card",
showUploadList: { showPreviewIcon: true, showRemoveIcon: !readOnly },
customRequest: (data) => COS.cosUpload({ ...data, uploadPath: "/api/file/upload" }),
disabled: readOnly,
onPreview: (file) => onPreView(file, false),
beforeUpload
};
const onPreView = (file: UploadFile, isFid?: boolean) => {
getFidFile(file.response.data, isFid);
};
const videoProps: UploadProps = {
accept: "video/mp4",
listType: "text",
disabled: readOnly,
customRequest: (data) => COS.cosUpload({ ...data, uploadPath: "/api/file/upload" }),
onPreview: (file) => onPreView(file, false),
beforeUpload(file: any, fileList: any): boolean {
if (file.type !== "video/mp4") {
message.error("仅限传入 MP4 文件!");
return false;
}
if (file.size / 1024 / 1024 > 50) {
message.error("视频上传大小不能超过50MB!");
return false;
}
return true;
},
};
function valueFromEvent(e: any) {
if (Array.isArray(e)) {
return e;
}
const { status, response } = e.file;
if (!e.file.status) {
return [];
}
if (e.file.status == "error") {
message.error("图片上传出错,请重新上传");
return [];
}
if (status == "removed" && response) {
COS.cosDelete({ filePath: response.data });
}
return e?.fileList;
}
const uploadButton = (
<div>
<Button icon={<UploadOutlined />}>上传</Button>
</div>
);
return (
<Card
type="inner"
title="活动图片"
className={detailS.detailBox}
>
<div className={detailS.left}>
<ImgCropItem
// multiple
required
fidFile
label="活动轮播图"
name="bannerId"
labelCol={{ span: 4 }}
form={form}
extra={
<div style={{ fontSize: 10 }}>
<p style={{ margin: 0 }}>(售前)建议宽高尺寸: 750*750;</p>
<p style={{ margin: 0 }}>(售后)建议宽高尺寸: 670*240</p>
</div>
}
aspectXY={bizType == 2 ? { width: 670, height: 240 } : { width: 750, height: 750 }}
// setFormStorage={setFormStorage}
{...uploadProps}
>
{!readOnly ? uploadButton : null}
</ImgCropItem>
<FormItem
name="bgId"
required
label="活动主图"
labelCol={{ span: 4 }}
extra={
<div style={{ fontSize: 10 }}>
<div>活动概括,用于活动列表展示,(建议尺寸 750*520)</div>
<div>图片格式要求png、jpg、gif、jpeg,大小限制 5 MB 以内</div>
</div>
}
valuePropName="fileList"
getValueFromEvent={valueFromEvent}
>
<Upload
maxCount={1}
{...ImageUploadProps}
>
{!readOnly ? uploadButton : null}
</Upload>
</FormItem>
<FormItem
labelCol={{ span: 4 }}
name="videoId"
label="活动视频"
extra="视频格式要求 MP4,大小限制 50 MB 以内"
valuePropName="fileList"
getValueFromEvent={(e) => {
if (Array.isArray(e)) {
return e;
}
const { status, response } = e.file;
if (!status) {
return [];
}
if (status == "error") {
message.error("视频上传出错,请重新上传");
return [];
}
if (status == "removed" && response) {
COS.cosDelete({ filePath: response.data });
}
return e && e.fileList;
}}
>
<Upload maxCount={1} multiple {...videoProps}>
{uploadButton}
</Upload>
</FormItem>
<FormItem
name="content"
label="图文详情"
required
labelCol={{ span: 4 }}
extra={
<div style={{ fontSize: 10 }}>
<div>图文详情一般上传活动规则,时间,流程等内容,可以多张(建议尺寸 750*任意高)</div>
<div>图片格式要求png、jpg、gif、jpeg,大小限制 5 MB 以内</div>
</div>
}
valuePropName="fileList"
getValueFromEvent={valueFromEvent}
>
<Upload
multiple
maxCount={10}
{...ImageUploadProps}
>
{!readOnly ? uploadButton : null}
</Upload>
</FormItem>
<FormItem
name="shareId"
label="分享图"
required
labelCol={{ span: 4 }}
extra={
<>
<span style={{ fontSize: 10 }}>建议尺寸 750*1206</span>
</>
}
valuePropName="fileList"
getValueFromEvent={valueFromEvent}
>
<Upload
// accept="image/*"
// listType="picture"
// action="/api/file/upload"
// beforeUpload={beforeUpload}
// onPreview={(file: UploadFile) => onPreView(file, true)}
maxCount={1}
{...ImageUploadProps}
>
{!readOnly ? uploadButton : null}
</Upload>
</FormItem>
</div>
<div className={detailS.right}>
<CardDetailPreview form={form} />
</div>
</Card>
);
}