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.

App.vue 3.8KB

5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div id="app" @touchstart="startEvent" @touchend="endEvent">
  3. <transition name="fade">
  4. <router-view />
  5. </transition>
  6. <btn-music :bgLoop="bgLoop"></btn-music>
  7. <!-- <sidebar style="position: absolute;top: 20vw;left: 10vw;"></sidebar> -->
  8. </div>
  9. </template>
  10. <script>
  11. let allPage = [];//所有可滑动的页面
  12. let stopSliding = [];//仅可向上或向下滑动的页面
  13. let siteRecord = 0;
  14. import BtnMusic from './components/music.vue'
  15. // import Sidebar from './components/sidebar.vue'
  16. export default {
  17. name: 'APP',
  18. data() {
  19. return {
  20. btnAudio: null,
  21. bgLoop: false,
  22. }
  23. },
  24. components: {
  25. BtnMusic
  26. },
  27. mounted() {
  28. var that = this;
  29. this.bgAudio=window['bgAudio'];
  30. this.bgLoop=window['bgLoop'];
  31. if(!this.bgLoop){
  32. this.bgAudio.removeEventListener('play',window['openLoop']);
  33. }
  34. this.bgAudio.addEventListener('play', function() {
  35. that.bgLoop = true;
  36. })
  37. this.bgAudio.addEventListener('pause', function() {
  38. that.bgLoop = false;
  39. })
  40. this.calculateJumpRules();
  41. },
  42. methods: {
  43. playMusic() {
  44. if (this.bgLoop) { //暂停
  45. this.bgAudio.pause();
  46. } else { //播放
  47. this.bgAudio.play();
  48. }
  49. },
  50. startEvent(e){
  51. siteRecord=0;
  52. var _y= e.changedTouches[0].clientY;
  53. siteRecord=_y;
  54. var type = e.target.dataset.type;
  55. },
  56. endEvent(e){//抬起事件
  57. var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  58. let direction = "";//可滑动的方向
  59. //获取当前页面路径
  60. let path = this.$route.path;
  61. //判断是否在可滑动切换页面的列表中
  62. if(allPage.indexOf(path)==-1 || scrollTop){
  63. return;
  64. }
  65. //判断是否只可向一个方向滑动
  66. for(let i=0;i<stopSliding.length;i++){
  67. if(stopSliding[i]["page"]==path){
  68. direction = stopSliding[i]['direction'];
  69. break;
  70. }
  71. }
  72. var _y= e.changedTouches[0].clientY;
  73. if(direction=="next"){
  74. if(siteRecord-_y>=50){
  75. console.log("只能换到下一页");
  76. this.$router.replace(allPage[allPage.indexOf(path)+1]);
  77. }
  78. }else if(direction=="prev"){
  79. if(siteRecord-_y<-50){
  80. console.log("只能换到上一页");
  81. this.$router.replace(allPage[allPage.indexOf(path)-1]);
  82. }
  83. }else{
  84. if(siteRecord-_y>=50){
  85. console.log("下一页");
  86. this.$router.replace(allPage[allPage.indexOf(path)+1]);
  87. }else if(siteRecord-_y<-50){
  88. console.log("上一页");
  89. this.$router.replace(allPage[allPage.indexOf(path)-1]);
  90. }
  91. }
  92. },
  93. calculateJumpRules(){
  94. let pagePath = this.$store.state.pagePath;
  95. for(let i=0;i<pagePath.length;i++){
  96. for(let j=0;j<pagePath[i].length;j++){
  97. for(let key in pagePath[i][j]){
  98. if(pagePath[i][j][key]){
  99. allPage.push(pagePath[i][j][key]);
  100. }
  101. }
  102. stopSliding.push({page:pagePath[i][j]['店外'],direction:"next"});
  103. stopSliding.push({page:pagePath[i][j]['浏览全部物料'],direction:"prev"});
  104. }
  105. }
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss">
  111. * {
  112. margin: 0;
  113. padding: 0;
  114. }
  115. html,
  116. body {
  117. position: absolute;
  118. width: 100%;
  119. height: 100%;
  120. background-color: #3f4447;
  121. }
  122. body {
  123. -webkit-touch-callout: none;
  124. -webkit-user-select: none;
  125. -khtml-user-select: none;
  126. -moz-user-select: none;
  127. -ms-user-select: none;
  128. user-select: none;
  129. }
  130. img {
  131. display: block;
  132. }
  133. #app {
  134. position: relative;
  135. height: 100%;
  136. text-align: center;
  137. }
  138. .middleContainer {
  139. position: absolute;
  140. width: 100%;
  141. height: calc(1206/750*100vw);
  142. left: 50%;
  143. top: 50%;
  144. transform: translate(-50%, -50%);
  145. }
  146. .showBg {
  147. position: absolute;
  148. width: 100%;
  149. left: 50%;
  150. top: 50%;
  151. transform: translate(-50%, -50%);
  152. }
  153. .fade-enter-active, .fade-leave-active {
  154. transition: opacity .5s;
  155. }
  156. .fade-enter, .fade-leave-to{
  157. opacity: 0;
  158. }
  159. </style>