CommentSection.vue 10 KB

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