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

209 lines
5.0 KiB
Vue
Raw Normal View History

2022-10-05 23:54:53 +08:00
<template>
2022-10-12 19:00:26 +08:00
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
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 18:18:19 +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">
2022-10-11 18:18:19 +08:00
<span class="justtitle"> 大白</span>
2022-10-08 23:05:19 +08:00
<br />
2022-10-11 18:18:19 +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-11 18:18:19 +08:00
<van-col class="rowBody" span="24">{{ item.content }}</van-col>
2022-10-05 23:54:53 +08:00
2022-10-08 23:05:19 +08:00
<van-col
span="8"
2022-10-11 18:18:19 +08:00
v-for="(image, imageIndex) in item.images"
2022-10-11 16:48:25 +08:00
: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 18:18:19 +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 18:18:19 +08:00
</van-pull-refresh>
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"
2022-10-11 18:18:19 +08:00
:closeable="true"
2022-10-08 23:05:19 +08:00
>
2022-10-11 18:18:19 +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 18:18:19 +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 18:18:19 +08:00
import AppCreateTime from "@/components/AppCreateTime.vue";
2022-10-11 16:48:25 +08:00
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-12 14:20:03 +08:00
const url = `${import.meta.env.VITE_APP_BASE_API}/file/`;
2022-10-11 18:18:19 +08:00
const data = reactive({
queryParams: {
2022-10-11 16:48:25 +08:00
pageNum: 1,
pageSize: 10,
// dictName: undefined,
// dictType: undefined,
2022-10-11 18:18:19 +08:00
isDeleted: false,
},
2022-10-11 16:48:25 +08:00
});
2022-10-11 18:18:19 +08:00
const { queryParams } = toRefs(data);
2022-10-11 16:48:25 +08:00
2022-10-11 18:18:19 +08:00
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 18:18:19 +08:00
let imagesPreview = ref<string[]>([]);
2022-10-11 16:48:25 +08:00
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-11 18:18:19 +08:00
const actions = [{ name: "取消关注" }, { name: "将TA拉黑" }, { name: "举报" }];
const onLoad = async () => {
if (refreshing.value) {
articleList.value = [];
refreshing.value = false;
}
// 异步更新数据
// setTimeout 仅做示例,真实场景中一般为 ajax 请求
articleApi.pageList(queryParams.value).then((response: any) => {
if (response.data.data.length == 0) {
console.log("结束");
finished.value = true;
} else {
console.log("执行");
articleList.value.push(...(response.data.data as ArticleEntity[]));
totol.value = response.data.totol;
queryParams.value.pageNum += 1;
}
loading.value = false;
console.log(loading.value);
});
};
2022-10-05 23:54:53 +08:00
const onRefresh = () => {
finished.value = false;
// 重新加载数据
// 将 loading 设置为 true表示处于加载状态
loading.value = true;
2022-10-11 18:18:19 +08:00
queryParams.value.pageNum = 1;
onLoad();
};
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;
}
2022-10-11 18:18:19 +08:00
.subtitle {
color: #cbcbcb;
2022-10-08 23:05:19 +08:00
}
2022-10-11 18:18:19 +08:00
.justtitle {
2022-10-08 23:05:19 +08:00
font-size: large;
}
2022-10-11 18:18:19 +08:00
.bottomRow {
2022-10-08 23:05:19 +08:00
color: #979797;
2022-10-05 23:54:53 +08:00
}
2022-10-11 18:18:19 +08:00
.down {
2022-10-09 00:14:17 +08:00
text-align: right;
padding-right: 0.5rem;
}
2022-10-05 23:54:53 +08:00
</style>