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

Commit

Permalink
fix(group): (#516, #517) 管理员可以置顶帖子和撤销置顶帖子了
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Sep 27, 2018
1 parent f8c5ffc commit e2c70d8
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 71 deletions.
27 changes: 27 additions & 0 deletions src/api/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ export function rewardPost(postId, data) {
return api.post(url, data, { validateStatus: s => s === 201 });
}

/**
* 获取帖子详情
* @author mutoe <[email protected]>
* @export
* @param {number} groupId
* @param {number} postId
* @returns
*/
export function getGroupPost(groupId, postId) {
const url = `/plus-group/groups/${groupId}/posts/${postId}`;
return api.get(url, { validateStatus: s => s === 200 });
}

/**
* 创建帖子
* @author mutoe <[email protected]>
Expand Down Expand Up @@ -472,6 +485,20 @@ export function changePermissions(groupId, params) {
return api.patch(url, params, { validateStatus: s => s === 204 });
}

/**
* 管理员置顶帖子
* @author mutoe <[email protected]>
* @export
* @param {number} postId
* @param {Object} params
* @param {number} params.day
* @returns
*/
export function pinnedPost(postId, params) {
const url = `/plus-group/pinned/posts/${postId}/create`;
return api.post(url, params, { validateStatus: s => s === 201 });
}

/**
* 管理员取消置顶帖子
* @author mutoe <[email protected]>
Expand Down
65 changes: 42 additions & 23 deletions src/components/FeedCard/GroupFeedCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export default {
},
isGroupOwner() {
return this.group.founder.user_id === this.currentUser.id;
},
isGroupManager() {
const { role = "" } = this.group.joined || {};
return ["founder", "administrator"].includes(role);
}
},
methods: {
Expand Down Expand Up @@ -137,42 +141,57 @@ export default {
}
});
}
if (!this.pinned) {
this.isMine &&
if (this.isGroupManager) {
if (!this.pinned)
actions.push({
text: "申请帖子置顶",
text: "置顶帖子",
method: () => {
bus.$emit("applyTop", {
type: "post",
api: api.applyTopPost,
payload: this.feed.id
type: "post-manager",
api: api.pinnedPost,
payload: this.feed.id,
callback: () => {
this.$Message.success("置顶成功!");
this.$emit("reload");
}
});
}
});
} else {
this.isGroupOwner &&
else
actions.push({
text: "撤销置顶",
method: () => {
setTimeout(() => {
const actionSheet = [
{
text: "撤销置顶",
method: () => {
this.$store
.dispatch("group/unpinnedPost", {
postId: this.post.id
})
.then(() => {
this.$router.go(0);
});
}
const actions = [
{
text: "撤销置顶",
method: () => {
this.$store
.dispatch("group/unpinnedPost", {
postId: this.feed.id
})
.then(() => {
this.$Message.success("撤销置顶成功!");
this.$emit("reload");
});
}
];
bus.$emit("actionSheet", actionSheet, "取消", "确认撤销置顶?");
}
];
setTimeout(() => {
bus.$emit("actionSheet", actions, "取消", "确认撤销置顶?");
}, 200);
}
});
} else if (this.isMine && !this.pinned) {
actions.push({
text: "申请帖子置顶",
method: () => {
bus.$emit("applyTop", {
type: "post",
api: api.applyTopPost,
payload: this.feed.id
});
}
});
}
if (this.isMine) {
// 是否是自己文章
Expand Down
64 changes: 33 additions & 31 deletions src/components/applyForTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,42 @@
</div>
</div>

<div
class="m-box m-aln-center m-justify-bet m-bb1 m-pinned-row plr20 m-pinned-amount-customize m-main"
style="margin-top: .2rem">
<span>置顶金额</span>
<div class="m-box m-aln-center">
<input
v-model="customAmount"
type="number"
pattern="[0-9]*"
placeholder="输入金额"
oninput="value=value.slice(0,8)"
class="m-flex-grow1 m-flex-shrink1 m-text-r">
<span>{{ currency_name }}</span>
<template v-if="applyType !== 'post-manager'">
<div class="m-box m-aln-center m-justify-bet m-bb1 m-pinned-row plr20 m-pinned-amount-customize m-main" style="margin-top: .2rem">
<span>置顶金额</span>
<div class="m-box m-aln-center">
<input
v-model="customAmount"
type="number"
pattern="[0-9]*"
placeholder="输入金额"
oninput="value=value.slice(0,8)"
class="m-flex-grow1 m-flex-shrink1 m-text-r">
<span>{{ currency_name }}</span>
</div>
</div>
</div>

<div class="m-box m-aln-center m-justify-bet m-pinned-row plr20 m-pinned-amount-customize m-main">
<span>总金额</span>
<div class="m-box m-aln-center">
<input
v-model="amount"
class="m-flex-grow1 m-flex-shrink1 m-text-r"
type="number"
pattern="[0-9]*"
disabled="true"
readonly="true"
placeholder="总金额"
style="background-color: transparent">
<span>{{ currency_name }}</span>
<div class="m-box m-aln-center m-justify-bet m-pinned-row plr20 m-pinned-amount-customize m-main">
<span>总金额</span>
<div class="m-box m-aln-center">
<input
v-model="amount"
class="m-flex-grow1 m-flex-shrink1 m-text-r"
type="number"
pattern="[0-9]*"
disabled="true"
readonly="true"
placeholder="总金额"
style="background-color: transparent">
<span>{{ currency_name }}</span>
</div>
</div>
</div>
<p class="placeholder m-flex-grow1 m-flex-shrink1">
可用积分{{ currencySum }}
</p>
<p class="placeholder m-flex-grow1 m-flex-shrink1">
可用积分{{ currencySum }}
</p>
</template>


</div>
<div class="plr20 m-lim-width" style="margin-top: 0.6rem">
<button
Expand Down
8 changes: 6 additions & 2 deletions src/page/group/detail/GroupDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@
<group-feed-card
:pinned="true"
:feed="feed"
:group="group" />
:group="group"
@reload="updateData" />
</li>
<li v-for="(feed, index) in posts" :key="`gdf-${groupId}-feed-${feed.id}-${index}`">
<group-feed-card :feed="feed" :group="group" />
<group-feed-card
:feed="feed"
:group="group"
@reload="updateData" />
</li>
</ul>
<div class="m-box m-aln-center m-justify-center load-more-box">
Expand Down
79 changes: 64 additions & 15 deletions src/page/group/detail/GroupPostDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ import wechatShare from "@/util/wechatShare.js";
import { followUserByStatus } from "@/api/user.js";
import { limit } from "@/api/api.js";
import * as api from "@/api/group.js";
import { noop } from "@/util";
export default {
name: "GroupPostDetail",
Expand Down Expand Up @@ -169,6 +170,9 @@ export default {
groupId() {
return this.$route.params.groupId;
},
group() {
return this.feed.group || {};
},
likes() {
return this.feed.likes || [];
},
Expand Down Expand Up @@ -227,6 +231,10 @@ export default {
this.feed.collected = val;
}
},
isGroupManager() {
const { role = "" } = this.group.joined || {};
return ["founder", "administrator"].includes(role);
},
relation: {
get() {
const relations = {
Expand Down Expand Up @@ -301,7 +309,7 @@ export default {
.use(plusImagePlugin, `${this.$http.defaults.baseURL}/files/`)
.render(body);
},
fetchFeed(callback) {
fetchFeed(callback = noop) {
if (this.fetching) return;
this.fetching = true;
Expand All @@ -312,16 +320,20 @@ export default {
const signUrl =
this.$store.state.BROWSER.OS === "IOS" ? window.initUrl : shareUrl;
this.$http
.get(`/plus-group/groups/${this.groupId}/posts/${this.feedID}`)
.then(({ data = {} }) => {
this.$store
.dispatch("group/getPostDetail", {
groupId: this.groupId,
postId: this.feedID
})
.then(data => {
this.feed = { ...data };
this.user = this.feed.user;
this.oldID = this.feedID;
this.fetching = false;
this.fetchFeedComments();
this.fetchRewards();
this.fetchLikes();
this.isWechat &&
wechatShare(signUrl, {
title: `${data.user.name}的动态`,
Expand All @@ -334,15 +346,12 @@ export default {
}`
: ""
});
if (callback && typeof callback === "function") {
callback();
}
callback();
})
.catch(() => {
this.goBack();
if (callback && typeof callback === "function") {
callback();
}
callback();
});
},
fetchRewards() {
Expand Down Expand Up @@ -452,18 +461,58 @@ export default {
});
}
if (this.isMine) {
if (this.isGroupManager) {
if (!this.feed.pinned)
actions.push({
text: "申请帖子置顶",
text: "置顶帖子",
method: () => {
bus.$emit("applyTop", {
type: "post",
api: api.applyTopPost,
payload: this.postID
type: "post-manager",
api: api.pinnedPost,
payload: this.feed.id,
callback: () => {
this.$Message.success("置顶成功!");
this.fetchFeed();
}
});
}
});
else
actions.push({
text: "撤销置顶",
method: () => {
const actions = [
{
text: "撤销置顶",
method: () => {
this.$store
.dispatch("group/unpinnedPost", {
postId: this.feed.id
})
.then(() => {
this.$Message.success("撤销置顶成功!");
this.fetchFeed();
});
}
}
];
setTimeout(() => {
bus.$emit("actionSheet", actions, "取消", "确认撤销置顶?");
}, 200);
}
});
} else if (this.isMine && !this.feed.pinned)
actions.push({
text: "申请帖子置顶",
method: () => {
bus.$emit("applyTop", {
type: "post",
api: api.applyTopPost,
payload: this.postID
});
}
});
if (this.isMine) {
actions.push({
text: "删除帖子",
method: () => {
Expand Down
11 changes: 11 additions & 0 deletions src/stores/module/group/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,16 @@ export default {
const { postId } = payload;
const { data } = await api.unpinnedPost(postId);
return data;
},

/**
* 获取帖子详情
* @author mutoe <[email protected]>
* @returns
*/
async getPostDetail(store, payload) {
const { postId, groupId } = payload;
const { data } = await api.getGroupPost(groupId, postId);
return data;
}
};

0 comments on commit e2c70d8

Please sign in to comment.