Browse Source

Merge branch 'master' of http://git.ycjcjy.com/xiangsong/miniapp into master

1002884655 4 years ago
parent
commit
9c8b941108
1 changed files with 27 additions and 0 deletions
  1. 27
    0
      src/utils/index.js

+ 27
- 0
src/utils/index.js View File

10
   const router = getCurrentInstance().router
10
   const router = getCurrentInstance().router
11
   return pages.filter(x => router.path.indexOf(x.page) > -1)[0]
11
   return pages.filter(x => router.path.indexOf(x.page) > -1)[0]
12
 }
12
 }
13
+
14
+/**
15
+ * 压缩图片 80%, 最大宽度 750
16
+ * @param {*} img
17
+ */
18
+export function transferImage(img) {
19
+  if (!img) return img;
20
+
21
+  const ossStr = 'oss-'
22
+
23
+  if (img.indexOf(ossStr) > -1) {
24
+    if (store.getState().system.systemInfo.platform !== "ios") {
25
+      // ios 暂时不支持 webp
26
+      return `${img.replace(
27
+        ossPath,
28
+        ossFastPath
29
+      )}?x-oss-process=style/transwebp`;
30
+    }
31
+
32
+    return `${img.replace(
33
+      ossPath,
34
+      ossFastPath
35
+    )}?x-oss-process=style/compress`;
36
+  }
37
+
38
+  return img;
39
+}