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

Commit

Permalink
fix: 修复圈子帖子详情打不开
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonleex committed May 16, 2018
1 parent 5d5cc45 commit 96c125b
Showing 1 changed file with 102 additions and 194 deletions.
296 changes: 102 additions & 194 deletions src/page/group/GroupPostDetail.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,93 @@
<script>
import bus from "@/bus.js";
import Wx from "weixin-js-sdk";
import wx from "@/util/share.js";
import markdownIt from "markdown-it";
import FeedDetail from "../feed/feedDetail.vue";
import plusImagePlugin from "markdown-it-plus-image";
import FeedDetail from "../feed/feedDetail.vue";
import { likeGroupPost, collectGroupPost } from "@/api/group.js";
import wechatShare from "@/util/wechatShare.js";
export default {
name: "group-post-detail",
extends: FeedDetail,
data: () => ({
feed: {
likes: []
}
}),
computed: {
feedID() {
return this.$route.params.postID;
},
video_file() {
return false;
},
cover_file() {
return false;
},
postID() {
return this.$route.params.postID;
},
groupID() {
return this.$route.params.groupID;
},
likes() {
return this.feed.likes || [];
},
liked: {
get() {
return !!this.feed.liked;
},
set(val) {
this.feed.liked = val;
}
},
likeCount: {
get() {
return this.feed.likes_count || 0;
},
set(val) {
this.feed.likes_count = ~~val;
}
},
commentCount: {
get() {
return this.feed.comments_count || 0;
},
set(val) {
val > 0, (this.feed.comments_count = val);
}
},
images() {
return this.feed.images || [];
},
firstImage() {
let images = this.images;
if (!images.length) {
return "";
}
const file = images[0] || {};
return this.$http.defaults.baseURL + "/files/" + file.id + "?w=300&h=300";
},
feedContent() {
const { body = "" } = this.feed;
// return render(body);
// return this.$options.filters.markdownHtml(body);
return body;
},
reward() {
return (
{
amount: this.feed.reward_amount,
count: this.feed.reward_number
} || {}
);
}
},
methods: {
/**
* 收藏
Expand All @@ -39,137 +112,40 @@ export default {
fetchFeed() {
if (this.fetching) return;
this.fetching = true;
const shareUrl =
window.location.origin +
process.env.BASE_URL.substr(0, process.env.BASE_URL.length - 1) +
this.$route.fullPath;
const signUrl =
this.$store.state.BROWSER.OS === "IOS" ? window.initUrl : shareUrl;
this.$http
.get(`/plus-group/groups/${this.groupID}/posts/${this.postID}`)
.get(`/plus-group/groups/${this.groupID}/posts/${this.feedID}`)
.then(({ data = {} }) => {
this.feed = { ...data };
this.share.title = data.title;
this.share.desc = data.summary;
this.oldID = this.postID;
this.oldID = this.feedID;
this.fetching = false;
this.fetchFeedComments();
this.fetchRewards();
this.fetchLikes();
if (this.isWechat) {
this.getWeChatConfig(this.feed.title, this.feed.summary);
}
this.isWechat &&
wechatShare(signUrl, {
title: `${data.user.name}的动态`,
desc: `${data.feed_content}`,
link: shareUrl,
imgUrl:
data.images.length > 0
? `${this.$http.defaults.baseURL}/files/${
data.images[0].file
}`
: ""
});
})
.catch(() => {
this.$router.back();
});
},
getWeChatConfig(title = "", desc = "") {
const link =
window.location.origin +
process.env.BASE_URL.substr(0, process.env.BASE_URL.length - 1) +
this.$route.fullPath;
const imgUrl = this.firstImage ? this.firstImage : "";
if (this.config.appid === "") {
wx.getOauth(link).then(res => {
this.config.timestamp = res.timestamp || "";
this.config.signature = res.signature || "";
this.config.appid = res.appid || "";
this.config.noncestr = res.noncestr || "";
Wx.config({
debug: false,
appId: this.config.appid,
timestamp: this.config.timestamp,
signature: this.config.signature,
nonceStr: this.config.noncestr,
jsApiList: this.appList
});
Wx.error(() => {
// console.log(res);
});
Wx.ready(() => {
Wx.onMenuShareTimeline({
title,
desc,
link,
imgUrl,
success: () => {
this.shareSuccess();
},
cancel: () => {
this.shareCancel();
}
});
Wx.onMenuShareAppMessage({
title,
desc,
link,
success: () => {
this.shareSuccess();
},
cancel: () => {
this.shareCancel();
}
});
Wx.onMenuShareQQ({
title,
desc,
link,
imgUrl,
success: () => {
this.shareSuccess();
},
cancel: () => {
this.shareCancel();
}
});
});
});
} else {
Wx.config({
debug: false,
appId: this.config.appid,
timestamp: this.config.timestamp,
signature: this.config.signature,
nonceStr: this.config.noncestr,
jsApiList: this.appList
});
Wx.ready(() => {
Wx.onMenuShareTimeline({
title,
desc,
link,
imgUrl,
success: () => {
this.shareSuccess();
},
cancel: () => {
this.shareCancel();
}
});
Wx.onMenuShareAppMessage({
title,
desc,
link,
success: () => {
this.shareSuccess();
},
cancel: () => {
this.shareCancel();
}
});
Wx.onMenuShareQQ({
title,
desc,
link,
imgUrl,
success: () => {
this.shareSuccess();
},
cancel: () => {
this.shareCancel();
}
});
}),
Wx.error(() => {});
}
},
fetchRewards() {
this.$http
.get(`/plus-group/group-posts/${this.postID}/rewards`, {
Expand All @@ -192,6 +168,7 @@ export default {
pinneds &&
pinneds.length &&
(this.pinnedCom = after ? [...this.pinneds, ...pinneds] : pinneds);
comments && comments.length
? ((this.comments = after
? [...this.comments, ...comments]
Expand All @@ -209,6 +186,7 @@ export default {
this.fetchComing = false;
});
},
fetchLikes() {
this.$http
.get(
Expand All @@ -225,6 +203,7 @@ export default {
this.feed = { ...this.feed, ...{ likes: data } };
});
},
likeFeed() {
likeGroupPost(this.postID, this.liked)
.then(() => {
Expand Down Expand Up @@ -252,6 +231,7 @@ export default {
this.fetching = false;
});
},
sendComment({ reply_user: replyUser, body }) {
const params = {};
if (body && body.length > 0) {
Expand All @@ -278,76 +258,6 @@ export default {
bus.$emit("reward:groupPost", this.postID);
}
},
computed: {
feedID() {
return this.$route.params.postID;
},
video_file() {
return false;
},
cover_file() {
return false;
},
postID() {
return this.$route.params.postID;
},
groupID() {
return this.$route.params.groupID;
},
likes() {
return this.feed.likes || [];
},
liked: {
get() {
return !!this.feed.liked;
},
set(val) {
this.feed.liked = val;
}
},
likeCount: {
get() {
return this.feed.likes_count || 0;
},
set(val) {
this.feed.likes_count = ~~val;
}
},
commentCount: {
get() {
return this.feed.comments_count || 0;
},
set(val) {
val > 0, (this.feed.comments_count = val);
}
},
images() {
return this.feed.images || [];
},
firstImage() {
let images = this.images;
if (!images.length) {
return "";
}
const file = images[0] || {};
return this.$http.defaults.baseURL + "/files/" + file.id + "?w=300&h=300";
},
feedContent() {
const { body = "" } = this.feed;
// return render(body);
// return this.$options.filters.markdownHtml(body);
return body;
},
reward() {
return (
{
amount: this.feed.reward_amount,
count: this.feed.reward_number
} || {}
);
}
},
activated() {
if (this.postID) {
this.postID !== this.oldID
Expand All @@ -359,5 +269,3 @@ export default {
}
};
</script>
<style>
</style>

0 comments on commit 96c125b

Please sign in to comment.