CommentSection.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="comment-section">
  3. <view class="section-header">
  4. <text class="fa fa-comments"></text>
  5. <text class="section-title">评论区</text>
  6. <text class="comment-count">({{ tableTotal }})</text>
  7. </view>
  8. <CComment ref="ccRef" :myInfo="myInfo" :userInfo="userInfo" :tableData="tableData" :tableTotal.sync="tableTotal"
  9. :deleteMode="deleteMode" @likeFun="likeFun" @replyFun="replyFun" @deleteFun="deleteFun"></CComment>
  10. <view class="comment-button" @tap="openComment">
  11. <text class="fa fa-pencil"></text>
  12. <text>发表新评论</text>
  13. </view>
  14. <view class="bottomFixed">
  15. <view class="inbutBox"></view>
  16. <view class="giveTheThumbsUpBox"></view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import CComment from "@/components/cc-comment/cc-comment.vue";
  22. export default {
  23. name: 'CommentSection',
  24. components: {
  25. CComment
  26. },
  27. props: {
  28. myInfo: {
  29. type: Object,
  30. required: true
  31. },
  32. userInfo: {
  33. type: Object,
  34. required: true
  35. },
  36. articleId: {
  37. type: [Number, String],
  38. required: true
  39. },
  40. type: {
  41. type: String,
  42. default: 'work'
  43. }
  44. },
  45. data() {
  46. return {
  47. deleteMode: "all",
  48. tableTotal: 0,
  49. tableData: []
  50. }
  51. },
  52. created() {
  53. this.loadCommentData();
  54. },
  55. methods: {
  56. loadCommentData() {
  57. uni.request({
  58. url: this.$apiHost + '/Article/getcomments',
  59. data: {
  60. uuid: getApp().globalData.uuid,
  61. type: this.type,
  62. id: this.articleId,
  63. page: 1,
  64. limit: 10
  65. },
  66. header: {
  67. "content-type": "application/json",
  68. 'sign': getApp().globalData.headerSign
  69. },
  70. success: (res) => {
  71. console.log("评论列表:", res.data);
  72. if (res.data.success == "yes") {
  73. this.$set(this, 'tableData', res.data.list);
  74. this.tableTotal = res.data.total;
  75. let newData = res.data.total
  76. this.$emit('totalNumberOfComments', newData);
  77. console.log("tabddd", this.tableData)
  78. } else {
  79. uni.showToast({
  80. title: '获取评论列表失败',
  81. icon: 'none'
  82. });
  83. }
  84. },
  85. fail: (e) => {
  86. console.log("----e:", e);
  87. }
  88. });
  89. },
  90. openComment() {
  91. let ccRef = this.$refs["ccRef"];
  92. ccRef.newCommentFun();
  93. },
  94. likeFun({ params }, callback) {
  95. console.log("likeFun", params);
  96. uni.request({
  97. url: this.$apiHost + '/Article/zanComment',
  98. data: {
  99. uuid: getApp().globalData.uuid,
  100. id: params.id
  101. },
  102. header: {
  103. "content-type": "application/json",
  104. 'sign': getApp().globalData.headerSign
  105. },
  106. success: (res) => {
  107. console.log("点赞结果:", res.data);
  108. if (res.data.success !== "yes") {
  109. callback(res); // 请求失败时重置点赞效果
  110. }
  111. },
  112. fail: (e) => {
  113. console.log("点赞失败:", e);
  114. callback(e); // 请求失败时重置点赞效果
  115. }
  116. });
  117. },
  118. replyFun({ params }, callback) {
  119. console.log("replyFun", {
  120. uuid: getApp().globalData.uuid,
  121. type: this.type,
  122. article_id: this.articleId,
  123. content: params.user_content,
  124. parent_id: params.parent_id || 0,
  125. reply_id: params.reply_id || 0,
  126. reply_name: params.reply_name || ''
  127. });
  128. uni.request({
  129. url: this.$apiHost + '/Article/newComment',
  130. data: {
  131. uuid: getApp().globalData.uuid,
  132. type: this.type,
  133. article_id: this.articleId,
  134. content: params.user_content,
  135. parent_id: params.parent_id || 0,
  136. reply_id: params.reply_id || 0,
  137. reply_name: params.reply_name || ''
  138. },
  139. header: {
  140. "content-type": "application/json",
  141. 'sign': getApp().globalData.headerSign
  142. },
  143. success: (res) => {
  144. console.log("评论结果:", res.data);
  145. if (res.data.success === "yes") {
  146. callback(res.data);
  147. this.loadCommentData(); // 重新加载评论列表
  148. }
  149. },
  150. fail: (e) => {
  151. console.log("评论失败:", e);
  152. uni.showToast({
  153. title: '评论失败,请重试',
  154. icon: 'none'
  155. });
  156. }
  157. });
  158. },
  159. deleteFun({ params, mode }, callback) {
  160. console.log("deleteFun", { params, mode });
  161. const idsString = Array.isArray(params) ? params.join(',') : params.toString();
  162. console.log("删除评论", idsString, mode)
  163. uni.request({
  164. url: this.$apiHost + '/Article/delComment',
  165. data: {
  166. uuid: getApp().globalData.uuid,
  167. ids: idsString,
  168. mode: mode
  169. },
  170. header: {
  171. "content-type": "application/json",
  172. 'sign': getApp().globalData.headerSign
  173. },
  174. success: (res) => {
  175. console.log("删除结果:", res.data);
  176. if (res.data.success === "yes") {
  177. callback(res);
  178. this.loadCommentData(); // 重新加载评论列表
  179. }
  180. },
  181. fail: (e) => {
  182. console.log("删除失败:", e);
  183. uni.showToast({
  184. title: '删除失败,请重试',
  185. icon: 'none'
  186. });
  187. }
  188. });
  189. },
  190. }
  191. }
  192. </script>
  193. <style lang="scss">
  194. .comment-section {
  195. background-color: #fff;
  196. padding: 20rpx;
  197. margin-top: 20rpx;
  198. border-radius: 12rpx;
  199. .section-header {
  200. display: flex;
  201. align-items: center;
  202. margin-bottom: 20rpx;
  203. .fa {
  204. font-size: 36rpx;
  205. color: #666;
  206. margin-right: 10rpx;
  207. }
  208. .section-title {
  209. font-size: 32rpx;
  210. font-weight: bold;
  211. color: #333;
  212. }
  213. .comment-count {
  214. font-size: 28rpx;
  215. color: #999;
  216. margin-left: 10rpx;
  217. }
  218. }
  219. .comment-button {
  220. display: flex;
  221. align-items: center;
  222. justify-content: center;
  223. height: 80rpx;
  224. margin-top: 20rpx;
  225. background-color: #f8f8f8;
  226. border-radius: 40rpx;
  227. cursor: pointer;
  228. .fa {
  229. font-size: 32rpx;
  230. color: #666;
  231. margin-right: 10rpx;
  232. }
  233. text {
  234. font-size: 28rpx;
  235. color: #666;
  236. }
  237. &:active {
  238. background-color: #f0f0f0;
  239. }
  240. }
  241. .bottomFixed {
  242. width: 100vw;
  243. height: 104rpx;
  244. padding: 20rpx 32rpx 16rpx 32rpx;
  245. background-color: #fff;
  246. // position: fixed;
  247. left: 0;
  248. bottom: var(--window-bottom);
  249. .inbutBox {
  250. background: #F6F6F6;
  251. border-radius: 34rpx;
  252. width: 576rpx;
  253. height: 68rpx;
  254. }
  255. .giveTheThumbsUpBox{
  256. }
  257. }
  258. }
  259. </style>