gaoluyang
2026-06-24 c0cb161bb52ce0fbdce5c66ec391d107c75e2452
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!-- 数据字典 Select 选择器 -->
<script lang="ts" setup>
import type { DictSelectProps } from '../typing';
 
import { computed, useAttrs } from 'vue';
 
import { getDictOptions } from '..\..\..\packages\effects\hooks\src';
 
import {
  Checkbox,
  CheckboxGroup,
  Radio,
  RadioGroup,
  Select,
  SelectOption,
} from 'ant-design-vue';
 
defineOptions({ name: 'DictSelect' });
 
const props = withDefaults(defineProps<DictSelectProps>(), {
  valueType: 'str',
  selectType: 'select',
});
 
const attrs = useAttrs();
 
/** 获得字典配置 */
const getDictOption = computed(() => {
  switch (props.valueType) {
    case 'bool': {
      return getDictOptions(props.dictType, 'boolean');
    }
    case 'int': {
      return getDictOptions(props.dictType, 'number');
    }
    case 'str': {
      return getDictOptions(props.dictType, 'string');
    }
    default: {
      return [];
    }
  }
});
</script>
 
<template>
  <Select v-if="selectType === 'select'" class="w-full" v-bind="attrs">
    <SelectOption
      v-for="(dict, index) in getDictOption"
      :key="index"
      :value="dict.value"
    >
      {{ dict.label }}
    </SelectOption>
  </Select>
  <RadioGroup v-if="selectType === 'radio'" class="w-full" v-bind="attrs">
    <Radio
      v-for="(dict, index) in getDictOption"
      :key="index"
      :value="dict.value"
    >
      {{ dict.label }}
    </Radio>
  </RadioGroup>
  <CheckboxGroup v-if="selectType === 'checkbox'" class="w-full" v-bind="attrs">
    <Checkbox
      v-for="(dict, index) in getDictOption"
      :key="index"
      :value="dict.value"
    >
      {{ dict.label }}
    </Checkbox>
  </CheckboxGroup>
</template>