index.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <el-card v-loading="loading" shadow="never" class="search-wrapper">
  3. <el-form ref="searchFormRef" :inline="true" :model="searchForm">
  4. <el-form-item :prop="item.field" :label="item.label" v-for="(item, index) in searchList" :key="index">
  5. <el-input v-model="searchForm[`${item.field}`]" :placeholder="item.placeholder" />
  6. </el-form-item>
  7. <el-form-item>
  8. <el-button type="primary" :icon="Search" @click="handleSearch">查询</el-button>
  9. <el-button :icon="Refresh" @click="resetSearch">重置</el-button>
  10. </el-form-item>
  11. </el-form>
  12. </el-card>
  13. </template>
  14. <script setup lang="ts">
  15. import { shallowRef, ref, watch } from "vue"
  16. import { Search, Refresh, CirclePlus, Delete, Download, RefreshRight } from "@element-plus/icons-vue"
  17. import { type FormInstance, type FormRules, ElMessage, ElMessageBox } from "element-plus"
  18. const loading = ref<boolean>(false)
  19. const props = defineProps({
  20. searchTerms: {
  21. type: Array,
  22. default() {
  23. return []
  24. }
  25. },
  26. ruleForm: {
  27. type: Object,
  28. default() {
  29. return {}
  30. }
  31. },
  32. })
  33. const searchList: any = shallowRef(props.searchTerms)
  34. const searchForm: any = shallowRef(props.ruleForm)
  35. const emit = defineEmits(['handleSearch']);
  36. // 搜索
  37. const handleSearch = () => {
  38. emit('handleSearch');
  39. }
  40. const searchFormRef = shallowRef<FormInstance | null>(null)
  41. // 重置
  42. const resetSearch = () => {
  43. searchFormRef.value?.resetFields()
  44. handleSearch()
  45. }
  46. </script>
  47. <style lang="scss" scoped>
  48. .search-wrapper {
  49. margin-bottom: 20px;
  50. :deep(.el-card__body) {
  51. padding-bottom: 2px;
  52. }
  53. }
  54. </style>