acdr-ui/dist/dev/mp-weixin/pages/space/components/UserPost.js

275 lines
9.7 KiB
JavaScript

"use strict";
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const common_vendor = require("../../../common/vendor.js");
const utils_commUtils = require("../../../utils/commUtils.js");
const utils_http = require("../../../utils/http.js");
if (!Array) {
const _easycom_wd_img2 = common_vendor.resolveComponent("wd-img");
_easycom_wd_img2();
}
const _easycom_wd_img = () => "../../../node-modules/wot-design-uni/components/wd-img/wd-img.js";
if (!Math) {
_easycom_wd_img();
}
const _sfc_main = {
__name: "UserPost",
props: {
post: Object
},
setup(__props) {
const props = __props;
const action = common_vendor.ref({});
const isPop = common_vendor.ref(false);
const comments = common_vendor.ref({});
const beCommentId = common_vendor.ref(null);
const contentText = common_vendor.ref("");
const beComment = (comment) => {
beCommentId.value = comment;
};
const popAction = () => __async(this, null, function* () {
isPop.value = !isPop.value;
if (isPop.value) {
yield commentsList();
}
});
const commentsList = (current = 1, size = 10) => __async(this, null, function* () {
var _a;
try {
const res = yield utils_http.httpGet(
`/posts/commentsList?postId=${props.post.id}&current=${current}&size=${size}`
);
if (res.code == 200) {
comments.value = res;
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
utils_commUtils.toast(((_a = e.data) == null ? void 0 : _a.message) || "评论获取失败");
}
});
const sendComment = () => __async(this, null, function* () {
var _a, _b;
try {
const res = yield utils_http.httpPost("/posts/comments/" + props.post.id, {
postId: props.post.id,
content: contentText.value,
beCommentsId: ((_a = beCommentId.value) == null ? void 0 : _a.id) || null
});
if (res.code == 200) {
utils_commUtils.toast("评论成功");
yield commentsList();
beCommentId.value = null;
contentText.value = "";
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
utils_commUtils.toast(((_b = e.data) == null ? void 0 : _b.message) || "评论失败");
}
});
const isAction = () => __async(this, null, function* () {
try {
const res = yield utils_http.httpGet(`/posts/actions?postId=${props.post.id}`);
if (res.code == 200) {
action.value = res.data;
props.post.favorites = res.data.post.favorites;
props.post.comments = res.data.post.comments;
props.post.likes = res.data.post.likes;
props.post.isFollowed = res.data.post.isFollowed;
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
console.log(e);
}
});
const like = () => __async(this, null, function* () {
var _a;
try {
const res = yield utils_http.httpPost("/posts/like", {}, { postId: props.post.id });
if (res.code == 200) {
yield isAction();
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
console.log(e);
utils_commUtils.toast(((_a = e.data) == null ? void 0 : _a.message) || "点赞失败");
}
});
const unlike = () => __async(this, null, function* () {
var _a;
try {
const res = yield utils_http.http({
url: "/posts/unlike?postId=" + props.post.id,
method: "DELETE"
});
if (res.code == 200) {
yield isAction();
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
utils_commUtils.toast(((_a = e.data) == null ? void 0 : _a.message) || "取消点赞失败");
}
});
const favorite = () => __async(this, null, function* () {
var _a;
try {
const res = yield utils_http.httpPost("/posts/favorite", {}, { postId: props.post.id });
if (res.code == 200) {
yield isAction();
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
utils_commUtils.toast(((_a = e.data) == null ? void 0 : _a.message) || "收藏失败");
}
});
const unfavorite = () => __async(this, null, function* () {
var _a;
try {
const res = yield utils_http.http({
url: "/unfavorite?postId=" + props.post.id,
method: "DELETE"
});
if (res.code == 200) {
yield isAction();
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
utils_commUtils.toast(((_a = e.data) == null ? void 0 : _a.message) || "取消收藏失败");
}
});
const follow = () => __async(this, null, function* () {
var _a;
try {
const res = yield utils_http.httpPost("/posts/follow", {}, { followingId: props.post.userId });
if (res.code == 200) {
yield isAction();
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
utils_commUtils.toast(((_a = e.data) == null ? void 0 : _a.message) || "关注失败");
}
});
const unfollow = () => __async(this, null, function* () {
try {
const res = yield utils_http.http({
url: "/posts/unfollow?followingId=" + props.post.userId,
method: "POST"
});
if (res.code == 200) {
yield isAction();
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
}
});
common_vendor.onLoad(() => __async(this, null, function* () {
yield isAction();
}));
return (_ctx, _cache) => {
return common_vendor.e({
a: __props.post.isFollowed != void 0
}, __props.post.isFollowed != void 0 ? common_vendor.e({
b: !__props.post.isFollowed
}, !__props.post.isFollowed ? {
c: common_vendor.o(follow)
} : {
d: common_vendor.o(unfollow)
}) : {}, {
e: common_vendor.unref(utils_commUtils.imgUrl)(__props.post.avatar),
f: common_vendor.t(__props.post.username),
g: common_vendor.t(__props.post.location),
h: common_vendor.t(__props.post.time),
i: common_vendor.f(__props.post.images, (image, index, i0) => {
return {
a: index,
b: "624bde23-0-" + i0,
c: common_vendor.p({
radius: 8,
mode: "center",
["enable-preview"]: true,
src: common_vendor.unref(utils_commUtils.imgUrl)(image),
alt: image
})
};
}),
j: common_vendor.t(__props.post.content),
k: !common_vendor.unref(action).likes
}, !common_vendor.unref(action).likes ? {
l: common_vendor.o(like),
m: common_vendor.unref(utils_commUtils.imgUrl)("@/static/space/thumbs.svg")
} : {
n: common_vendor.o(unlike),
o: common_vendor.unref(utils_commUtils.imgUrl)("@/static/space/favorites.png")
}, {
p: common_vendor.t(__props.post.likes || "0"),
q: !common_vendor.unref(action).favorites
}, !common_vendor.unref(action).favorites ? {
r: common_vendor.o(favorite),
s: common_vendor.unref(utils_commUtils.imgUrl)("@/static/space/like.svg")
} : {
t: common_vendor.o(unfavorite),
v: common_vendor.unref(utils_commUtils.imgUrl)("@/static/space/likes-on.png")
}, {
w: common_vendor.t(__props.post.favorites || "0"),
x: common_vendor.o(popAction),
y: common_vendor.unref(utils_commUtils.imgUrl)("@/static/space/comment.svg"),
z: common_vendor.t(__props.post.comments || "0"),
A: common_vendor.unref(isPop)
}, common_vendor.unref(isPop) ? common_vendor.e({
B: common_vendor.unref(comments).total > 0
}, common_vendor.unref(comments).total > 0 ? common_vendor.e({
C: common_vendor.f(common_vendor.unref(comments).records, (comment, index, i0) => {
return {
a: common_vendor.unref(utils_commUtils.imgUrl)(comment.avatar),
b: common_vendor.t(comment.userName),
c: common_vendor.t(comment.content),
d: common_vendor.t(comment.createdTime),
e: common_vendor.o(($event) => beComment(comment), comment.id),
f: comment.id
};
}),
D: common_vendor.t("国内"),
E: common_vendor.unref(comments).total > 10
}, common_vendor.unref(comments).total > 10 ? {
F: common_vendor.o(($event) => commentsList(-1, -1))
} : {}) : {}) : {}, {
G: common_vendor.unref(isPop)
}, common_vendor.unref(isPop) ? {
H: common_vendor.unref(contentText),
I: common_vendor.o(($event) => common_vendor.isRef(contentText) ? contentText.value = $event.detail.value : null),
J: common_vendor.t(common_vendor.unref(beCommentId) ? "@" + common_vendor.unref(beCommentId).userName : common_vendor.unref(beCommentId).userNamebeCommentId.userName),
K: common_vendor.o(sendComment)
} : {});
};
}
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-624bde23"]]);
wx.createComponent(Component);
//# sourceMappingURL=UserPost.js.map