CommentSection.vue 9.5 KB

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