index.js 850B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { getCurrentInstance } from '@tarojs/taro'
  2. const pages = require('../pages')
  3. // 深度拷贝
  4. export const deepCopy = x => JSON.parse(JSON.stringify(X))
  5. // 获取当前页面配置
  6. export const getPage = () => {
  7. const router = getCurrentInstance().router
  8. return pages.filter(x => router.path.indexOf(x.page) > -1)[0]
  9. }
  10. /**
  11. * 压缩图片 80%, 最大宽度 750
  12. * @param {*} img
  13. */
  14. export function transferImage(img) {
  15. if (!img) return img;
  16. const ossStr = 'oss-'
  17. if (img.indexOf(ossStr) > -1) {
  18. if (store.getState().system.systemInfo.platform !== "ios") {
  19. // ios 暂时不支持 webp
  20. return `${img.replace(
  21. ossPath,
  22. ossFastPath
  23. )}?x-oss-process=style/transwebp`;
  24. }
  25. return `${img.replace(
  26. ossPath,
  27. ossFastPath
  28. )}?x-oss-process=style/compress`;
  29. }
  30. return img;
  31. }