Sfoglia il codice sorgente

fix: UploadToOss改为props注入,删除掉winow.oss的调用依赖

Roxas 4 anni fa
parent
commit
e6f4c20aa9
3 ha cambiato i file con 60 aggiunte e 70 eliminazioni
  1. 30
    34
      src/components/Editor/Upload.js
  2. 30
    34
      src/components/Editor/index.js
  3. 0
    2
      src/constant.js

+ 30
- 34
src/components/Editor/Upload.js Vedi File

@@ -3,44 +3,39 @@ import { Upload, Icon, Modal, message, Spin } from "antd";
3 3
 import dayjs from "dayjs";
4 4
 import shortid from "shortid";
5 5
 import intl from "react-intl-universal";
6
-import {
7
-  OSS_ENDPOINT,
8
-  OSS_BUCKET,
9
-  DRIVER_LICENSE_PATH,
10
-  ERROR_DEFAULT
11
-} from "../../constant";
6
+import { DRIVER_LICENSE_PATH, ERROR_DEFAULT } from "../../constant";
12 7
 import Comment from "../../Comment";
13 8
 import "./Upload.css";
14 9
 
15
-const client = oss => {
16
-  return new window.OSS.Wrapper({
17
-    accessKeyId: oss.access_key_id,
18
-    accessKeySecret: oss.access_key_secret,
19
-    stsToken: oss.security_token,
20
-    endpoint: OSS_ENDPOINT, //常量,你可以自己定义
21
-    bucket: OSS_BUCKET
22
-  });
23
-};
10
+// const client = oss => {
11
+//   return new window.OSS.Wrapper({
12
+//     accessKeyId: oss.access_key_id,
13
+//     accessKeySecret: oss.access_key_secret,
14
+//     stsToken: oss.security_token,
15
+//     endpoint: OSS_ENDPOINT, //常量,你可以自己定义
16
+//     bucket: OSS_BUCKET
17
+//   });
18
+// };
24 19
 
25
-const uploadPath = (path, file) => {
26
-  return `${path}/${dayjs().format("YYYYMMDD")}/${shortid.generate()}.${
27
-    file.type.split("/")[1]
28
-  }`;
29
-};
20
+// const uploadPath = (path, file) => {
21
+//   return `${path}/${dayjs().format("YYYYMMDD")}/${shortid.generate()}.${
22
+//     file.type.split("/")[1]
23
+//   }`;
24
+// };
30 25
 
31
-const UploadToOss = (oss, path, file) => {
32
-  const url = uploadPath(path, file);
33
-  return new Promise((resolve, reject) => {
34
-    client(oss)
35
-      .multipartUpload(url, file)
36
-      .then(data => {
37
-        resolve(data);
38
-      })
39
-      .catch(error => {
40
-        reject(error);
41
-      });
42
-  });
43
-};
26
+// const UploadToOss = (oss, path, file) => {
27
+//   const url = uploadPath(path, file);
28
+//   return new Promise((resolve, reject) => {
29
+//     client(oss)
30
+//       .multipartUpload(url, file)
31
+//       .then(data => {
32
+//         resolve(data);
33
+//       })
34
+//       .catch(error => {
35
+//         reject(error);
36
+//       });
37
+//   });
38
+// };
44 39
 
45 40
 class App extends React.Component {
46 41
   constructor(props) {
@@ -94,7 +89,8 @@ class App extends React.Component {
94 89
     reader.onloadend = () => {
95 90
       info.onProgress({ percent: 20 });
96 91
       // DRIVER_LICENSE_PATH oss 的存储路径位置
97
-      UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
92
+      this.props.app
93
+        .UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
98 94
         .then(data => {
99 95
           info.onProgress({ percent: 100 });
100 96
           info.onSuccess(data);

+ 30
- 34
src/components/Editor/index.js Vedi File

@@ -11,45 +11,40 @@ import Comment from "../../Comment";
11 11
 import { isMobile } from "./../../utils";
12 12
 import { OSS_LINK } from "../../constant";
13 13
 import { isFunction } from "../../helper";
14
-import {
15
-  OSS_ENDPOINT,
16
-  OSS_BUCKET,
17
-  DRIVER_LICENSE_PATH,
18
-  ERROR_DEFAULT
19
-} from "../../constant";
14
+import { DRIVER_LICENSE_PATH, ERROR_DEFAULT } from "../../constant";
20 15
 import "./index.css";
21 16
 
22 17
 const { TextArea } = Input;
23 18
 
24
-const client = oss => {
25
-  return new window.OSS.Wrapper({
26
-    accessKeyId: oss.access_key_id,
27
-    accessKeySecret: oss.access_key_secret,
28
-    stsToken: oss.security_token,
29
-    endpoint: OSS_ENDPOINT, //常量,你可以自己定义
30
-    bucket: OSS_BUCKET
31
-  });
32
-};
19
+// const client = oss => {
20
+//   return new window.OSS.Wrapper({
21
+//     accessKeyId: oss.access_key_id,
22
+//     accessKeySecret: oss.access_key_secret,
23
+//     stsToken: oss.security_token,
24
+//     endpoint: OSS_ENDPOINT, //常量,你可以自己定义
25
+//     bucket: OSS_BUCKET
26
+//   });
27
+// };
33 28
 
34
-const uploadPath = (path, file) => {
35
-  return `${path}/${dayjs().format("YYYYMMDD")}/${shortid.generate()}.${
36
-    file.type.split("/")[1]
37
-  }`;
38
-};
29
+// const uploadPath = (path, file) => {
30
+//   return `${path}/${dayjs().format("YYYYMMDD")}/${shortid.generate()}.${
31
+//     file.type.split("/")[1]
32
+//   }`;
33
+// };
39 34
 
40
-const UploadToOss = (oss, path, file) => {
41
-  const url = uploadPath(path, file);
42
-  return new Promise((resolve, reject) => {
43
-    client(oss)
44
-      .multipartUpload(url, file)
45
-      .then(data => {
46
-        resolve(data);
47
-      })
48
-      .catch(error => {
49
-        reject(error);
50
-      });
51
-  });
52
-};
35
+// const UploadToOss = (oss, path, file) => {
36
+//   const url = uploadPath(path, file);
37
+//   return new Promise((resolve, reject) => {
38
+//     client(oss)
39
+//       .multipartUpload(url, file)
40
+//       .then(data => {
41
+//         resolve(data);
42
+//       })
43
+//       .catch(error => {
44
+//         reject(error);
45
+//       });
46
+//   });
47
+// };
53 48
 
54 49
 class Editor extends React.Component {
55 50
   constructor(props) {
@@ -214,7 +209,8 @@ class Editor extends React.Component {
214 209
     reader.readAsDataURL(file);
215 210
     reader.onloadend = () => {
216 211
       // DRIVER_LICENSE_PATH oss 的存储路径位置
217
-      UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
212
+      this.props.app
213
+        .UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
218 214
         .then(data => {
219 215
           const fileList = this.state.fileList.concat({
220 216
             url: OSS_LINK + data.name,

+ 0
- 2
src/constant.js Vedi File

@@ -2,8 +2,6 @@ export const ERROR_DEFAULT = "出错了!";
2 2
 
3 3
 export const LIMIT = 10; // 默认 limit
4 4
 
5
-export const OSS_ENDPOINT = "oss-cn-beijing.aliyuncs.com";
6
-export const OSS_BUCKET = "links-comment";
7 5
 export const DRIVER_LICENSE_PATH = "/comment";
8 6
 
9 7
 export const OSS_LINK = "//links-comment.oss-cn-beijing.aliyuncs.com";