CommentSection.vue 7.7 KB

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