comment-placeholder.js
2.15 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
import {createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('comment');
const {mapActions: articleMapActions} = createNamespacedHelpers('article');
export default {
name: 'CommentPlaceholder',
props: {
tag: String,
destId: Number,
addType: Number,
columnType: {
type: Number,
default: 1001
},
user: {
type: String,
default: ''
}
},
methods: {
...mapActions(['postComment']),
...articleMapActions(['fetchArticleUpdate']),
async openComentInput() {
const user = await this.$sdk.getUser();
if (user && user.uid) {
const hint = this.user ? `回复${this.user}:` : '评论:';
if (this.$yoho.isYohoBuy) {
this.$yoho.getInput({hint}, (content) => {
this.comment(content);
}, (e) => {
console.error(e);
});
} else {
this.$createDialog({
type: 'prompt',
title: '测试-输入',
prompt: {
placeholder: hint
},
onConfirm: (e, promptValue) => {
this.comment(promptValue);
}
}).show();
}
} else {
this.$sdk.goLogin();
}
},
async comment(content) {
const result = await this.postComment({
content: content,
destId: this.addType === 0 ? this.destId : void 0,
commentId: this.addType === 1 ? this.destId : void 0,
addType: this.addType,
columnType: this.columnType
});
if (result.code === 200) {
this.$emit('on-comment', {
destId: this.destId,
addType: this.addType,
columnType: this.columnType
});
if (this.addType === 0) {
this.fetchArticleUpdate({articleId: this.destId});
}
} else {
this.$createToast({
txt: result.message || '服务器开小差了',
type: 'warn',
time: 1000
}).show();
}
}
},
render(h) {
return h(this.tag || 'div', {
on: {
click: () => {
this.openComentInput();
}
}
}, this.$slots.default);
}
};