CommentSection.vue 12 KB

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