CommentSection.vue 7.9 KB

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