search-form.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <!-- 搜索框入口 -->
  3. <wd-search
  4. :placeholder="placeholder"
  5. :hide-cancel="true"
  6. disabled
  7. @click="visible = true"
  8. />
  9. <!-- 搜索弹窗 -->
  10. <wd-popup
  11. v-model="visible"
  12. position="top"
  13. custom-style="border-radius: var(--yd-search-form-popup-radius);"
  14. safe-area-inset-top
  15. @close="visible = false"
  16. >
  17. <view class="yd-search-form-container">
  18. <view class="yd-search-form-title">
  19. 搜索角色
  20. </view>
  21. <view class="yd-search-form-item">
  22. <view class="yd-search-form-label">
  23. 角色名称
  24. </view>
  25. <wd-input
  26. v-model="formData.name"
  27. placeholder="请输入角色名称"
  28. clearable
  29. />
  30. </view>
  31. <view class="yd-search-form-item">
  32. <view class="yd-search-form-label">
  33. 角色标识
  34. </view>
  35. <wd-input
  36. v-model="formData.code"
  37. placeholder="请输入角色标识"
  38. clearable
  39. />
  40. </view>
  41. <view class="yd-search-form-item">
  42. <view class="yd-search-form-label">
  43. 状态
  44. </view>
  45. <wd-radio-group v-model="formData.status" shape="button">
  46. <wd-radio :value="-1">
  47. 全部
  48. </wd-radio>
  49. <wd-radio
  50. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  51. :key="dict.value"
  52. :value="dict.value"
  53. >
  54. {{ dict.label }}
  55. </wd-radio>
  56. </wd-radio-group>
  57. </view>
  58. <view class="yd-search-form-actions">
  59. <wd-button class="flex-1" plain @click="handleReset">
  60. 重置
  61. </wd-button>
  62. <wd-button class="flex-1" type="primary" @click="handleSearch">
  63. 搜索
  64. </wd-button>
  65. </view>
  66. </view>
  67. </wd-popup>
  68. </template>
  69. <script lang="ts" setup>
  70. import { computed, reactive, ref } from 'vue'
  71. import { getDictLabel, getIntDictOptions } from '@/hooks/useDict'
  72. import { DICT_TYPE } from '@/utils/constants'
  73. const emit = defineEmits<{
  74. search: [data: Record<string, any>]
  75. reset: []
  76. }>()
  77. const visible = ref(false)
  78. const formData = reactive({
  79. name: undefined as string | undefined,
  80. code: undefined as string | undefined,
  81. status: -1, // -1 表示全部
  82. })
  83. /** 搜索条件 placeholder 拼接 */
  84. const placeholder = computed(() => {
  85. const conditions: string[] = []
  86. if (formData.name) {
  87. conditions.push(`名称:${formData.name}`)
  88. }
  89. if (formData.code) {
  90. conditions.push(`标识:${formData.code}`)
  91. }
  92. if (formData.status !== -1) {
  93. conditions.push(`状态:${getDictLabel(DICT_TYPE.COMMON_STATUS, formData.status)}`)
  94. }
  95. return conditions.length > 0 ? conditions.join(' | ') : '搜索角色'
  96. })
  97. /** 搜索 */
  98. function handleSearch() {
  99. visible.value = false
  100. emit('search', { ...formData })
  101. }
  102. /** 重置 */
  103. function handleReset() {
  104. formData.name = undefined
  105. formData.code = undefined
  106. formData.status = -1
  107. visible.value = false
  108. emit('reset')
  109. }
  110. </script>