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

155 lines
3.9 KiB

  1. <template>
  2. <view class="content">
  3. <!-- 小程序环境使用web-view加载StPageFlip -->
  4. <web-view
  5. :src="webviewUrl"
  6. @message="handleMessage"
  7. class="webview-container"
  8. ></web-view>
  9. <!-- 控制按钮
  10. <view class="controls">
  11. <button @click="prevPage" :disabled="currentPage <= 0" class="control-btn">上一页</button>
  12. <text class="page-info">{{ currentPage + 1 }} / {{ totalPages }}</text>
  13. <button @click="nextPage" :disabled="currentPage >= totalPages - 1" class="control-btn">下一页</button>
  14. </view> -->
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. // 当前页码
  22. currentPage: 0,
  23. // 总页数
  24. totalPages: 6,
  25. // webview URL - 需要部署到服务器或使用本地路径
  26. webviewUrl: 'https://hfllll.github.io/My/', // 请替换为实际的服务器地址
  27. // 本地测试可以使用: '/static/stpageflip.html'
  28. };
  29. },
  30. methods: {
  31. // 处理来自webview的消息
  32. handleMessage(e) {
  33. console.log('收到webview消息:', e.detail.data);
  34. const data = e.detail.data[0]; // 小程序webview消息格式
  35. if (data.type === 'pageFlip') {
  36. this.currentPage = data.currentPage;
  37. this.totalPages = data.totalPages;
  38. } else if (data.type === 'stateChange') {
  39. console.log('翻页状态变化:', data.state);
  40. if (data.state === 'flipping') {
  41. uni.showToast({
  42. title: '翻页中',
  43. duration: 500,
  44. icon: 'none'
  45. });
  46. }
  47. }
  48. },
  49. // 上一页
  50. prevPage() {
  51. this.sendMessageToWebview({
  52. type: 'prevPage'
  53. });
  54. },
  55. // 下一页
  56. nextPage() {
  57. this.sendMessageToWebview({
  58. type: 'nextPage'
  59. });
  60. },
  61. // 跳转到指定页面
  62. turnToPage(pageNumber) {
  63. this.sendMessageToWebview({
  64. type: 'turnToPage',
  65. pageNumber: pageNumber
  66. });
  67. },
  68. // 向webview发送消息
  69. sendMessageToWebview(data) {
  70. // 注意:小程序向webview发送消息需要特殊处理
  71. // 这里只是示例,实际可能需要其他方式
  72. console.log('向webview发送消息:', data);
  73. }
  74. },
  75. onLoad() {
  76. console.log('StPageFlip翻页组件加载完成');
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. page {
  82. width: 100%;
  83. height: 100%;
  84. }
  85. .content {
  86. width: 100%;
  87. height: 100vh;
  88. position: relative;
  89. background: #f5f5f5;
  90. }
  91. .webview-container {
  92. width: 100%;
  93. height: calc(100vh - 80px);
  94. }
  95. .controls {
  96. position: fixed;
  97. bottom: 0;
  98. left: 0;
  99. right: 0;
  100. height: 80px;
  101. background: rgba(255, 255, 255, 0.95);
  102. backdrop-filter: blur(10px);
  103. display: flex;
  104. align-items: center;
  105. justify-content: space-between;
  106. padding: 0 30px;
  107. box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  108. z-index: 1000;
  109. }
  110. .control-btn {
  111. padding: 12px 24px;
  112. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  113. color: white;
  114. border: none;
  115. border-radius: 25px;
  116. font-size: 16px;
  117. font-weight: 500;
  118. box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  119. transition: all 0.3s ease;
  120. }
  121. .control-btn:active {
  122. transform: translateY(2px);
  123. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  124. }
  125. .control-btn:disabled {
  126. background: #bdc3c7;
  127. color: #7f8c8d;
  128. box-shadow: none;
  129. transform: none;
  130. }
  131. .page-info {
  132. font-size: 16px;
  133. font-weight: 500;
  134. color: #2c3e50;
  135. background: rgba(255, 255, 255, 0.8);
  136. padding: 8px 16px;
  137. border-radius: 20px;
  138. border: 1px solid #e0e0e0;
  139. }
  140. </style>