message.vue
5.53 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<template>
<van-list v-model:loading="loading" :finished="finished" :finished-text="finishedTextStatus ? '没有更多了' : ''"
@load="onLoad">
<div v-for="(item, key) in commentList" :key="key" class="comment">
<div class="comment-wrapper">
<van-row style="font-size: 0.9rem;">
<van-col span="4">
<van-image v-if="item.avatar" round width="3rem" height="3rem" :src="item.avatar" />
<van-image v-else round width="3rem" height="3rem" :src="icon_avatar" />
</van-col>
<van-col span="15">
<p>{{ item.name }}</p>
<p>{{ item.kg_name }}</p>
</van-col>
<van-col span="5" style="text-align: right;">
<p style="color: #333333;" @click="deleteComment(item.id)">删除</p>
<p>{{ item.comment_time }}</p>
</van-col>
</van-row>
<van-row>
<van-col>
<span style="color: #222222;">{{ item.c_action }}<span style="color: #0B3A72;">@{{ item.c_name }}</span>:{{
item.note
}}</span>
</van-col>
</van-row>
</div>
<div class="raw-ref" @click="goToVideoDetail(item)">
<van-row>
<van-col span="8" class="image">
<van-image width="8rem" height="5rem" fit="cover" :src="item.cover"
style="vertical-align: text-bottom;">
<template #error>加载失败</template>
</van-image>
<!-- <div style="position: absolute; top: 2rem; left: 3rem;">
<van-image width="2rem" height="2rem" :src="icon_player" style="vertical-align: text-bottom;"> </van-image>
</div> -->
</van-col>
<van-col span="14" class="text">
<p style="font-size: 1.15rem;">{{ item.perf_name }}</p>
<p style="color: #999999;">{{ item.book_name }} | {{ item.localism_type }}</p>
</van-col>
</van-row>
</div>
</div>
</van-list>
<van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无留言" />
</template>
<script lang="ts" setup>
// import { mainStore } from '@/store'
// import icon_player from '@images/bofang@2x.png'
import no_image from '@images/que-shuju@2x.png'
import icon_avatar from '@images/que-touxiang@2x.png'
import { ref, onActivated } from 'vue'
// import { useRouter } from 'vue-router'
// import axios from '@/utils/axios';
import _ from 'lodash'
import { Toast, Dialog } from 'vant';
// import { addPages } from '@/hooks/useKeepAlive'
import goToVideoDetail from '@/router/methods/videoDetail'
import { myCommentAPI, delCommentAPI } from '@/api/C/me.js'
// const $route = useRoute();
// const $router = useRouter();
// 我的留言接口联调
const loading = ref(false);
const finished = ref(false);
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;
}
const commentList = ref<commentListType[]>([])
let limit = ref(10);
let offset = ref(0)
// 因为不能让空图标提前出来的写法
const finishedTextStatus = ref(false);
const emptyStatus = ref(false);
const onLoad = async () => {
const { data } = await myCommentAPI({ limit: limit.value, offset: offset.value });
//
// _.each(data, item => {
// let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名
// item.c_action = arr[0]; // 评论动作
// item.c_name = arr[1]; // 评论姓名
// })
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]; // 评论姓名
});
commentList.value = [...commentList.value, ...data];
// commentList.value = _.uniqBy(commentList.value, 'id');
offset.value = commentList.value.length;
loading.value = false;
// 数据全部加载完成
if (!data.length) {
// 加载状态结束
finished.value = true;
}
// 隐藏loading标识,空列表图标
if (!commentList.value.length) {
finishedTextStatus.value = false;
emptyStatus.value = true;
} else {
emptyStatus.value = false;
}
}
const deleteComment = (id: string) => { // 删除评论
Dialog.confirm({
title: '温馨提示',
message: '是否确认删除该评论?',
confirmButtonColor: '#713610'
})
.then(async () => {
const result = await delCommentAPI({ comment_id: id });
if (result) {
// 移除当前选中评论,避免刷新页面
_.remove(commentList.value, comment => comment.id === id);
Toast.success('删除成功');
}
})
.catch(() => {
// on cancel
});
}
/****************** keepAlive 模块 *******************/
// TAG: keepAlive 缓存页面
// addPages()
onActivated(() => { // keepAlive 重置后执行回调
});
/*********************************************************/
</script>
<style lang="less" scoped>
.comment-wrapper {
color: #999999;
padding: 1rem;
line-height: 1.75;
.reply-wrapper {
background: #F7F7F7;
border-radius: 10px;
padding: 0.5rem;
margin-top: 0.5rem;
color: #0B3A72;
.content {
color: #222222;
}
}
}
.raw-ref {
padding: 1rem;
background-color: #F7F7F7;
.image {
position: relative;
}
.text {
line-height: 2;
margin-left: 1rem;
}
}
</style>