From b9a0e8541f0959db5d848f7b893c8838851ce411 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 09 四月 2020 13:29:49 +0800
Subject: [PATCH] 2020-04-09

---
 src/tabviews/zshare/fileupload/index.jsx |  100 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 68 insertions(+), 32 deletions(-)

diff --git a/src/tabviews/zshare/fileupload/index.jsx b/src/tabviews/zshare/fileupload/index.jsx
index 2074c98..ca939be 100644
--- a/src/tabviews/zshare/fileupload/index.jsx
+++ b/src/tabviews/zshare/fileupload/index.jsx
@@ -1,6 +1,7 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Upload, message, Button, Icon, Progress } from 'antd'
+import { Upload, message, Button, Icon, Progress, notification } from 'antd'
+import md5 from 'md5'
 import Api from '@/api'
 import './index.scss'
 
@@ -62,52 +63,88 @@
   shardupload = (file, shardSize, shardCount, i, fileList) => {
     let start = i * shardSize
     let end = Math.min(file.size, start + shardSize)
+    // let param = {
+    //   file: file.slice(start, end),
+    //   fileMd5: md5(''),
+    //   shardingMd5: md5(''),
+    //   baseDomain: '',
+    //   rootPath: 'Content/images/upload/',
+    //   fileName: file.name,
+    //   fileExt: file.type.replace('image/', ''),
+    //   shardingCnt: shardCount,
+    //   shardingNo: i + 1
+    // }
+
     let form = new FormData()
+    let pice = file.slice(start, end)
 
-    form.append('file', file.slice(start, end)) //slice鏂规硶鐢ㄤ簬鍒囧嚭鏂囦欢鐨勪竴閮ㄥ垎
-    form.append('RootPath', 'Content/images/upload/')
-    form.append('name', file.name)
-    form.append('total', shardCount)
-    form.append('index', i + 1)
+    form.append('file', pice) //slice鏂规硶鐢ㄤ簬鍒囧嚭鏂囦欢鐨勪竴閮ㄥ垎
+    form.append('fileMd5', md5(file))
+    form.append('shardingMd5', md5(pice))
+    form.append('baseDomain', '')
+    form.append('rootPath', 'Content/images/upload/')
+    form.append('fileName', file.name)
+    form.append('fileExt', file.type.replace('image/', ''))
+    form.append('shardingCnt', shardCount)
+    form.append('shardingNo', i + 1)
 
-    if (i < shardCount) {
-      i++
-      Api.getFileUpload(form).then(res => {
-        if (res) {
+    Api.getLargeFileUpload(form).then(res => {
+      if (res.status) {
+        if (i < shardCount) {
+          i++
+
           this.setState({
             percent: Math.floor(100 * (i / shardCount))
           })
           this.shardupload(file, shardSize, shardCount, i, fileList)
         }
-      })
-    } else {
-      this.setState({
-        percent: 100
-      }, () => {
-        setTimeout(() => {
-          this.setState({
-            showprogress: false,
-            percent: 0
-          })
-        }, 200)
-      })
-    }
+      } else {
+        fileList = fileList.filter(item => !!item.url)
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+      }
+    })
+    // } else {
+    //   this.setState({
+    //     percent: 100
+    //   }, () => {
+    //     setTimeout(() => {
+    //       this.setState({
+    //         showprogress: false,
+    //         percent: 0
+    //       })
+    //     }, 200)
+    //   })
+    // }
   }
 
   beforeUpload = (file, fileList) => {
     let shardSize = 2 * 1024 * 1024
-    // let shardSize = 3 * 1024
 
     if (file.size > shardSize) {
-      this.setState({
-        showprogress: true,
-        percent: 0
-      })
-      let shardCount = Math.ceil(file.size / shardSize)
-      this.shardupload(file, shardSize, shardCount, 0, fileList)
-      return false
+      // this.setState({
+      //   showprogress: true,
+      //   percent: 0
+      // })
+      // let shardCount = Math.ceil(file.size / shardSize)
+
+      // this.shardupload(file, shardSize, shardCount, 0, fileList)
+      // return false
+      return true
     } else {
       return true
+    }
+  }
+
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
     }
   }
 
@@ -129,7 +166,6 @@
       action: baseUrl,
       method: 'post',
       multiple: true,
-      // headers: {'RootPath': 'Content/images/upload/'},
       onChange: this.onChange,
       onRemove: this.onRemove,
       data: this.getExtraData,

--
Gitblit v1.8.0