menuIcon.vue 6.0 KB

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