Skip to content
This repository was archived by the owner on Nov 15, 2018. It is now read-only.

Commit f8ab7c6

Browse files
committed
feat: (#608) 举报帖子评论
1 parent 9c17005 commit f8ab7c6

File tree

4 files changed

+174
-93
lines changed

4 files changed

+174
-93
lines changed

src/api/group.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,17 @@ export function reportPost(postId, reason) {
556556
const url = `/plus-group/reports/posts/${postId}`;
557557
return api.post(url, { content: reason }, { validateStatus: s => s === 201 });
558558
}
559+
560+
/**
561+
* 举报评论
562+
*
563+
* @author mutoe <[email protected]>
564+
* @export
565+
* @param {number} commentId
566+
* @param {string} reason
567+
* @returns
568+
*/
569+
export function reportPostComment(commentId, reason) {
570+
const url = `/plus-group/reports/comments/${commentId}`;
571+
return api.post(url, { content: reason }, { validateStatus: s => s === 201 });
572+
}

src/components/FeedCard/GroupFeedCard.vue

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,28 +245,47 @@ export default {
245245
this.$bus.$emit("actionSheet", actions, "取消");
246246
},
247247
commentAction({ isMine = false, placeholder, reply_user, comment }) {
248+
const actions = [];
248249
if (isMine) {
249250
const isOwner = this.feed.user.id === this.CURRENTUSER.id;
250-
this.$bus.$emit("actionSheet", [
251-
{
252-
text: isOwner ? "评论置顶" : "申请评论置顶",
253-
method: () => {
254-
this.$bus.$emit("applyTop", {
255-
isOwner,
256-
type: "postComment",
257-
api: api.applyTopPostComment,
258-
payload: { postId: this.feedID, commentId: comment.id }
259-
});
260-
}
261-
},
262-
{ text: "删除评论", method: () => this.deleteComment(comment.id) }
263-
]);
251+
actions.push({
252+
text: isOwner ? "评论置顶" : "申请评论置顶",
253+
method: () => {
254+
this.$bus.$emit("applyTop", {
255+
isOwner,
256+
type: "postComment",
257+
api: api.applyTopPostComment,
258+
payload: { postId: this.feedID, commentId: comment.id }
259+
});
260+
}
261+
});
262+
actions.push({
263+
text: "删除评论",
264+
method: () => this.deleteComment(comment.id)
265+
});
264266
} else {
265-
this.handleComment({
266-
placeholder,
267-
reply_user
267+
actions.push({
268+
text: "回复",
269+
method: () => {
270+
this.handleComment({
271+
placeholder,
272+
reply_user
273+
});
274+
}
275+
});
276+
actions.push({
277+
text: "举报",
278+
method: () => {
279+
this.$bus.$emit("report", {
280+
type: "postComment",
281+
payload: comment.id,
282+
username: comment.user.name,
283+
reference: comment.body
284+
});
285+
}
268286
});
269287
}
288+
this.$bus.$emit("actionSheet", actions);
270289
},
271290
deleteComment(commentId) {
272291
this.$store

src/components/Report.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
import { noop } from "@/util";
3939
import { reportFeed } from "@/api/feeds";
4040
import { reportNews } from "@/api/news";
41-
import { reportPost } from "@/api/group";
41+
import { reportPost, reportPostComment } from "@/api/group";
4242
import TextareaInput from "@/components/common/TextareaInput";
4343
4444
const apiMap = {
4545
feed: reportFeed,
4646
news: reportNews,
47-
post: reportPost
47+
post: reportPost,
48+
postComment: reportPostComment
4849
};
4950
5051
export default {
@@ -75,6 +76,8 @@ export default {
7576
return "资讯";
7677
case "group":
7778
return "帖子";
79+
case "postComment":
80+
return "评论";
7881
default:
7982
return "";
8083
}

src/directives/index.js

Lines changed: 119 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// import autosize from 'autosize'
22
import { getStyle, getScrollTop, getScrollEventTarget } from "@/util/";
3+
34
const autosize = el => {
45
const originalHeight = el.style.height;
56
el.style.height = "";
@@ -10,88 +11,132 @@ const autosize = el => {
1011
}
1112
el.style.height = endHeight + "px";
1213
};
14+
15+
const loadMore = {
16+
bind: (el, binding) => {
17+
let windowHeight = window.screen.height;
18+
let height;
19+
let setTop;
20+
let paddingBottom;
21+
let marginBottom;
22+
let requestFram;
23+
let oldScrollTop;
24+
let scrollEl;
25+
let heightEl;
26+
let scrollType = el.attributes.type && el.attributes.type.value;
27+
let scrollReduce = 2;
28+
if (scrollType === 2) {
29+
scrollEl = el;
30+
heightEl = el.children[0];
31+
} else {
32+
scrollEl = getScrollEventTarget(el);
33+
heightEl = el;
34+
}
35+
el.addEventListener(
36+
"touchstart",
37+
() => {
38+
height = heightEl.clientHeight;
39+
if (scrollType === 2) {
40+
// height = height
41+
}
42+
setTop = el.offsetTop;
43+
paddingBottom = getStyle(el, "paddingBottom");
44+
marginBottom = getStyle(el, "marginBottom");
45+
},
46+
false
47+
);
48+
49+
el.addEventListener(
50+
"touchmove",
51+
() => {
52+
loadMore();
53+
},
54+
false
55+
);
56+
57+
el.addEventListener(
58+
"touchend",
59+
() => {
60+
oldScrollTop = getScrollTop(scrollEl);
61+
moveEnd();
62+
},
63+
false
64+
);
65+
66+
const moveEnd = () => {
67+
requestFram = requestAnimationFrame(() => {
68+
if (getScrollTop(scrollEl) !== oldScrollTop) {
69+
oldScrollTop = getScrollTop(scrollEl);
70+
moveEnd();
71+
} else {
72+
cancelAnimationFrame(requestFram);
73+
height = heightEl.clientHeight;
74+
loadMore();
75+
}
76+
});
77+
};
78+
79+
const loadMore = () => {
80+
if (
81+
getScrollTop(scrollEl) + windowHeight >=
82+
height + setTop + paddingBottom + marginBottom - scrollReduce
83+
) {
84+
binding.value();
85+
}
86+
};
87+
}
88+
};
89+
90+
/**
91+
* 长按指令
92+
*/
93+
const press = {
94+
bind: function(el, binding) {
95+
let pressTimer = null;
96+
if (typeof binding.fn !== "function")
97+
// eslint-disable-next-line
98+
console.warn(
99+
`vue directive 'v-press' not include function with the prop 'fn'`
100+
);
101+
102+
const handler = e => void binding.value.fn(e);
103+
const start = e => {
104+
if (e.type === "click" && e.button !== 0) return;
105+
if (pressTimer === null) {
106+
pressTimer = setTimeout(() => {
107+
handler();
108+
}, binding.value.time || 650);
109+
}
110+
};
111+
112+
const cancel = e => {
113+
if (pressTimer !== null) {
114+
clearTimeout(pressTimer);
115+
pressTimer = null;
116+
}
117+
};
118+
119+
el.addEventListener("mousedown", start);
120+
el.addEventListener("touchstart", start);
121+
122+
el.addEventListener("click", cancel);
123+
el.addEventListener("mouseout", cancel);
124+
el.addEventListener("touchend", cancel);
125+
el.addEventListener("touchcancel", cancel);
126+
}
127+
};
128+
13129
export default {
14130
txtautosize: {
15131
inserted(el) {
16132
autosize(el);
17133
},
18134
update(el) {
19135
autosize(el);
20-
},
21-
unbind() {}
136+
}
22137
},
23-
"load-more": {
24-
bind: (el, binding) => {
25-
let windowHeight = window.screen.height;
26-
let height;
27-
let setTop;
28-
let paddingBottom;
29-
let marginBottom;
30-
let requestFram;
31-
let oldScrollTop;
32-
let scrollEl;
33-
let heightEl;
34-
let scrollType = el.attributes.type && el.attributes.type.value;
35-
let scrollReduce = 2;
36-
if (scrollType === 2) {
37-
scrollEl = el;
38-
heightEl = el.children[0];
39-
} else {
40-
scrollEl = getScrollEventTarget(el);
41-
heightEl = el;
42-
}
43-
el.addEventListener(
44-
"touchstart",
45-
() => {
46-
height = heightEl.clientHeight;
47-
if (scrollType === 2) {
48-
// height = height
49-
}
50-
setTop = el.offsetTop;
51-
paddingBottom = getStyle(el, "paddingBottom");
52-
marginBottom = getStyle(el, "marginBottom");
53-
},
54-
false
55-
);
56138

57-
el.addEventListener(
58-
"touchmove",
59-
() => {
60-
loadMore();
61-
},
62-
false
63-
);
64-
65-
el.addEventListener(
66-
"touchend",
67-
() => {
68-
oldScrollTop = getScrollTop(scrollEl);
69-
moveEnd();
70-
},
71-
false
72-
);
73-
74-
const moveEnd = () => {
75-
requestFram = requestAnimationFrame(() => {
76-
if (getScrollTop(scrollEl) !== oldScrollTop) {
77-
oldScrollTop = getScrollTop(scrollEl);
78-
moveEnd();
79-
} else {
80-
cancelAnimationFrame(requestFram);
81-
height = heightEl.clientHeight;
82-
loadMore();
83-
}
84-
});
85-
};
139+
"load-more": loadMore,
86140

87-
const loadMore = () => {
88-
if (
89-
getScrollTop(scrollEl) + windowHeight >=
90-
height + setTop + paddingBottom + marginBottom - scrollReduce
91-
) {
92-
binding.value();
93-
}
94-
};
95-
}
96-
}
141+
press
97142
};

0 commit comments

Comments
 (0)