TinyModule.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-prev-Tiny Big-Book-prev-Tiny-phone" v-if="curQue">
  4. <div
  5. v-html="curQue.con_new"
  6. class="tiny-box"
  7. @click="showImg($event)"
  8. :style="{ fontSize: baseSizePhone + 2 + 'px' }"
  9. ></div>
  10. <el-dialog
  11. title=""
  12. :visible.sync="dialogImg"
  13. width="100%"
  14. :show-close="false"
  15. >
  16. <img :src="dialogueImgSrc" width="100%" />
  17. </el-dialog>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. components: {},
  23. props: ["curQue", "baseSizePhone"],
  24. data() {
  25. return {
  26. dialogImg: false,
  27. dialogueImgSrc: ""
  28. };
  29. },
  30. computed: {},
  31. watch: {},
  32. //方法集合
  33. methods: {
  34. showImg(e) {
  35. if (e.target.tagName === "IMG") {
  36. this.dialogueImgSrc = e.target.src;
  37. this.dialogImg = true;
  38. }
  39. }
  40. },
  41. //生命周期 - 创建完成(可以访问当前this实例)
  42. created() {
  43. let imgArr = this.curQue.con.split("<img");
  44. let con_new = "";
  45. if (imgArr.length > 1) {
  46. con_new += imgArr[0];
  47. for (let i = 1; i < imgArr.length; i++) {
  48. let widthStr = imgArr[i].substring(imgArr[i].indexOf('width="') + 7);
  49. widthStr = widthStr.substring(0, widthStr.indexOf('"'));
  50. if (widthStr < 780) {
  51. let heightStr = imgArr[i].substring(
  52. imgArr[i].indexOf('height="') + 8
  53. );
  54. heightStr = heightStr.substring(0, heightStr.indexOf('"'));
  55. heightStr = 'height="' + heightStr + '"';
  56. imgArr[i].replace(heightStr, 'height="auto"');
  57. imgArr[i] =
  58. imgArr[i].substring(0, imgArr[i].indexOf('width="') + 7) +
  59. "70%" +
  60. imgArr[i].substring(
  61. imgArr[i].indexOf('width="') + 7 + widthStr.length,
  62. imgArr[i].indexOf(heightStr)
  63. ) +
  64. 'height="auto"' +
  65. imgArr[i].substring(
  66. imgArr[i].indexOf(heightStr) + heightStr.length
  67. );
  68. }
  69. con_new += "<img " + imgArr[i];
  70. }
  71. } else {
  72. con_new = this.curQue.con;
  73. }
  74. this.curQue.con_new = con_new;
  75. },
  76. //生命周期 - 挂载完成(可以访问DOM元素)
  77. mounted() {},
  78. beforeCreate() {}, //生命周期 - 创建之前
  79. beforeMount() {}, //生命周期 - 挂载之前
  80. beforeUpdate() {}, //生命周期 - 更新之前
  81. updated() {}, //生命周期 - 更新之后
  82. beforeDestroy() {}, //生命周期 - 销毁之前
  83. destroyed() {}, //生命周期 - 销毁完成
  84. activated() {} //如果页面有keep-alive缓存功能,这个函数会触发
  85. };
  86. </script>
  87. <style lang="scss" scoped>
  88. //@import url(); 引入公共css类
  89. .Big-Book-prev-Tiny {
  90. width: 100%;
  91. // margin-bottom: 24px;
  92. h2 {
  93. margin: 16px 0 0;
  94. font-weight: 500;
  95. font-size: 16px;
  96. line-height: 24px;
  97. color: #000000;
  98. }
  99. .tiny-box {
  100. word-break: break-word;
  101. overflow: hidden;
  102. }
  103. }
  104. </style>
  105. <style lang="scss">
  106. .Big-Book-prev-Tiny {
  107. p {
  108. margin: 0;
  109. }
  110. }
  111. .Big-Book-prev-Tiny-phone {
  112. img {
  113. max-width: 100%;
  114. height: auto;
  115. }
  116. .el-dialog__header,
  117. .el-dialog__body {
  118. padding: 0;
  119. background: none;
  120. }
  121. }
  122. </style>