BasicSearch.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div class="search-box">
  3. <section class="select-box">
  4. <div class="select-box--item" v-for="item in searchConfig" :key="item.prop">
  5. <span>{{ item.label }}</span>
  6. <template v-if="item.slot">
  7. <slot :name="item.slot" />
  8. </template>
  9. <template v-else>
  10. <component :is="item.component" v-model="searchData[item.prop]" v-bind="item.componentProps">
  11. <el-option
  12. v-for="option in item.selectOptions"
  13. :key="option.value"
  14. :label="option.label"
  15. :value="option.value"
  16. />
  17. </component>
  18. </template>
  19. </div>
  20. </section>
  21. <section class="search-btn">
  22. <el-button type="primary" @click="handleSearch">查询</el-button>
  23. <el-button @click="handleReset">重置</el-button>
  24. </section>
  25. </div>
  26. </template>
  27. <script lang="ts" setup>
  28. import type { SearchConfig } from '@/types/basic-search';
  29. const props = defineProps<{
  30. searchConfig: SearchConfig[];
  31. searchData: any;
  32. customReset?: boolean;
  33. }>();
  34. const emits = defineEmits<{
  35. (e: 'update:searchData'): void;
  36. (e: 'custom-reset'): void;
  37. }>();
  38. const handleSearch = () => {
  39. emits('update:searchData');
  40. };
  41. const handleReset = () => {
  42. if (props.customReset) {
  43. emits('custom-reset');
  44. return;
  45. }
  46. for (const key in props.searchData) {
  47. props.searchData[key] = null;
  48. }
  49. emits('update:searchData');
  50. };
  51. </script>
  52. <style lang="scss" scoped>
  53. .search-box {
  54. @include flex-center;
  55. justify-content: space-between;
  56. width: 100%;
  57. }
  58. .select-box {
  59. display: flex;
  60. align-items: center;
  61. flex-wrap: wrap;
  62. gap: 32px;
  63. &--item {
  64. @include flex-center;
  65. white-space: nowrap;
  66. }
  67. span {
  68. color: rgba(0, 0, 0, 0.85);
  69. font-size: 14px;
  70. }
  71. .el-select {
  72. width: 200px;
  73. }
  74. }
  75. .search-btn {
  76. display: flex;
  77. }
  78. </style>