Search.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <van-sticky class="van-fade-an" :offset-top="Offset">
  3. <div class="click-pop" v-if="type === 'click'" @click="onClick"></div>
  4. <van-search @input="$emit('input', $event)" @search="onSearch" class="my-search" left-icon="diy-search" v-model.trim="input" placeholder="搜索文档" />
  5. </van-sticky>
  6. </template>
  7. <script lang="ts">
  8. import { Component, Vue, Prop } from 'vue-property-decorator'
  9. import { Icon, Search, Sticky } from 'vant'
  10. // @ is an alias to /src
  11. @Component({
  12. name: 'Search',
  13. components: {
  14. [Search.name]: Search,
  15. [Sticky.name]: Sticky,
  16. [Icon.name]: Icon
  17. }
  18. })
  19. export default class Empty extends Vue {
  20. @Prop({ default: 'input' }) type?: string | undefined;
  21. input = ''
  22. onSearch () {
  23. this.$emit('submit', this.input)
  24. }
  25. onClick () {
  26. if (this.type === 'click') {
  27. this.$emit('click')
  28. }
  29. }
  30. get Offset () {
  31. const tempN = document.querySelector('.j-header.jy-app-header') as HTMLDivElement
  32. if (tempN) {
  33. return tempN.offsetHeight - 1
  34. } else {
  35. return 0
  36. }
  37. }
  38. }
  39. </script>
  40. <style scoped lang="scss">
  41. @keyframes show {
  42. to {
  43. opacity: 1;
  44. }
  45. }
  46. .van-fade-an {
  47. opacity: 0;
  48. animation: show 1s 300ms ease forwards;
  49. z-index: 666;
  50. position: relative;
  51. }
  52. .click-pop {
  53. position: absolute;
  54. width: 100%;
  55. height: 100%;
  56. z-index: 99;
  57. opacity: 0;
  58. }
  59. .my-search {
  60. &::v-deep.van-search {
  61. padding: 7px 16px;
  62. .van-search__content {
  63. border-radius: 8px;
  64. background: #F5F6F7;
  65. border: 1px solid rgba(0, 0, 0, 0.05);
  66. }
  67. .van-cell {
  68. align-items: center;
  69. height: 38px;
  70. }
  71. .van-field__left-icon {
  72. height: 20px;
  73. margin-right: 8px;
  74. }
  75. .van-field__control {
  76. color: #171826;
  77. font-family: PingFang SC;
  78. font-size: 14px;
  79. letter-spacing: 0px;
  80. text-align: left;
  81. }
  82. }
  83. @include diy-icon('search', 20, 20)
  84. }
  85. </style>