util.js 495 B

123456789101112131415161718192021
  1. // 将rpx转px
  2. function sizeDeal (size) {
  3. const info = uni.getSystemInfoSync()
  4. let scale = 750 / info.windowWidth;
  5. // 分离字体大小和单位,rpx 转 px
  6. let s = Number.isNaN(parseFloat(size)) ? 0 : parseFloat(size)
  7. let u = size.toString().replace(/[0-9]/g, '').replace('-', '')
  8. if (u == 'rpx') {
  9. s /= scale
  10. u = 'px'
  11. } else if (u == '') {
  12. u = 'px'
  13. } else if (u == 'vw') {
  14. u = 'px'
  15. s = s / 100 * 750 / scale
  16. }
  17. return [s, u, s + u]
  18. }
  19. module.exports = {
  20. sizeDeal:sizeDeal
  21. }