選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

168 行
3.8KB

  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. this.$stopPullDown();
  42. },
  43. methods: {
  44. playMusic() {
  45. if (this.bgLoop) { //暂停
  46. this.bgAudio.pause();
  47. } else { //播放
  48. this.bgAudio.play();
  49. }
  50. },
  51. startEvent(e){
  52. siteRecord=0;
  53. var _y= e.changedTouches[0].clientY;
  54. siteRecord=_y;
  55. var type = e.target.dataset.type;
  56. },
  57. endEvent(e){//抬起事件
  58. var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  59. let direction = "";//可滑动的方向
  60. //获取当前页面路径
  61. let path = this.$route.path;
  62. //判断是否在可滑动切换页面的列表中
  63. if(allPage.indexOf(path)==-1 || scrollTop || this.$store.state.menuState || this.$store.state.commonWin){
  64. return;
  65. }
  66. //判断是否只可向一个方向滑动
  67. for(let i=0;i<stopSliding.length;i++){
  68. if(stopSliding[i]["page"]==path){
  69. direction = stopSliding[i]['direction'];
  70. break;
  71. }
  72. }
  73. var _y= e.changedTouches[0].clientY;
  74. if(direction=="next"){
  75. if(siteRecord-_y>=50){
  76. console.log("只能换到下一页");
  77. this.$router.replace(allPage[allPage.indexOf(path)+1]);
  78. }
  79. }else if(direction=="prev"){
  80. if(siteRecord-_y<-50){
  81. console.log("只能换到上一页");
  82. this.$router.replace(allPage[allPage.indexOf(path)-1]);
  83. }
  84. }else{
  85. if(siteRecord-_y>=50){
  86. console.log("下一页");
  87. this.$router.replace(allPage[allPage.indexOf(path)+1]);
  88. }else if(siteRecord-_y<-50){
  89. console.log("上一页");
  90. this.$router.replace(allPage[allPage.indexOf(path)-1]);
  91. }
  92. }
  93. },
  94. calculateJumpRules(){
  95. let pagePath = this.$store.state.pagePath;
  96. for(let i=0;i<pagePath.length;i++){
  97. for(let j=0;j<pagePath[i].length;j++){
  98. for(let key in pagePath[i][j]){
  99. if(pagePath[i][j][key]){
  100. allPage.push(pagePath[i][j][key]);
  101. }
  102. }
  103. stopSliding.push({page:pagePath[i][j]['店外'],direction:"next"});
  104. stopSliding.push({page:pagePath[i][j]['浏览全部物料'],direction:"prev"});
  105. }
  106. }
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss">
  112. * {
  113. margin: 0;
  114. padding: 0;
  115. }
  116. html,
  117. body {
  118. position: absolute;
  119. width: 100%;
  120. height: 100%;
  121. background-color: #3f4447;
  122. }
  123. body {
  124. -webkit-touch-callout: none;
  125. -webkit-user-select: none;
  126. -khtml-user-select: none;
  127. -moz-user-select: none;
  128. -ms-user-select: none;
  129. user-select: none;
  130. }
  131. img {
  132. display: block;
  133. }
  134. #app {
  135. position: relative;
  136. height: 100%;
  137. text-align: center;
  138. }
  139. .middleContainer {
  140. position: absolute;
  141. width: 100%;
  142. height: calc(1206/750*100vw);
  143. left: 50%;
  144. top: 50%;
  145. transform: translate(-50%, -50%);
  146. }
  147. .showBg {
  148. position: absolute;
  149. width: 100%;
  150. left: 50%;
  151. top: 50%;
  152. transform: translate(-50%, -50%);
  153. }
  154. .fade-enter-active, .fade-leave-active {
  155. transition: opacity .5s;
  156. }
  157. .fade-enter, .fade-leave-to{
  158. opacity: 0;
  159. }
  160. </style>