utils.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. export const toInteger = function (num) {
  2. // 取整
  3. let toNum = "";
  4. toNum = parseInt(num);
  5. return toNum;
  6. }
  7. export const twoFloating = function (num) {
  8. // 获取两位小数
  9. let price = "";
  10. price = num * 1;
  11. price = String(price).split(".")[1];
  12. if (price !== undefined && price.length === 1) {
  13. price = `.${price}0`;
  14. } else {
  15. price === undefined ? (price = ".00") : (price = `.${price}`);
  16. }
  17. return price;
  18. }
  19. /**
  20. * 获取开发平台
  21. * @returns {string}
  22. */
  23. export const getPlatform = function () {
  24. let platForm = undefined;
  25. // #ifdef H5
  26. platForm = 'H5';
  27. //#endif
  28. // #ifdef APP-PLUS
  29. platForm = 'APP';
  30. //#endif
  31. // #ifdef APP-PLUS-NVUE
  32. platForm = 'APP';
  33. //#endif
  34. // #ifdef APP-NVUE
  35. platForm = 'APP';
  36. //#endif
  37. // #ifdef MP-WEIXIN
  38. platForm = 'MP-WEIXIN';
  39. //#endif
  40. // #ifdef MP-ALIPAY
  41. platForm = 'MP-ALIPAY';
  42. //#endif
  43. // #ifdef MP-BAIDU
  44. platForm = 'MP-BAIDU';
  45. //#endif
  46. // #ifdef MP-TOUTIAO
  47. platForm = 'MP-TOUTIAO';
  48. //#endif
  49. // #ifdef MP-LARK
  50. platForm = 'MP-LARK';
  51. //#endif
  52. // #ifdef MP-QQ
  53. platForm = 'MP-QQ';
  54. //#endif
  55. // #ifdef MP-KUAISHOU
  56. platForm = 'MP-KUAISHOU';
  57. //#endif
  58. // #ifdef QUICKAPP-WEBVIEW
  59. platForm = 'QUICKAPP-WEBVIEW';
  60. //#endif
  61. return platForm;
  62. }
  63. /**
  64. * 获取小程序胶囊居中对齐的高度
  65. */
  66. export const getNavHeight = function () {
  67. let platForm = getPlatform();
  68. if (platForm === 'MP-WEIXIN') {
  69. let res = uni.getSystemInfoSync();
  70. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  71. let navHeight =
  72. menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2;
  73. return navHeight
  74. } else {
  75. return 44;
  76. }
  77. }
  78. /**
  79. * 手机顶部高度
  80. */
  81. export const getPhoneTopHeight = function () {
  82. let platForm = getPlatform();
  83. if (platForm === 'MP-WEIXIN') {
  84. let height = uni.getSystemInfoSync().statusBarHeight;
  85. return height
  86. } else {
  87. return 0;
  88. }
  89. }