CommentSection.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <view class="comment-section">
  3. <!-- <template v-if="articleInfo.can_view_comment"> -->
  4. <template>
  5. <view class="section-header">
  6. <!-- <text class="fa fa-comments"></text> -->
  7. <!-- <text class="section-title">评论区</text> -->
  8. <text class="comment-count">共 {{ tableTotal }} 条评论</text>
  9. </view>
  10. <CComment v-if="userInfo.user_id" ref="ccRef" :myInfo="userInfo" :userInfo="author" :tableData="tableData"
  11. :tableTotal.sync="tableTotal" :deleteMode="deleteMode" @likeFun="likeFun" @replyFun="replyFun"
  12. @deleteFun="deleteFun" :isComment="articleInfo.can_comment"></CComment>
  13. <!-- <view class="comment-button" @tap="openComment">
  14. <text class="fa fa-pencil"></text>
  15. <text>发表新评论</text>
  16. </view> -->
  17. <view class="bottomFixed">
  18. <view class="inbutBox" @tap="openComment">
  19. <view class="left-box">
  20. <image src="@/static/icon/cz_icon_xiugaifengmian.png"></image>
  21. <text>发表你的想法...</text>
  22. </view>
  23. <view class="emoji-trigger">
  24. <text class="fa fa-smile-o"></text>
  25. </view>
  26. </view>
  27. <view class="giveTheThumbsUpBox" @click="giveTheThumbsUp()">
  28. <image v-if="!isLikeFalg" src="@/static/icon/icon-19.png"></image>
  29. <image v-else src="@/static/icon/icon-18.png"></image>
  30. {{ articleInfo.num_like }}
  31. </view>
  32. </view>
  33. </template>
  34. </view>
  35. </template>
  36. <script>
  37. import CComment from "@/components/cc-comment/cc-comment.vue";
  38. import { getStorage, setStorage, removeStorage } from "@/common/util.js";
  39. import { mapState, mapMutations, mapGetters } from 'vuex';
  40. export default {
  41. name: 'CommentSection',
  42. components: {
  43. CComment
  44. },
  45. computed: {
  46. ...mapState('rightsManagement', ['teenageMode'])
  47. },
  48. props: {
  49. myInfo: {
  50. type: Object,
  51. required: true
  52. },
  53. articleInfo: {
  54. // type
  55. default: () => ({ is_like: 0 })
  56. },
  57. articleId: {
  58. type: [Number, String],
  59. required: true
  60. },
  61. type: {
  62. type: String,
  63. default: 'work'
  64. },
  65. find: {
  66. type: String,
  67. default: ''
  68. },
  69. author: { // 文章作者信息
  70. type: Object,
  71. default: () => { },
  72. },
  73. },
  74. data() {
  75. return {
  76. deleteMode: "all",
  77. tableTotal: 0,
  78. tableData: [],
  79. isLikeFalg: this.articleInfo.is_like,
  80. userInfo: {}
  81. }
  82. },
  83. created() {
  84. this.loadCommentData();
  85. this.getInfoData()
  86. },
  87. onMounted() {
  88. },
  89. methods: {
  90. giveTheThumbsUp() {
  91. let url = '/Article/like'
  92. if (this.find == 'work') {
  93. url = '/Work/like'
  94. }
  95. uni.request({
  96. url: this.$apiHost + url,
  97. data: {
  98. uuid: getApp().globalData.uuid,
  99. id: this.articleId
  100. },
  101. header: {
  102. "content-type": "application/json",
  103. 'sign': getApp().globalData.headerSign
  104. },
  105. success: (res) => {
  106. console.log("点赞结果:", res.data);
  107. if (res.data.str == "取消点赞") {
  108. this.isLikeFalg = false
  109. this.articleInfo.num_like--
  110. }
  111. if (res.data.str == "点赞成功") {
  112. this.isLikeFalg = true
  113. this.articleInfo.num_like++
  114. }
  115. uni.showToast({
  116. title: res.data.str,
  117. icon: 'none'
  118. });
  119. },
  120. fail: (e) => {
  121. console.log("点赞失败:", e);
  122. }
  123. });
  124. },
  125. loadCommentData() {
  126. uni.request({
  127. url: this.$apiHost + '/Article/getcomments',
  128. data: {
  129. uuid: getApp().globalData.uuid,
  130. type: this.type,
  131. id: this.articleId,
  132. page: 1,
  133. limit: 10,
  134. sms_id: this.articleInfo.sms_id ? this.articleInfo.sms_id : 0
  135. },
  136. header: {
  137. "content-type": "application/json",
  138. 'sign': getApp().globalData.headerSign
  139. },
  140. success: (res) => {
  141. console.log("评论列表:", res.data);
  142. if (res.data.success == "yes") {
  143. this.$set(this, 'tableData', res.data.list);
  144. this.tableTotal = res.data.total;
  145. let newData = res.data.total
  146. this.$emit('totalNumberOfComments', newData);
  147. console.log("tabddd", this.tableData)
  148. } else {
  149. uni.showToast({
  150. title: '获取评论列表失败',
  151. icon: 'none'
  152. });
  153. }
  154. },
  155. fail: (e) => {
  156. console.log("----e:", e);
  157. }
  158. });
  159. },
  160. openComment() {
  161. let isContentRecommendation
  162. if (this.teenageMode != 1) {
  163. isContentRecommendation = true;
  164. } else {
  165. isContentRecommendation = false;
  166. }
  167. if (!isContentRecommendation) {
  168. uni.showToast({
  169. title: '当前无法评论',
  170. icon: 'none'
  171. });
  172. return;
  173. }
  174. uni.$emit('check_login', () => {
  175. let ccRef = this.$refs["ccRef"];
  176. ccRef.newCommentFun();
  177. })
  178. },
  179. likeFun({ params }, callback) {
  180. uni.$emit('check_login', () => {
  181. uni.request({
  182. url: this.$apiHost + '/Article/zanComment',
  183. data: {
  184. uuid: getApp().globalData.uuid,
  185. id: params.id
  186. },
  187. header: {
  188. "content-type": "application/json",
  189. 'sign': getApp().globalData.headerSign
  190. },
  191. success: (res) => {
  192. console.log("点赞结果:", res.data);
  193. if (res.data.success !== "yes") {
  194. callback(res); // 请求失败时重置点赞效果
  195. }
  196. },
  197. fail: (e) => {
  198. console.log("点赞失败:", e);
  199. callback(e); // 请求失败时重置点赞效果
  200. }
  201. });
  202. })
  203. },
  204. replyFun({ params }, callback) {
  205. uni.$emit('check_login', () => {
  206. console.log("replyFun", {
  207. uuid: getApp().globalData.uuid,
  208. type: this.type,
  209. article_id: this.articleId,
  210. content: params.user_content,
  211. parent_id: params.parent_id || 0,
  212. reply_id: params.reply_id || 0,
  213. reply_name: params.reply_name || ''
  214. });
  215. uni.request({
  216. url: this.$apiHost + '/Article/newComment',
  217. data: {
  218. uuid: getApp().globalData.uuid,
  219. type: this.type,
  220. article_id: this.articleId,
  221. content: params.user_content,
  222. parent_id: params.parent_id || 0,
  223. reply_id: params.reply_id || 0,
  224. reply_name: params.reply_name || ''
  225. },
  226. header: {
  227. "content-type": "application/json",
  228. 'sign': getApp().globalData.headerSign
  229. },
  230. success: (res) => {
  231. console.log("评论结果:", res.data);
  232. if (res.data.success === "yes") {
  233. callback(res.data.comment);
  234. this.loadCommentData(); // 重新加载评论列表
  235. }
  236. },
  237. fail: (e) => {
  238. console.log("评论失败:", e);
  239. uni.showToast({
  240. title: '评论失败,请重试',
  241. icon: 'none'
  242. });
  243. }
  244. });
  245. })
  246. },
  247. deleteFun({ params, mode }, callback) {
  248. uni.$emit('check_login', () => {
  249. console.log("deleteFun", { params, mode });
  250. const idsString = Array.isArray(params) ? params.join(',') : params.toString();
  251. console.log("删除评论", idsString, mode)
  252. uni.request({
  253. url: this.$apiHost + '/Article/delComment',
  254. data: {
  255. uuid: getApp().globalData.uuid,
  256. ids: idsString,
  257. mode: mode
  258. },
  259. header: {
  260. "content-type": "application/json",
  261. 'sign': getApp().globalData.headerSign
  262. },
  263. success: (res) => {
  264. console.log("删除结果:", res.data);
  265. if (res.data.success === "yes") {
  266. this.loadCommentData(); // 重新加载评论列表
  267. }
  268. callback(res);
  269. if (res.data.success === "no" && res.data.str) {
  270. console.log(1);
  271. uni.showToast({
  272. title: res.data.str,
  273. icon: 'none'
  274. });
  275. }
  276. },
  277. fail: (e) => {
  278. console.log("删除失败:", e);
  279. uni.showToast({
  280. title: '删除失败,请重试',
  281. icon: 'none'
  282. });
  283. }
  284. });
  285. })
  286. },
  287. // 获取当前用户信息
  288. getInfoData() {
  289. uni.request({
  290. url: this.$apiHost + '/User/getinfo',
  291. data: {
  292. uuid: getApp().globalData.uuid
  293. },
  294. header: {
  295. 'content-type': 'application/json'
  296. },
  297. success: (res) => {
  298. this.userInfo = res.data;
  299. console.log("获取用户信息成功:", res.data);
  300. }
  301. });
  302. },
  303. }
  304. }
  305. </script>
  306. <style lang="scss">
  307. .comment-section {
  308. background-color: #fff;
  309. padding: 20rpx;
  310. margin-top: 20rpx;
  311. border-radius: 12rpx;
  312. .section-header {
  313. display: flex;
  314. align-items: center;
  315. margin-bottom: 20rpx;
  316. padding-left: 28rpx;
  317. .fa {
  318. font-size: 36rpx;
  319. color: #666;
  320. margin-right: 10rpx;
  321. }
  322. .section-title {
  323. font-size: 32rpx;
  324. font-weight: bold;
  325. color: #333;
  326. }
  327. .comment-count {
  328. font-size: 28rpx;
  329. // margin-left: 10rpx;
  330. font-family: 'PingFang SC-Medium';
  331. font-weight: 400;
  332. color: #1F1F1F;
  333. }
  334. }
  335. .comment-button {
  336. display: flex;
  337. align-items: center;
  338. justify-content: center;
  339. height: 80rpx;
  340. margin-top: 20rpx;
  341. background-color: #f8f8f8;
  342. border-radius: 40rpx;
  343. cursor: pointer;
  344. .fa {
  345. font-size: 32rpx;
  346. color: #666;
  347. margin-right: 10rpx;
  348. }
  349. text {
  350. font-size: 28rpx;
  351. color: #666;
  352. }
  353. &:active {
  354. background-color: #f0f0f0;
  355. }
  356. }
  357. .bottomFixed {
  358. width: 100vw;
  359. height: 104rpx;
  360. padding: 20rpx 32rpx 16rpx 32rpx;
  361. background-color: #fff;
  362. // position: fixed;
  363. left: 0;
  364. bottom: var(--window-bottom);
  365. display: flex;
  366. align-items: center;
  367. justify-content: space-between;
  368. .inbutBox {
  369. background: #F6F6F6;
  370. border-radius: 34rpx;
  371. width: 576rpx;
  372. height: 68rpx;
  373. display: flex;
  374. align-items: center;
  375. justify-content: space-between;
  376. padding: 24rpx 18rpx;
  377. .left-box {
  378. display: flex;
  379. align-items: center;
  380. }
  381. image {
  382. width: 32rpx;
  383. height: 32rpx;
  384. margin-right: 12rpx;
  385. }
  386. .emoji-trigger {
  387. font-size: 48rpx;
  388. }
  389. }
  390. .giveTheThumbsUpBox {
  391. display: flex;
  392. align-items: center;
  393. justify-content: center;
  394. image {
  395. width: 40rpx;
  396. height: 40rpx;
  397. margin-right: 10rpx;
  398. }
  399. }
  400. }
  401. }
  402. </style>