四零语境前端代码仓库
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.

143 lines
4.8 KiB

  1. <template>
  2. <view class="content">
  3. <nx-turn
  4. :initPage="page"
  5. :pageCount="pageContent.length"
  6. custom-class="theme-blue"
  7. @init-completed="initCompleted"
  8. @turning="handleTurning"
  9. @turned="handleTurned"
  10. @click-center="handleClickCenter"
  11. >
  12. <template v-slot:page-content="{ page }">
  13. <view class="page-content">
  14. <!-- 对于非富文本页直接显示文本对于富文本页使用 rich-text -->
  15. <uv-parse :content="formatContent(pageContent[page])" />
  16. </view>
  17. </template>
  18. <template v-slot:next-page-content="{ page }">
  19. <view class="page-content">
  20. <uv-parse :content="formatContent(pageContent[page])" />
  21. </view>
  22. </template>
  23. </nx-turn>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. page: 0,
  31. pageContent: [
  32. "使用须知\n1. 这是一个翻页组件,适用于小说翻页功能\n2. 这个插件支持APP-VUE、H5、微信小程序",
  33. "我是第二页我是第二页我是第二页我是第二页我是第二页我是第二页",
  34. "大家好我是第三页大家好我是第三页大家好我是第三页大家好我是第三页",
  35. [
  36. {
  37. name: 'h3',
  38. attrs: { class: 'rich-title' },
  39. children: [{ type: 'text', text: '第四章:星夜下的秘密' }]
  40. },
  41. {
  42. name: 'p',
  43. attrs: { class: 'rich-paragraph' },
  44. children: [{ type: 'text', text: '夜幕低垂,星光如织,月光洒在林间小路上,映照出一片朦胧的光影。林若曦站在古树下,手中紧握着一封泛黄的信笺。' }]
  45. },
  46. {
  47. name: 'p',
  48. attrs: { class: 'rich-paragraph' },
  49. children: [
  50. {
  51. name: 'strong',
  52. children: [{ type: 'text', text: '“你相信命运吗?”' }]
  53. },
  54. { type: 'text', text: ' 她低声呢喃,目光投向远方的星空。信中所述的秘密让她心跳加速,却又充满了未知的恐惧。' }
  55. ]
  56. },
  57. {
  58. name: 'p',
  59. attrs: { class: 'rich-paragraph rich-indent' },
  60. children: [{ type: 'text', text: '风轻轻吹过,树叶沙沙作响,仿佛在诉说一个古老的传说。她深吸一口气,决定踏上这条无人知晓的旅程……' }]
  61. },
  62. {
  63. name: 'img',
  64. attrs: { src: '/static/default-image.png' }
  65. }
  66. ],
  67. ],
  68. };
  69. },
  70. methods: {
  71. // 格式化内容,确保普通文本和富文本都能正确显示
  72. formatContent(content) {
  73. if (typeof content === 'string') {
  74. return [{ type: 'text', text: content }];
  75. }
  76. return content; // 已经是节点数组,直接返回
  77. },
  78. initCompleted(pageWrapperInfo) {
  79. console.log('页面节点信息:', pageWrapperInfo);
  80. },
  81. handleTurning() {
  82. uni.showToast({
  83. title: '翻页中',
  84. duration: 100,
  85. icon: 'none'
  86. });
  87. },
  88. handleTurned(info) {
  89. console.log('当前页面信息:', info);
  90. if (info.isFirst) {
  91. uni.showToast({
  92. title: '已经是第一页了',
  93. icon: 'none'
  94. });
  95. }
  96. if (info.isLast) {
  97. uni.showToast({
  98. title: '已经是最后一页了',
  99. icon: 'none'
  100. });
  101. }
  102. },
  103. handleClickCenter() {
  104. uni.showModal({
  105. title: '提示',
  106. content: '点击中部',
  107. });
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. page {
  114. width: 100%;
  115. height: 100%;
  116. }
  117. .content {
  118. width: 100%;
  119. height: 100%;
  120. }
  121. ::v-deep .theme-blue {
  122. background-color: #DCE2F1;
  123. color: mix(#000000, #DCE2F1, 50%);
  124. border-color: mix(#FFFFFF, #DCE2F1, 70%);
  125. }
  126. .page-content {
  127. padding: 15px;
  128. font-size: 16px;
  129. line-height: 1.5;
  130. }
  131. ::v-deep .rich-title {
  132. font-size: 20px;
  133. font-weight: bold;
  134. margin-bottom: 10px;
  135. }
  136. ::v-deep .rich-paragraph {
  137. margin-bottom: 10px;
  138. }
  139. ::v-deep .rich-indent {
  140. text-indent: 2em;
  141. }
  142. </style>