menuBtn.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view>
  3. <view
  4. class="menuBtn"
  5. v-if="list.length > 0"
  6. @click="showMenu"
  7. >
  8. <text class="menuText">{{ title }}</text>
  9. <text class="menuText">{{ list[value].title }}</text>
  10. <image
  11. src="@/devTools/page/static/menu.png"
  12. class="menuIcon"
  13. />
  14. </view>
  15. <view
  16. v-if="showMenuList"
  17. class="menuMock"
  18. :style="{
  19. height: height + 'px',
  20. }"
  21. @click.stop
  22. >
  23. <view
  24. class="closeBtn"
  25. @click="close"
  26. >
  27. <text class="closeText">关闭</text>
  28. </view>
  29. <scroll-view
  30. :style="{
  31. maxHeight: height * 0.7 + 'px',
  32. }"
  33. scroll-y
  34. class="scrollList"
  35. >
  36. <view
  37. v-for="(item, index) in list"
  38. :key="item.title"
  39. class="menuSelectItem"
  40. :class="[index > 0 ? 'tl' : '', index == 0 ? 'i-s' : '', index == list.length ? 'i-e' : '']"
  41. @click="menuSelect(index)"
  42. >
  43. <text
  44. class="menuSelectText"
  45. :style="{
  46. color: index == value ? '#ff2d55' : '#333333',
  47. }"
  48. >
  49. {{ item.title }}
  50. </text>
  51. <view v-if="item.msg">
  52. <text class="menuSelectMsg">{{ item.msg }}</text>
  53. </view>
  54. </view>
  55. </scroll-view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. props: {
  62. /**
  63. * 按钮列表
  64. */
  65. list: {
  66. type: Array,
  67. default: () => [],
  68. },
  69. /**
  70. * 当前选中的按钮索引
  71. */
  72. value: {
  73. type: Number,
  74. default: 0,
  75. },
  76. /**
  77. * 标题
  78. */
  79. title: {
  80. type: String,
  81. default: "",
  82. },
  83. },
  84. data() {
  85. return {
  86. /**
  87. * 屏幕高度
  88. */
  89. height: uni.getSystemInfoSync().windowHeight,
  90. /**
  91. * 是否展示菜单列表
  92. */
  93. showMenuList: false,
  94. };
  95. },
  96. methods: {
  97. /**
  98. * 展示菜单
  99. */
  100. showMenu() {
  101. this.showMenuList = true;
  102. },
  103. /**
  104. * 点击菜单选择事件
  105. */
  106. menuSelect(index) {
  107. this.$emit("indexChange", index);
  108. this.showMenuList = false;
  109. },
  110. /**
  111. * 关闭菜单弹窗
  112. */
  113. close() {
  114. this.showMenuList = false;
  115. },
  116. },
  117. };
  118. </script>
  119. <style lang="scss" scoped>
  120. .menuBtn {
  121. display: flex;
  122. flex-direction: row;
  123. align-items: center;
  124. justify-content: center;
  125. border-radius: 8rpx;
  126. height: 40rpx;
  127. border: 1px solid rgba(0, 0, 0, 0.05);
  128. padding: 0 8rpx;
  129. &:active {
  130. background-color: rgba(0, 0, 0, 0.05);
  131. }
  132. .menuText {
  133. font-size: 20rpx;
  134. line-height: 40rpx;
  135. color: #333;
  136. }
  137. .menuIcon {
  138. margin-left: 8rpx;
  139. width: 28rpx;
  140. height: 28rpx;
  141. }
  142. }
  143. .menuMock {
  144. position: fixed;
  145. z-index: 90;
  146. width: 750rpx;
  147. left: 0;
  148. top: 0;
  149. flex: 1;
  150. /* #ifndef APP-PLUS */
  151. height: 100vh;
  152. backdrop-filter: blur(2px);
  153. /* #endif */
  154. display: flex;
  155. flex-direction: column-reverse;
  156. align-items: center;
  157. background-color: rgba(0, 0, 0, 0.3);
  158. .closeBtn {
  159. width: 710rpx;
  160. height: 80rpx;
  161. margin-bottom: 80rpx;
  162. border-radius: 20rpx;
  163. display: flex;
  164. flex-direction: row;
  165. align-items: center;
  166. justify-content: center;
  167. background-color: #fff;
  168. transition: background-color 200ms ease-in-out;
  169. &:active {
  170. background-color: #dcdcdc;
  171. }
  172. .closeText {
  173. font-size: 24rpx;
  174. color: #333;
  175. line-height: 24rpx;
  176. }
  177. }
  178. }
  179. .scrollList {
  180. display: flex;
  181. flex-direction: column;
  182. align-items: center;
  183. width: 710rpx;
  184. margin-bottom: 30rpx;
  185. border-radius: 20rpx;
  186. overflow: hidden;
  187. .menuSelectItem {
  188. width: 710rpx;
  189. /* #ifndef APP-PLUS */
  190. min-height: 80rpx;
  191. /* #endif */
  192. padding: 15rpx 0;
  193. background-color: #fff;
  194. transition: background-color 200ms ease-in-out;
  195. display: flex;
  196. flex-direction: column;
  197. align-items: center;
  198. justify-content: center;
  199. &.tl {
  200. border-top: 1px solid rgba(0, 0, 0, 0.1);
  201. }
  202. &.i-s {
  203. border-radius: 20rpx 20rpx 0 0;
  204. }
  205. &.i-e {
  206. border-radius: 0 0 20rpx 20rpx;
  207. }
  208. &:active {
  209. background-color: #dcdcdc;
  210. }
  211. .menuSelectText {
  212. font-size: 24rpx;
  213. line-height: 24rpx;
  214. color: #333;
  215. }
  216. .menuSelectMsg {
  217. font-size: 20rpx;
  218. line-height: 20rpx;
  219. margin-top: 10rpx;
  220. color: #999999;
  221. }
  222. }
  223. }
  224. </style>