useMessageList.ts
1.9 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
/*
* @Date: 2022-06-12 22:51:21
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-12 23:00:04
* @FilePath: /tswj/src/composables/useMessageList.ts
* @Description: 文件描述
*/
import { ref } from 'vue'
import { myCommentAPI } from '@/api/C/me'
import _ from 'lodash'
export const useMessageList = () => {
// 我的留言接口联调
interface commentListType {
id: string;
avatar: string;
name: string;
kg_name: string;
comment_time: string;
note: string;
c_action: string;
c_name: string;
cover: string;
prod_id: string;
perf_id: string;
book_id: string;
perf_name: string;
book_name: string;
localism_type: string;
is_new: number;
}
const commentList = ref<commentListType[]>([])
const loading = ref(false);
const finished = ref(false);
const limit = ref(10);
const offset = ref(0)
const finishedTextStatus = ref(false);
const emptyStatus = ref(false);
const onLoad = async () => {
const { data } = await myCommentAPI({ limit: limit.value, offset: offset.value });
data.forEach((item: { target_name: string | null | undefined; c_action: string; c_name: string; }) => {
let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名
item.c_action = arr[0]; // 评论动作
item.c_name = arr[1]; // 评论姓名
});
// 数据全部加载完成
if (!data.length) {
// 加载状态结束
finished.value = true;
}
commentList.value = [...commentList.value, ...data];
offset.value = commentList.value.length;
loading.value = false;
// 隐藏loading标识,空列表图标
if (!commentList.value.length) {
finishedTextStatus.value = false;
emptyStatus.value = true;
} else {
emptyStatus.value = false;
}
}
return {
onLoad,
commentList,
loading,
finished,
finishedTextStatus,
emptyStatus,
};
}