TableSearchFrom.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script setup lang="ts">
  2. import type { VbFormItem, VbFormRowItem } from "@/components/form/models"
  3. const props = withDefaults(
  4. defineProps<{
  5. searchFormRowItems?: Array<VbFormRowItem>
  6. searchFormItems?: Array<VbFormItem>
  7. searchFormSpan?: number
  8. queryParams: any
  9. resetSearchForm?: () => void
  10. queryTable?: () => void
  11. tableSearchBtnSpan?: number
  12. }>(),
  13. {
  14. tableSearchBtnSpan: 1.5,
  15. searchFormSpan: 4,
  16. }
  17. )
  18. const { queryParams } = toRefs(props)
  19. const _searchFormItems = computed(() => {
  20. if (props.searchFormItems || props.searchFormRowItems) {
  21. const items = props.searchFormItems ?? []
  22. if (
  23. !items.find((v) => {
  24. return v.field == "searchbtn"
  25. })
  26. )
  27. items.push({
  28. field: "searchbtn",
  29. component: "slot",
  30. span: 1.5,
  31. })
  32. return items
  33. }
  34. return props.searchFormItems
  35. })
  36. const searchFormRef = ref<any>()
  37. //form表单的插槽 需要tool-form_,并tool-form_传递给VbForm组件
  38. function isFormSlot(v: string | number): string | undefined {
  39. const formSlotSuffix = "tool-form_"
  40. v = v as string
  41. if (v.search(formSlotSuffix) == 0) {
  42. return v.substring(formSlotSuffix.length)
  43. }
  44. return undefined
  45. }
  46. function customSearch() {
  47. props.queryTable && props.queryTable()
  48. }
  49. function resetForm() {
  50. searchFormRef.value.clearValidate()
  51. searchFormRef.value.resetFields()
  52. props.resetSearchForm && props.resetSearchForm()
  53. setTimeout(customSearch, 100)
  54. }
  55. </script>
  56. <template>
  57. <template v-if="searchFormRowItems || searchFormItems">
  58. <VbForm
  59. ref="searchFormRef"
  60. v-model:data="queryParams"
  61. :row-items="searchFormRowItems"
  62. :items="_searchFormItems"
  63. :span="searchFormSpan"
  64. >
  65. <template v-for="(_, name) in $slots" #[`${isFormSlot(name)}`]>
  66. <slot v-if="isFormSlot(name)" :name="name" />
  67. </template>
  68. <template #searchbtn>
  69. <el-col :span="tableSearchBtnSpan">
  70. <el-button class="btn btn-primary" @click="customSearch">
  71. <template #icon>
  72. <KTIcon icon-name="magnifier" icon-type="solid"></KTIcon>
  73. </template>
  74. 搜索
  75. </el-button>
  76. <el-button class="btn btn-light-primary" @click="resetForm">
  77. <template #icon>
  78. <KTIcon icon-name="arrows-loop" icon-type="solid"></KTIcon>
  79. </template>
  80. 重置
  81. </el-button>
  82. </el-col>
  83. </template>
  84. </VbForm>
  85. </template>
  86. <el-form v-else ref="searchFormRef" :inline="true" :model="queryParams" class="el-row">
  87. <slot name="table-search-form" />
  88. <el-col :span="tableSearchBtnSpan">
  89. <el-form-item>
  90. <el-button class="btn btn-primary" @click="customSearch">
  91. <template #icon>
  92. <KTIcon icon-name="magnifier" icon-type="solid"></KTIcon>
  93. </template>
  94. 搜索
  95. </el-button>
  96. <el-button class="btn btn-light-primary" @click="resetForm">
  97. <template #icon>
  98. <KTIcon icon-name="arrows-loop" icon-type="solid"></KTIcon>
  99. </template>
  100. 重置
  101. </el-button>
  102. </el-form-item>
  103. </el-col>
  104. </el-form>
  105. </template>