search-form.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.name"
  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-radio-group v-model="formData.status" shape="button">
  24. <wd-radio v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" :key="dict.value" :value="dict.value">
  25. {{ dict.label }}
  26. </wd-radio>
  27. </wd-radio-group>
  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 { getIntDictOptions } from '@/hooks/useDict'
  43. import { getNavbarHeight } from '@/utils'
  44. import { DICT_TYPE } from '@/utils/constants'
  45. const emit = defineEmits<{
  46. search: [data: Record<string, any>]
  47. reset: []
  48. }>()
  49. const visible = ref(false)
  50. const formData = reactive({
  51. name: undefined as string | undefined,
  52. status: undefined as number | undefined,
  53. })
  54. /** 搜索条件 placeholder 拼接 */
  55. const placeholder = computed(() => {
  56. const conditions: string[] = []
  57. if (formData.name) {
  58. conditions.push(`名称:${formData.name}`)
  59. }
  60. if (formData.status !== undefined) {
  61. const dict = getIntDictOptions(DICT_TYPE.COMMON_STATUS).find(d => d.value === formData.status)
  62. if (dict) {
  63. conditions.push(`状态:${dict.label}`)
  64. }
  65. }
  66. return conditions.length > 0 ? conditions.join(' | ') : '搜索菜单'
  67. })
  68. /** 搜索 */
  69. function handleSearch() {
  70. visible.value = false
  71. emit('search', { ...formData })
  72. }
  73. /** 重置 */
  74. function handleReset() {
  75. formData.name = undefined
  76. formData.status = undefined
  77. visible.value = false
  78. emit('reset')
  79. }
  80. </script>