zlisen преди 3 години
родител
ревизия
8fbd00750e
променени са 2 файла, в които са добавени 37 реда и са изтрити 20 реда
  1. 36
    19
      src/components/XForm/ImageListUpload.jsx
  2. 1
    1
      src/pages/staff/staff/Edit/index.jsx

+ 36
- 19
src/components/XForm/ImageListUpload.jsx Целия файл

@@ -15,55 +15,68 @@ class ImageListUpload extends React.Component {
15 15
   };
16 16
 
17 17
   getFileList = () => {
18
-    return (this.props.value || []).map((img, inx) => ({ uid: inx, url: getImgURL(img), status: 'done' }))
19
-  }
18
+    return (this.props.value || []).map((img, inx) => ({
19
+      uid: inx,
20
+      url: getImgURL(img),
21
+      status: 'done',
22
+    }));
23
+  };
20 24
 
21 25
   handleCancel = () => this.setState({ previewVisible: false });
22 26
 
23 27
   handlePreview = async file => {
24 28
     this.setState({
25
-      previewImage: file.url ,
29
+      previewImage: file.url,
26 30
       previewVisible: true,
27 31
     });
28 32
   };
29 33
 
30
-  handleChange = (e) => {
31
-    if (e.file.status === "uploading") {
34
+  handleChange = e => {
35
+    if (e.file.status === 'uploading') {
32 36
       this.setState({ loading: true });
33 37
       return;
34 38
     }
35
-console.log(e,'handleChange')
39
+    console.log(e, 'handleChange');
36 40
     // const fileList = (this.props.value || []).filter(x => x != e.file.url);
37 41
     // this.props.onChange(fileList);
38 42
 
39 43
     // console.log('删除图片触发了', e.file)
40 44
     if (e.file.status === 'removed') {
41
-      console.log(e,'handleChange22')
42
-      const fileList = (this.props.value || []).filter(x => getImgURL(x) != e.file.url);
43
-      this.props.onChange(fileList);
45
+      console.log(e, 'handleChange22');
46
+
47
+      Modal.confirm({
48
+        title: '确认要删除该图片吗?',
49
+        okText: '确认',
50
+        okType: 'danger',
51
+        cancelText: '取消',
52
+        onOk() {
53
+          const fileList = (this.props.value || []).filter(x => getImgURL(x) != e.file.url);
54
+          this.props.onChange(fileList);
55
+        },
56
+      });
44 57
     }
45 58
 
46
-    if (e.file.status === "done") {
59
+    if (e.file.status === 'done') {
47 60
       this.setState({
48 61
         loading: false,
49
-      })
62
+      });
50 63
 
51 64
       if (e.file.response && e.file.response.url) {
52 65
         if (typeof this.props.onChange === 'function') {
53
-          const fileList = this.getFileList()
54
-          this.props.onChange([...fileList || [], e.file.response.url]);
66
+          const fileList = this.getFileList();
67
+          this.props.onChange([...(fileList || []), e.file.response.url]);
55 68
         }
56 69
       }
57 70
     }
58 71
   };
59 72
 
60
-  handleUploadSucess = (url) => {
73
+  handleUploadSucess = url => {
61 74
     this.setState({ loading: false });
62 75
     if (typeof this.props.onChange === 'function') {
63 76
       const fileList = this.props.value || [];
64 77
       this.props.onChange([...fileList, url]);
65 78
     }
66
-  }
79
+  };
67 80
 
68 81
   render() {
69 82
     const { previewVisible, previewImage } = this.state;
@@ -71,7 +84,10 @@ console.log(e,'handleChange')
71 84
 
72 85
     const uploadButton = (
73 86
       <div>
74
-        <Icon style={{ fontSize: '2em', color: '#aaa' }} type={this.state.loading ? "loading" : "plus"}  />
87
+        <Icon
88
+          style={{ fontSize: '2em', color: '#aaa' }}
89
+          type={this.state.loading ? 'loading' : 'plus'}
90
+        />
75 91
       </div>
76 92
     );
77 93
     return (
@@ -82,13 +98,14 @@ console.log(e,'handleChange')
82 98
           fileList={fileList}
83 99
           onPreview={this.handlePreview}
84 100
           onChange={this.handleChange}
85
-          { ...uploaderProps }
101
+          {...uploaderProps}
86 102
           onSuccess={this.handleUploadSucess}
87 103
         >
88 104
           {/* unlimited 表示上传无限制数量 */}
89
-          {(this.props.unlimited && uploadButton) || ((fileList || images).length >= 8 ? null : uploadButton)}
105
+          {(this.props.unlimited && uploadButton) ||
106
+            ((fileList || images).length >= 8 ? null : uploadButton)}
90 107
         </Upload>
91
-        <Modal visible={previewVisible} footer={null} onCancel={this.handleCancel}>
108
+        <Modal id={'ImageListUpload-preview'} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
92 109
           <img alt="example" style={{ width: '100%' }} src={getImgURL(previewImage)} />
93 110
         </Modal>
94 111
       </div>

+ 1
- 1
src/pages/staff/staff/Edit/index.jsx Целия файл

@@ -74,7 +74,7 @@ const StaffEdit = props => {
74 74
     console.log(val, userId, '----------111------------');
75 75
     // val.institutionIdLis =  val?.institutionIdLis?.split(',')
76 76
     // console.log(val,userId,'----------------------')
77
-    if (val.loginName) {
77
+    if (!val.loginName) {
78 78
       val.loginName = val.phone;
79 79
     }
80 80