|
|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
<view v-for="(item,index) in tabbar" :key="index" class="u-tab-item"
|
|
|
|
|
:class="[current==index ? 'u-tab-item-active' : '']" :data-current="index"
|
|
|
|
|
@tap.stop="swichMenu(index)">
|
|
|
|
|
|
|
|
|
|
<text class="u-line-1">{{item.categoryName}}</text>
|
|
|
|
|
</view>
|
|
|
|
|
</scroll-view>
|
|
|
|
|
@ -17,8 +18,8 @@
|
|
|
|
|
</view> -->
|
|
|
|
|
<view class="item-container">
|
|
|
|
|
<view class="thumb-box" v-for="(item1, index1) in item.goods" :key="index1">
|
|
|
|
|
<image @click="toDetails(item1)" class="item-menu-image" :src="item1.goodsImage.split(',')[0]" mode="">
|
|
|
|
|
</image>
|
|
|
|
|
<image @click="toDetails(item1)" class="item-menu-image"
|
|
|
|
|
:src="item1.goodsImage.split(',')[0]" mode=""></image>
|
|
|
|
|
<view class="item-menu-name">{{item1.goodsName}}</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
@ -40,18 +41,21 @@
|
|
|
|
|
} from "vue"
|
|
|
|
|
// 获取组件实例
|
|
|
|
|
const instance = getCurrentInstance();
|
|
|
|
|
|
|
|
|
|
const tabbar = ref([])
|
|
|
|
|
const scrollTop = ref(0)
|
|
|
|
|
const current = ref(0)
|
|
|
|
|
const menuHeight = ref(0)
|
|
|
|
|
const menuItemHeight = ref(0)
|
|
|
|
|
const menuItemHeight = ref(0) const getImg = ()=>{
|
|
|
|
|
const getImg = () => {
|
|
|
|
|
return Math.floor(Math.random() * 35)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const swichMenu = async (index) => {
|
|
|
|
|
if (index == current.value) return;
|
|
|
|
|
current.value = index;
|
|
|
|
|
// 如果为0,意味着尚未初始化
|
|
|
|
|
|
|
|
|
|
if (menuHeight.value == 0 || menuItemHeight.value == 0) {
|
|
|
|
|
await getElRect('menu-scroll-view', 'menuHeight');
|
|
|
|
|
await getElRect('u-tab-item', 'menuItemHeight');
|
|
|
|
|
@ -59,17 +63,21 @@
|
|
|
|
|
// 将菜单菜单活动item垂直居中
|
|
|
|
|
scrollTop.value = index * menuItemHeight.value + menuItemHeight.value / 2 - menuHeight.value / 2;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
const getElRect = (elClass, dataVal) => {
|
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
|
const query = uni.createSelectorQuery().in(instance);
|
|
|
|
|
|
|
|
|
|
query.select('.' + elClass).fields({
|
|
|
|
|
size: true
|
|
|
|
|
}, res => {
|
|
|
|
|
// 如果节点尚未生成,res值为null,循环调用执行
|
|
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
getElRect(elClass);
|
|
|
|
|
}, 10);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
instance[dataVal] = res.height;
|
|
|
|
|
@ -215,4 +223,5 @@
|
|
|
|
|
width: 120rpx;
|
|
|
|
|
height: 120rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|