|
|
|
@ -5,7 +5,8 @@
|
|
|
|
|
<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.name}}</text>
|
|
|
|
|
|
|
|
|
|
<text class="u-line-1">{{item.categoryName}}</text>
|
|
|
|
|
</view>
|
|
|
|
|
</scroll-view>
|
|
|
|
|
<block v-for="(item,index) in tabbar" :key="index">
|
|
|
|
@ -16,9 +17,10 @@
|
|
|
|
|
<text>{{item.name}}</text>
|
|
|
|
|
</view> -->
|
|
|
|
|
<view class="item-container">
|
|
|
|
|
<view class="thumb-box" v-for="(item1, index1) in item.foods" :key="index1">
|
|
|
|
|
<image class="item-menu-image" :src="item1.icon" mode=""></image>
|
|
|
|
|
<view class="item-menu-name">{{item1.name}}</view>
|
|
|
|
|
<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>
|
|
|
|
|
<view class="item-menu-name">{{item1.goodsName}}</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
@ -30,84 +32,76 @@
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import {
|
|
|
|
|
getCategoryListApi
|
|
|
|
|
} from "../../api/category";
|
|
|
|
|
import {
|
|
|
|
|
ref,
|
|
|
|
|
getCurrentInstance
|
|
|
|
|
} from "vue"
|
|
|
|
|
// 获取组件实例
|
|
|
|
|
const instance = getCurrentInstance();
|
|
|
|
|
const tabbar = ref([{
|
|
|
|
|
"name": "早点",
|
|
|
|
|
"foods": [{
|
|
|
|
|
"name": "豆浆",
|
|
|
|
|
"key": "豆浆",
|
|
|
|
|
"icon": "/static/test-5.png",
|
|
|
|
|
"cat": 6
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "油条",
|
|
|
|
|
"key": "糕点饼干",
|
|
|
|
|
"icon": "/static/test-8.png",
|
|
|
|
|
"cat": 6
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "油条",
|
|
|
|
|
"key": "糕点饼干",
|
|
|
|
|
"icon": "/static/test-8.png",
|
|
|
|
|
"cat": 6
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "米线",
|
|
|
|
|
"foods": [{
|
|
|
|
|
"name": "小锅米线",
|
|
|
|
|
"key": "豆浆",
|
|
|
|
|
"icon": "/static/test-5.png",
|
|
|
|
|
"cat": 6
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "豆花米线",
|
|
|
|
|
"key": "糕点饼干",
|
|
|
|
|
"icon": "/static/test-5.png",
|
|
|
|
|
"cat": 6
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
const tabbar = ref([])
|
|
|
|
|
const scrollTop = ref(0)
|
|
|
|
|
const current = ref(0)
|
|
|
|
|
const menuHeight = ref(0)
|
|
|
|
|
const menuItemHeight = ref(0)
|
|
|
|
|
const getImg = ()=>{
|
|
|
|
|
const menuItemHeight = ref(0) const getImg = ()=>{
|
|
|
|
|
const getImg = () => {
|
|
|
|
|
return Math.floor(Math.random() * 35)
|
|
|
|
|
}
|
|
|
|
|
const swichMenu = async(index)=>{
|
|
|
|
|
if(index == current.value) return ;
|
|
|
|
|
|
|
|
|
|
const swichMenu = async (index) => {
|
|
|
|
|
if (index == current.value) return;
|
|
|
|
|
current.value = index;
|
|
|
|
|
// 如果为0,意味着尚未初始化
|
|
|
|
|
if(menuHeight.value == 0 || menuItemHeight.value == 0) {
|
|
|
|
|
|
|
|
|
|
if (menuHeight.value == 0 || menuItemHeight.value == 0) {
|
|
|
|
|
await getElRect('menu-scroll-view', 'menuHeight');
|
|
|
|
|
await getElRect('u-tab-item', 'menuItemHeight');
|
|
|
|
|
}
|
|
|
|
|
// 将菜单菜单活动item垂直居中
|
|
|
|
|
scrollTop.value = index * menuItemHeight.value + menuItemHeight.value / 2 - menuHeight.value / 2;
|
|
|
|
|
}
|
|
|
|
|
const getElRect = (elClass, dataVal)=>{
|
|
|
|
|
{
|
|
|
|
|
const getElRect = (elClass, dataVal) => {
|
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
|
const query = uni.createSelectorQuery().in(instance);
|
|
|
|
|
query.select('.' + elClass).fields({size: true},res => {
|
|
|
|
|
|
|
|
|
|
query.select('.' + elClass).fields({
|
|
|
|
|
size: true
|
|
|
|
|
}, res => {
|
|
|
|
|
// 如果节点尚未生成,res值为null,循环调用执行
|
|
|
|
|
if(!res) {
|
|
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
getElRect(elClass);
|
|
|
|
|
}, 10);
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
instance[dataVal] = res.height;
|
|
|
|
|
}).exec();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
//获取分类数据
|
|
|
|
|
const getCategoryList = async () => {
|
|
|
|
|
let res = await getCategoryListApi()
|
|
|
|
|
if (res && res.code == 200) {
|
|
|
|
|
tabbar.value = res.data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//跳转详情
|
|
|
|
|
const toDetails = (item) => {
|
|
|
|
|
console.log(item)
|
|
|
|
|
//在起始页面跳转到details.vue页面并传递参数
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url: '../detail/detail?goods=' + JSON.stringify(item)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
onLoad(() => {
|
|
|
|
|
getCategoryList()
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -229,5 +223,5 @@
|
|
|
|
|
width: 120rpx;
|
|
|
|
|
height: 120rpx;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
</style>
|