SearchInput.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <section class="menu-search-input" @Click="handleClick" :class="searchClass">
  3. <a-input-search
  4. placeholder="菜单搜索"
  5. class="menu-search-input__search"
  6. allowClear
  7. @change="handleChange"
  8. />
  9. </section>
  10. </template>
  11. <script lang="ts">
  12. import type { PropType } from 'vue';
  13. import { defineComponent, computed } from 'vue';
  14. import { MenuThemeEnum } from '/@/enums/menuEnum';
  15. // hook
  16. import { useDebounce } from '/@/hooks/core/useDebounce';
  17. //
  18. export default defineComponent({
  19. name: 'BasicMenuSearchInput',
  20. props: {
  21. // Whether to expand, used in the left menu
  22. collapsed: {
  23. type: Boolean as PropType<boolean>,
  24. default: true,
  25. },
  26. theme: {
  27. type: String as PropType<MenuThemeEnum>,
  28. },
  29. },
  30. setup(props, { emit }) {
  31. const [debounceEmitChange] = useDebounce(emitChange, 200);
  32. function emitChange(value?: string): void {
  33. emit('change', value);
  34. }
  35. function handleChange(e: ChangeEvent): void {
  36. const { collapsed } = props;
  37. if (collapsed) return;
  38. debounceEmitChange(e.target.value);
  39. }
  40. function handleClick(): void {
  41. emit('click');
  42. }
  43. const searchClass = computed(() => {
  44. const cls: string[] = [];
  45. cls.push(props.theme ? `menu-search-input__search--${props.theme}` : '');
  46. // cls.push(props.collapsed ? 'hide-search-icon' : '');
  47. return cls;
  48. });
  49. return { handleClick, searchClass, handleChange };
  50. },
  51. });
  52. </script>
  53. <style lang="less">
  54. @import (reference) '../../../design/index.less';
  55. // 输入框背景颜色 深
  56. @input-dark-bg-color: #516085;
  57. @icon-color: #c0c4cc;
  58. .menu-search-input {
  59. margin: 12px 8px;
  60. // &.hide-search-icon {
  61. // .ant-input,
  62. // .ant-input-suffix {
  63. // opacity: 0;
  64. // }
  65. // }
  66. &__search--dark {
  67. .ant-input-affix-wrapper,
  68. .ant-input {
  69. .set-bg();
  70. }
  71. .ant-input-search-icon,
  72. .ant-input-clear-icon {
  73. color: rgba(255, 255, 255, 0.4) !important;
  74. }
  75. }
  76. &__search--light {
  77. .ant-input-affix-wrapper,
  78. .ant-input {
  79. color: @text-color-base;
  80. background: #fff;
  81. outline: none;
  82. }
  83. .ant-input-search-icon {
  84. color: @icon-color;
  85. }
  86. }
  87. }
  88. .set-bg() {
  89. color: #fff;
  90. background: @input-dark-bg-color;
  91. border: 0;
  92. outline: none;
  93. }
  94. .hide-outline() {
  95. border: none;
  96. outline: none;
  97. box-shadow: none;
  98. }
  99. </style>