StateSelect.vue 925 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <a-select
  3. placeholder="状态"
  4. allowClear
  5. :disabled="props.disabled"
  6. :value="valueStr"
  7. @change="handleChange"
  8. style="width: 80px"
  9. >
  10. <a-select-option value="true">启用</a-select-option>
  11. <a-select-option value="false">禁止</a-select-option>
  12. </a-select>
  13. </template>
  14. <script setup lang="ts">
  15. import { computed } from "vue-demi";
  16. const props = withDefaults(
  17. defineProps<{
  18. value?: boolean;
  19. disabled?: boolean;
  20. }>(),
  21. {
  22. value: undefined,
  23. disabled: false,
  24. }
  25. );
  26. const emit = defineEmits(["update:value"]);
  27. const valueStr = computed(() => {
  28. let res: undefined | boolean | string = props.value ?? undefined;
  29. if (typeof res === "boolean") res = props.value + "";
  30. return res as undefined | string;
  31. });
  32. function handleChange(v: undefined | string) {
  33. // console.log(v);
  34. emit("update:value", typeof v === "undefined" ? v : JSON.parse(v));
  35. }
  36. </script>