CommentSection.vue 9.9 KB

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