From 70f30488f31c2adb1cfb3cb2452ea27c85167019 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 06 八月 2024 11:22:19 +0800
Subject: [PATCH] 2024-08-06

---
 src/tabviews/custom/components/module/voucher/resetAttach/addAttach/fileupload/index.jsx |  109 ++++++++++--------------------------------------------
 1 files changed, 21 insertions(+), 88 deletions(-)

diff --git a/src/tabviews/custom/components/module/voucher/resetAttach/addAttach/fileupload/index.jsx b/src/tabviews/custom/components/module/voucher/resetAttach/addAttach/fileupload/index.jsx
index 627a699..03c3d0f 100644
--- a/src/tabviews/custom/components/module/voucher/resetAttach/addAttach/fileupload/index.jsx
+++ b/src/tabviews/custom/components/module/voucher/resetAttach/addAttach/fileupload/index.jsx
@@ -1,10 +1,9 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import moment from 'moment'
 import { Upload, Button, Progress, notification } from 'antd'
 import { UploadOutlined } from '@ant-design/icons'
-import SparkMD5 from 'spark-md5'
+
 import Api from '@/api'
 import './index.scss'
 
@@ -90,54 +89,6 @@
     })
   }
 
-  shardupload = (param, name) => {
-    let form = new FormData()
-
-    form.append('file', param.binary)
-    form.append('fileMd5', param.fileMd5)
-    form.append('shardingMd5', param.fileMd5)
-    form.append('baseDomain', window.GLOB.baseurl)
-    form.append('rootPath', 'Content/images/upload/')
-    form.append('fileName', param.fileName)
-    form.append('fileExt', param.fileType)
-    form.append('shardingCnt', 1)
-    form.append('shardingNo', 1)
-    form.append('LoginUID', sessionStorage.getItem('LoginUID') || '')
-    form.append('UserID', sessionStorage.getItem('UserID') || '')
-
-    Api.getLargeFileUpload(form).then(res => {
-      if (res.status) {
-        if (res.urlPath) {
-          this.onUpdate(res.urlPath, name)
-        } else {
-          this.onFail()
-        }
-        this.setState({
-          percent: 100
-        }, () => {
-          setTimeout(() => {
-            this.setState({
-              showprogress: false,
-              percent: 0
-            })
-          }, 200)
-        })
-      } else {
-        this.onFail(res.message)
-      }
-    })
-  }
-
-  getuuid = () => {
-    let uuid = []
-    let _options = '0123456789abcdefghigklmnopqrstuv'
-    for (let i = 0; i < 19; i++) {
-      uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
-    }
-    uuid = uuid.join('')
-    return uuid
-  }
-
   beforeUpload = (file) => {
     const { accepts, maxSize } = this.state
 
@@ -172,49 +123,31 @@
       percent: 0
     })
 
-    // 鍏煎鎬х殑澶勭悊
-    let spark = new SparkMD5.ArrayBuffer()         // 瀵筧rrayBuffer鏁版嵁杩涜md5鍔犲瘑锛屼骇鐢熶竴涓猰d5瀛楃涓�
-    let totalFileReader = new FileReader()         // 鐢ㄤ簬璁$畻鍑烘�绘枃浠剁殑fileMd5
-    let param = {}
+    let form = new FormData()
 
-    param.fileName = file.name.replace(/\.{1}[^.]*$/ig, '')  // 鏂囦欢鍚嶏紙鍘婚櫎鍚庣紑鍚嶏級
-    param.fileType = file.name.replace(/^.*\.{1}/ig, '')     // 鏂囦欢绫诲瀷
+    form.append('file', file)
 
-    if (!/^[A-Za-z0-9]+$/.test(param.fileName)) {            // 鏂囦欢鍚嶇О鍚湁鑻辨枃鍙婃暟瀛椾箣澶栧瓧绗︽椂锛屽悕绉扮郴缁熺敓鎴�
-      param.fileName = moment().format('YYYYMMDDHHmmss') + this.getuuid()
-    }
-
-    totalFileReader.readAsArrayBuffer(file)
-    totalFileReader.onload = (e) => {   // 瀵规暣涓猼otalFile鐢熸垚md5
-      spark.append(e.target.result)
-      param.fileMd5 = spark.end()       // 璁$畻鏁翠釜鏂囦欢鐨刦ileMd5
-      param.binary = file
-
-      let _param = new FormData()
-      _param.append('fileMd5', param.fileMd5)
-      
-      Api.getFilePreUpload(_param).then(res => {
-        if (res.status && res.urlPath) {
+    Api.getFileUpload(form).then(res => {
+      if (res.status) {
+        if (res.urlPath) {
           this.onUpdate(res.urlPath, file.name)
-          this.setState({
-            percent: 100
-          }, () => {
-            setTimeout(() => {
-              this.setState({
-                showprogress: false,
-                percent: 0
-              })
-            }, 200)
-          })
         } else {
-          this.shardupload(param, file.name)
+          this.onFail()
         }
-      })
-    }
-
-    totalFileReader.onerror = () => {
-      this.onFail('鏂囦欢璇诲彇澶辫触锛�')
-    }
+        this.setState({
+          percent: 100
+        }, () => {
+          setTimeout(() => {
+            this.setState({
+              showprogress: false,
+              percent: 0
+            })
+          }, 200)
+        })
+      } else {
+        this.onFail(res.message)
+      }
+    })
 
     return false
   }

--
Gitblit v1.8.0