export const toInteger = function (num) { // 取整 let toNum = ""; toNum = parseInt(num); return toNum; } export const twoFloating = function (num) { // 获取两位小数 let price = ""; price = num * 1; price = String(price).split(".")[1]; if (price !== undefined && price.length === 1) { price = `.${price}0`; } else { price === undefined ? (price = ".00") : (price = `.${price}`); } return price; } /** * 获取开发平台 * @returns {string} */ export const getPlatform = function () { let platForm = undefined; // #ifdef H5 platForm = 'H5'; //#endif // #ifdef APP-PLUS platForm = 'APP'; //#endif // #ifdef APP-PLUS-NVUE platForm = 'APP'; //#endif // #ifdef APP-NVUE platForm = 'APP'; //#endif // #ifdef MP-WEIXIN platForm = 'MP-WEIXIN'; //#endif // #ifdef MP-ALIPAY platForm = 'MP-ALIPAY'; //#endif // #ifdef MP-BAIDU platForm = 'MP-BAIDU'; //#endif // #ifdef MP-TOUTIAO platForm = 'MP-TOUTIAO'; //#endif // #ifdef MP-LARK platForm = 'MP-LARK'; //#endif // #ifdef MP-QQ platForm = 'MP-QQ'; //#endif // #ifdef MP-KUAISHOU platForm = 'MP-KUAISHOU'; //#endif // #ifdef QUICKAPP-WEBVIEW platForm = 'QUICKAPP-WEBVIEW'; //#endif return platForm; } /** * 获取小程序胶囊居中对齐的高度 */ export const getNavHeight = function () { let platForm = getPlatform(); if (platForm === 'MP-WEIXIN') { let res = uni.getSystemInfoSync(); let menuButtonInfo = uni.getMenuButtonBoundingClientRect(); let navHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2; return navHeight } else { return 44; } } /** * 手机顶部高度 */ export const getPhoneTopHeight = function () { let platForm = getPlatform(); if (platForm === 'MP-WEIXIN') { let height = uni.getSystemInfoSync().statusBarHeight; return height } else { return 0; } }