menuIcon.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view>
  3. <view id="home" class="home acea-row row-center-wrapper"
  4. :class="[returnShow ? 'p10':'p20', text_opacity >= 1 ? 'opacity':'']" :style="{ top: homeTop +'rpx'}">
  5. <view v-if="returnShow" class="iconfont icon-xiangzuo" :class="text_opacity >= 1 ? 'opacity':''"
  6. @tap="returns">
  7. </view>
  8. <view class="line" v-if="returnShow" :class="text_opacity >= 1 ? 'opacity':''"></view>
  9. <view class="animation-box">
  10. <transition name="fade">
  11. <view v-if="!Active" class="iconfont icon-gengduo4" :class="text_opacity >= 1 ? 'opacity':''"
  12. @click="open">
  13. </view>
  14. <!-- <view v-if="Active" class="iconfont icon-guanbi5" @click="open">
  15. </view> -->
  16. </transition>
  17. <transition name="fade" mode="out-in">
  18. <!-- <view v-if="!Active" class="iconfont icon-gengduo4" @click="open">
  19. </view> -->
  20. <view v-if="Active" class="iconfont icon-guanbi5" :class="text_opacity >= 1 ? 'opacity':''"
  21. @click="open">
  22. </view>
  23. </transition>
  24. </view>
  25. <view class="homeCon bg-color" :class="Active === true ? 'active' : ''" v-if="Active" @click="open">
  26. <view class="homeCon-box" v-for="(item,index) in iconList" :key="index"
  27. @click="jumpUrl(item.path,item.jumpType)">
  28. <text class='iconfont' :class="item.iconName">
  29. </text>
  30. <text class="text">{{item.name}}</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. name: "menuIcon",
  39. data() {
  40. return {
  41. Active: false,
  42. returnShow: true, //判断顶部返回是否出现
  43. homeTop: 20,
  44. text_opacity: 0,
  45. iconList: [{
  46. name: '首页',
  47. iconName: "icon-shouye8",
  48. path: '/pages/index/index',
  49. jumpType: 1
  50. },
  51. {
  52. name: '购物车',
  53. iconName: "icon-gouwuche7",
  54. path: '/pages/order_addcart/order_addcart',
  55. jumpType: 1
  56. },
  57. {
  58. name: '搜索',
  59. iconName: "icon-sousuo6",
  60. path: '/pages/goods_search/index',
  61. jumpType: 0
  62. },
  63. {
  64. name: '收藏',
  65. iconName: "icon-shoucang3",
  66. path: '/pages/users/user_goods_collection/index',
  67. jumpType: 0
  68. },
  69. {
  70. name: '我的',
  71. iconName: "icon-yonghu1",
  72. path: '/pages/user/index',
  73. jumpType: 1
  74. },
  75. {
  76. name: '首页',
  77. iconName: "icon-shouye8",
  78. path: '/pages/index/index',
  79. jumpType: 1
  80. }
  81. ]
  82. };
  83. },
  84. props: {
  85. showMenuIcon: {
  86. type: Boolean,
  87. default: false
  88. },
  89. opacity: {
  90. type: Number,
  91. default: 1
  92. }
  93. },
  94. watch: {
  95. showMenuIcon(e) {
  96. this.Active = e
  97. },
  98. opacity(e) {
  99. this.text_opacity = e
  100. }
  101. },
  102. mounted() {
  103. var pages = getCurrentPages();
  104. this.returnShow = pages.length === 1 ? false : true;
  105. this.$nextTick(() => {
  106. // #ifdef MP
  107. const menuButton = uni.getMenuButtonBoundingClientRect();
  108. const query = uni.createSelectorQuery().in(this);
  109. query
  110. .select('#home')
  111. .boundingClientRect(data => {
  112. this.homeTop = menuButton.top * 2 + menuButton.height - data.height;
  113. })
  114. .exec();
  115. // #endif
  116. });
  117. },
  118. methods: {
  119. open() {
  120. this.Active = !this.Active
  121. if (this.Active) this.$emit('open', true)
  122. },
  123. // 后退
  124. returns() {
  125. uni.navigateBack();
  126. },
  127. jumpUrl(url, type) {
  128. (type === 1 ? uni.switchTab : uni.navigateTo)({
  129. url
  130. })
  131. },
  132. }
  133. }
  134. </script>
  135. <style lang="scss">
  136. .home {
  137. /* #ifdef H5 */
  138. top: 20rpx !important;
  139. /* #endif */
  140. }
  141. .home.opacity {
  142. background: rgba(255, 255, 255, 1);
  143. border: 1px solid #f2f2f2;
  144. }
  145. .home {
  146. color: #fff;
  147. position: fixed;
  148. // width: 130rpx;
  149. // padding: 0 20rpx;
  150. height: 56rpx;
  151. z-index: 99;
  152. left: 33rpx;
  153. background: rgba(190, 190, 190, 0.5);
  154. border-radius: 30rpx;
  155. display: flex;
  156. align-items: center;
  157. .opacity {
  158. color: #050505;
  159. }
  160. .icon-gengduo4,
  161. .icon-guanbi5 {
  162. position: absolute;
  163. width: 40rpx;
  164. }
  165. .icon-gengduo4 {
  166. font-size: 28rpx;
  167. text-align: center;
  168. }
  169. }
  170. .home .animation-box {
  171. position: relative;
  172. width: 39rpx;
  173. height: 28rpx;
  174. }
  175. .icon-guanbi5 {
  176. font-size: 28rpx;
  177. text-align: center;
  178. }
  179. // .home .icon-gengduo4,
  180. // .home.close .icon-guanbi5 {
  181. // opacity: 1;
  182. // transform: scale(1);
  183. // }
  184. // .home.close .icon-gengduo4 {
  185. // opacity: 0;
  186. // transform: scale(0);
  187. // }
  188. .home .homeCon {
  189. display: flex;
  190. flex-direction: column;
  191. font-size: 26rpx;
  192. padding: 4rpx;
  193. opacity: 0;
  194. border: 1px solid #f2f2f2;
  195. &::before {
  196. content: "";
  197. width: 0;
  198. height: 0;
  199. border-left: 15rpx solid transparent;
  200. border-right: 15rpx solid transparent;
  201. border-bottom: 17rpx solid #fff;
  202. position: absolute;
  203. top: -15rpx;
  204. right: 66rpx;
  205. border-bottom-color: #f2f2f2;
  206. }
  207. &::after {
  208. content: "";
  209. width: 0;
  210. height: 0;
  211. border-left: 15rpx solid transparent;
  212. border-right: 15rpx solid transparent;
  213. border-bottom: 17rpx solid #fff;
  214. position: absolute;
  215. top: -13rpx;
  216. right: 66rpx;
  217. }
  218. .homeCon-box {
  219. display: flex;
  220. align-items: center;
  221. flex-wrap: nowrap;
  222. width: 100%;
  223. padding: 15rpx 18rpx;
  224. .text {
  225. display: flex;
  226. flex-wrap: nowrap;
  227. }
  228. }
  229. .iconfont {
  230. display: flex;
  231. align-items: center;
  232. padding: 5rpx 3rpx;
  233. margin-right: 5rpx;
  234. }
  235. .homeCon-box:nth-child(even) {
  236. border-top: 1px solid #f2f2f2;
  237. border-bottom: 1px solid #f2f2f2;
  238. }
  239. }
  240. .home .homeCon.active {
  241. position: absolute;
  242. opacity: 1;
  243. top: 75rpx;
  244. animation: bounceInLeft 0.5s cubic-bezier(0.215, 0.310, 0.655, 1.000);
  245. width: max-content;
  246. display: flex;
  247. justify-content: center;
  248. align-items: center;
  249. border-radius: 10rpx;
  250. color: #333;
  251. background: #fff !important;
  252. box-shadow: $uni-index-box-shadow;
  253. }
  254. .home .line {
  255. width: 2rpx;
  256. height: 24rpx;
  257. margin: 0 12rpx 0 10rpx;
  258. background: rgba(255, 255, 255, 0.25);
  259. }
  260. .home .line.opacity {
  261. color: #050505;
  262. background-color: #050505;
  263. }
  264. .home .icon-xiangzuo {
  265. font-size: 28rpx;
  266. }
  267. .fade-enter-active,
  268. .fade-leave-active {
  269. transition: opacity .3s;
  270. }
  271. .fade-enter,
  272. .fade-leave-to
  273. /* .fade-leave-active below version 2.1.8 */
  274. {
  275. opacity: 0;
  276. }
  277. .p10 {
  278. padding: 0 20rpx;
  279. }
  280. .p20 {
  281. padding: 0 40rpx;
  282. }
  283. </style>