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

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