QueryItem.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <script setup lang="ts">
  2. import { inject, PropType, ref, toRefs } from 'vue';
  3. const props = defineProps({
  4. label: { type: String, required: true },
  5. name: { type: String, required: true },
  6. // 'string' | 'date' | 'datetime' | 'number'
  7. type: { type: String, default: null },
  8. options: { type: Object as PropType<Array<{ label: string; value: string | number }>>, default: null },
  9. });
  10. const params = inject<any>('params');
  11. const { name } = toRefs(props);
  12. const [firstName, secondName] = name.value.split(',');
  13. const first = ref<string>(firstName);
  14. const second = ref<string>(secondName);
  15. </script>
  16. <template>
  17. <slot>
  18. <div v-if="type === 'number'" class="inline-block">
  19. <el-input-number v-model="params[first]" :placeholder="$t('begin.number')" class="w-48"></el-input-number>
  20. <el-input-number v-model="params[second]" :placeholder="$t('end.number')" class="w-48"></el-input-number>
  21. </div>
  22. <el-date-picker
  23. v-else-if="type === 'date'"
  24. v-model="params[name]"
  25. type="daterange"
  26. :start-placeholder="$t('begin.date')"
  27. :end-placeholder="$t('end.date')"
  28. class="w-96"
  29. ></el-date-picker>
  30. <el-date-picker
  31. v-else-if="type === 'datetime'"
  32. v-model="params[name]"
  33. type="datetimerange"
  34. :start-placeholder="$t('begin.date')"
  35. :end-placeholder="$t('end.date')"
  36. class="w-96"
  37. >
  38. </el-date-picker>
  39. <!--
  40. <div v-else-if="type === 'date'" class="inline-block">
  41. <el-date-picker v-model="params[first]" type="date" :placeholder="$t('begin.date')" class="w-48"></el-date-picker>
  42. <el-date-picker v-model="params[second]" type="date" :placeholder="$t('end.date')" class="w-48"></el-date-picker>
  43. </div>
  44. <div v-else-if="type === 'datetime'" class="inline-block">
  45. <el-date-picker v-model="params[first]" type="datetime" class="w-48"></el-date-picker>
  46. <el-date-picker v-model="params[second]" type="datetime" class="w-48"></el-date-picker>
  47. </div>
  48. -->
  49. <el-select v-else-if="options" v-model="params[name]" multiple class="w-96">
  50. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  51. </el-select>
  52. <el-input v-else v-model="params[name]" class="w-96"></el-input>
  53. </slot>
  54. </template>