newsInfo.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="main">
  3. <view class="u-margin-bottom-30 u-skeleton">
  4. <view class="titleStyle u-skeleton-rect">
  5. {{news.title}}
  6. </view>
  7. <view class="info_time u-margin-top-20 u-skeleton-rect">
  8. 丹棱检察 {{$u.timeFormat(parseInt(news.created_at), 'yyyy-mm-dd')}}
  9. </view>
  10. </view>
  11. <view class="">
  12. <u-parse :show-with-animation="true" use-cache lazy-load :html="news.content"></u-parse>
  13. </view>
  14. <u-skeleton :loading="loading" :animation="true"></u-skeleton>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. id: null,
  22. callUrl: '',
  23. news: {},
  24. loading: true
  25. }
  26. },
  27. onLoad(op) {
  28. this.id = op.id
  29. console.log(this.id)
  30. if (op.type != 4) {
  31. this.callUrl = '/home/news_detail'
  32. this.getNewsInfo()
  33. } else {
  34. this.callUrl = '/home/notice_detail'
  35. this.getNewsInfo()
  36. }
  37. if (op.title != undefined) {
  38. uni.setNavigationBarTitle({
  39. title: op.title
  40. })
  41. }
  42. },
  43. methods: {
  44. async getNewsInfo() {
  45. let res = await this.$u.get(this.callUrl, {
  46. id: this.id
  47. })
  48. this.news = res
  49. this.news.content = this.formatRichText(this.news.content)
  50. this.loading = false
  51. },
  52. formatRichText(html) { //控制小程序中图片大小
  53. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  54. if (match.search(/style=/gi) == -1) {
  55. match = match.replace(/\<img/gi, '<img style=""');
  56. }
  57. return match;
  58. });
  59. newContent = newContent.replace(/style="/gi, '$& max-width:100% !important; ');
  60. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  61. return newContent;
  62. }
  63. }
  64. }
  65. </script>
  66. <style>
  67. .main {
  68. min-height: 100vh;
  69. padding: 40rpx 28rpx;
  70. background: #fff;
  71. }
  72. .titleStyle {
  73. font-size: 30rpx;
  74. font-family: PingFang-SC-Bold, PingFang-SC;
  75. font-weight: bold;
  76. color: #333333;
  77. width: 100%;
  78. display: -webkit-box;
  79. -webkit-box-orient: vertical;
  80. -webkit-line-clamp: 2;
  81. overflow: hidden;
  82. }
  83. .info_time {
  84. font-size: 22rpx;
  85. font-family: PingFang-SC-Bold, PingFang-SC;
  86. font-weight: 500;
  87. color: #999;
  88. width: 400rpx;
  89. }
  90. </style>