pan-mini/pages/category/category.vue

121 lines
2.9 KiB
Vue

<template>
<smart-tabs
:tabs="tabs"
:initial-index="current"
:scrollEnable="true"
:activeColor="'#19c324'"
@change="handleTabChange"
>
</smart-tabs>
<!-- 视频列表 -->
<view class="video-container">
<image-grid-simple
:imageList="list"
:columns="2"
:height="'80vh'"
@image-click="handlerClick"
@load-more-action = "queryList"
>
<!-- <template #empty>
<view class="custom-empty">
<image src="/static/images/no-videos.png" />
<text>没有找到视频内容</text>
</view>
</template> -->
</image-grid-simple>
</view>
</template>
<script>
export default {
data() {
return {
current:0,
tabs:[],
list:[],
pageInfo:{
index:1,
size:10,
isEnd:false,
sub_category_id:0
}
}
},
onLoad() {
this.getCategory()
},
methods: {
getCategory() {
// 获取分类
let param = {
index:1,
size:1000,
target:'sub'
}
try {
this.$http.get('/category/list',param).then((resp)=>{
this.tabs = [];
resp.data?.list.forEach((item,idx)=>{
this.tabs.push({
id:item?.id,
label:item?.name,
});
});
this.pageInfo.sub_category_id = this.tabs[this.current].id
this.queryList()
})
} catch(err){
console.log("query category error",err)
}
},
handleTabChange(idx) {
this.current = idx;
this.pageInfo.sub_category_id = this.tabs[this.current].id
},
queryList() {
if (this.pageInfo.isEnd) {
uni.showToast({
title: '没有更多数据了哦!^v^',
icon: 'none',
complete: () => {
console.log("no more data")
}
});
return
}
let param = {
...this.pageInfo
}
try {
uni.$http.get('/resource/list',param).then((resp) => {
console.log("resp data",resp.data);
resp.data?.list.forEach((item,idx)=>{
this.list.push({
id:item?.id,
name:item?.name,
src:item?.thumb_src,
android_src:item?.android_src,
});
});
console.log("length:",this.list.length,resp.data.page.rows,resp.data.page)
if (this.list.length >= resp.data.page.rows) {
this.pageInfo.isEnd = true
} else {
this.pageInfo.isEnd = false
this.pageInfo.index++
}
})
}catch(err) {
console.log("catch query list err:",err)
}
}
}
}
</script>
<style>
</style>