comment-placeholder-actionsheet.vue
3.34 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
<template>
<div class="actionsheet" @click.capture.stop="onClick">
<CommentPlaceholder ref="placeholder" v-bind="$attrs" v-on="$listeners">
<slot></slot>
</CommentPlaceholder>
</div>
</template>
<script>
import { createNamespacedHelpers } from 'vuex';
import CommentPlaceholder from './comment-placeholder';
import { get } from 'lodash';
const { mapActions } = createNamespacedHelpers('comment');
const ITEM = {
comment: '回复',
remove: '删除',
report: '举报'
};
export default {
name: 'CommentPlaceholderActionSheet',
components: { CommentPlaceholder },
data() {
return {};
},
methods: {
...mapActions(['setCommentStatus']),
async onClick() {
const authorUid = this.$attrs.authorUid;
const commentUid = this.$attrs.commentUid;
const uid = get(await this.$sdk.getUser(), 'uid', 0);
const commentId = this.$attrs['dest-id'];
let menu = [];
if (authorUid === uid || commentUid === uid) {
menu = [
{
content: ITEM.comment
},
{
content: ITEM.remove
},
{
content: ITEM.report
}
];
} else {
menu = [
{
content: ITEM.comment
},
{
content: ITEM.report
}
];
}
this.$createActionSheet({
data: menu,
zIndex: 200,
onSelect: (item) => {
switch (item.content) {
case ITEM.comment: {
this.$refs.placeholder.openComentInput();
break;
}
case ITEM.remove: {
this.setCommentStatus({ type: 1, commentId }).then(result => {
if (result.code === 200) {
this.$createToast({
txt: '已删除',
type: 'correct',
time: 2000,
}).show();
this.$emit('remove-comment', { commentId });
} else {
this.$createToast({
txt: '删除失败,请重试',
type: 'warn',
time: 2000,
}).show();
}
});
break;
}
case ITEM.report: {
this.setCommentStatus({ type: 2, commentId }).then(result => {
if (result.code === 200) {
this.$createToast({
txt: '已举报',
type: 'correct',
time: 2000,
}).show();
} else {
this.$createToast({
txt: '举报失败,请重试',
type: 'warn',
time: 2000,
}).show();
}
});
break;
}
}
},
}).show();
},
}
};
</script>
<style lang="scss">
.cube-action-sheet-panel {
margin-left: 15px;
margin-right: 15px;
margin-bottom: 17px;
border-radius: 10px;
overflow: hidden;
}
.cube-action-sheet-item {
color: #222 !important;
font-weight: bold !important;
}
.cube-action-sheet-cancel {
span {
color: #222 !important;
font-weight: bold !important;
}
}
.cube-action-sheet-space {
height: 1px !important;
background-color: rgb(235, 235, 235) !important;
}
</style>