newssq.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="car">
  3. <view class="cartop">
  4. <view class="tabtop flexc">
  5. <view class="tabt" :class="tabval==ite.dictValue?'act':''" v-for="(ite,idx) in wzlxList" :key="idx" @click="getTabFn(ite.dictValue)">{{ite.dictLabel}}</view>
  6. </view>
  7. <view class="numbox" @click="getHdFn">
  8. 未读互动<text>{{hdcount}}</text>
  9. </view>
  10. </view>
  11. <!-- 列表 -->
  12. <view class="carlists">
  13. <box-list :datainfo="list" :wtdt="wtdt" type='newssq' @getDetail="getDetail"></box-list>
  14. </view>
  15. <loading></loading>
  16. </view>
  17. </template>
  18. <script>
  19. import config from '@/config'
  20. const baseUrl = config.baseUrl
  21. import boxList from "@/news/components/box/list.vue"
  22. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  23. import {getDictionaryFn} from "@/api/system/user.js"
  24. import {newsList,newsDel} from "@/api/work/manage.js"
  25. import {getCommentInteractionCount} from "@/api/work/news.js"
  26. export default{
  27. components:{boxList},
  28. data(){
  29. return{
  30. cxrq:"",
  31. text:'',
  32. list:[],
  33. pageSize: 10,
  34. pageNum: 1,
  35. reachflag: true,
  36. wtdt:'',
  37. tabval:'',
  38. wzlxList:[],
  39. hdcount:0,
  40. baseUrl:config.baseUrl,
  41. }
  42. },
  43. onUnload() {
  44. uni.$off('newsList')
  45. },
  46. onLoad: function() {
  47. uni.$on('newsList',(res)=>{
  48. this.getrefreshData()
  49. })
  50. this.init()
  51. this.getCommentInteractionCount()
  52. },
  53. // 上拉触底加载更多触发事件
  54. onReachBottom() {
  55. if (this.reachflag) {
  56. this.pageNum++
  57. this.getDataFn()
  58. }
  59. },
  60. methods:{
  61. checkPermi, checkRole,
  62. init(){
  63. // 社区资讯类型
  64. getDictionaryFn('community_typ').then(res=>{
  65. if(res.code==200){
  66. if(res.data){
  67. this.tabval=res.data[0].dictValue;
  68. this.wzlxList = res.data.map(v => {
  69. return {
  70. dictLabel: v.dictLabel,
  71. dictValue: v.dictValue
  72. }
  73. })
  74. this.getDataFn()
  75. }
  76. }
  77. })
  78. },
  79. getCommentInteractionCount(){
  80. var params={}
  81. getCommentInteractionCount(params).then(res=>{
  82. if(res.code==200){
  83. this.hdcount=res.data
  84. }
  85. })
  86. },
  87. getHdFn(){
  88. this.$tab.navigateTo("/mine/pages/news/index");
  89. this.hdcount=0;
  90. },
  91. getDetail(id){
  92. this.$tab.navigateTo("/news/pages/news/detail?id="+id)
  93. },
  94. getrefreshData(){
  95. this.pageNum=1;
  96. this.list=[];
  97. this.reachflag=true;
  98. this.getDataFn()
  99. },
  100. getTabFn(val){
  101. this.tabval=val;
  102. this.getrefreshData()
  103. },
  104. bindDateChangea(e){
  105. var val=e.detail.value;
  106. this.cxrq=val;
  107. },
  108. formatRichText(html) {
  109. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  110. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  111. // match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  112. // match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  113. return match;
  114. });
  115. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  116. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  117. return match;
  118. });
  119. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  120. newContent = newContent.replace(/\<img src="/gi,
  121. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +this.baseUrl);
  122. return newContent;
  123. },
  124. getDataFn(){
  125. var params={
  126. pageSize:this.pageSize,
  127. pageNum: this.pageNum,
  128. status:'0',
  129. communityType:this.tabval
  130. }
  131. newsList(params).then(res=>{
  132. if(res.code==200){
  133. if (res.rows.length < this.pageSize) {
  134. this.reachflag = false
  135. this.wtdt = '到底了~';
  136. } else {
  137. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  138. if (num < res.total) {
  139. this.reachflag = true
  140. this.wtdt = ''
  141. } else {
  142. this.reachflag = false
  143. this.wtdt = '到底了~';
  144. }
  145. }
  146. var newArr=JSON.parse(JSON.stringify(res.rows))
  147. if(newArr&&newArr.length){
  148. newArr.forEach(ite=>{
  149. if(ite.communityContent){
  150. ite.communityContent=this.formatRichText(ite.communityContent)
  151. }
  152. ite.right=0;
  153. })
  154. }
  155. if (this.pageNum == 1) {
  156. this.list = newArr;
  157. } else {
  158. this.list = this.list.concat(newArr)
  159. }
  160. }else{
  161. this.$toast(res.msg)
  162. }
  163. })
  164. },
  165. }
  166. }
  167. </script>
  168. <style>
  169. page{background: #F3F3F0;}
  170. </style>
  171. <style lang="scss" scoped>
  172. .car{padding: 148rpx 0 10rpx;}
  173. .cartop{position: fixed;left: 0;right: 0;top: 0;background-color: #ffffff;z-index: 2;
  174. .tabtop{padding:28rpx 200rpx 40rpx 0;position: relative;overflow: auto;
  175. .tabt{font-weight: 500;font-size: 32rpx;color: #666666;position: relative;line-height: 56rpx;flex: 0 0 auto;text-align: center;margin: 0 10rpx;padding: 0 20rpx;
  176. &.act{font-weight: bold;font-size: 32rpx;color: #272727;
  177. &::after{content: '';width: 40rpx;height: 10rpx;background: #0156FE;border-radius: 6rpx;position: absolute;left: 50%;margin-left: -20rpx;bottom: -10rpx;}
  178. }
  179. }
  180. }
  181. .numbox{width: 188rpx;height: 58rpx;background-color: #E6E6E6;border-radius: 29rpx 0 0 29rpx;font-weight: 500;font-size: 26rpx;color: #0156FE;display: flex;align-items: center;justify-content: center;position: absolute;right: 0;top: 28rpx;
  182. text{height: 20rpx;min-width: 20rpx;padding: 0 8rpx;box-sizing: border-box;line-height: 20rpx;margin-left: 10rpx;font-weight: bold;
  183. font-size:16rpx;
  184. color: #FCF9F1;
  185. background: #D32C26;
  186. border-radius: 5px;}
  187. }
  188. }
  189. .carlists{padding: 0 18rpx;}
  190. </style>