HeaderSearchInput.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div class="header-search">
  3. <div class="search-input">
  4. <el-input
  5. v-model="searchKey"
  6. clearable
  7. :placeholder="searchTips"
  8. :style="{ '--innerWidth': innerWidth }"
  9. @focus="handleFocus"
  10. @blur="handleBlur"
  11. @keyup.enter.native="searchByKey"
  12. ></el-input>
  13. <el-button type="primary" class="search-button-div" @click="searchByKey">
  14. <i class="el-icon-search input-button-icon"></i>
  15. {{ $t('ht.common.searchFor') }}
  16. </el-button>
  17. <!-- <i
  18. ref="icon"
  19. class="iconfont icon-flow-center-search"
  20. @click="searchByKey"
  21. ></i> -->
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import { mapGetters } from 'vuex'
  27. export default {
  28. name: 'HeaderSearch',
  29. props: {
  30. searchTips: {
  31. type: String,
  32. default: '请输入关键词进行检索',
  33. },
  34. innerWidth: {
  35. type: String,
  36. default: '330px',
  37. },
  38. },
  39. data() {
  40. return {
  41. searchKey: '',
  42. }
  43. },
  44. computed: {
  45. ...mapGetters({
  46. themeColor: 'settings/themeColor',
  47. }),
  48. },
  49. methods: {
  50. handleAdd() {
  51. this.$emit('handle-add')
  52. },
  53. handleDel() {
  54. this.$emit('handle-del')
  55. },
  56. searchByKey() {
  57. this.$emit('search-by-key', this.searchKey)
  58. },
  59. handleFocus() {
  60. this.$refs.icon.style.color = this.themeColor
  61. },
  62. handleBlur() {
  63. this.$refs.icon.style.color = '#c0c4cc'
  64. },
  65. },
  66. }
  67. </script>
  68. <style lang="scss" scoped>
  69. .header-search {
  70. display: inline-block;
  71. ::v-deep .el-input {
  72. width: var(--innerWidth);
  73. .el-input__inner {
  74. padding-right: 60px;
  75. }
  76. .el-input__suffix {
  77. right: 30px;
  78. }
  79. }
  80. .search-input {
  81. position: relative;
  82. display: flex;
  83. align-items: center;
  84. .iconfont {
  85. position: absolute;
  86. top: 0px;
  87. right: 0px;
  88. width: 30px;
  89. height: 32px;
  90. font-size: 14px;
  91. line-height: 32px;
  92. color: #c0c4cc;
  93. text-align: center;
  94. cursor: pointer;
  95. }
  96. .search-button-div {
  97. z-index: 2;
  98. height: 32px;
  99. margin-left: -30px;
  100. font-size: 14px;
  101. border-top-left-radius: 0px;
  102. border-bottom-left-radius: 0px;
  103. }
  104. }
  105. }
  106. </style>