Showing
2 changed files
with
68 additions
and
39 deletions
src/composables/useUnwatchList.js
0 → 100644
| 1 | +import { ref } from 'vue' | ||
| 2 | +import axios from '@/utils/axios'; | ||
| 3 | +import _ from 'lodash' | ||
| 4 | +import { Toast } from 'vant'; | ||
| 5 | + | ||
| 6 | +export const useUnwatchList = () => { | ||
| 7 | + // 绑定页面数据 | ||
| 8 | + const prod_list = ref([]); | ||
| 9 | + const limit = ref(10) | ||
| 10 | + const offset = ref(0) | ||
| 11 | + | ||
| 12 | + // 处理书籍下作品列表 | ||
| 13 | + const loading = ref(false); | ||
| 14 | + const finished = ref(false); | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 向下滚动查询数据 | ||
| 18 | + */ | ||
| 19 | + const onLoad = () => { | ||
| 20 | + // 异步更新数据 | ||
| 21 | + axios.get('/srv/?a=my_unplay', { | ||
| 22 | + params: { | ||
| 23 | + limit: limit.value, | ||
| 24 | + offset: offset.value | ||
| 25 | + } | ||
| 26 | + }) | ||
| 27 | + .then(res => { | ||
| 28 | + if (res.data.code === 1) { | ||
| 29 | + prod_list.value = _.concat(prod_list.value, res.data.data.prod); | ||
| 30 | + offset.value = prod_list.value.length; | ||
| 31 | + loading.value = false; | ||
| 32 | + // 数据全部加载完成 | ||
| 33 | + if (!res.data.data.prod.length) { | ||
| 34 | + // 加载状态结束 | ||
| 35 | + finished.value = true; | ||
| 36 | + } | ||
| 37 | + } else { | ||
| 38 | + // tslint:disable-next-line: no-console | ||
| 39 | + console.warn(res); | ||
| 40 | + Toast({ | ||
| 41 | + icon: 'close', | ||
| 42 | + message: res.data.msg | ||
| 43 | + }); | ||
| 44 | + } | ||
| 45 | + }) | ||
| 46 | + .catch(err => { | ||
| 47 | + // tslint:disable-next-line: no-console | ||
| 48 | + console.error(err); | ||
| 49 | + }) | ||
| 50 | + }; | ||
| 51 | + | ||
| 52 | + return { | ||
| 53 | + onLoad, | ||
| 54 | + prod_list, | ||
| 55 | + finished, | ||
| 56 | + loading | ||
| 57 | + } | ||
| 58 | +} |
| 1 | <template> | 1 | <template> |
| 2 | <div class="unwatch-list-page"> | 2 | <div class="unwatch-list-page"> |
| 3 | - <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> | 3 | + <div class="book-video-list"> |
| 4 | - <template v-for="item in dataList" :key="item" style="height: 3rem;"> | 4 | + <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> |
| 5 | - <video-card :item="item"></video-card> | 5 | + <template v-for="item in prod_list" :key="item" style="height: 3rem;"> |
| 6 | - </template> | 6 | + <video-card :item="item"></video-card> |
| 7 | - </van-list> | 7 | + </template> |
| 8 | + </van-list> | ||
| 9 | + </div> | ||
| 8 | </div> | 10 | </div> |
| 9 | </template> | 11 | </template> |
| 10 | 12 | ||
| 11 | <script setup> | 13 | <script setup> |
| 12 | -import dataList from '@/mock/video_list' | 14 | +import { useUnwatchList } from '@/composables/useUnwatchList.js' |
| 13 | -import VideoCard from '@/components/VideoCard/index.vue' | ||
| 14 | - | ||
| 15 | -import { ref, reactive, onMounted } from 'vue' | ||
| 16 | -import { useRoute, useRouter } from 'vue-router' | ||
| 17 | -import axios from '@/utils/axios'; | ||
| 18 | -import $ from 'jquery' | ||
| 19 | -import { Toast } from 'vant'; | ||
| 20 | -const $route = useRoute(); | ||
| 21 | -const $router = useRouter(); | ||
| 22 | - | ||
| 23 | -// 处理书籍下作品列表 | ||
| 24 | -const list = ref([]); | ||
| 25 | -const loading = ref(false); | ||
| 26 | -const finished = ref(false); | ||
| 27 | - | ||
| 28 | -const onLoad = () => { | ||
| 29 | - // 异步更新数据 | ||
| 30 | - // setTimeout 仅做示例,真实场景中一般为 ajax 请求 | ||
| 31 | - setTimeout(() => { | ||
| 32 | - for (let i = 0; i < 20; i++) { | ||
| 33 | - list.value.push(list.value.length + 1); | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - // 加载状态结束 | ||
| 37 | - loading.value = false; | ||
| 38 | 15 | ||
| 39 | - // 数据全部加载完成 | 16 | +import VideoCard from '@/components/VideoCard/index.vue' |
| 40 | - if (list.value.length >= 100) { | ||
| 41 | - finished.value = true; | ||
| 42 | - } | ||
| 43 | - }, 1000); | ||
| 44 | -}; | ||
| 45 | 17 | ||
| 46 | -onMounted(() => { | 18 | +const { onLoad, prod_list, finished, loading } = useUnwatchList(); |
| 47 | 19 | ||
| 48 | -}) | ||
| 49 | </script> | 20 | </script> |
| 50 | 21 | ||
| 51 | <script> | 22 | <script> | ... | ... |
-
Please register or login to post a comment