四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.4 KiB

  1. <template>
  2. <view class="yingbing-computed" :style="[computedStyle]">
  3. <reader-header :text="chapter.title || ''" v-if="headerShowSync"></reader-header>
  4. <web-view ref="webview" style="flex:1" src="/uni_modules/yingbing-ReadPage/hybrid/html/computed.html" @onPostMessage="onPostMessage"></web-view>
  5. <reader-footer v-if="footerShowSync"></reader-footer>
  6. </view>
  7. </template>
  8. <script>
  9. import ReaderHeader from '../../header/header.vue'
  10. import ReaderFooter from '../../footer/footer.vue'
  11. export default {
  12. inject: ['fontSize', 'fontFamily', 'lineHeight', 'topGap', 'bottomGap', 'slide', 'headerShow', 'footerShow', 'totalChapter'],
  13. components: {
  14. ReaderHeader,
  15. ReaderFooter
  16. },
  17. computed: {
  18. computedStyle () {
  19. return {
  20. 'padding-top': this.topGap + 'px',
  21. 'padding-bottom': this.bottomGap + 'px',
  22. 'padding-left': this.slide + 'px',
  23. 'padding-right': this.slide + 'px'
  24. }
  25. }
  26. },
  27. data () {
  28. return {
  29. chapter: {},//章节内容临时存储
  30. success: null,//成功回调
  31. fail: null,//失败回调,
  32. headerShowSync: false,//展示头部
  33. footerShowSync: false//展示底部
  34. }
  35. },
  36. beforeDestroy() {
  37. this.$refs.webview && this.$refs.webview.evalJS("destroyHandleTimer()")
  38. },
  39. methods: {
  40. start ({chapter, success, fail}) {
  41. this.chapter = chapter
  42. this.success = success
  43. this.fail = fail
  44. this.headerShowSync = typeof chapter.headerShow == 'boolean' ? chapter.headerShow : this.headerShow//判断是否显示头部
  45. this.footerShowSync = typeof chapter.footerShow == 'boolean' ? chapter.footerShow : this.footerShow//判断是否显示底部
  46. const style = {fontSize: this.fontSize, fontFamily: this.fontFamily, lineHeight: this.lineHeight, totalChapter: this.totalChapter}
  47. this.$nextTick(function () {
  48. setTimeout(() => {
  49. this.$refs.webview && this.$refs.webview.evalJS("start(" + encodeURIComponent(JSON.stringify(chapter)) + ', ' + encodeURIComponent(JSON.stringify(style)) + ")")
  50. }, 100)
  51. })
  52. },
  53. onPostMessage (e) {
  54. e.detail.data.forEach(item => {
  55. if ( item.handleSuccess ) {
  56. this.success && this.success(item.handleSuccess)
  57. this.success = null
  58. this.fail = null
  59. this.chapter = {}
  60. }
  61. })
  62. }
  63. }
  64. }
  65. </script>
  66. <style scoped>
  67. .yingbing-computed {
  68. position: absolute;
  69. top: 0;
  70. left: 0;
  71. right: 0;
  72. bottom: 0;
  73. transform: translateX(-1000px);
  74. }
  75. </style>