CommentSection.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. uni.$emit('check_login', () => {
  149. let ccRef = this.$refs["ccRef"];
  150. ccRef.newCommentFun();})
  151. },
  152. likeFun({ params }, callback) {
  153. uni.$emit('check_login', () => {
  154. console.log("likeFun", params);
  155. uni.request({
  156. url: this.$apiHost + '/Article/zanComment',
  157. data: {
  158. uuid: getApp().globalData.uuid,
  159. id: params.id
  160. },
  161. header: {
  162. "content-type": "application/json",
  163. 'sign': getApp().globalData.headerSign
  164. },
  165. success: (res) => {
  166. console.log("点赞结果:", res.data);
  167. if (res.data.success !== "yes") {
  168. callback(res); // 请求失败时重置点赞效果
  169. }
  170. },
  171. fail: (e) => {
  172. console.log("点赞失败:", e);
  173. callback(e); // 请求失败时重置点赞效果
  174. }
  175. }); })
  176. },
  177. replyFun({ params }, callback) {
  178. uni.$emit('check_login', () => {
  179. console.log("replyFun", {
  180. uuid: getApp().globalData.uuid,
  181. type: this.type,
  182. article_id: this.articleId,
  183. content: params.user_content,
  184. parent_id: params.parent_id || 0,
  185. reply_id: params.reply_id || 0,
  186. reply_name: params.reply_name || ''
  187. });
  188. uni.request({
  189. url: this.$apiHost + '/Article/newComment',
  190. data: {
  191. uuid: getApp().globalData.uuid,
  192. type: this.type,
  193. article_id: this.articleId,
  194. content: params.user_content,
  195. parent_id: params.parent_id || 0,
  196. reply_id: params.reply_id || 0,
  197. reply_name: params.reply_name || ''
  198. },
  199. header: {
  200. "content-type": "application/json",
  201. 'sign': getApp().globalData.headerSign
  202. },
  203. success: (res) => {
  204. console.log("评论结果:", res.data);
  205. if (res.data.success === "yes") {
  206. callback(res.data);
  207. this.loadCommentData(); // 重新加载评论列表
  208. }
  209. },
  210. fail: (e) => {
  211. console.log("评论失败:", e);
  212. uni.showToast({
  213. title: '评论失败,请重试',
  214. icon: 'none'
  215. });
  216. }
  217. }); })
  218. },
  219. deleteFun({ params, mode }, callback) {
  220. uni.$emit('check_login', () => {
  221. console.log("deleteFun", { params, mode });
  222. const idsString = Array.isArray(params) ? params.join(',') : params.toString();
  223. console.log("删除评论", idsString, mode)
  224. uni.request({
  225. url: this.$apiHost + '/Article/delComment',
  226. data: {
  227. uuid: getApp().globalData.uuid,
  228. ids: idsString,
  229. mode: mode
  230. },
  231. header: {
  232. "content-type": "application/json",
  233. 'sign': getApp().globalData.headerSign
  234. },
  235. success: (res) => {
  236. console.log("删除结果:", res.data);
  237. if (res.data.success === "yes") {
  238. this.loadCommentData(); // 重新加载评论列表
  239. }
  240. callback(res);
  241. if (res.data.success === "no" && res.data.str) {
  242. console.log(1);
  243. uni.showToast({
  244. title: res.data.str,
  245. icon: 'none'
  246. });
  247. }
  248. },
  249. fail: (e) => {
  250. console.log("删除失败:", e);
  251. uni.showToast({
  252. title: '删除失败,请重试',
  253. icon: 'none'
  254. });
  255. }
  256. });})
  257. },
  258. }
  259. }
  260. </script>
  261. <style lang="scss">
  262. .comment-section {
  263. background-color: #fff;
  264. padding: 20rpx;
  265. margin-top: 20rpx;
  266. border-radius: 12rpx;
  267. .section-header {
  268. display: flex;
  269. align-items: center;
  270. margin-bottom: 20rpx;
  271. .fa {
  272. font-size: 36rpx;
  273. color: #666;
  274. margin-right: 10rpx;
  275. }
  276. .section-title {
  277. font-size: 32rpx;
  278. font-weight: bold;
  279. color: #333;
  280. }
  281. .comment-count {
  282. font-size: 28rpx;
  283. margin-left: 10rpx;
  284. font-family: 'PingFang SC-Medium';
  285. font-weight: 400;
  286. color: #1F1F1F;
  287. }
  288. }
  289. .comment-button {
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. height: 80rpx;
  294. margin-top: 20rpx;
  295. background-color: #f8f8f8;
  296. border-radius: 40rpx;
  297. cursor: pointer;
  298. .fa {
  299. font-size: 32rpx;
  300. color: #666;
  301. margin-right: 10rpx;
  302. }
  303. text {
  304. font-size: 28rpx;
  305. color: #666;
  306. }
  307. &:active {
  308. background-color: #f0f0f0;
  309. }
  310. }
  311. .bottomFixed {
  312. width: 100vw;
  313. height: 104rpx;
  314. padding: 20rpx 32rpx 16rpx 32rpx;
  315. background-color: #fff;
  316. // position: fixed;
  317. left: 0;
  318. bottom: var(--window-bottom);
  319. display: flex;
  320. align-items: center;
  321. justify-content: space-between;
  322. .inbutBox {
  323. background: #F6F6F6;
  324. border-radius: 34rpx;
  325. width: 576rpx;
  326. height: 68rpx;
  327. display: flex;
  328. align-items: center;
  329. justify-content: space-between;
  330. padding: 24rpx 18rpx;
  331. .left-box {
  332. display: flex;
  333. align-items: center;
  334. }
  335. image {
  336. width: 32rpx;
  337. height: 32rpx;
  338. margin-right: 12rpx;
  339. }
  340. .emoji-trigger {
  341. font-size: 48rpx;
  342. }
  343. }
  344. .giveTheThumbsUpBox {
  345. display: flex;
  346. align-items: center;
  347. justify-content: center;
  348. image {
  349. width: 40rpx;
  350. height: 40rpx;
  351. margin-right: 10rpx;
  352. }
  353. }
  354. }
  355. }
  356. </style>