djdetail.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="ndetail ">
  3. <image :src="nonews" v-if="datainfo.status==2" class="noimg"></image>
  4. <!-- 详情 -->
  5. <view class="ndbox mb12" v-else>
  6. <view class="plr15">
  7. <view class="tit">{{datainfo.partyTitle}}</view>
  8. <view class="time mb12">{{datainfo.publishTime}}</view>
  9. <view class="rich">
  10. <rich-text :nodes="partyContent" style="word-break: break-all;"></rich-text>
  11. </view>
  12. </view>
  13. <view class="ndbfox flexc">
  14. <!-- <view class="flexcc ndbflist">
  15. <image :src="nicona"></image>
  16. <view>32</view>
  17. </view> -->
  18. <view class="flexcc ndbflist">
  19. <image :src="eye" class="imgb"></image>
  20. <view>{{datainfo.viewCount}}</view>
  21. </view>
  22. <view class="flexcc ndbflist" @click="getScFn()">
  23. <image :src="starb" v-if="datainfo.isStars=='Y'"></image>
  24. <image :src="niconc" v-else></image>
  25. <view>{{datainfo.starsCount}}</view>
  26. </view>
  27. </view>
  28. </view>
  29. <loading></loading>
  30. </view>
  31. </template>
  32. <script>
  33. import config from '@/config'
  34. const baseUrl = config.baseUrl
  35. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  36. import {partyNewsDet,getStarsDj} from "@/api/work/manage.js"
  37. export default{
  38. components:{},
  39. data(){
  40. return{
  41. nicona:require('@/manage/static/news/nicona.png'),
  42. niconb:require('@/manage/static/news/niconb.png'),
  43. niconc:require('@/manage/static/news/niconc.png'),
  44. nicond:require('@/manage/static/news/nicond.png'),
  45. nicone:require('@/manage/static/news/nicone.png'),
  46. head:require('@/manage/static/news/head.png'),
  47. starb:require('@/manage/static/news/starb.png'),
  48. eye:require('@/manage/static/news/eye.png'),
  49. nonews:require('@/manage/static/news/nonews.png'),
  50. datainfo:{
  51. },
  52. partyContent:'',
  53. text:'',
  54. id:"",
  55. userId:this.$store.state.user.userId,
  56. nickName:this.$store.state.user.nickName,
  57. avatar:this.$store.state.user.avatar,
  58. tenantId:this.$store.state.user.tenantId
  59. }
  60. },
  61. onLoad: function(e) {
  62. this.id=e.id;
  63. this.getDetailFn()
  64. },
  65. // 上拉触底加载更多触发事件
  66. onReachBottom() {
  67. if (this.reachflag) {
  68. this.pageNum++
  69. this.getDataFn()
  70. }
  71. },
  72. methods:{
  73. checkPermi, checkRole,
  74. getDetailFn(){
  75. partyNewsDet(this.id).then(res=>{
  76. if(res.code==200){
  77. this.datainfo=res.data;
  78. var data=JSON.parse(JSON.stringify(res.data))
  79. if(data.partyContent){
  80. this.partyContent=this.formatRichText(data.partyContent)
  81. }
  82. }
  83. })
  84. },
  85. getScFn(type){
  86. var params={
  87. userId:this.userId,
  88. nickName:this.nickName,
  89. avatar:this.avatar,
  90. targetType:'2',//目标类型(1:社区 2:党建 )
  91. targetId:this.id,
  92. targetTitle:this.datainfo.partyTitle,
  93. tenantId:this.tenantId
  94. }
  95. getStarsDj(params).then(res=>{
  96. if(res.code==200){
  97. uni.$emit('partyNewsList')
  98. if(this.datainfo.isStars=='Y'){
  99. this.$toast("取消收藏成功");
  100. this.datainfo.isStars='N';
  101. this.datainfo.starsCount--;
  102. }else{
  103. this.$toast("收藏成功");
  104. this.datainfo.isStars='Y';
  105. this.datainfo.starsCount++
  106. }
  107. }
  108. })
  109. },
  110. //解析富文本方法
  111. formatRichText(html) {
  112. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  113. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  114. // match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  115. // match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  116. return match;
  117. });
  118. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  119. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  120. return match;
  121. });
  122. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  123. newContent = newContent.replace(/\<img src="/gi,
  124. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +baseUrl);
  125. return newContent;
  126. },
  127. }
  128. }
  129. </script>
  130. <style>
  131. page{background: #F3F3F0;}
  132. </style>
  133. <style lang="scss" scoped>
  134. .ndetail{
  135. min-height: 100vh;padding: 20rpx 18rpx 100rpx;
  136. .ndbox{background: #FFFFFF;border-radius: 20rpx;padding-top: 30rpx;
  137. .tit{font-weight: bold;font-size: 32rpx;color: #272727;margin-bottom: 14rpx;text-align: center;padding-top: 4rpx;}
  138. .time{font-weight: 500;font-size: 24rpx;color: #AAAAAA;text-align: center;}
  139. .rich{border-top: 2rpx solid #E5E5E5;padding: 28rpx 0;}
  140. .ndbfox{
  141. border-top: 2rpx solid #E5E5E5;
  142. .ndbflist{width: 33.3%;min-height: 78rpx;padding: 16rpx 0;box-sizing: border-box;
  143. image{width: 26rpx;height: 26rpx;margin-right: 26rpx;}
  144. view{font-weight: 500;font-size: 26rpx;color: #666666;}
  145. .imgb{width: 24rpx;height: 18rpx;margin-right: 10rpx;}
  146. }
  147. }
  148. }
  149. }
  150. </style>