weiximei 5 anni fa
parent
commit
f4b1ce6bf5

+ 16
- 5
src/components/XForm/FileUpload.jsx Vedi File

@@ -4,12 +4,13 @@ import { uploaderProps } from '../../utils/upload';
4 4
 
5 5
 /**
6 6
  * value 数据的接收格式 [{ url: xxxxx.mp4 }]
7
- * @param {*} props 
7
+ * size  参数限制可以上传多少个文件
8
+ * @param { value, size } props
8 9
  */
9 10
 function fileUpload(props) {
10 11
 
11 12
   const { value } = props
12
-  console.log('fileUploadProps: ', props)
13
+  // console.log('fileUploadProps: ', props)
13 14
   // eslint-disable-next-line react-hooks/rules-of-hooks
14 15
   const [defaultFileList, setDefaultFileList] = useState([])
15 16
 
@@ -62,9 +63,19 @@ function fileUpload(props) {
62 63
         onChange={onFileChange}
63 64
         fileList={defaultFileList}
64 65
       >
65
-        <Button>
66
-          <Icon type="upload" /> {props.label}
67
-        </Button>
66
+        {
67
+          props.size ?
68
+          (props.size > defaultFileList.length
69
+          && (
70
+            <Button>
71
+                <Icon type="upload" /> {props.label}
72
+              </Button>
73
+          )) : (
74
+            <Button>
75
+              <Icon type="upload" /> {props.label}
76
+            </Button>
77
+          )
78
+        }
68 79
       </Upload>
69 80
     </>
70 81
   )

+ 2
- 11
src/pages/building/list/add/components/base.jsx Vedi File

@@ -45,9 +45,6 @@ function AddBuilding(props) {
45 45
 
46 46
   const [poi, setPoi] = useState([])
47 47
 
48
-  // 视频上传按钮是否 禁用
49
-  const [fileUploadDisabled, setFileUploadDisabled] = useState(false)
50
-
51 48
   // console.log('props.building: ', props.building)
52 49
   const { buildingId } = props.building
53 50
      // eslint-disable-next-line react-hooks/rules-of-hooks
@@ -78,8 +75,6 @@ function AddBuilding(props) {
78 75
       res.mapCoordinate = res.coordinate
79 76
       if (res.videoUrl) {
80 77
         res.videoUrl = [].concat(res.videoUrl)
81
-        // 视频上传按钮禁用
82
-        setFileUploadDisabled(true)
83 78
       }
84 79
       if (res.videoImage) {
85 80
         res.videoImage = res.videoImage[0].url
@@ -138,11 +133,7 @@ function AddBuilding(props) {
138 133
   function fileUploadBeforeUpload(file, fileList) {
139 134
     // console.log('视频文件上传前 回调: ', file, fileList)
140 135
     return new Promise((resolve, reject) => {
141
-      if (fileUploadDisabled) {
142
-        openNotificationWithIcon('error', '项目视频,只允许上传一个')
143
-        reject()
144
-      } else if (file.type === 'video/mp4' || file.type === '.mp4') {
145
-          setFileUploadDisabled(true)
136
+      if (file.type === 'video/mp4' || file.type === '.mp4') {
146 137
           resolve(file)
147 138
       } else {
148 139
         openNotificationWithIcon('error', '项目视频,仅支持MP4格式')
@@ -292,7 +283,7 @@ function AddBuilding(props) {
292 283
           <Form.Item label="项目视频" help="视频仅支持mp4格式,建议尺寸:1920*1080,比例16:9">
293 284
             {getFieldDecorator('videoUrl')(
294 285
               // disabled={fileUploadDisabled}
295
-              <FileUpload accept=".mp4" beforeUpload={fileUploadBeforeUpload} label="上传视频" />,
286
+              <FileUpload accept=".mp4" beforeUpload={fileUploadBeforeUpload} label="上传视频" size={1} />,
296 287
             )}
297 288
           </Form.Item>
298 289
           <Form.Item label="视频封面图" help="建议图片尺寸:750*600px,比例5:4,格式:jpg,用于视频封面" >