CommentSection.vue 11 KB

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