newssq.vue 5.6 KB

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