CommentSection.vue 8.9 KB

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