index.vue
9.11 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<template>
<div class="me-index-page">
<div class="header-wrapper">
<div class="info">
<van-row>
<van-col>
<van-image v-if="userInfo.avatar" @click="handleUser('EDIT')" round width="50" height="50" :src="userInfo.avatar" style="padding-right: 1rem;" />
<van-image v-else @click="handleUser('EDIT')" 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="actions.length" class="toggle-user" @click="toggleUser">切换儿童</div>
</div>
<div class="address">{{ userInfo.kg_name }}</div>
</van-col>
</van-row>
</div>
<div class="sub-data">
<van-row>
<van-col span="5" offset="1" class="un-tap-color">
<p>获赞</p>
<p>{{ userInfo.perf_like_num }}</p>
</van-col>
<van-col span="1" class="divide">|</van-col>
<van-col span="5" class="un-tap-color">
<p>粉丝</p>
<p>{{ userInfo.fans_num }}</p>
</van-col>
<van-col span="1" class="divide">|</van-col>
<van-col span="5" @click="getFollow">
<p class="tap-color">关注</p>
<p>{{ userInfo.follow_num }}</p>
</van-col>
<van-col span="1" class="divide">|</van-col>
<van-col span="5" @click="getUnwatch">
<p class="tap-color">未看</p>
<p><van-tag round color="red">{{ userInfo.unplay_num }}</van-tag></p>
</van-col>
</van-row>
</div>
</div>
<div class="van-hairline--bottom sub-handle">
<div>
<my-button v-if="userInfo.status === 'apply'" type="custom" :custom-style="styleObject1" @on-click="goTo('/me/verifyUser')">实名认证</my-button>
<my-button v-else type="custom" :custom-style="styleObject3">已认证</my-button>
</div>
<div>
<my-button v-if="userInfo.status === 'enable'" type="custom" :custom-style="styleObject2" @on-click="handleUser('ADD')">新增儿童</my-button>
<my-button v-else type="custom" :custom-style="styleObject4">新增儿童</my-button>
</div>
</div>
<template v-for="(item, key) in itemList" :key="key">
<div class="van-hairline--bottom item-list" @click="goTo(item.to)">
<van-row>
<van-col span="12">{{ item.name }}</van-col>
<van-col span="12" style="text-align: right; color: #777777;">
<span v-if="!item.tag">{{ item.sum }} </span>
<span v-else><van-tag round color="red">{{ item.sum }}</van-tag> </span>
<van-icon name="arrow" /></van-col>
</van-row>
</div>
</template>
</div>
<van-action-sheet v-model:show="show" :actions="actions" @select="onSelect" />
</template>
<script setup>
import { mainStore } from '@/store'
import icon_avatar from '@images/que-touxiang@2x.png'
import MyButton from '@/components/MyButton/index.vue'
import { ref, reactive, onMounted } from 'vue'
import { onBeforeRouteLeave, useRoute, useRouter } from 'vue-router'
import axios from '@/utils/axios';
import $ from 'jquery'
import _ from 'lodash'
import { Toast } from 'vant';
const $route = useRoute();
const $router = useRouter();
// 删除 keep-alive 缓存
const store = mainStore();
store.changeKeepPages('clear');
// onBeforeRouteLeave(() => {
// 重置位置缓存
// store.changeScrollTopCollection(0);
// store.changeScrollTopLike(0);
// })
/********** 切换用户功能 START *************/
const show = ref(false);
let actions = ref([]);
axios.get('/srv/?a=my_performer')
.then(res => {
if (res.data.code === 1) {
actions.value = res.data.data;
} else {
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
console.error(err);
})
const toggleUser = () => {
show.value = true;
}
const onSelect = (item) => {
// 默认情况下点击选项时不会自动收起
// 可以通过 close-on-click-action 属性开启自动收起
show.value = false;
// 切换当前角色
axios.post('/srv/?a=change_performer', {
perf_id: item.id
})
.then(res => {
if (res.data.code === 1) {
// 重新获取新角色的信息
axios.get('/srv/?a=my_info')
.then(res => {
if (res.data.code === 1) {
userInfo.value = res.data.data;
_.each(itemList, item => {
item.sum = userInfo.value[item.key]
});
} else {
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
console.error(err);
})
} else {
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
console.error(err);
})
};
/********** 切换用户功能 END *************/
// 查询用户信息
const itemList = [
{
name: '我的捐赠',
key: 'donate_num',
sum: 0,
to: '/me/donateList'
},
{
name: '我的作品',
key: 'prod_num',
sum: 0,
to: '/me/videoList'
},
{
name: '我的订阅',
key: 'subs_num',
sum: 0,
to: '/me/subscribe'
},
{
name: '我的收藏',
key: 'favor_num',
sum: 0,
to: '/me/collection'
},
{
name: '我的点赞',
key: 'like_num',
sum: 0,
to: '/me/like'
},
{
name: '我的留言',
key: 'comment_num',
sum: 0,
tag: true,
to: '/me/message'
},
{
name: '@我的',
key: 'reply_num',
sum: 0,
tag: true,
to: '/me/callMe'
},
]
const userInfo = ref({})
axios.get('/srv/?a=my_info')
.then(res => {
if (res.data.code === 1) {
userInfo.value = res.data.data;
_.each(itemList, item => {
item.sum = userInfo.value[item.key]
});
} else {
console.warn(res);
if (!res.data.show) return false;
Toast({
icon: 'close',
message: res.data.msg
});
}
})
.catch(err => {
console.error(err);
})
/************************************************ */
// 跳转相关页面
const goTo = (path) => {
$router.push({
path: path,
query: {
kg_id: userInfo.value.kg_id,
kg_name: userInfo.value.kg_name
}
})
}
// 新增/编辑儿童信息
const handleUser = (type) => {
if (type === 'ADD') {
$router.push({
path: '/me/handleUser',
query: {
perf_id: userInfo.value.perf_id,
kg_id: '',
kg_name: '',
type
}
})
} else {
$router.push({
path: '/me/handleUser',
query: {
avatar: userInfo.value.avatar,
name: userInfo.value.name,
perf_id: userInfo.value.perf_id,
kg_id: userInfo.value.kg_id,
kg_name: userInfo.value.kg_name,
type
}
})
}
}
// 自定义按钮颜色样式
const styleObject1 = reactive({
backgroundColor: '#FFFFFF',
color: '#713610',
borderColor: '#713610'
})
const styleObject2 = reactive({
backgroundColor: '#FFFFFF',
color: '#0B3A72',
borderColor: '#0B3A72'
})
const styleObject3 = reactive({
backgroundColor: '#FFFFFF',
color: '#FDD347',
borderColor: '#FDD347'
})
const styleObject4 = reactive({
backgroundColor: '#FFFFFF',
color: '#777777',
borderColor: '#777777'
})
const getFollow = () => {
$router.push({
path: '/me/followList'
})
}
const getUnwatch = () => {
$router.push({
path: '/me/unwatchList'
})
}
</script>
<script>
import mixin from 'common/mixin';
import Cookies from 'js-cookie'
export default {
mixins: [mixin.init],
data() {
return {
}
},
mounted() {
},
methods: {
}
}
</script>
<style lang="less" scoped>
.me-index-page {
.header-wrapper {
background: linear-gradient(310deg, #FDD347 0%, #FFED6D 100%);
.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;
opacity: 0.8;
}
}
.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;
}
}
}
.sub-handle {
padding: 1rem 0;
margin: 0 1rem;
overflow: auto;
div:first-child {
width: 48%;
float: left;
margin-right: 2%;
}
div:last-child {
width: 48%;
float: left;
margin-left: 2%;
}
}
.item-list {
padding: 1rem 0;
margin: 0 1rem;
}
}
</style>