viewerDemo.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="demo-page">
  3. <view class="header">
  4. <text class="title">富文本预览组件演示</text>
  5. </view>
  6. <view class="viewer-container">
  7. <rich-media-viewer
  8. :content="demoContent"
  9. :startScroll="250"
  10. :threshold="450"
  11. />
  12. </view>
  13. <view class="action-buttons">
  14. <button class="demo-btn" @click="clearContent">清空内容</button>
  15. <button class="demo-btn primary" @click="loadSampleData">加载示例数据</button>
  16. <button class="demo-btn secondary" @click="openPreviewPage">新页面预览</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import RichMediaViewer from '../../components/RichMediaViewer/index.vue';
  22. export default {
  23. name: 'RichMediaViewerDemo',
  24. components: {
  25. RichMediaViewer
  26. },
  27. data() {
  28. return {
  29. demoContent: []
  30. };
  31. },
  32. methods: {
  33. clearContent() {
  34. this.demoContent = [];
  35. },
  36. loadSampleData() {
  37. this.demoContent = [
  38. {
  39. type: 1,
  40. content: 'https://commimg.pddpic.com/monica/2025-07-23/950edee8-e9f6-4ed9-9a20-70751dd43654.jpeg.suffix.jpeg'
  41. },
  42. {
  43. type: 3,
  44. content: '这是一个高级的富文本预览组件演示。它支持大图、小图网格和文本的完美展示,同时提供了优雅的图片预览功能。'
  45. },
  46. {
  47. type: 2,
  48. content: [
  49. 'https://commimg.pddpic.com/monica/2025-07-23/d85bf082-abda-4725-b5f5-93c9800647d8.jpeg.suffix.jpeg',
  50. 'https://commimg.pddpic.com/monica/2025-07-23/950edee8-e9f6-4ed9-9a20-70751dd43654.jpeg.suffix.jpeg',
  51. 'https://commimg.pddpic.com/monica/2025-07-23/c3b8894a-52ee-4962-b879-5a311e761375.jpeg.suffix.jpeg',
  52. 'https://commimg.pddpic.com/monica/2025-07-23/0beeb89e-7e0a-4755-9ed3-6b5d139023ab.jpeg.suffix.jpeg',
  53. 'https://commimg.pddpic.com/monica/2025-07-23/4d299be0-5782-4b3f-84a7-cdd49da703f2.jpeg.suffix.jpeg',
  54. 'https://commimg.pddpic.com/monica/2025-07-23/d85bf082-abda-4725-b5f5-93c9800647d8.jpeg.suffix.jpeg'
  55. ]
  56. },
  57. {
  58. type: 3,
  59. content:
  60. '小图支持点击放大预览,可以左右滑动查看多张图片。预览界面提供了优雅的交互体验和清晰的图片展示效果。\n文本内容支持换行显示,保持良好的阅读体验。'
  61. },
  62. {
  63. type: 1,
  64. content: 'https://commimg.pddpic.com/monica/2025-07-23/c3b8894a-52ee-4962-b879-5a311e761375.jpeg.suffix.jpeg'
  65. }
  66. ];
  67. },
  68. openPreviewPage() {
  69. if (this.demoContent.length === 0) {
  70. uni.showToast({
  71. title: '请先加载示例数据',
  72. icon: 'none'
  73. });
  74. return;
  75. }
  76. // 准备预览数据
  77. const previewData = {
  78. title: '预览组件演示',
  79. content: this.demoContent
  80. };
  81. // 通过全局数据传递
  82. const app = getApp();
  83. app.globalData = app.globalData || {};
  84. app.globalData.previewData = previewData;
  85. // 跳转到预览页面
  86. uni.navigateTo({
  87. url: './preview'
  88. });
  89. }
  90. }
  91. };
  92. </script>
  93. <style lang="scss" scoped>
  94. .demo-page {
  95. min-height: 100vh;
  96. padding: 8rpx;
  97. background-color: #f5f5f5;
  98. }
  99. .header {
  100. text-align: center;
  101. margin-bottom: 30rpx;
  102. .title {
  103. font-size: 36rpx;
  104. font-weight: bold;
  105. color: #333;
  106. }
  107. }
  108. .viewer-container {
  109. margin-bottom: 30rpx;
  110. border-radius: 12rpx;
  111. overflow: hidden;
  112. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.1);
  113. }
  114. .action-buttons {
  115. display: flex;
  116. gap: 20rpx;
  117. margin-top: 30rpx;
  118. .demo-btn {
  119. flex: 1;
  120. height: 80rpx;
  121. border-radius: 10rpx;
  122. font-size: 28rpx;
  123. background-color: #fff;
  124. border: 2rpx solid #e5e5e5;
  125. &.primary {
  126. background-color: #007aff;
  127. color: white;
  128. border-color: #007aff;
  129. }
  130. &.secondary {
  131. background-color: #34c759;
  132. color: white;
  133. border-color: #34c759;
  134. }
  135. }
  136. }
  137. </style>