2020-02-25自动换算 2倍图 3倍图

    var this_ = this;
    wx.getSystemInfo({
      success: function (res) {
        if (res.pixelRatio <= 1) {
          this_.globalData.pr = 1
        } else if (res.pixelRatio <= 2) {
          this_.globalData.pr = 2
        } else {
          this_.globalData.pr = 3
        }
      },
      fail: function () {
        this.globalData.pr = 1
      }
    })
  },
  globalData: {
    userInfo: null,
    httpurl: 'https://dkapi.stack.xin',
    pr: 1,
    user_id: null
  },

utils.js

var pr = app.globalData.pr
const imageSrc = src => {
  return (pr == 1 || !pr) ? src : src.replace(/^(.*@)\d(x\.(png|jp?g))$/g, "$1" + pr + "$2")
}
module.exports = {
  imageSrc: imageSrc,
}

使用方法

//引入 util 
import {
  imageSrc
} from "../../utils/util.js"
var image = {
  search: imageSrc("https://dk-shop-img.oss-cn-beijing.aliyuncs.com/index/[email protected]"),
  wx: imageSrc("https://dk-shop-img.oss-cn-beijing.aliyuncs.com/index/[email protected]"),
}

你可能感兴趣的:(2020-02-25自动换算 2倍图 3倍图)