Files
Yi.Admin/Yi.Vue3.x.Vant/src/view/main/recommend.vue

229 lines
5.0 KiB
Vue
Raw Normal View History

2022-10-05 23:54:53 +08:00
<template>
2022-10-11 16:48:25 +08:00
2022-10-05 23:54:53 +08:00
<van-list
class="list"
v-model:loading="loading"
:finished="finished"
finished-text="没有更多了"
@load="onLoad"
>
2022-10-11 16:48:25 +08:00
<van-row v-for="(item,index) in articleList" :key="index" class="row">
2022-10-08 23:05:19 +08:00
<van-col span="4" class="leftCol">
2022-10-05 23:54:53 +08:00
<van-image
round
width="3rem"
height="3rem"
src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
/>
</van-col>
2022-10-08 23:05:19 +08:00
<van-col span="14" class="centerTitle">
<span class="justtitle"> 大白</span>
<br />
2022-10-11 16:48:25 +08:00
<app-createTime :time="item.createTime"/>
2022-10-05 23:54:53 +08:00
</van-col>
2022-10-09 00:14:17 +08:00
<van-col span="6" class="down">
2022-10-08 23:05:19 +08:00
<van-icon name="arrow-down" @click="show = true" />
2022-10-05 23:54:53 +08:00
</van-col>
2022-10-08 23:05:19 +08:00
<van-col class="rowBody" span="24"
2022-10-11 16:48:25 +08:00
>{{item.content}}</van-col
2022-10-08 23:05:19 +08:00
>
2022-10-05 23:54:53 +08:00
2022-10-08 23:05:19 +08:00
<van-col
span="8"
2022-10-11 16:48:25 +08:00
v-for="(image,imageIndex) in item.images"
:key="imageIndex"
2022-10-08 23:05:19 +08:00
class="imageCol"
2022-10-11 16:48:25 +08:00
@click="openImage(item.images)"
2022-10-08 23:05:19 +08:00
><van-image
width="100%"
height="7rem"
2022-10-11 16:48:25 +08:00
:src="url+image"
2022-10-08 23:05:19 +08:00
radius="5"
/>
</van-col>
2022-10-05 23:54:53 +08:00
2022-10-08 23:05:19 +08:00
<van-col span="24" class="bottomRow">
2022-10-05 23:54:53 +08:00
<van-grid direction="horizontal" :column-num="3">
<van-grid-item icon="share-o" text="分享" />
2022-10-08 23:05:19 +08:00
<van-grid-item icon="comment-o" text="评论" />
2022-10-05 23:54:53 +08:00
<van-grid-item icon="good-job-o" text="点赞" />
</van-grid>
</van-col>
</van-row>
</van-list>
2022-10-11 16:48:25 +08:00
2022-10-05 23:54:53 +08:00
<!-- 功能页面 -->
<van-action-sheet
2022-10-08 23:05:19 +08:00
v-model:show="show"
:actions="actions"
cancel-text="取消"
close-on-click-action
/>
<!-- 图片预览 -->
<van-image-preview
v-model:show="imageShow"
2022-10-11 16:48:25 +08:00
:images="imagesPreview"
2022-10-08 23:05:19 +08:00
@change="onChange"
:closeable=true
>
2022-10-11 16:48:25 +08:00
<template v-slot:index>{{ index+1 }}</template>
2022-10-08 23:05:19 +08:00
</van-image-preview>
2022-10-05 23:54:53 +08:00
</template>
<script setup lang="ts">
2022-10-11 16:48:25 +08:00
import { ref ,onMounted,reactive, toRefs} from "vue";
2022-10-08 23:05:19 +08:00
import { ImagePreview, Toast } from "vant";
2022-10-11 16:48:25 +08:00
import AppCreateTime from '@/components/AppCreateTime.vue'
import articleApi from "@/api/articleApi.ts";
import { ArticleEntity } from "@/type/interface/ArticleEntity.ts";
2022-10-08 23:05:19 +08:00
const VanImagePreview = ImagePreview.Component;
2022-10-11 16:48:25 +08:00
const url=`${import.meta.env.VITE_APP_BASE_API}/file/image/`
const data=reactive({
queryParams:{
pageNum: 1,
pageSize: 10,
// dictName: undefined,
// dictType: undefined,
isDeleted: false
}
});
const {queryParams} =toRefs(data);
const articleList=ref<ArticleEntity[]>([]);
const totol=ref<Number>(0);
2022-10-08 23:05:19 +08:00
const imageShow = ref(false);
const index = ref(0);
2022-10-11 16:48:25 +08:00
let imagesPreview =ref<string[]>([]);
2022-10-08 23:05:19 +08:00
const onChange = (newIndex: any) => {
index.value = newIndex;
};
2022-10-05 23:54:53 +08:00
const list = ref<Number[]>([]);
const loading = ref(false);
const finished = ref(false);
const refreshing = ref(false);
2022-10-08 23:05:19 +08:00
2022-10-05 23:54:53 +08:00
const show = ref(false);
2022-10-08 23:05:19 +08:00
const actions = [
2022-10-10 00:02:13 +08:00
{ name: "取消关注" },
{ name: "将TA拉黑" },
{ name: "举报"}
2022-10-08 23:05:19 +08:00
];
2022-10-11 16:48:25 +08:00
// const onLoad = () => {
// if (refreshing.value) {
// articleList.value = [];
// refreshing.value = false;
// queryParams.value.pageNum=0;
// }
// queryParams.value.pageNum+=1;
// getList();
// loading.value = false;
// if (articleList.value.length >= 40) {
// finished.value = true;
// }
// };
const onLoad = async() => {
// 异步更新数据
// setTimeout 仅做示例,真实场景中一般为 ajax 请求
setTimeout(async() => {
console.log("执行")
// await getList();
// queryParams.value.pageNum+=1
// 加载状态结束
loading.value = false;
// 数据全部加载完成
if (list.value.length >= 4000) {
finished.value = true;
}
}, 1000);
};
2022-10-05 23:54:53 +08:00
const onRefresh = () => {
// 清空列表数据
finished.value = false;
// 重新加载数据
// 将 loading 设置为 true表示处于加载状态
loading.value = true;
2022-10-11 16:48:25 +08:00
// onLoad();
2022-10-05 23:54:53 +08:00
};
2022-10-11 16:48:25 +08:00
const openImage=(imagesUrl :string[])=>{
imagesPreview.value=imagesUrl.map(i=>url+i);
imageShow.value=true;
}
onMounted(()=>{
articleList.value=[];
getList();
})
const getList=()=>{
articleApi.pageList(queryParams.value).then((response:any)=>{
articleList.value.push(...response.data.data as ArticleEntity[]);
totol.value=response.data.totol;
})
}
2022-10-05 23:54:53 +08:00
</script>
<style scoped>
.list {
2022-10-08 23:05:19 +08:00
background-color: #efefef;
2022-10-05 23:54:53 +08:00
}
.row {
background-color: white;
padding-top: 1rem;
margin-bottom: 1rem;
padding-left: 1rem;
2022-10-09 00:14:17 +08:00
padding-right: 1rem;
2022-10-05 23:54:53 +08:00
}
.rowBody {
2022-10-08 23:05:19 +08:00
text-align: left;
2022-10-05 23:54:53 +08:00
background-color: white;
2022-10-08 23:05:19 +08:00
min-height: 2rem;
2022-10-09 00:14:17 +08:00
margin-top: 1rem;
margin-bottom: 1rem;
2022-10-05 23:54:53 +08:00
}
.title {
2022-10-08 23:05:19 +08:00
padding-top: 1rem;
2022-10-05 23:54:53 +08:00
min-height: 3rem;
text-align: left;
}
2022-10-08 23:05:19 +08:00
.leftCol {
align-content: left;
text-align: left;
}
.centerTitle {
text-align: left;
}
.imageCol {
padding: 0.1rem 0.1rem 0.1rem 0.1rem;
}
.subtitle{
color: #CBCBCB;
}
.justtitle{
font-size: large;
}
.bottomRow{
color: #979797;
2022-10-05 23:54:53 +08:00
}
2022-10-09 00:14:17 +08:00
.down
{
text-align: right;
padding-right: 0.5rem;
}
2022-10-05 23:54:53 +08:00
</style>