widget-follow.vue
3.42 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
<template>
<AuthComponent class="btn-follow hover-opacity" :class="followClass" :requiredAuth="isAuth" @click="onFollow">
<span>{{followText}}</span>
</AuthComponent>
</template>
<script>
import { createNamespacedHelpers } from 'vuex';
import YAS from 'utils/yas-constants';
const { mapActions } = createNamespacedHelpers('user');
export default {
name: 'WidgetFollow',
props: {
authorUid: [Number, String],
follow: [String, Boolean],
authorType: {
type: [Number, String],
default: 1
},
topicId: [Number, String],
share: Boolean,
posId: Number
},
data() {
return {
loading: false,
followStatus: this.follow === 'Y' || this.follow === 'O'
};
},
watch: {
follow(val) {
this.followStatus = val === 'Y' || val === 'O';
}
},
computed: {
followClass() {
return {
loading: this.loading,
follow: this.followStatus
};
},
followText() {
switch (this.follow) {
case 'Y': {
return '已关注';
}
case 'N': {
return '关注';
}
case 'O': {
return '已相互关注';
}
default: {
return '关注';
}
}
},
isAuth() {
return !this.share;
}
},
methods: {
...mapActions(['followUser', 'followTopic']),
syncServiceFollow() {
if (this.topicId) {
return this.followTopic({
topicId: this.topicId,
status: this.followStatus ? 1 : 0
});
} else {
return this.followUser({
followUid: this.authorUid,
status: this.followStatus ? 1 : 0,
authorType: this.authorType
});
}
},
async onFollow() {
if (this.share) {
return this.$links.toDownloadApp();
}
if (this.loading) {
return;
}
this.loading = true;
const result = await this.syncServiceFollow();
this.loading = false;
if (result.code === 200) {
this.followStatus = !this.followStatus;
if (this.followStatus) {
this.$createToast && this.$createToast({
txt: '关注成功',
type: 'txt',
time: 1000
}).show();
this.reportFellow();
}
this.$emit('on-follow', this.followStatus ? 'Y' : 'N');
} else {
this.$createToast && this.$createToast({
txt: result.message || '服务器开小差了',
type: 'warn',
time: 1000
}).show();
}
},
reportFellow() {
if (!this.authorUid) {
return;
}
this.$store.dispatch('reportYas', {
params: {
appop: YAS.eventName.fellow,
param: {
AUTH_ID: this.authorUid,
POS_ID: this.posId
}
}
});
}
}
};
</script>
<style lang="scss" scoped>
.btn-follow {
min-width: 110px;
height: 50px;
padding: 0 10px;
font-size: 24px;
color: #222;
border-radius: 26px;
border: solid 1px #222;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
&.follow {
border-color: #b0b0b0;
color: #b0b0b0;
}
&.loading {
padding: 0;
}
> span {
line-height: 1;
font-weight: 500;
}
.each-follow {
width: 110px;
height: 50px;
background-image: url("~statics/image/userpage/follow.png");
background-size: cover;
}
}
</style>