personIndex.vue
6.31 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<template>
<div class="person-index-page">
<div class="header-wrapper">
<div class="info">
<van-row>
<van-col>
<van-image v-if="userInfo.avatar" round width="50" height="50" :src="userInfo.avatar" style="padding-right: 1rem;" />
<van-image v-else round width="50" height="50" :src="icon_avatar" style="padding-right: 1rem;" />
</van-col>
<van-col class="text-wrapper" span="18">
<div>
<div class="username">{{ userInfo.name }}</div>
<div v-if="!userInfo.is_follow" class="toggle-user" @click="followUser()">
<van-icon name="plus" /> 关注
</div>
<div v-else class="toggle-user" @click="followUser()"> 取消关注</div>
</div>
<div class="address">{{ userInfo.kg_name }}</div>
</van-col>
</van-row>
</div>
<div class="sub-data">
<van-row>
<van-col span="11" offset="1" class="un-tap-color">
<p>获赞</p>
<p>{{ userInfo.like_num }}</p>
</van-col>
<van-col span="1" class="divide">|</van-col>
<van-col span="11" class="un-tap-color">
<p>粉丝</p>
<p>{{ userInfo.fans_num }}</p>
</van-col>
</van-row>
</div>
</div>
<div class="list-title">
<van-row>
<van-col span="6">
<div class="title">发布作品</div>
</van-col>
<van-col span="12" offset="6" style="text-align: right; color: #626262;">
<div style="padding-top: 0.5rem;">{{ userInfo.prod?.length }}个作品</div>
</van-col>
</van-row>
</div>
<div>
<template v-for="item in userInfo.prod" :key="item">
<video-card :item="item" />
</template>
<div style="height: 5rem;" />
</div>
<div class="donate-bar">
<div class="text">
<span style="font-size: 0.85rem; color: #999999;">收到小红花 </span>
<van-icon :name="icon_flower" color="#c5c5c5" size="1.25rem" style="margin: 0 auto;" />
<span> 3000</span>
</div>
<div class="button">
<my-button type="primary">为TA助力</my-button>
</div>
</div>
</div>
<van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无作品信息" />
</template>
<script setup>
import { ref, onActivated, onMounted } from 'vue'
import { useRoute, onBeforeRouteLeave } from 'vue-router'
import { storeToRefs } from 'pinia'
import { MyButton, VideoCard } from '@/utils/generateModules'
import { icon_avatar, no_image, icon_flower } from '@/utils/generateIcons.js'
import { _, Toast } from '@/utils/generatePackage.js'
import { addPages, store } from '@/hooks/useKeepAlive'
import { perfInfoAPI, addFollowAPI } from '@/api/C/perf.js'
import { useScrollTop } from '@/composables';
const { resetScrollTop } = useScrollTop(); // 页面滚动恢复
resetScrollTop('scrollTopPerson');
const $route = useRoute();
const userInfo = ref({});
// 因为不能让空图标提前出来的写法
const emptyStatus = ref(false);
onMounted(async () => {
// 获取表演者信息
const { data } = await perfInfoAPI({ perf_id: $route.query.perf_id });
if (!data.prod.length) {
emptyStatus.value = true;
} else {
_.each(data.prod, (item) => {
item.type = 'read-only' // 特殊标识,判断入口 为keepAlive使用
})
userInfo.value = data;
}
});
// 关注个人用户
const followUser = async () => {
const { msg } = await addFollowAPI({ perf_id: $route.query.perf_id });
if (msg === 'add follow OK') {
userInfo.value.is_follow = 1
Toast.success('关注成功')
} else {
userInfo.value.is_follow = 0
Toast.success('取消关注')
}
};
/****************** keepAlive 模块 *******************/
// TAG: keepAlive 缓存页面
addPages()
onActivated(() => { // keepAlive 重置后执行回调
// TAG: pinia应用,动态刷新数据
// 处理数据未刷新数据显示问题
const { video_detail } = storeToRefs(store);
// 如果作品信息有变化及时修正
const arr = ref([]);
_.each(userInfo.value.prod, (item) => {
if (item.id === video_detail.value.id) {
item = video_detail.value
}
arr.value.push(item);
})
// 触发更新
userInfo.value.prod = arr.value;
// 滚动恢复
resetScrollTop('scrollTopPerson');
});
onBeforeRouteLeave(() => {
store.changeScrollTopPerson(window.scrollY)
})
/*********************************************************/
</script>
<style lang="less" scoped>
.person-index-page {
.header-wrapper {
// background: linear-gradient(310deg, #FDD347 0%, #FFED6D 100%);
background: @base-color;
.info {
padding: 2rem;
padding-right: 0;
.text-wrapper {
line-height: 1.5;
.username {
display: inline-block;
overflow: auto;
font-size: 1.15rem;
color: #222222;
}
.toggle-user {
float: right;
font-size: 0.8rem;
background-color: white;
border-radius: 15px;
padding: 5px 10px;
color: #713610;
}
}
.address {
font-size: 0.85rem;
color: #999999;
}
}
.sub-data {
text-align: center;
overflow: auto;
padding-bottom: 1rem;
.un-tap-color {
color: #666666;
}
.tap-color {
color: #713610;
}
.divide {
line-height: 2.5;
color: #999999;
font-size: 1rem;
}
}
}
.list-title {
padding: 0 1rem;
background-color: #F7F7F7;
.title {
color: #222222;
font-size: 1.1rem;
border-bottom: 2px solid @base-color;
padding: 0.5rem;
text-align: center;
}
}
.donate-bar {
z-index: 999;
position: fixed;
right: 0;
bottom: 0;
left: 0;
display: flex;
align-items: center;
box-sizing: content-box;
background-color: white;
padding: 1rem;
box-shadow: 0px -2px 4px 0px rgba(0, 0, 0, 0.07);
.text {
display: flex;
// flex-direction: column;
justify-content: center;
// flex: 1;
color: #713610;
text-align: center;
}
.button {
display: flex;
flex-direction: column;
justify-content: center;
flex: 1;
padding: 0 0.5rem;
}
}
}
</style>