CommentSection.vue 8.1 KB

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