account-search-form.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.mail"
  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.username"
  25. placeholder="请输入用户名"
  26. clearable
  27. />
  28. </view>
  29. <view class="yd-search-form-actions">
  30. <wd-button class="flex-1" plain @click="handleReset">
  31. 重置
  32. </wd-button>
  33. <wd-button class="flex-1" type="primary" @click="handleSearch">
  34. 搜索
  35. </wd-button>
  36. </view>
  37. </view>
  38. </wd-popup>
  39. </template>
  40. <script lang="ts" setup>
  41. import { computed, reactive, ref } from 'vue'
  42. import { getNavbarHeight } from '@/utils'
  43. const emit = defineEmits<{
  44. search: [data: Record<string, any>]
  45. reset: []
  46. }>()
  47. const visible = ref(false)
  48. const formData = reactive({
  49. mail: undefined as string | undefined,
  50. username: undefined as string | undefined,
  51. })
  52. /** 搜索条件 placeholder 拼接 */
  53. const placeholder = computed(() => {
  54. const conditions: string[] = []
  55. if (formData.mail) {
  56. conditions.push(`邮箱:${formData.mail}`)
  57. }
  58. if (formData.username) {
  59. conditions.push(`用户名:${formData.username}`)
  60. }
  61. return conditions.length > 0 ? conditions.join(' | ') : '搜索邮箱账号'
  62. })
  63. /** 搜索 */
  64. function handleSearch() {
  65. visible.value = false
  66. emit('search', {
  67. mail: formData.mail || undefined,
  68. username: formData.username || undefined,
  69. })
  70. }
  71. /** 重置 */
  72. function handleReset() {
  73. formData.mail = undefined
  74. formData.username = undefined
  75. visible.value = false
  76. emit('reset')
  77. }
  78. </script>