ss-preview.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view class="page">
  3. <!-- 预览图片 -->
  4. <swiper class="swiper" style="width:100%;height:calc(100vh - 44px);margin:0 auto;" v-if="fileType === '1'">
  5. <swiper-item v-for="(item,index) in imageList" :key="'key'+index">
  6. <image :src="item" style="width:100%;height:100%;" mode="aspectFit"></image>
  7. </swiper-item>
  8. </swiper>
  9. <!-- 预览文件 -->
  10. <web-view :webview-styles="webviewStyles" :src="src" v-if="fileType === '2'"></web-view>
  11. <!-- 预览视频 -->
  12. <view class="video-detail-page" v-if="fileType === '3'">
  13. <view class="video-box">
  14. <video :src="fileUrl" controls></video>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'ss-preview',
  22. props: {
  23. fileUrl: {
  24. type: String,
  25. default: ''
  26. },
  27. fileType: {
  28. type: String,
  29. default: '', //1.预览图片,2.预览文件,3.预览视频
  30. },
  31. imageList:{//预览图片,可以预览多张
  32. type: Array,
  33. default:()=>{
  34. return []
  35. }
  36. },
  37. },
  38. data() {
  39. return {
  40. webviewStyles: {
  41. progress: {
  42. color: '#FF3333'
  43. }
  44. },
  45. src: '',
  46. };
  47. },
  48. methods: {
  49. //APP,H5预览文档图片和视频,微信小程序预览图片和视频
  50. previewPdf(value) {
  51. this.src = `/uni_modules/ss-preview/hybrid/html/pdf-reader/index.html?file=${encodeURIComponent(value)}`;
  52. //此处路径为项目根路径,如果是uni-modules处于src下方,则地址应该为下方地址,否则会读取失败
  53. // this.src = `/src/uni_modules/ss-preview/hybrid/html/pdf-reader/index.html?file=${encodeURIComponent(value)}`;
  54. },
  55. },
  56. watch: {
  57. fileType: {
  58. deep: true,
  59. immediate: true,
  60. handler: function(value) {
  61. if(value === '2'){//预览文档
  62. //#ifdef APP-PLUS || H5
  63. this.previewPdf(this.fileUrl)
  64. //#endif
  65. }
  66. }
  67. }
  68. }
  69. };
  70. </script>
  71. <style lang="scss" scoped>
  72. .page {
  73. height: 100%;
  74. .video-detail-page {
  75. width: 100%;
  76. uni-video {
  77. width: 100%;
  78. }
  79. video {
  80. width: 100%;
  81. }
  82. }
  83. }
  84. </style>