richTextEditor.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <!-- 富文本 -->
  3. <view v-if="description" :style="[boxStyle]">
  4. <view class="rich_text">
  5. <!-- #ifdef MP || APP-PLUS -->
  6. <mp-html :content="description" :tag-style="tagStyle" selectable="true" show-img-menu="true"/>
  7. <!-- #endif -->
  8. <!-- #ifdef H5 -->
  9. <view v-html="description"></view>
  10. <!-- #endif -->
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. // +----------------------------------------------------------------------
  16. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  17. // +----------------------------------------------------------------------
  18. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  19. // +----------------------------------------------------------------------
  20. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  21. // +----------------------------------------------------------------------
  22. // | Author: CRMEB Team <admin@crmeb.com>
  23. // +----------------------------------------------------------------------
  24. import mpHtml from "@/uni_modules/mp-html/components/mp-html/mp-html.vue";
  25. export default {
  26. name: 'richText',
  27. props: {
  28. dataConfig: {
  29. type: Object,
  30. default: () => {}
  31. },
  32. richTextVal: {
  33. type: String,
  34. default: () => ''
  35. }
  36. },
  37. data(){
  38. return{
  39. tagStyle: {
  40. img: 'width:100%;display:block;',
  41. table: 'width:100%',
  42. video: 'width:100%'
  43. },
  44. }
  45. },
  46. components:{
  47. mpHtml
  48. },
  49. computed: {
  50. //最外层盒子的样式
  51. boxStyle() {
  52. if(this.dataConfig){
  53. return {
  54. borderRadius: this.dataConfig.bgStyle.val * 2 + 'rpx',
  55. background: `linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`,
  56. margin: this.dataConfig.mbConfig.val * 2 + 'rpx' + ' ' + this.dataConfig.lrConfig.val * 2 + 'rpx' +
  57. ' ' + 0,
  58. }
  59. }
  60. },
  61. //富文本内容
  62. description() {
  63. return this.richTextVal.replace(/\<img/gi, '<img style="max-width:100%;height:auto" ')
  64. .replace(/style="text-wrap: wrap;"/gi, '')
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .rich_text {
  71. padding: 10px;
  72. width: 100%;
  73. overflow: hidden;
  74. }
  75. </style>