course_intr.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="page_body">
  3. <view class="banner_container"><image :src="banner" mode="scaleToFill" class="banner_img" /></view>
  4. <view class="richText ql-snow ql-editor" v-if="userInfo.course"><rich-text :nodes="userInfo.course | formatRichText" ></rich-text></view>
  5. <view class="submit_container"><view class="sign_up flexC" @click.stop="backIndex">返回首页</view></view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. userInfo: {}, //用户信息
  13. banner: '' //banner图
  14. };
  15. },
  16. onLoad(options) {
  17. this.banner = options.banner;
  18. },
  19. onShow() {
  20. if (uni.getStorageSync('userInfo')) {
  21. this.userInfo = uni.getStorageSync('userInfo');
  22. }
  23. },
  24. methods: {
  25. backIndex() {
  26. uni.reLaunch({
  27. url: '../index/index'
  28. });
  29. }
  30. },
  31. filters: {
  32. /**
  33. * 处理富文本里的图片宽度自适应
  34. * 1.去掉img标签里的style、width、height属性
  35. * 2.img标签添加style属性:max-width:100%;height:auto
  36. * 3.修改所有style里的width属性为max-width:100%
  37. * 4.去掉<br/>标签
  38. * @param html
  39. * @returns {void|string|*}
  40. */
  41. formatRichText(html) {
  42. //控制小程序中图片大小
  43. if (html) {
  44. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  45. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  46. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  47. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  48. return match;
  49. });
  50. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  51. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  52. return match;
  53. });
  54. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  55. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
  56. return newContent;
  57. }
  58. }
  59. }
  60. };
  61. </script>
  62. <style>
  63. page {
  64. height: 100%;
  65. min-height: 100%;
  66. background-color: #fff;
  67. }
  68. </style>
  69. <style lang="scss" scoped>
  70. .banner_container {
  71. width: 730rpx;
  72. height:369rpx;
  73. margin: 0 auto;
  74. .banner_img {
  75. width: 100%;
  76. height: 100%;
  77. border-radius: 15rpx;
  78. }
  79. }
  80. .richText {
  81. width: 632rpx;
  82. margin: 28rpx auto 0;
  83. z-index: 99;
  84. min-height: 500rpx;
  85. padding-bottom: 110rpx;
  86. }
  87. uni-rich-text img {
  88. max-width: 100% !important;
  89. }
  90. .submit_container {
  91. position: fixed;
  92. left: 0;
  93. right: 0;
  94. bottom: 0;
  95. width: 100%;
  96. font-size: 36rpx;
  97. z-index: 9999;
  98. height: 118rpx;
  99. display: flex;
  100. justify-content: space-between;
  101. align-items: center;
  102. padding: 0 30rpx;
  103. box-sizing: border-box;
  104. .share {
  105. image {
  106. height: 46rpx;
  107. width: 46rpx;
  108. }
  109. view {
  110. font-size: 28rpx;
  111. color: #333333;
  112. margin-top: 5rpx;
  113. }
  114. }
  115. .sign_up {
  116. width: 690rpx;
  117. height: 90rpx;
  118. background-color: #ea4a41;
  119. border-radius: 45rpx;
  120. color: #ffffff;
  121. }
  122. }
  123. </style>