richText.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <!-- 富文本 -->
  3. <view v-show="!isSortType">
  4. <view class='richText' :style="'background-color:'+bgColor+';margin:'+ udConfig +'rpx '+ lrConfig +'rpx;'" v-if="description">
  5. <!-- #ifndef APP-PLUS -->
  6. <jyf-parser :html="description" ref="article" :tag-style="tagStyle"></jyf-parser>
  7. <!-- #endif -->
  8. <!-- #ifdef APP-PLUS -->
  9. <view v-html="description"></view>
  10. <!-- #endif -->
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import parser from "@/components/jyf-parser/jyf-parser";
  16. export default {
  17. name: 'richText',
  18. props: {
  19. dataConfig: {
  20. type: Object,
  21. default: () => {}
  22. },
  23. isSortType:{
  24. type: String | Number,
  25. default:0
  26. }
  27. },
  28. components: {
  29. "jyf-parser": parser
  30. },
  31. data() {
  32. return {
  33. tagStyle: {
  34. img: 'width:100%;display:block;',
  35. table: 'width:100%',
  36. video: 'width:100%'
  37. },
  38. bgColor:this.dataConfig.bgColor.color[0].item,
  39. lrConfig:this.dataConfig.lrConfig.val,
  40. description:this.dataConfig.richText.val,
  41. udConfig:this.dataConfig.udConfig.val
  42. };
  43. },
  44. created() {
  45. if(this.description){
  46. this.description = this.description.replace(
  47. /<img/gi,
  48. '<img style="max-width:100%;height:auto;float:left;display:block" '
  49. );
  50. this.description = this.description.replace(
  51. /<video/gi,
  52. '<video style="width:100%;height:auto;display:block" '
  53. );
  54. }
  55. },
  56. methods: {
  57. }
  58. }
  59. </script>
  60. <style lang="scss">
  61. .richText{
  62. padding: 20rpx;
  63. background-color: #fff;
  64. margin: 0 20rpx;
  65. border-radius: 24rpx;
  66. }
  67. /deep/uni-video{
  68. width: 100%!important;
  69. }
  70. /deep/video{
  71. width: 100%!important;
  72. }
  73. </style>