StateRenderer.vue 902 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <span>
  3. <a-badge
  4. v-if="currentState"
  5. :status="currentState.badgeState"
  6. :color="currentState.badgeColor"
  7. :text="currentState.text"
  8. />
  9. <span v-else>未知状态:{{value}}</span>
  10. </span>
  11. </template>
  12. <script lang="ts">
  13. import type { IDynamicFormItemSelectOption } from "@imengyu/vue-dynamic-form";
  14. import { defineComponent, type PropType } from "vue";
  15. export interface IStateOption extends IDynamicFormItemSelectOption {
  16. badgeState?: 'success' | 'processing' | 'error' | 'default' | 'warning';
  17. badgeColor?: string;
  18. }
  19. export default defineComponent({
  20. props: {
  21. value: {
  22. },
  23. stateValues: {
  24. type: Object as PropType<Array<IStateOption>>,
  25. },
  26. },
  27. computed: {
  28. currentState() {
  29. return (this.stateValues as IStateOption[])
  30. .find(k => k.value === this.value || k.text === this.value);
  31. },
  32. },
  33. });
  34. </script>