useUnwatchList.js
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { ref } from 'vue'
import axios from '@/utils/axios';
import _ from 'lodash'
import { Toast } from 'vant';
export const useUnwatchList = () => {
// 绑定页面数据
const prod_list = ref([]);
const limit = ref(10)
const offset = ref(0)
// 处理书籍下作品列表
const loading = ref(false);
const finished = ref(false);
// 因为不能让空图标提前出来的写法
const finishedTextStatus = ref(false);
const emptyStatus = ref(false);
/**
* 向下滚动查询数据
*/
const onLoad = () => {
// 异步更新数据
axios.get('/srv/?a=my_unplay', {
params: {
limit: limit.value,
offset: offset.value
}
})
.then(res => {
if (res.data.code === 1) {
prod_list.value = _.concat(prod_list.value, res.data.data.prod);
prod_list.value = _.uniqBy(prod_list.value, 'id');
_.each(prod_list.value, (item) => {
item.type = 'read-only' // 特殊标识,判断入口 为keepAlive使用
})
offset.value = prod_list.value.length;
loading.value = false;
// 数据全部加载完成
if (!res.data.data.prod.length) {
// 加载状态结束
finished.value = true;
}
// 空数据提示
if (!prod_list.value.length) {
finishedTextStatus.value = false;
emptyStatus.value = true;
}
} else {
// tslint:disable-next-line: no-console
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
// tslint:disable-next-line: no-console
console.error(err);
})
};
return {
onLoad,
prod_list,
finished,
loading,
finishedTextStatus,
emptyStatus,
}
}