newssq.vue 5.8 KB

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