张延森 3 vuotta sitten
vanhempi
commit
cb70418d05
1 muutettua tiedostoa jossa 22 lisäystä ja 0 poistoa
  1. 22
    0
      src/util/index.js

+ 22
- 0
src/util/index.js Näytä tiedosto

@@ -0,0 +1,22 @@
1
+
2
+/**
3
+ * 压缩图片
4
+ * @param {*} url 
5
+ * @returns 
6
+ */
7
+ export function compressImage(url, typ) {
8
+  if (!url) return url;
9
+
10
+  // GIF 不压缩
11
+  if (url.indexOf('.gif') > -1) return url;
12
+
13
+  const style = typ || 'cmp80'
14
+
15
+  // eslint-disable-next-line no-undef
16
+  const ossLike = 'aliyuncs.com'
17
+  if (url.indexOf(ossLike) > -1) {
18
+    return `${url}?x-oss-process=style/${style}` //.replace('http://', 'https://')
19
+  }
20
+
21
+  return url;
22
+}