richText.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <!-- 富文本 -->
  3. <view v-show="!isSortType" :style="[richTextWrapStyle]">
  4. <view class="richText" v-if="description" :style="[richTextStyle]">
  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: '',
  39. lrConfig: 0,
  40. udConfig: 0
  41. };
  42. },
  43. computed: {
  44. description() {
  45. let description = this.dataConfig.richText.val;
  46. if (description) {
  47. description = description.replace(
  48. /<img/gi,
  49. '<img style="max-width:100%;height:auto;float:left;display:block" '
  50. );
  51. description = description.replace(
  52. /<video/gi,
  53. '<video style="width:100%;height:auto;display:block" '
  54. );
  55. }
  56. return description;
  57. },
  58. richTextStyle() {
  59. let borderRadius = `${this.dataConfig.fillet.val * 2}rpx`;
  60. if (this.dataConfig.fillet.type) {
  61. borderRadius =
  62. `${this.dataConfig.fillet.valList[0].val * 2}rpx ${this.dataConfig.fillet.valList[1].val * 2}rpx ${this.dataConfig.fillet.valList[2].val * 2}rpx ${this.dataConfig.fillet.valList[3].val * 2}rpx`;
  63. }
  64. return {
  65. 'border-radius': borderRadius,
  66. 'background': this.dataConfig.bgColor.color[0].item,
  67. };
  68. },
  69. richTextWrapStyle() {
  70. return {
  71. 'padding': `${this.dataConfig.topConfig.val}rpx ${this.dataConfig.lrConfig.val}rpx ${this.dataConfig.bottomConfig.val}rpx`,
  72. 'margin-top': `${this.dataConfig.udConfig.val}rpx`,
  73. 'background': this.dataConfig.bottomBgColor.color[0].item,
  74. };
  75. },
  76. },
  77. }
  78. </script>
  79. <style lang="scss">
  80. .richText {
  81. padding: 30rpx;
  82. background-color: #fff;
  83. // margin: 0 20rpx;
  84. // border-radius: 24rpx;
  85. &::after {
  86. content: "";
  87. display: table;
  88. clear: both;
  89. }
  90. }
  91. /deep/uni-video {
  92. width: 100% !important;
  93. }
  94. /deep/video {
  95. width: 100% !important;
  96. }
  97. </style>