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/icon_search@1x.png"),
wx: imageSrc("https://dk-shop-img.oss-cn-beijing.aliyuncs.com/index/icon_message@1x.png"),
}
网友评论