searchBar.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view class="nav-bar-wrap" :style="{ height: navBarStyle.height, paddingTop: navBarStyle.paddingTop, paddingBottom: navBarStyle.paddingBottom }">
  3. <slot name="content-left"> </slot>
  4. <view class="search-box" @click="goSearch" :style="{ width: `${width}%` }">
  5. <icon type="search" size="15" class="search_ico" />
  6. <text class="sea_ipt">{{ searchTitle || "" }}</text>
  7. </view>
  8. <slot name="content-right"> </slot>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. props: {
  14. searchTitle: {
  15. type: String,
  16. requer: true,
  17. default: "",
  18. },
  19. width: {
  20. type: Number,
  21. requer: true,
  22. default: "",
  23. },
  24. },
  25. data() {
  26. return {
  27. navBarStyle: {
  28. height: 60 + "px",
  29. paddingTop: 40 + "px",
  30. paddingBottom: "4px",
  31. },
  32. };
  33. },
  34. mounted() {
  35. this.initNavBar();
  36. },
  37. methods: {
  38. initNavBar() {
  39. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  40. this.navBarStyle = {
  41. height: menuButtonInfo.height + menuButtonInfo.top + 8 + "px",
  42. paddingTop: menuButtonInfo.top - 4 + "px",
  43. paddingBottom: "4px",
  44. };
  45. },
  46. goSearch() {
  47. this.$emit("goSearch");
  48. },
  49. },
  50. };
  51. </script>
  52. <style scoped lang="scss">
  53. .nav-bar-wrap {
  54. background-color: #fff;
  55. width: 100%;
  56. display: flex;
  57. align-items: center;
  58. .search-box {
  59. position: relative;
  60. display: flex;
  61. align-items: center;
  62. width: 55%;
  63. height: 63rpx;
  64. font-size: 30rpx;
  65. color: #8d8d8d;
  66. background-color: #f3f3f3;
  67. padding-left: 33rpx;
  68. border-radius: 70rpx;
  69. .sea_ipt {
  70. padding-left: 15rpx;
  71. }
  72. }
  73. }
  74. </style>