CommentSection.vue 6.8 KB

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