newsdj.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view class="car">
  3. <view class="cartop">
  4. <view class="toptit">
  5. <image :src="djtop"></image>本社区党员共<text>367</text>人
  6. </view>
  7. <view class="tabtop flexc">
  8. <view class="tabt" :class="tabval==ite.dictValue?'act':''" v-for="(ite,idx) in wzlxList" :key="idx" @click="getTabFn(ite.dictValue)">{{ite.dictLabel}}</view>
  9. </view>
  10. </view>
  11. <!-- 列表 -->
  12. <view class="carlists">
  13. <car-list :datainfo="list" :wzlxList="wzlxList" :wtdt="wtdt" type='newsdj' @getDetail="getDetail" @getDelFn="getDelFn"></car-list>
  14. </view>
  15. <block v-if="checkPermi(['wuYe:partyNews:add'])">
  16. <view style="height: 100rpx;"></view>
  17. <view class="rfbtn" @click="getAddFn" >发布</view>
  18. </block>
  19. <loading></loading>
  20. </view>
  21. </template>
  22. <script>
  23. import config from '@/config'
  24. // const baseUrl = config.baseUrl,
  25. import carList from "@/manage/components/car/list.vue"
  26. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  27. import {getDictionaryFn} from "@/api/system/user.js"
  28. import {partyNewsList,partyNewsDel} from "@/api/work/manage.js"
  29. export default{
  30. components:{carList},
  31. data(){
  32. return{
  33. djtop:require('@/manage/static/community/djtop.png'),
  34. cxrq:"",
  35. text:'',
  36. list:[],
  37. pageSize: 10,
  38. pageNum: 1,
  39. reachflag: true,
  40. wtdt:'',
  41. tabval:'',
  42. wzlxList:[],
  43. baseUrl:config.baseUrl,
  44. }
  45. },
  46. onUnload() {
  47. uni.$off('partyNewsList')
  48. },
  49. onLoad: function() {
  50. uni.$on('partyNewsList',(res)=>{
  51. this.getrefreshData()
  52. })
  53. this.init()
  54. },
  55. // 上拉触底加载更多触发事件
  56. onReachBottom() {
  57. if (this.reachflag) {
  58. this.pageNum++
  59. this.getDataFn()
  60. }
  61. },
  62. methods:{
  63. checkPermi, checkRole,
  64. init(){
  65. // 文章类型
  66. getDictionaryFn('article_type').then(res=>{
  67. if(res.code==200){
  68. if(res.data){
  69. this.tabval=res.data[0].dictValue;
  70. this.wzlxList = res.data.map(v => {
  71. return {
  72. dictLabel: v.dictLabel,
  73. dictValue: v.dictValue
  74. }
  75. })
  76. this.getDataFn()
  77. }
  78. }
  79. })
  80. },
  81. getAddFn(){
  82. this.$tab.navigateTo("/manage/pages/community/newsadddj")
  83. },
  84. getDetail(id){
  85. this.$tab.navigateTo("/manage/pages/community/newsadddj?id="+id)
  86. },
  87. getrefreshData(){
  88. this.pageNum=1;
  89. this.list=[];
  90. this.reachflag=true;
  91. this.getDataFn()
  92. },
  93. getTabFn(val){
  94. this.tabval=val;
  95. this.getrefreshData()
  96. },
  97. getDelFn(data){
  98. var that=this;
  99. partyNewsDel(data).then(res=>{
  100. if(res.code==200){
  101. this.$toast("删除成功");
  102. setTimeout(function(){
  103. that.getrefreshData()
  104. },1500)
  105. }
  106. })
  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. partyType:this.tabval
  129. }
  130. partyNewsList(params).then(res=>{
  131. if(res.code==200){
  132. if (res.rows.length < this.pageSize) {
  133. this.reachflag = false
  134. this.wtdt = '到底了~';
  135. } else {
  136. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  137. if (num < res.total) {
  138. this.reachflag = true
  139. this.wtdt = ''
  140. } else {
  141. this.reachflag = false
  142. this.wtdt = '到底了~';
  143. }
  144. }
  145. var newArr=JSON.parse(JSON.stringify(res.rows))
  146. newArr.forEach(ite=>{
  147. if(ite.partyContent){
  148. ite.partyContent=this.formatRichText(ite.partyContent)
  149. }
  150. ite.right=0;
  151. })
  152. if (this.pageNum == 1) {
  153. this.list = newArr;
  154. } else {
  155. this.list = this.list.concat(newArr)
  156. }
  157. }else{
  158. this.$toast(res.msg)
  159. }
  160. })
  161. },
  162. }
  163. }
  164. </script>
  165. <style>
  166. page{background: #F3F3F0;}
  167. </style>
  168. <style lang="scss" scoped>
  169. .car{padding: 200rpx 0 10rpx;}
  170. .cartop{position: fixed;left: 0;right: 0;top: 0;background-color: #ffffff;z-index: 2;
  171. .toptit{display: flex;justify-content: center;font-weight: 500;font-size: 26rpx;color: #8592AA;height: 70rpx;align-items: center;
  172. background: #E4EDFF;
  173. text{font-size: 32rpx;color: #0156FE;padding: 0 10rpx;}
  174. image{width: 28rpx;height: 26rpx;flex: 0 0 auto;margin-right: 12rpx;}
  175. }
  176. .tabtop{padding-bottom: 40rpx;padding-top: 14rpx;
  177. .tabt{font-weight: 500;font-size: 32rpx;color: #666666;position: relative;line-height: 56rpx;padding: 0 40rpx;
  178. &.act{font-weight: bold;font-size: 32rpx;color: #272727;
  179. &::after{content: '';width: 40rpx;height: 10rpx;background: #0156FE;border-radius: 6rpx;position: absolute;left: 50%;margin-left: -20rpx;bottom: -10rpx;}
  180. }
  181. }
  182. }
  183. }
  184. .carlists{padding: 0 18rpx;}
  185. </style>