Search.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 '@/views/disaster/types';
  29. const props = defineProps<{
  30. searchConfig: SearchConfig[];
  31. searchData: any;
  32. }>();
  33. const emit = defineEmits<{
  34. (e: 'update:searchData'): void;
  35. }>();
  36. const handleSearch = () => {
  37. emit('update:searchData');
  38. };
  39. const handleReset = () => {
  40. for (const key in props.searchData) {
  41. props.searchData[key] = '';
  42. }
  43. emit('update:searchData');
  44. };
  45. </script>
  46. <style lang="scss" scoped>
  47. .search-box {
  48. @include flex-center;
  49. justify-content: space-between;
  50. width: 100%;
  51. }
  52. .select-box {
  53. display: flex;
  54. align-items: center;
  55. flex-wrap: wrap;
  56. gap: 10cpx;
  57. &--item {
  58. @include flex-center;
  59. white-space: nowrap;
  60. gap: 10cpx;
  61. }
  62. span {
  63. color: rgba(0, 0, 0, 0.85);
  64. font-size: 14cpx;
  65. }
  66. .el-select {
  67. width: 200cpx;
  68. }
  69. }
  70. .search-btn {
  71. display: flex;
  72. }
  73. </style>