index.vue 7.0 KB

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