292 lines
9.3 KiB
JavaScript
292 lines
9.3 KiB
JavaScript
|
"use strict";
|
||
|
const common_vendor = require("../../common/vendor.js");
|
||
|
const common_js_util = require("../../common/js/util.js");
|
||
|
const api_index = require("../../api/index.js");
|
||
|
if (!Array) {
|
||
|
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
||
|
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
|
||
|
(_easycom_uni_icons2 + _easycom_uni_popup2)();
|
||
|
}
|
||
|
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
|
||
|
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
|
||
|
if (!Math) {
|
||
|
(_easycom_uni_icons + _easycom_uni_popup)();
|
||
|
}
|
||
|
const _sfc_main = {
|
||
|
__name: "commentArea",
|
||
|
setup(__props, { expose: __expose }) {
|
||
|
const {
|
||
|
proxy
|
||
|
} = common_vendor.getCurrentInstance();
|
||
|
let detail = common_vendor.reactive({});
|
||
|
let content = common_vendor.ref("");
|
||
|
const showLoad = common_vendor.ref(true);
|
||
|
let listProperty = common_vendor.reactive({
|
||
|
data: [],
|
||
|
pageSize: 10,
|
||
|
pageNum: 1,
|
||
|
total: 0
|
||
|
});
|
||
|
const reply = common_vendor.reactive({});
|
||
|
const placeholder = common_vendor.computed(() => {
|
||
|
let result = "评论一下吧~";
|
||
|
if (reply.id)
|
||
|
result = `回复 @${reply.userNickname}`;
|
||
|
return result;
|
||
|
});
|
||
|
function refreshList() {
|
||
|
listProperty.total = 0;
|
||
|
listProperty.pageNum = 1;
|
||
|
getList();
|
||
|
}
|
||
|
function getList() {
|
||
|
api_index.api.video.commentList({
|
||
|
query: {
|
||
|
videoId: detail.videoId,
|
||
|
pageSize: listProperty.pageSize,
|
||
|
pageNume: listProperty.pageNum
|
||
|
}
|
||
|
}).then((rs) => {
|
||
|
console.log("commentList", rs);
|
||
|
if (rs.code == 200) {
|
||
|
if (listProperty.pageNum == 1)
|
||
|
listProperty.data.length = 0;
|
||
|
listProperty.data.push(...rs.rows.map((item) => {
|
||
|
item.pageSize = 10;
|
||
|
item.pageNum = 0;
|
||
|
item.child = [];
|
||
|
item.formatUserPortrait = common_js_util.util.format_url(item.userPortrait, "img");
|
||
|
item.childShow = true;
|
||
|
return item;
|
||
|
}));
|
||
|
listProperty.total = rs.total;
|
||
|
return;
|
||
|
}
|
||
|
common_js_util.util.alert({
|
||
|
content: rs.msg,
|
||
|
showCancel: false
|
||
|
});
|
||
|
}).finally(() => {
|
||
|
showLoad.value = false;
|
||
|
});
|
||
|
}
|
||
|
function handleSubmit() {
|
||
|
if (!content.value) {
|
||
|
common_js_util.util.alert("请输入评论的内容");
|
||
|
return;
|
||
|
}
|
||
|
api_index.api.video.comment({
|
||
|
query: {
|
||
|
partentId: reply.id ? reply.id : 0,
|
||
|
videoId: detail.videoId,
|
||
|
context: content.value
|
||
|
}
|
||
|
}).then((rs) => {
|
||
|
console.log("handleCommentSubmit", rs);
|
||
|
if (rs.code == 200) {
|
||
|
proxy.$refs.comment.close();
|
||
|
detail.comment++;
|
||
|
refreshList();
|
||
|
setTimeout(() => {
|
||
|
content.value = "";
|
||
|
}, 500);
|
||
|
common_vendor.index.$emit("updateVideo", detail);
|
||
|
return;
|
||
|
}
|
||
|
common_js_util.util.alert({
|
||
|
content: rs.msg,
|
||
|
showCancel: false
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
function open(item) {
|
||
|
if (detail.videoId != item.videoId) {
|
||
|
Object.assign(detail, {}, item);
|
||
|
refreshList();
|
||
|
}
|
||
|
proxy.$refs.commentArea.open();
|
||
|
}
|
||
|
function close() {
|
||
|
proxy.$refs.commentArea.close();
|
||
|
}
|
||
|
function handleReply(item) {
|
||
|
Object.assign(reply, item);
|
||
|
proxy.$refs.comment.open();
|
||
|
}
|
||
|
function showComment() {
|
||
|
reply.id = "";
|
||
|
proxy.$refs.comment.open();
|
||
|
}
|
||
|
function handleExpansion(item, index) {
|
||
|
if (item.childShow == false) {
|
||
|
item.childShow = true;
|
||
|
return;
|
||
|
}
|
||
|
if (item.child.length >= item.num && item.childShow) {
|
||
|
item.childShow = false;
|
||
|
return;
|
||
|
}
|
||
|
item.pageNum++;
|
||
|
getLevelCommentList(item, index);
|
||
|
}
|
||
|
function getLevelCommentList(item, index) {
|
||
|
api_index.api.video.levelCommentList({
|
||
|
query: {
|
||
|
commentId: item.id,
|
||
|
pageSize: item.pageSize,
|
||
|
pageNum: item.pageNum
|
||
|
}
|
||
|
}).then((rs) => {
|
||
|
if (rs.code == 200) {
|
||
|
listProperty.data[index].child.push(...rs.rows.map((node) => {
|
||
|
node.formatUserPortrait = common_js_util.util.format_url(node.userPortrait, "img");
|
||
|
return node;
|
||
|
}));
|
||
|
item.childShow = true;
|
||
|
return;
|
||
|
}
|
||
|
common_js_util.util.alert({
|
||
|
content: rs.msg,
|
||
|
showCancel: false
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
function handleLike(item) {
|
||
|
common_js_util.util.isLogin().then((rs) => {
|
||
|
api_index.api.video.thumbsUp({
|
||
|
query: {
|
||
|
// 0取消 1点赞
|
||
|
type: item.isLike ? 0 : 1,
|
||
|
// 评论id
|
||
|
commentId: item.id
|
||
|
}
|
||
|
}).then((rs2) => {
|
||
|
if (rs2.code == 200) {
|
||
|
if (item.isLike)
|
||
|
item.likes--;
|
||
|
else
|
||
|
item.likes++;
|
||
|
item.isLike = !item.isLike;
|
||
|
listProperty.data = JSON.parse(JSON.stringify(listProperty.data));
|
||
|
return;
|
||
|
}
|
||
|
common_js_util.util.alert({
|
||
|
content: rs2.msg,
|
||
|
showCancel: false
|
||
|
});
|
||
|
});
|
||
|
}).catch(() => {
|
||
|
common_vendor.index.navigateTo({
|
||
|
url: "/pages/login/loginPhone"
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
function toUser(user) {
|
||
|
common_vendor.index.navigateTo({
|
||
|
url: common_js_util.util.setUrl("/pages/index/videoHome", {
|
||
|
userId: user.userId
|
||
|
})
|
||
|
});
|
||
|
}
|
||
|
__expose({
|
||
|
open,
|
||
|
close
|
||
|
});
|
||
|
return (_ctx, _cache) => {
|
||
|
return common_vendor.e({
|
||
|
a: showLoad.value
|
||
|
}, showLoad.value ? {
|
||
|
b: common_vendor.p({
|
||
|
type: "spinner-cycle"
|
||
|
})
|
||
|
} : common_vendor.e({
|
||
|
c: common_vendor.f(common_vendor.unref(listProperty).data, (item, index, i0) => {
|
||
|
return common_vendor.e({
|
||
|
a: item.formatUserPortrait,
|
||
|
b: common_vendor.o$1(($event) => toUser(item), index),
|
||
|
c: common_vendor.t(item.userNickname),
|
||
|
d: common_vendor.o$1(($event) => toUser(item), index),
|
||
|
e: item.context,
|
||
|
f: "272d58c8-2-" + i0 + ",272d58c8-0",
|
||
|
g: common_vendor.p({
|
||
|
type: "heart-filled",
|
||
|
color: item.isLike ? "#F84259" : "#b3b3b3",
|
||
|
size: "32rpx"
|
||
|
}),
|
||
|
h: common_vendor.t(item.likes),
|
||
|
i: common_vendor.o$1(($event) => handleLike(item), index),
|
||
|
j: common_vendor.t(item.createTime),
|
||
|
k: common_vendor.o$1(($event) => handleReply(item), index),
|
||
|
l: item.num != 0
|
||
|
}, item.num != 0 ? common_vendor.e({
|
||
|
m: item.childShow
|
||
|
}, item.childShow ? {
|
||
|
n: common_vendor.f(item.child, (secItem, secIndex, i1) => {
|
||
|
return common_vendor.e({
|
||
|
a: secItem.formatUserPortrait,
|
||
|
b: common_vendor.o$1(($event) => toUser(secItem), secItem.id),
|
||
|
c: common_vendor.t(secItem.userNickname),
|
||
|
d: common_vendor.o$1(($event) => toUser(secItem), secItem.id),
|
||
|
e: secItem.context,
|
||
|
f: "272d58c8-3-" + i0 + "-" + i1 + ",272d58c8-0",
|
||
|
g: common_vendor.p({
|
||
|
type: "heart-filled",
|
||
|
color: secItem.isLike ? "#F84259" : "#b3b3b3",
|
||
|
size: "32rpx"
|
||
|
}),
|
||
|
h: common_vendor.t(secItem.likes),
|
||
|
i: common_vendor.o$1(($event) => handleLike(secItem), secItem.id),
|
||
|
j: common_vendor.t(secItem.createTime)
|
||
|
}, {}, {
|
||
|
l: secItem.id
|
||
|
});
|
||
|
})
|
||
|
} : {}, {
|
||
|
o: item.childShow
|
||
|
}, item.childShow ? common_vendor.e({
|
||
|
p: item.num == item.child.length
|
||
|
}, item.num == item.child.length ? {
|
||
|
q: "272d58c8-4-" + i0 + ",272d58c8-0",
|
||
|
r: common_vendor.p({
|
||
|
type: "top"
|
||
|
})
|
||
|
} : {
|
||
|
s: common_vendor.t(item.num - item.child.length),
|
||
|
t: "272d58c8-5-" + i0 + ",272d58c8-0",
|
||
|
v: common_vendor.p({
|
||
|
type: "bottom"
|
||
|
})
|
||
|
}) : {
|
||
|
w: common_vendor.t(item.num),
|
||
|
x: "272d58c8-6-" + i0 + ",272d58c8-0",
|
||
|
y: common_vendor.p({
|
||
|
type: "bottom"
|
||
|
})
|
||
|
}, {
|
||
|
z: common_vendor.o$1(($event) => handleExpansion(item, index), index)
|
||
|
}) : {}, {
|
||
|
A: index
|
||
|
});
|
||
|
}),
|
||
|
d: !common_vendor.unref(listProperty).data[0]
|
||
|
}, !common_vendor.unref(listProperty).data[0] ? {} : {}), {
|
||
|
e: common_vendor.o$1(showComment),
|
||
|
f: common_vendor.sr("commentArea", "272d58c8-0"),
|
||
|
g: common_vendor.p({
|
||
|
type: "bottom"
|
||
|
}),
|
||
|
h: placeholder.value,
|
||
|
i: common_vendor.unref(content),
|
||
|
j: common_vendor.o$1(($event) => common_vendor.isRef(content) ? content.value = $event.detail.value : content = $event.detail.value),
|
||
|
k: common_vendor.o$1(handleSubmit),
|
||
|
l: common_vendor.sr("comment", "272d58c8-7"),
|
||
|
m: common_vendor.p({
|
||
|
type: "bottom"
|
||
|
})
|
||
|
});
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-272d58c8"]]);
|
||
|
wx.createComponent(Component);
|