JM-MiniApp/pages/wikipedia/index.vue

113 lines
2.6 KiB
Vue
Raw Normal View History

2023-10-19 23:23:22 +08:00
<script setup>
// 引入依赖
// import uniDatetimePicker from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue'
// import uniEasyinput from '@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue'
import { onLoad,onPullDownRefresh,onReachBottom } from "@dcloudio/uni-app"
// import mySwiper from "@/components/mySwiper.vue"
import {ref,onMounted,nextTick} from "vue"
import {useStore} from '@/store/index.js'
import api from "@/api/index"
2023-11-28 22:30:40 +08:00
import emptyCard from "@/components/emptyCard.vue"
2023-10-19 23:23:22 +08:00
// 生命周期
onLoad(() => {
getList()
})
// 下拉刷新
onPullDownRefresh(()=>{
init()
getList()
// setTimeout(function () {
// uni.stopPullDownRefresh();
// }, 1000);
})
// 上拉触底
onReachBottom(()=>{
queryParams.value.page ++
getList()
})
// 变量
const queryParams = ref({
page:1,
pageSize:10
})
2023-11-01 00:33:57 +08:00
const list = ref([])
2023-10-19 23:23:22 +08:00
// 方法
function init() {
queryParams.page = 1
queryParams.pageSize = 10
2023-11-01 00:33:57 +08:00
list.value = []
2023-10-19 23:23:22 +08:00
}
async function getList(){
const res = await api.getArticleList(queryParams.value)
2023-11-01 00:33:57 +08:00
if(res.code == 0) {
if( res.data.list.length>0) {
list.value.push(...res.data.list)
}
else{
queryParams.page-=1
}
}
else{
uni.showToast({
title:'获取失败',
icon:"error",
duration:2000
})
}
2023-10-19 23:23:22 +08:00
}
function toDetail(item) {
2023-12-29 00:12:16 +08:00
// let info = encodeURIComponent(JSON.stringify(item))
2023-10-19 23:23:22 +08:00
// console.log(info)
uni.navigateTo({
2023-11-01 00:33:57 +08:00
url:"./detail?id="+item.ID
2023-10-19 23:23:22 +08:00
})
}
2023-10-08 21:21:21 +08:00
</script>
2023-10-19 23:23:22 +08:00
<template>
<view class="articleBox page-box">
<view class="userInfoBox">
</view>
<view class="list-box">
2023-11-28 22:30:40 +08:00
<view v-if="list.length>0" class="lb-card" v-for="(item,i) in list" @tap="toDetail(item)">
2023-10-19 23:23:22 +08:00
<view class="lb-left">
<image :src="item.cover_img" mode="aspectFill"></image>
</view>
<view class="lb-right">
<view class="lb-title">{{item.title}}</view>
2023-11-01 00:33:57 +08:00
<view class="lb-content text-ellipsis-1 small-text" v-html="item.content"></view>
2023-10-19 23:23:22 +08:00
</view>
</view>
2023-11-28 22:30:40 +08:00
<emptyCard v-else></emptyCard>
2023-10-19 23:23:22 +08:00
</view>
</view>
</template>
<style scoped lang="scss">
.articleBox{
.list-box{
.lb-card{
display: flex;
align-items: center;
padding: 20rpx;
border-bottom: 2rpx solid #eaeaea;
.lb-left{
image{
width: 120rpx;
height: 120rpx;
margin-right: 20rpx;
}
}
.lb-right{
display: flex;
flex-direction: column;
justify-content: space-between;
.lb-title{
font-weight: 900;
font-size:32rpx ;
margin-bottom: 20rpx;
}
}
}
}
}
2023-10-08 21:21:21 +08:00
</style>