CommentSection.vue 8.7 KB

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