nav-button.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="wrap-nav-button" v-if="menus && menus.length > 0">
  3. <nav-bottom height="152rpx">
  4. <view class="menu-layout">
  5. <u-button
  6. v-for="(item, index) in menus"
  7. :key="index"
  8. :text="item.title"
  9. :custom-style="{...btnStyle, color: item.plain?item.bgColor:'#FFFFFF',backgroundColor: item.plain?'transparent':item.bgColor,borderColor: item.plain?item.bgColor:'transparent',flex:'none',width: getBtnWidth()}"
  10. shape="square"
  11. :hair-line="item.plain || false"
  12. :plain="item.plain || false"
  13. :disabled="item.disabled"
  14. @click="onclick(index, item)"></u-button>
  15. </view>
  16. </nav-bottom>
  17. </view>
  18. </template>
  19. <script>
  20. import NavBottom from '@/components/nav-bottom/index.vue'
  21. export default {
  22. components: {
  23. NavBottom
  24. },
  25. props: {
  26. menus: {
  27. type: Array,
  28. default: () => []
  29. }
  30. },
  31. data() {
  32. return {
  33. btnStyle: {
  34. height: '100rpx',
  35. fontSize: '30rpx',
  36. borderRadius: '12rpx',
  37. overflow: 'hidden',
  38. margin: '0'
  39. }
  40. }
  41. },
  42. methods: {
  43. getBtnWidth() {
  44. if(this.menus.length === 1) {
  45. return '100%'
  46. } else if(this.menus.length === 2) {
  47. return '280rpx'
  48. } else {
  49. return '190rpx'
  50. }
  51. },
  52. onclick(index = 0, value) {
  53. this.$emit('itemClick', index, value)
  54. }
  55. }
  56. }
  57. </script>
  58. <style lang="scss" scoped>
  59. .wrap-nav-button {
  60. z-index: 998;
  61. position: fixed;
  62. left: 0;
  63. bottom: env(safe-area-inset-bottom);
  64. width: 100%;
  65. padding: 0;
  66. margin: 0;
  67. .menu-layout {
  68. display: flex;
  69. align-items: center;
  70. justify-content: space-between;
  71. padding: 0 60rpx;
  72. height: 100%;
  73. }
  74. }
  75. </style>