zlisen 3 лет назад
Родитель
Сommit
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
   };
15
   };
16
 
16
 
17
   getFileList = () => {
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
   handleCancel = () => this.setState({ previewVisible: false });
25
   handleCancel = () => this.setState({ previewVisible: false });
22
 
26
 
23
   handlePreview = async file => {
27
   handlePreview = async file => {
24
     this.setState({
28
     this.setState({
25
-      previewImage: file.url ,
29
+      previewImage: file.url,
26
       previewVisible: true,
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
       this.setState({ loading: true });
36
       this.setState({ loading: true });
33
       return;
37
       return;
34
     }
38
     }
35
-console.log(e,'handleChange')
39
+    console.log(e, 'handleChange');
36
     // const fileList = (this.props.value || []).filter(x => x != e.file.url);
40
     // const fileList = (this.props.value || []).filter(x => x != e.file.url);
37
     // this.props.onChange(fileList);
41
     // this.props.onChange(fileList);
38
 
42
 
39
     // console.log('删除图片触发了', e.file)
43
     // console.log('删除图片触发了', e.file)
40
     if (e.file.status === 'removed') {
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
       this.setState({
60
       this.setState({
48
         loading: false,
61
         loading: false,
49
-      })
62
+      });
50
 
63
 
51
       if (e.file.response && e.file.response.url) {
64
       if (e.file.response && e.file.response.url) {
52
         if (typeof this.props.onChange === 'function') {
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
     this.setState({ loading: false });
74
     this.setState({ loading: false });
62
     if (typeof this.props.onChange === 'function') {
75
     if (typeof this.props.onChange === 'function') {
63
       const fileList = this.props.value || [];
76
       const fileList = this.props.value || [];
64
       this.props.onChange([...fileList, url]);
77
       this.props.onChange([...fileList, url]);
65
     }
78
     }
66
-  }
79
+  };
67
 
80
 
68
   render() {
81
   render() {
69
     const { previewVisible, previewImage } = this.state;
82
     const { previewVisible, previewImage } = this.state;
71
 
84
 
72
     const uploadButton = (
85
     const uploadButton = (
73
       <div>
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
       </div>
91
       </div>
76
     );
92
     );
77
     return (
93
     return (
82
           fileList={fileList}
98
           fileList={fileList}
83
           onPreview={this.handlePreview}
99
           onPreview={this.handlePreview}
84
           onChange={this.handleChange}
100
           onChange={this.handleChange}
85
-          { ...uploaderProps }
101
+          {...uploaderProps}
86
           onSuccess={this.handleUploadSucess}
102
           onSuccess={this.handleUploadSucess}
87
         >
103
         >
88
           {/* unlimited 表示上传无限制数量 */}
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
         </Upload>
107
         </Upload>
91
-        <Modal visible={previewVisible} footer={null} onCancel={this.handleCancel}>
108
+        <Modal id={'ImageListUpload-preview'} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
92
           <img alt="example" style={{ width: '100%' }} src={getImgURL(previewImage)} />
109
           <img alt="example" style={{ width: '100%' }} src={getImgURL(previewImage)} />
93
         </Modal>
110
         </Modal>
94
       </div>
111
       </div>

+ 1
- 1
src/pages/staff/staff/Edit/index.jsx Просмотреть файл

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