index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view style="touch-action: none;">
  3. <view class="home" style="position:fixed;" :style="{ top: top + 'px', bottom: bottom }" id="right-nav"
  4. @touchmove.stop.prevent="setTouchMove">
  5. <view class="homeCon bg-color-red dd" :class="homeActive === true ? 'on' : ''" v-if="homeActive"
  6. :style="{'width': showH?'100rpx':'200rpx'}">
  7. <image src="../../static/icon/home.png" mode="heightFix" class="logo" style="margin-right: 20rpx;"
  8. @click="goHome" v-if="!showH"></image>
  9. <button open-type="contact" bindcontact="handleContact" class="logo">
  10. <image src="../../static/icon/kf.png" mode="heightFix" class="logo"></image>
  11. </button>
  12. <!-- <navigator hover-class='none' url='/pages/index/index' open-type='switchTab' class='iconfont icon-shouye-xianxing'></navigator>
  13. <navigator hover-class='none' url='/pages/order_addcart/order_addcart' open-type='switchTab' class='iconfont icon-caigou-xianxing'></navigator>
  14. <navigator hover-class='none' url='/pages/user/index' open-type='switchTab' class='iconfont icon-yonghu1'></navigator> -->
  15. </view>
  16. <view @click="open" class="pictrueBox" id="home">
  17. <view class="pictrue">
  18. <image :src="
  19. homeActive === true
  20. ? 'https://xmyl.qiniu1314.com/static/images/close.gif'
  21. : 'https://xmyl.qiniu1314.com/static/images/open.gif'
  22. " class="image" />
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import {
  30. mapGetters
  31. } from "vuex";
  32. export default {
  33. name: "Home",
  34. props: {},
  35. data: function() {
  36. return {
  37. top: "",
  38. bottom: "",
  39. homeActive: false,
  40. showH: false,
  41. pagesH: 580
  42. };
  43. },
  44. onReady() {
  45. let that = this
  46. wx.getSystemInfo({
  47. success: function(res) {
  48. const screenWidth = res.screenWidth; // 屏幕宽度
  49. const screenHeight = res.screenHeight; // 屏幕高度
  50. wx.createSelectorQuery().selectViewport().boundingClientRect(function(rect) {
  51. const viewportWidth = rect.width; // 视口宽度
  52. const viewportHeight = rect.height; // 视口高度
  53. const fullScreenWidth = screenWidth * viewportWidth / rect.width; // 页面全屏宽度
  54. const fullScreenHeight = screenHeight * viewportHeight / rect.height; // 页面全屏高度
  55. console.log('页面全屏宽度:', fullScreenWidth);
  56. console.log('页面全屏高度:', fullScreenHeight);
  57. that.pagesH = fullScreenHeight *1 - 100;
  58. }).exec();
  59. },
  60. fail: function(error) {
  61. console.log('获取系统信息失败', error);
  62. }
  63. });
  64. },
  65. methods: {
  66. handleContact(e) {
  67. console.log(e)
  68. },
  69. goHome() {
  70. uni.switchTab({
  71. url: '/pages/index/index'
  72. })
  73. },
  74. setTouchMove(e) {
  75. var that = this;
  76. console.log(e.touches[0].clientY)
  77. if (e.touches[0].clientY < that.pagesH && e.touches[0].clientY > 66) {
  78. that.top = e.touches[0].clientY
  79. }
  80. },
  81. open: function() {
  82. this.homeActive ?
  83. this.closeHome() :
  84. this.openHome();
  85. },
  86. openHome() {
  87. this.homeActive = true;
  88. uni.setStorageSync('homeActive', true)
  89. },
  90. closeHome() {
  91. this.homeActive = false;
  92. uni.setStorageSync('homeActive', false)
  93. },
  94. },
  95. created() {
  96. // 获取当前页面的实例
  97. const pages = getCurrentPages();
  98. const currentPage = pages[pages.length - 1];
  99. // 获取页面路由信息
  100. const route = currentPage.route
  101. this.showH = (route == 'pages/index/index')
  102. console.log(this.showH, 'route')
  103. this.bottom = "50px";
  104. this.homeActive = uni.getStorageSync('homeActive')
  105. }
  106. };
  107. </script>
  108. <style scoped>
  109. .pictrueBox {
  110. width: 130rpx;
  111. height: 120rpx;
  112. }
  113. /*返回主页按钮*/
  114. .home {
  115. position: fixed;
  116. color: white;
  117. text-align: center;
  118. z-index: 9999;
  119. right: 15rpx;
  120. display: flex;
  121. }
  122. .home .homeCon {
  123. border-radius: 50rpx;
  124. opacity: 0;
  125. height: 0;
  126. color: #e93323;
  127. width: 0;
  128. }
  129. .home .homeCon.on {
  130. opacity: 1;
  131. animation: bounceInRight 0.5s cubic-bezier(0.215, 0.610, 0.355, 1.000);
  132. width: 200rpx;
  133. height: 86rpx;
  134. margin-bottom: 20rpx;
  135. display: flex;
  136. justify-content: center;
  137. align-items: center;
  138. background: #9b0000 !important;
  139. }
  140. .home .homeCon .iconfont {
  141. font-size: 48rpx;
  142. color: #fff;
  143. display: inline-block;
  144. margin: 0 auto;
  145. background: #9b0000 !important;
  146. }
  147. .home .pictrue {
  148. width: 86rpx;
  149. height: 86rpx;
  150. border-radius: 50%;
  151. margin: 0 auto;
  152. background: #9b0000 !important;
  153. }
  154. .home .pictrue .image {
  155. width: 100%;
  156. height: 100%;
  157. border-radius: 50%;
  158. /* transform: rotate(90deg);
  159. ms-transform: rotate(90deg);
  160. moz-transform: rotate(90deg);
  161. webkit-transform: rotate(90deg);
  162. o-transform: rotate(90deg); */
  163. }
  164. .logo {
  165. height: 60rpx;
  166. width: 60rpx;
  167. background: none;
  168. margin: 0;
  169. padding: 0;
  170. }
  171. .logo::after {
  172. border: none;
  173. }
  174. .dd {
  175. display: flex;
  176. /* justify-content: space-around; */
  177. }
  178. </style>