search-form.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <!-- 搜索框入口 -->
  3. <view @click="visible = true">
  4. <wd-search :placeholder="placeholder" hide-cancel disabled />
  5. </view>
  6. <!-- 搜索弹窗 -->
  7. <wd-popup v-model="visible" position="top" @close="visible = false">
  8. <view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
  9. <view class="yd-search-form-item">
  10. <view class="yd-search-form-label">
  11. 用户编号
  12. </view>
  13. <wd-input
  14. v-model="formData.userId"
  15. placeholder="请输入用户编号"
  16. clearable
  17. />
  18. </view>
  19. <view class="yd-search-form-item">
  20. <view class="yd-search-form-label">
  21. 应用名
  22. </view>
  23. <wd-input
  24. v-model="formData.applicationName"
  25. placeholder="请输入应用名"
  26. clearable
  27. />
  28. </view>
  29. <!-- TODO @芋艿:后续增加时间范围的检索 -->
  30. <view class="yd-search-form-actions">
  31. <wd-button class="flex-1" plain @click="handleReset">
  32. 重置
  33. </wd-button>
  34. <wd-button class="flex-1" type="primary" @click="handleSearch">
  35. 搜索
  36. </wd-button>
  37. </view>
  38. </view>
  39. </wd-popup>
  40. </template>
  41. <script lang="ts" setup>
  42. import { computed, reactive, ref } from 'vue'
  43. import { getNavbarHeight } from '@/utils'
  44. const emit = defineEmits<{
  45. search: [data: Record<string, any>]
  46. reset: []
  47. }>()
  48. const visible = ref(false)
  49. const formData = reactive({
  50. userId: undefined as number | undefined,
  51. applicationName: undefined as string | undefined,
  52. })
  53. /** 搜索条件 placeholder 拼接 */
  54. const placeholder = computed(() => {
  55. const conditions: string[] = []
  56. if (formData.userId) {
  57. conditions.push(`用户编号:${formData.userId}`)
  58. }
  59. if (formData.applicationName) {
  60. conditions.push(`应用名:${formData.applicationName}`)
  61. }
  62. return conditions.length > 0 ? conditions.join(' | ') : '搜索日志'
  63. })
  64. /** 搜索 */
  65. function handleSearch() {
  66. visible.value = false
  67. emit('search', { ...formData })
  68. }
  69. /** 重置 */
  70. function handleReset() {
  71. formData.userId = undefined
  72. formData.applicationName = undefined
  73. visible.value = false
  74. emit('reset')
  75. }
  76. </script>