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
| <template>
| <nut-radio-group v-model="model" direction="horizontal">
| <nut-radio
| v-for="item in optionsWithAll"
| :key="item.value"
| :label="item.value"
| :value="item.value"
| shape="button"
| >{{ item.text }}</nut-radio
| >
| </nut-radio-group>
| </template>
|
| <script setup lang="ts">
| import { computed } from 'vue';
| import { convertOptions, ValueEnum } from 'senin-mini/utils';
|
| defineOptions({
| name: 'ProRadio',
| });
|
| type Props = {
| showAllBtn?: boolean;
| allBtnLabel?: string;
| allBtnValue?: string | number | null;
| enumLabelKey?: string;
| enumValueKey?: string;
| valueEnum?: ValueEnum;
| };
|
| const props = withDefaults(defineProps<Props>(), {
| allBtnLabel: '不限',
| allBtnValue: '',
| enumLabelKey: 'name',
| enumValueKey: 'id',
| });
|
| const model = defineModel<string | number>();
|
| const options = computed(() =>
| convertOptions(props.valueEnum, props.enumLabelKey, props.enumValueKey)
| );
|
| const optionsWithAll = computed(() => {
| if (props.showAllBtn) {
| return [{ text: props.allBtnLabel, value: props.allBtnValue }, ...options.value];
| }
| return options.value;
| });
| </script>
|
| <style lang="scss">
| @import '@/styles/common.scss';
| </style>
|
|