App.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div id="app">
  3. <!-- <img alt="Vue logo" src="./assets/logo.png" />
  4. <HelloWorld msg="Welcome to Your Vue.js App" /> -->
  5. <keep-alive>
  6. <router-view :key="$route.fullPath"></router-view>
  7. </keep-alive>
  8. <Loading></Loading>
  9. </div>
  10. </template>
  11. <script>
  12. import Loading from '@/components/loading.vue';
  13. import EventBus from '@/utils/eventBus.js';
  14. export default {
  15. name: 'App',
  16. components: {
  17. Loading,
  18. },
  19. created(){
  20. EventBus.$on('preview', this.handlePreview);
  21. EventBus.$on('playVideo', this.handleVideoPlay);
  22. },
  23. methods: {
  24. handleVideoPlay(e){
  25. document.querySelectorAll('video').forEach(video => {
  26. if(e.target !== video && !video.paused) video.pause();
  27. })
  28. },
  29. handlePreview(url){
  30. const { data } = this.$store.state.pages;
  31. const { id = 'main' } = this.$route.params;
  32. const page = data.pages[id];
  33. if(!page) return;
  34. let images = this.findPreviewImage(page);
  35. this.$previewImage({
  36. urls: images,
  37. startPosition: images.indexOf(url),
  38. onClose () {
  39. console.log('关闭事件回调')
  40. }
  41. })
  42. },
  43. findPreviewImage(data, arr = []){
  44. if(Array.isArray(data)) {
  45. data.forEach(_data => {
  46. this.findPreviewImage(_data, arr);
  47. })
  48. return;
  49. }
  50. const { image, preview, children, nodes } = data;
  51. if(image && preview) arr.push(image);
  52. if(children) this.findPreviewImage(children, arr);
  53. if(nodes) this.findPreviewImage(nodes, arr);
  54. return arr;
  55. }
  56. },
  57. }
  58. </script>
  59. <style lang="less">
  60. #app {
  61. font-family: Avenir, Helvetica, Arial, sans-serif;
  62. -webkit-font-smoothing: antialiased;
  63. -moz-osx-font-smoothing: grayscale;
  64. text-align: center;
  65. color: #2c3e50;
  66. }
  67. .image-preview__swiper-container {
  68. z-index: 100000;
  69. }
  70. </style>