menuIcon.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. console.log(this.menuButton)
  105. query
  106. .select('#home')
  107. .boundingClientRect(data => {
  108. this.homeTop = this.menuButton.top * 2 + this.menuButton.height - data.height + 2;
  109. })
  110. .exec();
  111. // #endif
  112. });
  113. },
  114. methods: {
  115. open() {
  116. this.Active = !this.Active
  117. if (this.Active) this.$emit('open', true)
  118. },
  119. // 后退
  120. returns() {
  121. uni.navigateBack();
  122. },
  123. jumpUrl(url, type) {
  124. (type === 1 ? uni.switchTab : uni.navigateTo)({url})
  125. },
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. .home {
  131. /* #ifdef H5 */
  132. top: 20rpx !important;
  133. /* #endif */
  134. }
  135. .home.opacity {
  136. background: rgba(255, 255, 255, 1);
  137. border: 1px solid #d7d7d7;
  138. }
  139. .home {
  140. color: #333;
  141. position: fixed;
  142. // width: 130rpx;
  143. // padding: 0 20rpx;
  144. height: 62rpx;
  145. z-index: 99;
  146. left: 33rpx;
  147. border: 1px solid #d7d7d7;
  148. background: rgba(255, 255, 255, 0.8);
  149. border-radius: 30rpx;
  150. display: flex;
  151. align-items: center;
  152. justify-content: space-around;
  153. .opacity {
  154. color: #000;
  155. }
  156. .icon-gengduo4,
  157. .icon-guanbi5 {
  158. position: absolute;
  159. width: 40rpx;
  160. font-weight: bold;
  161. }
  162. .icon-xiangzuo{
  163. font-weight: bold;
  164. line-height: 28rpx;
  165. }
  166. .icon-gengduo4 {
  167. font-size: 28rpx;
  168. text-align: center;
  169. }
  170. }
  171. .home .animation-box {
  172. position: relative;
  173. width: 40rpx;
  174. height: 28rpx;
  175. }
  176. .icon-guanbi5 {
  177. font-size: 28rpx;
  178. text-align: center;
  179. }
  180. .home .homeCon {
  181. display: flex;
  182. flex-direction: column;
  183. font-size: 26rpx;
  184. padding: 4rpx;
  185. opacity: 0;
  186. border: 1px solid #f2f2f2;
  187. &::before {
  188. content: "";
  189. width: 0;
  190. height: 0;
  191. border-left: 15rpx solid transparent;
  192. border-right: 15rpx solid transparent;
  193. border-bottom: 17rpx solid #fff;
  194. position: absolute;
  195. top: -15rpx;
  196. right: 66rpx;
  197. border-bottom-color: #f2f2f2;
  198. }
  199. &::after {
  200. content: "";
  201. width: 0;
  202. height: 0;
  203. border-left: 15rpx solid transparent;
  204. border-right: 15rpx solid transparent;
  205. border-bottom: 17rpx solid #fff;
  206. position: absolute;
  207. top: -13rpx;
  208. right: 66rpx;
  209. }
  210. .homeCon-box {
  211. display: flex;
  212. align-items: center;
  213. flex-wrap: nowrap;
  214. width: 100%;
  215. padding: 15rpx 20rpx;
  216. .text {
  217. display: flex;
  218. flex-wrap: nowrap;
  219. }
  220. }
  221. .iconfont {
  222. display: flex;
  223. align-items: center;
  224. padding: 5rpx 3rpx;
  225. margin-right: 5rpx;
  226. }
  227. .homeCon-box:nth-child(even) {
  228. border-top: 1px solid #f2f2f2;
  229. border-bottom: 1px solid #f2f2f2;
  230. }
  231. }
  232. .home .homeCon.active {
  233. position: absolute;
  234. opacity: 1;
  235. top: 75rpx;
  236. animation: bounceInLeft 0.5s cubic-bezier(0.215, 0.310, 0.655, 1.000);
  237. width: max-content;
  238. display: flex;
  239. justify-content: center;
  240. align-items: center;
  241. border-radius: 10rpx;
  242. color: #333;
  243. background: #fff !important;
  244. box-shadow: $uni-index-box-shadow;
  245. }
  246. .home .line {
  247. width: 2rpx;
  248. height: 26rpx;
  249. margin: 0 18rpx 0 16rpx;
  250. background: rgba(255, 255, 255, 1);
  251. }
  252. .home .line.opacity {
  253. color: #050505;
  254. background-color: #050505;
  255. }
  256. .home .icon-xiangzuo {
  257. font-size: 28rpx;
  258. }
  259. .fade-enter-active,
  260. .fade-leave-active {
  261. transition: opacity .3s;
  262. }
  263. .fade-enter,
  264. .fade-leave-to
  265. /* .fade-leave-active below version 2.1.8 */
  266. {
  267. opacity: 0;
  268. }
  269. .p10 {
  270. padding: 0 25rpx;
  271. }
  272. .p20 {
  273. padding: 0 40rpx;
  274. }
  275. </style>