当前位置: 首页> 科技> 互联网 > 东莞企业网站价格_10大免费图片处理软件_深圳网络营销的公司哪家好_百度指数资讯指数是指什么

东莞企业网站价格_10大免费图片处理软件_深圳网络营销的公司哪家好_百度指数资讯指数是指什么

时间:2025/7/28 12:31:34来源:https://blog.csdn.net/qq_55111117/article/details/145927429 浏览次数:0次
东莞企业网站价格_10大免费图片处理软件_深圳网络营销的公司哪家好_百度指数资讯指数是指什么

 抽离公共方法用条件编译对微信小程序,抖音小程序适配

 公共组件模块建立一个导航模块

<template><view class="layout"><view class="navbar" ><view class="statusBar" :style="{height:getStatusBarHeight()+'px'}"></view><view class="titleBar" :style="{height:getTitleBarHeight()+'px'}"><view class="title">标题</view><view class="search"><uni-icons class="icon" type="search" size="18" color="#888"></uni-icons><text class="text">搜索</text></view></view></view><view class="fill" :style="{height:getNavBarHeight()+'px',marginLeft:getLeftIconLeft()+'px'}"></view></view>
</template><script setup>import { ref } from 'vue';import { getStatusBarHeight,getTitleBarHeight,getNavBarHeight,getLeftIconLeft } from '@/utils/system.js';// let SYSTEM_INFO = uni.getSystemInfoSync();// // 状态栏高度// let statusBarHeight = ref(SYSTEM_INFO.statusBarHeight);// // 胶囊按钮状态 解构// let {top,height} = uni.getMenuButtonBoundingClientRect();// let titleBarHeight = ref( height + (top - statusBarHeight.value)-2);// console.log(titleBarHeight);// console.log(top,height);
</script><style lang="scss" scoped>
.layout{.navbar{position: fixed;top: 0;left: 0;width: 100%;z-index: 10;background:linear-gradient(to bottom,transparent,#fff 400rpx),linear-gradient(to right,#beecd8 20%,#F4E2D8);.statusBar{// border: 1px solid red;}.titleBar{display: flex;padding: 0 30rpx;align-items: center;// border: 1px solid green;.title{font-size: 22px;font-weight: 700;color: $text-font-color-1;}.search{width: 220rpx;height: 50rpx;border-radius: 60rpx;background: rgba(255,255,255,0.4);border: 1px solid #fff;margin-left: 30rpx;color: #999;font-size: 28rpx;.text{// display: flex;align-items: center;padding-left: 10rpx;}.icon{margin-left: 5rpx;}}}}.fill{}
}
</style>

重新在项目下建立一个 utils文件夹 ,再建立一个获取系统信息的js文件,写逻辑代码

// 获取系统信息
const SYSTEM_INFO = uni.getSystemInfoSync();// 获取状态栏高度,若未获取到则默认为0
export const getStatusBarHeight = () => SYSTEM_INFO.statusBarHeight || 10 ;
// 获取标题栏高度
export const getTitleBarHeight = ()=>{if(uni.getMenuButtonBoundingClientRect){// 获取胶囊按钮的位置和尺寸信息let {top,height} = uni.getMenuButtonBoundingClientRect();// 计算标题栏高度return height + (top - getStatusBarHeight())*2;}else{// 若无法获取胶囊按钮信息,默认标题栏高度为80return 40;}
};
// 获取导航栏高度,导航栏高度对于状态栏高度加上标题栏高度
export const getNavBarHeight = ()=> getStatusBarHeight()+getTitleBarHeight();// 抖音小程序export const getLeftIconLeft = ()=>{// if(tt.getMenuButtonBoundingClientRect){// 	// 获取胶囊按钮的位置和尺寸信息// 	let {leftIcon:{left,width}} = tt.getMenuButtonBoundingClientRect();// 	// 计算标题栏高度// 	return left + parseInt(width)+100;// }else{// 	// 若无法获取胶囊按钮信息,默认标题栏高度为80// 	return 40;// }// #ifdef MP-TOUTIAO// 获取胶囊按钮的位置和尺寸信息let {leftIncon:{left,width}} = tt.getMenuButtonBoundingClientRect();// 计算标题栏高度return left + parseInt(width);// #endif// #ifdef MP-TOUTIAOreturn 0;// #endif
}

 可以在pages目录下的页面上进行引用

关键字:东莞企业网站价格_10大免费图片处理软件_深圳网络营销的公司哪家好_百度指数资讯指数是指什么

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: