index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="discover-details">
  3. <!-- #ifdef MP || APP-PLUS-->
  4. <!-- <nav-bar iconColor='#fff' navTitle='内容详情' :isBackgroundColor="false" ref="navBarRef" :isHeight="false">
  5. </nav-bar> -->
  6. <!-- #endif -->
  7. <discover-details v-if="noteDetail && !loading" :noteRecommendList="noteDetail" type="detail" @getComment="getComment"
  8. @onChangeReplyStatus="onChangeReplyStatus" :imageH="imageH" :isShowCommentView="isShowCommentView" :dazi="dazi"></discover-details>
  9. <view class='loadingicon acea-row row-center-wrapper' :hidden='loading==false'>
  10. <text class='loading iconfont icon-jiazai'></text>
  11. </view>
  12. <view class="commen_details borderPad" id="myElement">
  13. <view v-if="noteDetail.platReplySwitch" class="commen_count" id="commen_count">
  14. 评论<span class="ml10">{{noteDetail.replyNum == 0 ? '' : noteDetail.replyNum}}</span></view>
  15. <view>
  16. <discoverComment v-if="noteDetail" :noteId="noteId" :noteDetails="noteDetail" :isClickBtn="isClickBtn" fromTo="pageView"
  17. :isShowCommentView="isShowCommentView" @closeModelComment="closeModelComment">
  18. </discoverComment>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import discoverDetails from '@/components/discoverDetails/index.vue'
  25. import discoverComment from '@/components/discoverComment/index.vue'
  26. import navBar from '@/components/navBar';
  27. import { gameDetailApi } from '@/api/gameDazi.js';
  28. import {
  29. noteDetailApi
  30. } from '@/api/discover.js';
  31. import {
  32. silenceBindingSpread,
  33. getUserSpread
  34. } from '@/utils/index.js';
  35. import {
  36. mapGetters
  37. } from "vuex";
  38. import onShare from "../../../mixins/onShare";
  39. export default {
  40. components: {
  41. discoverDetails,
  42. discoverComment,
  43. navBar
  44. },
  45. mixins: [onShare],
  46. computed: mapGetters(['isLogin', 'uid', 'globalData']),
  47. data() {
  48. return {
  49. noteDetail: {}, //内容详情
  50. content: '',
  51. bottomVal: 0,
  52. placeholder: "快来说点儿什么吧...",
  53. loading: false,
  54. isShowComment: false, //真实评论弹窗显示隐藏
  55. noteId: 0,
  56. showComment: false, //评论弹窗
  57. imageH: 0, //图片高度
  58. appear: false,
  59. elementId: 'myElement',
  60. observer: null,
  61. isShowCommentView: false, //评论列表是否出现
  62. isClickBtn: false, //是否点击了评论按钮,
  63. title: '内容详情',
  64. dazi: ''
  65. }
  66. },
  67. onLoad: function(options) {
  68. let pages = getCurrentPages()
  69. console.log(options)
  70. this.noteId = Number(options.noteId);
  71. this.dazi = options.dazi || '';
  72. this.getNoteDetail(options.noteId);
  73. //分销码
  74. getUserSpread(options);
  75. },
  76. onReady() {
  77. setTimeout(() => {
  78. // 创建监听器
  79. this.observer = uni.createIntersectionObserver(this);
  80. // 监听评论列表是否出现
  81. this.observer.relativeToViewport('#myElement').observe('#commen_count', (res) => {
  82. // res.intersectionRatio 为相交区域和元素的比例
  83. if (res.intersectionRatio > 0) {
  84. this.isShowCommentView = true
  85. // 元素进入可视区域
  86. } else {
  87. this.isShowCommentView = false
  88. this.isClickBtn = false
  89. // 元素离开可视区域
  90. }
  91. });
  92. }, 500)
  93. },
  94. onUnload() {
  95. // 页面销毁时,停止监听
  96. if (this.observer) {
  97. this.observer.disconnect();
  98. }
  99. },
  100. onShow() {
  101. //分销绑定
  102. silenceBindingSpread(this.isLogin, this.globalData.spread);
  103. },
  104. methods: {
  105. // 计算图片高度
  106. computedHeight() {
  107. let that = this;
  108. if (this.noteDetail.image) {
  109. let windowWidth = uni.getSystemInfoSync().windowWidth;
  110. uni.getImageInfo({
  111. src: that.$util.setDomain(this.noteDetail.image.split(',')[0]),
  112. success: (image) => {
  113. let imageH = parseInt(image.height * windowWidth / image.width);
  114. if (imageH > 500) {
  115. this.isAuto = false;
  116. this.imageH = 500;
  117. } else {
  118. this.imageH = imageH;
  119. }
  120. if (this.dazi) {
  121. const arr = this.noteDetail.image.split(',');
  122. let qrCode = '';
  123. arr.forEach(item =>{
  124. if (this.noteDetail.cover !== item) {
  125. qrCode = item;
  126. } else {
  127. this.noteDetail.image = item;
  128. }
  129. });
  130. this.noteDetail.qrCode = qrCode;
  131. }
  132. console.log(this.imageH, 'inlailellelel')
  133. }
  134. })
  135. }
  136. },
  137. getReplyNum(n) {
  138. this.noteRecommendListNew[this.noteIndex].replyNum = n;
  139. },
  140. //触发评论输入框出现
  141. getComment(item) {
  142. this.showComment = true;
  143. this.isClickBtn = true
  144. this.noteDetails = item;
  145. },
  146. closeModelComment() {
  147. this.isClickBtn = false
  148. },
  149. //关闭评论回调
  150. onChangeReplyStatus(replyStatus) {
  151. if (replyStatus === 1) {
  152. this.$set(this.noteDetail, 'replyStatus', 2)
  153. this.$util.Tips({
  154. title: '禁止成功'
  155. });
  156. } else {
  157. this.$set(this.noteDetail, 'replyStatus', 1)
  158. this.$util.Tips({
  159. title: '开启成功'
  160. });
  161. }
  162. },
  163. // 内容详情
  164. getNoteDetail(noteId) {
  165. let api = this.dazi ? gameDetailApi : noteDetailApi;
  166. api(noteId).then(res => {
  167. this.loading = true;
  168. this.noteDetail = res.data;
  169. this.noteRecommendList = res.data;
  170. this.computedHeight()
  171. this.loading = false;
  172. }).catch(err => {
  173. this.loading = false;
  174. uni.showToast({
  175. title: err,
  176. icon: 'none'
  177. })
  178. });
  179. },
  180. }
  181. }
  182. </script>
  183. <style scoped lang="scss">
  184. /deep/.container {
  185. padding-bottom: 0 !important;
  186. }
  187. .commen_details {
  188. /deep/.container {
  189. height: auto !important;
  190. }
  191. /deep/.main_content {
  192. padding: 30rpx 0 !important;
  193. }
  194. }
  195. .commen_count {
  196. font-size: 26rpx;
  197. color: #282828;
  198. margin: 40rpx 0 0 0;
  199. // min-height: 1px;
  200. }
  201. .discover-details {
  202. padding-bottom: calc(80rpx+ constant(safe-area-inset-bottom)) !important; ///兼容 IOS<11.2/
  203. padding-bottom: calc(80rpx + env(safe-area-inset-bottom));
  204. background-color: #fff;
  205. }
  206. .details {
  207. padding-bottom: calc(40rpx+ constant(safe-area-inset-bottom)) !important; ///兼容 IOS<11.2/
  208. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  209. }
  210. .lang {
  211. width: 560rpx !important;
  212. }
  213. .send {
  214. font-size: 26rpx;
  215. color: #ffffff;
  216. width: 120rpx;
  217. height: 62rpx;
  218. line-height: 62rpx;
  219. text-align: center;
  220. @include linear-gradient(theme);
  221. border-radius: 30rpx;
  222. text-align: center;
  223. }
  224. .details {
  225. background-color: #fff;
  226. }
  227. </style>